www.pudn.com > x86.rar > chkResult.v, change:2007-12-05,size:5220b


/***********************************************************
 *                                                         *
 * This module is used to check the validity of the result *
 *                                                         *
 *                                                         *
 ***********************************************************/


/* Output values to represent the validity of the ouput

        00 - result is too big
        01 - result is too small
        10 - cant exactly represent
*/


// Including submodule files

module chkResult(chkResOut, Operand2chkResult, SPrDP);

// Input port declarations

input  [79:0] Operand2chkResult;
input         SPrDP;

// Output port declarations

output [1:0]  chkResOut;


// net type declarations

wire [15:0] cla16_Out, cla16_Out1, OP_OUT, OP_OUT1, OP_OUT2;
wire [16:1] cout,cout1;
wire [2:0]  compOut;
wire [5:0]  indexOutRev;

// reg type declarations

reg  [15:0]  cla16_In1,cla16_In2,OP_IN;
reg  [15:0]  cla16_1_In1,cla16_1_In2,OP_IN1,OP_IN2;
reg  [15:0]  compIn1, compIn2;
reg  [63:0]  scanInRev;
reg  [1:0]   chkResOut;
reg          cIn16_In, cIn16_1_In;


// Instantiations of sub modules

twosComp16 TC16_0(OP_OUT, OP_IN);
twosComp16 TC16_1(OP_OUT1, OP_IN1);
twosComp16 TC16_2(OP_OUT2, OP_IN2);

cla16Bit cla16Ins( cla16_Out, cout , cla16_In1, cla16_In2, cIn16_In);
cla16Bit cla16Ins1( cla16_Out1, cout1 , cla16_1_In1, cla16_1_In2, cIn16_1_In);

bitScanRev64 bsr64(indexOutRev, scanInRev);
compare16 cmp(compOut, compIn1, compIn2);

always @(Operand2chkResult or SPrDP or cla16_Out or OP_OUT1 or indexOutRev or OP_OUT or cla16_Out1 or compOut or OP_OUT2)               // If any of these values changes
begin

        if(SPrDP)                                               // if the destination is of Single-Precision type
        begin

                cIn16_1_In  = 1'b0;

                cla16_In1 = { 1'd0, Operand2chkResult[78:64] }; // give the exponent part of the DEP value to 16-bit adder &
                OP_IN     = 16'd16256;                          // subtract the constant value
                cla16_In2 = OP_OUT;
                cIn16_In  = 1'b0;

                cla16_1_In1 = cla16_Out;
                scanInRev = Operand2chkResult[63:0];            // Scan the significant part of the DEP value &
                OP_IN1 = indexOutRev;                           // subtract the value
                cla16_1_In2 = OP_OUT1;

                if(cla16_Out1[15] == 0)                         // The number is positive
                begin
                        compIn1 = cla16_Out1;                   // Check whether the result is greater that 128
                        compIn2 = 16'd128;
                        if(compOut[2] == 1)
                        begin
                                chkResOut = 2'b00;              // The result is too big
                        end
                end
                else                                            // The number is negative
                begin
                        OP_IN2  = cla16_Out1;
                        compIn1 = OP_OUT2;                      // Check whether the number is smaller than -127
                        compIn2 = 16'd127;
                        if(compOut[2] == 1)
                        begin
                                chkResOut = 2'b01;              // The result is too small
                        end
                end
        end
        else                                                    // if the destination is of Double-Precision type
        begin
                cIn16_1_In  = 1'b0;

                cla16_In1 = { 1'd0, Operand2chkResult[78:64] }; // give the exponent part the DEP value to 16-bit adder &
                OP_IN     = 16'd15360;                          // subtract the constant value
                cla16_In2 = OP_OUT;
                cIn16_In  = 1'b0;

                cla16_1_In1 = cla16_Out;
                scanInRev = Operand2chkResult[63:0];            // Scan the significant part of the DEP value &
                OP_IN1 = indexOutRev;                           // subtract the value
                cla16_1_In2 = OP_OUT1;

                if(cla16_Out1[15] == 0)                         // The number is positive
                begin
                        compIn1 = cla16_Out1;                   // Check whether the result is greater that 128
                        compIn2 = 16'd128;
                        if(compOut[2] == 1)
                        begin
                                chkResOut = 2'b00;              // The result is too big
                        end
                end
                else                                            // The number is negative
                begin
                        OP_IN2  = cla16_Out1;
                        compIn1 = OP_OUT2;
                        compIn2 = 16'd127;                      // Check whether the result is smaller that -127
                        if(compOut[2] == 1)
                        begin
                                chkResOut = 2'b01;              // The result is too small
                        end
                end
        end
end

endmodule