0b949dfe23115f7643c2011ee1116a5e343d0112
[shakti-core.git] / src / core / fpu / fpu_sign_injection.bsv
1 /*
2 Authors : Vinod.G, Aditya Govardhan
3 Email : g.vinod1993@gmail.com
4 Last Update : 27th November 2017
5 See LICENSE for more details
6
7 Description:
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
13 */
14
15 package fpu_sign_injection;
16
17 import defined_types::*;
18 `include "defined_parameters.bsv"
19
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);
22 endinterface
23
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);
27 endinterface
28
29 interface Ifc_fpu_sign_injection64;
30 method ActionValue#(Floating_output#(64)) _start(Bit#(64) operand1, Bit#(64) operand2, Bit#(3) operation);
31 endinterface
32 `endif
33
34
35 module mkfpu_sign_injection(Ifc_fpu_sign_injection#(fpinp,fpman,fpexp))
36 provisos (
37 Add#(TAdd#(fpexp,fpman),1,fpinp), //Defining fpinp to be fpexp + fpman + 1
38 Add#(fpexp,2,fpexp2)
39 );
40
41 let fPINP = valueOf(fpinp);
42
43 method ActionValue#(Floating_output#(fpinp)) _start(Bit#(fpinp) operand1, Bit#(fpinp) operand2, Bit#(3) operation);
44
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];
49 else //FSGNJX
50 operand1[fPINP-1] = operand1[fPINP-1]^operand2[fPINP-1];
51
52 Bit#(5) lv_exception = 0;
53
54 return Floating_output {
55 final_result : zeroExtend(operand1),
56 fflags : lv_exception};
57 endmethod
58 endmodule
59
60
61 `ifdef fpu_hierarchical
62 (*synthesize*)
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);
67 return x;
68 endmethod
69 endmodule
70
71 (*synthesize*)
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);
76 return x;
77 endmethod
78 endmodule
79 `endif
80
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);
86
87 // rule get_input(rg_clock == 0);
88 // inst_fpu_sign_injection._start(rg_operand1,rg_operand2,'b000);
89 // rg_clock <= rg_clock + 1;
90 // endrule
91
92 // rule get_output;
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
96 // $finish(0);
97 // endrule
98
99
100
101 // endmodule
102 endpackage