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


/**********************************************************
* This module is used to check the Operand is +0 or -0,   *
 * or + Normal or  - Normal or or + Denormal or - Denormal*
 * or + Infinity or - Infinity or NaN or SNaN or QNaN or  *
 * QNaN FPI                                               *
 **********************************************************/



`define SP_Exponent     30:23
`define SP_Significant  22:0
`define SP_Sign         31

`define DP_Exponent     62:52
`define DP_Significant  51:0
`define DP_Sign         63

`define DEP_Exponent     78:64
`define DEP_Significant  62:0
`define DEP_Sign         79

/* Output values to represent Fxam ouput

000 -  unsupported
001 -  NaN
010 -  Normal Finite Numbers
011 -  Infinity
100 -  zero
101 -  Empty
110 -  Denormal Numbers

*/


module chkOps(StatOut, ctrlOut, Op1_Tag2chkOps, Op2_Tag2chkOps, Operand1_2chkOps, Operand2_2chkOps, StatIn, TagWordIn2chkOps, ctrlIn, OpVal, MrR, MD);

// Instantiations

// Input Ports declaration

input  [79:0]  Operand1_2chkOps;
input  [79:0]  Operand2_2chkOps;
input  [3:0]   Op1_Tag2chkOps;
input  [3:0]   Op2_Tag2chkOps;
input  [15:0]  TagWordIn2chkOps;
input  [15:0]  StatIn;
input  [15:0]  ctrlIn;
input  [1:0]   MD;
input          MrR,OpVal;

// Output Ports Declaration

output [15:0]  StatOut;
output [15:0]  ctrlOut;

// Register type variable declaration

reg    [79:0]  Operand,Operand1;
reg    [79:0]  Operand2Fxam,Operand2Fxam1;
reg    [15:0]  TagWordIn2Fxam,TagWordIn2Fxam1;
reg    [1:0]   Opsize,Opsize1;
reg    [3:0]   Opval;
reg    [2:0]   Op1_Tag2Fxam,Op1_Tag2Fxam1;
reg    [15:0]  StatOut,strlOut;

// Net type variable declaration

wire   [3:0]   ResOut,ResOut1;
wire   [2:0]   FxamOut,FxamOut1;


Check4Nans chkNAN(ResOut, Operand, Opsize);
Check4Nans chkNAN1(ResOut1, Operand1, Opsize1);
FxamNumber xnum(FxamOut, Op1_Tag2Fxam, Operand2Fxam,TagWordIn2Fxam);
FxamNumber xnum1(FxamOut1, Op1_Tag2Fxam1, Operand2Fxam1,TagWordIn2Fxam1);



always@( Op1_Tag2chkOps or Op2_Tag2chkOps or Operand1_2chkOps or Operand2_2chkOps or StatIn or TagWordIn2chkOps or ctrlIn or OpVal or MrR or ResOut or FxamOut or ResOut1 or FxamOut1 or MD)
begin

        StatOut = StatIn;

        if(MrR == 0)    // If second operand is also from register stack
        begin
                Operand2Fxam = Operand1_2chkOps;        // Give the first operand to Fxam module
                Op1_Tag2Fxam = Op1_Tag2chkOps;          // Give the Op1_Tag to Fxam module
                TagWordIn2Fxam = TagWordIn2chkOps;      // Give the Tagword to Fxam module

                Operand2Fxam1 = Operand2_2chkOps;       // Give the first operand to Fxam module
                Op1_Tag2Fxam1 = Op2_Tag2chkOps;         // Give the Op1_Tag to Fxam module
                TagWordIn2Fxam1 = TagWordIn2chkOps;     // Give the Tagword to Fxam module

                case(FxamOut)

                3'b101:                         // If the stack is empty
                begin
                        StatOut[0] = 1; // Indication Invalid operation
                        StatOut[6] = 1; // Indicates stack fault
                        StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                end

                3'b001: // If the value is NaN
                begin
                        Operand = Operand1_2chkOps;
                        Opsize  = 2'd2;
                        if(ResOut == 4'd8 && OpVal == 0)        // If operand is SNaN
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                        else if((ResOut == 4'd8 || ResOut == 4'd9 || ResOut == 4'd10) && OpVal == 1)    // If operand is any type of NaN
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end

                end
                3'b000:         // If the value is unsupported format
                        begin
                                StatOut[0] = 1; // Indication Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end

                3'b011:         // If the value is infinity
                        begin
                                if((Operand2_2chkOps[79] ^ Operand1_2chkOps[79]))       // If operands have diff. in sign
                                begin
                                        Operand = Operand1_2chkOps;
                                        Opsize = 2'd2;
                                        if(ResOut == 4'd6 || ResOut == 4'd7)            // If operand1 is infinite number
                                        begin
                                                Operand1 = Operand2_2chkOps;
                                                Opsize1  = 2'd2;
                                                if(ResOut1 == 4'd6 || ResOut1 == 4'd7)  // If operand2 is infinite number
                                                begin
                                                        StatOut[0] = 1; // Indication Invalid operation
                                                        StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                                        StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                                                end
                                                else
                                                        StatOut = StatIn;
                                        end
                                end
                        end
                3'b110:         // If denomalized operand
                        begin
                                StatOut[1] = 1;
                        end
                default:
                        StatOut = StatIn;

                endcase

                case(FxamOut1)

                3'b101:                         // If the stack is empty
                begin
                        StatOut[0] = 1; // Indication Invalid operation
                        StatOut[6] = 1; // Indicates stack fault
                        StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                end

                3'b001: // If the value is NaN
                begin
                        Operand1 = Operand2_2chkOps;
                        Opsize1  = 2'd2;
                        if(ResOut1 == 4'd8 && OpVal == 1'b0)    // The value is SNaN
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                        else if((ResOut1 == 4'd8 || ResOut1 == 4'd9 || ResOut1 == 4'd10) && OpVal == 1'b1)      // If operand is any type of NaN
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end

                end
                3'b000:         // If the value is unsupported format
                        begin
                                StatOut[0] = 1; // Indication Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end

                3'b011:         // If the value is infinity
                        begin
                                if((Operand2_2chkOps[79] ^ Operand1_2chkOps[79]))       // If operands have diff. in sign
                                begin
                                        Operand1 = Operand1_2chkOps;
                                        Opsize1 = 2'd2;
                                        if(ResOut1 == 4'd6 || ResOut1 == 4'd7)          // If operand1 is infinite number
                                        begin
                                                Operand1 = Operand2_2chkOps;
                                                Opsize1  = 2'd2;
                                                if(ResOut == 4'd6 || ResOut == 4'd7)    // If operand2 is infinite number
                                                begin
                                                        StatOut[0] = 1; // Indication Invalid operation
                                                        StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                                        StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                                                end
                                        end
                                end
                                else
                                        StatOut = StatIn;

                        end
                3'b110:         // If denomalized operand
                        begin
                                StatOut[1] = 1;
                        end
                default:
                        StatOut = StatIn;

                endcase

                if(MD == 2'b00) // If the operation is multiplication
                begin
                        if( ( (ResOut == 4'd0) || (ResOut == 4'd1) ) && ( ( ResOut1 == 4'd6) || (ResOut1 == 4'd7) ) )
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                end
                else if(MD == 2'b01)// If the operation is division
                begin
                        if(((ResOut == 4'd0 || ResOut == 4'd1) && (ResOut1 == 4'd0 || ResOut1 == 4'd1)) || ((ResOut == 4'd6 || ResOut == 4'd7) && (ResOut1 == 4'd6 || ResOut1 == 4'd7)))
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                end

        end
        else    // If there is no second operand or second operand is from memory
        begin
                Operand2Fxam = Operand1_2chkOps;        // Give the first operand to Fxam module
                Op1_Tag2Fxam = Op1_Tag2chkOps;          // Give the Op1_Tag to Fxam module
                TagWordIn2Fxam = TagWordIn2chkOps;      // Give the Tagword to Fxam module

                case(FxamOut)

                3'b101:                 // If the stack is empty
                begin
                        StatOut[0] = 1; // Indication Invalid operation
                        StatOut[6] = 1; // Indicates stack fault
                        StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                end

                3'b001: // If the value is NaN
                begin
                        Operand = Operand1;
                        Opsize  = 2'd2;
                        if(ResOut == 4'd8 && OpVal == 1'b0)     // The value is SNaN
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                        else if((ResOut == 4'd8 || ResOut == 4'd9 || ResOut == 4'd10) && OpVal == 1'b1) // The value is SNaN
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end

                        else
                                StatOut = StatIn;

                end
                3'b000:         // If the value is unsupported format
                        begin
                                StatOut[0] = 1; // Indication Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                default:
                        StatOut = StatIn;
                endcase

                //Operand = Operand1_2chkOps;
                Opsize = 2'd2;
                Operand1 = Operand2_2chkOps;
                Opsize1  = 2'd2;

                if(MD == 2'b00) // If the operation is multiplication
                begin
                        if((ResOut == 4'd0 || ResOut == 4'd1) && (ResOut == 4'd6 || ResOut == 4'd7))
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                end
                else if(MD == 2'b01)// If the operation is division
                begin
                        if(((ResOut == 4'd0 || ResOut == 4'd1) && (ResOut1 == 4'd0 || ResOut1 == 4'd1)) || ((ResOut == 4'd6 || ResOut == 4'd7) && (ResOut1 == 4'd6 || ResOut1 == 4'd7)))
                        begin
                                StatOut[0] = 1; // Indicates Invalid operation
                                StatOut[6] = 0; // Indicates no stack fault - invalid operand
                                StatOut[9] = 0; // Cond. code flag to indicate stack underflow
                        end
                end
        end
end
endmodule