OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_processor/] [mor1kx-5.0/] [rtl/] [verilog/] [pfpu32/] [pfpu32_i2f.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  pfpu32_i2f                                                 ////
4
////  32-bit integer to floating point converter                 ////
5
////                                                             ////
6
////  Author: Andrey Bacherov                                    ////
7
////          avbacherov@opencores.org                           ////
8
////                                                             ////
9
/////////////////////////////////////////////////////////////////////
10
////                                                             ////
11
//// Copyright (C) 2014 Andrey Bacherov                          ////
12
////                    avbacherov@opencores.org                 ////
13
////                                                             ////
14
//// This source file may be used and distributed without        ////
15
//// restriction provided that this copyright statement is not   ////
16
//// removed from the file and that any derivative work contains ////
17
//// the original copyright notice and the associated disclaimer.////
18
////                                                             ////
19
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
20
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
21
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
22
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
23
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
24
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
25
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
26
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
27
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
28
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
29
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
30
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
31
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
32
////                                                             ////
33
/////////////////////////////////////////////////////////////////////
34
 
35
`include "mor1kx-defines.v"
36
 
37
module pfpu32_i2f
38
(
39
   input             clk,
40
   input             rst,
41
   input             flush_i,  // flush pipe
42
   input             adv_i,    // advance pipe
43
   input             start_i,  // start conversion
44
   input      [31:0] opa_i,
45
   output reg        i2f_rdy_o,       // i2f is ready
46
   output reg        i2f_sign_o,      // i2f signum
47
   output reg  [3:0] i2f_shr_o,
48
   output reg  [7:0] i2f_exp8shr_o,
49
   output reg  [4:0] i2f_shl_o,
50
   output reg  [7:0] i2f_exp8shl_o,
51
   output reg  [7:0] i2f_exp8sh0_o,
52
   output reg [31:0] i2f_fract32_o
53
);
54
 
55
  /*
56
     Any stage's output is registered.
57
     Definitions:
58
       s??o_name - "S"tage number "??", "O"utput
59
       s??t_name - "S"tage number "??", "T"emporary (internally)
60
  */
61
 
62
  // signum of input
63
  wire s1t_signa = opa_i[31];
64
  // magnitude (tow's complement for negative input)
65
  wire [31:0] s1t_fract32 =
66
      (opa_i ^ {32{s1t_signa}}) + {31'd0,s1t_signa};
67
  // normalization shifts
68
  reg [3:0] s1t_shrx;
69
  reg [4:0] s1t_shlx;
70
  // shift goal:
71
  // 23 22                    0
72
  // |  |                     |
73
  // h  fffffffffffffffffffffff
74
  // right shift
75
  always @(s1t_fract32[31:24]) begin
76
    casez(s1t_fract32[31:24])  // synopsys full_case parallel_case
77
      8'b1???????:  s1t_shrx = 4'd8;
78
      8'b01??????:  s1t_shrx = 4'd7;
79
      8'b001?????:  s1t_shrx = 4'd6;
80
      8'b0001????:  s1t_shrx = 4'd5;
81
      8'b00001???:  s1t_shrx = 4'd4;
82
      8'b000001??:  s1t_shrx = 4'd3;
83
      8'b0000001?:  s1t_shrx = 4'd2;
84
      8'b00000001:  s1t_shrx = 4'd1;
85
      8'b00000000:  s1t_shrx = 4'd0;
86
    endcase
87
  end
88
  // left shift
89
  always @(s1t_fract32[23:0]) begin
90
    casez(s1t_fract32[23:0])  // synopsys full_case parallel_case
91
      24'b1???????????????????????:  s1t_shlx = 5'd0; // hidden '1' is in its plase
92
      24'b01??????????????????????:  s1t_shlx = 5'd1;
93
      24'b001?????????????????????:  s1t_shlx = 5'd2;
94
      24'b0001????????????????????:  s1t_shlx = 5'd3;
95
      24'b00001???????????????????:  s1t_shlx = 5'd4;
96
      24'b000001??????????????????:  s1t_shlx = 5'd5;
97
      24'b0000001?????????????????:  s1t_shlx = 5'd6;
98
      24'b00000001????????????????:  s1t_shlx = 5'd7;
99
      24'b000000001???????????????:  s1t_shlx = 5'd8;
100
      24'b0000000001??????????????:  s1t_shlx = 5'd9;
101
      24'b00000000001?????????????:  s1t_shlx = 5'd10;
102
      24'b000000000001????????????:  s1t_shlx = 5'd11;
103
      24'b0000000000001???????????:  s1t_shlx = 5'd12;
104
      24'b00000000000001??????????:  s1t_shlx = 5'd13;
105
      24'b000000000000001?????????:  s1t_shlx = 5'd14;
106
      24'b0000000000000001????????:  s1t_shlx = 5'd15;
107
      24'b00000000000000001???????:  s1t_shlx = 5'd16;
108
      24'b000000000000000001??????:  s1t_shlx = 5'd17;
109
      24'b0000000000000000001?????:  s1t_shlx = 5'd18;
110
      24'b00000000000000000001????:  s1t_shlx = 5'd19;
111
      24'b000000000000000000001???:  s1t_shlx = 5'd20;
112
      24'b0000000000000000000001??:  s1t_shlx = 5'd21;
113
      24'b00000000000000000000001?:  s1t_shlx = 5'd22;
114
      24'b000000000000000000000001:  s1t_shlx = 5'd23;
115
      24'b000000000000000000000000:  s1t_shlx = 5'd0;
116
    endcase
117
  end
118
 
119
 
120
  // registering output
121
  always @(posedge clk) begin
122
    if(adv_i) begin
123
        // computation related
124
      i2f_sign_o    <= s1t_signa;
125
      i2f_shr_o     <= s1t_shrx;
126
      i2f_exp8shr_o <= 8'd150 + {4'd0,s1t_shrx};      // 150=127+23
127
      i2f_shl_o     <= s1t_shlx;
128
      i2f_exp8shl_o <= 8'd150 - {3'd0,s1t_shlx};
129
      i2f_exp8sh0_o <= {8{s1t_fract32[23]}} & 8'd150; // "1" is in [23] / zero
130
      i2f_fract32_o <= s1t_fract32;
131
    end // advance
132
  end // posedge clock
133
 
134
  // ready is special case
135
  always @(posedge clk `OR_ASYNC_RST) begin
136
    if (rst)
137
      i2f_rdy_o <= 1'b0;
138
    else if(flush_i)
139
      i2f_rdy_o <= 1'b0;
140
    else if(adv_i)
141
      i2f_rdy_o <= start_i;
142
  end // posedge clock
143
 
144
endmodule // pfpu32_i2f

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.