2 Authors : Vinod.G, Aditya Govardhan
3 Email : g.vinod1993@gmail.com
4 Last Update : 27th November 2017
5 See LICENSE for more details
8 This module performs the sign injection on the floating point value taken from the rs1 register.
9 The different instructions work as follows
10 FSGNJ : Operation bit - 000, The final result is same as that of operand1 but has the sign of operand 2's sign.
11 FSGNJN : Operation bit - 001, The final result is same as that of operand 1 but has the opposite sign of operand 2's sign
12 FSGNJX : Operation bit - 010, The final result is same as that of operand 1 but the sign bit is the exclusive-or of operand 1 and operand 2
15 package fpu_sign_injection;
17 import defined_types::*;
18 `include "defined_parameters.bsv"
20 interface Ifc_fpu_sign_injection#(numeric type fpinp, numeric type fpman, numeric type fpexp);
21 method ActionValue#(Floating_output#(fpinp)) _start(Bit#(fpinp) operand1, Bit#(fpinp) operand2, Bit#(3) operation);
24 `ifdef fpu_hierarchical
25 interface Ifc_fpu_sign_injection32;
26 method ActionValue#(Floating_output#(32)) _start(Bit#(32) operand1, Bit#(32) operand2, Bit#(3) operation);
29 interface Ifc_fpu_sign_injection64;
30 method ActionValue#(Floating_output#(64)) _start(Bit#(64) operand1, Bit#(64) operand2, Bit#(3) operation);
35 module mkfpu_sign_injection(Ifc_fpu_sign_injection#(fpinp,fpman,fpexp))
37 Add#(TAdd#(fpexp,fpman),1,fpinp), //Defining fpinp to be fpexp + fpman + 1
41 let fPINP = valueOf(fpinp);
43 method ActionValue#(Floating_output#(fpinp)) _start(Bit#(fpinp) operand1, Bit#(fpinp) operand2, Bit#(3) operation);
45 if(operation == 3'b000) //FSGNJ
46 operand1[fPINP-1] = operand2[fPINP-1];
47 else if(operation == 3'b001) //FSNGNJN
48 operand1[fPINP-1] = ~operand2[fPINP-1];
50 operand1[fPINP-1] = operand1[fPINP-1]^operand2[fPINP-1];
52 Bit#(5) lv_exception = 0;
54 return Floating_output {
55 final_result : zeroExtend(operand1),
56 fflags : lv_exception};
61 `ifdef fpu_hierarchical
63 module mkfpu_sign_injection32(Ifc_fpu_sign_injection32);
64 Ifc_fpu_sign_injection#(32,23,8) uut <- mkfpu_sign_injection();
65 method ActionValue#(Floating_output#(32)) _start(Bit#(32) operand1, Bit#(32) operand2, Bit#(3) operation);
66 let x <- uut._start(operand1,operand2,operation);
72 module mkfpu_sign_injection64(Ifc_fpu_sign_injection64);
73 Ifc_fpu_sign_injection#(64,52,11) uut <- mkfpu_sign_injection();
74 method ActionValue#(Floating_output#(64)) _start(Bit#(64) operand1, Bit#(64) operand2, Bit#(3) operation);
75 let x <- uut._start(operand1,operand2,operation);
81 // module mkTb_fpu_sign_injection();
82 // Ifc_fpu_sign_injection#(32,23,8) inst_fpu_sign_injection <- mkfpu_sign_injection();
83 // Reg#(Bit#(32)) rg_clock <- mkReg(0);
84 // Reg#(Bit#(32)) rg_operand1<-mkReg('hff800000);
85 // Reg#(Bit#(32)) rg_operand2<-mkReg('hff800000);
87 // rule get_input(rg_clock == 0);
88 // inst_fpu_sign_injection._start(rg_operand1,rg_operand2,'b000);
89 // rg_clock <= rg_clock + 1;
93 // let lv_result = inst_fpu_sign_injection.result_();
94 // `ifdef verbose $display("Result is: %h",lv_result.final_result); `endif
95 // `ifdef verbose $display("Sign=%b Exponent=%b Mantissa=%b",lv_result.final_result[31],lv_result.final_result[30:23],lv_result.final_result[22:0]); `endif