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_f2i.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  pfpu32_f2i                                                 ////
4
////  32-bit floating point to integer 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_f2i
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             signa_i,  // input 'a' related values
45
   input       [9:0] exp10a_i,
46
   input      [23:0] fract24a_i,
47
   input             snan_i,   // 'a'/'b' related
48
   input             qnan_i,
49
   output reg        f2i_rdy_o,       // f2i is ready
50
   output reg        f2i_sign_o,      // f2i signum
51
   output reg [23:0] f2i_int24_o,     // f2i fractional
52
   output reg  [4:0] f2i_shr_o,       // f2i required shift right value
53
   output reg  [3:0] f2i_shl_o,       // f2i required shift left value   
54
   output reg        f2i_ovf_o,       // f2i overflow flag
55
   output reg        f2i_snan_o       // f2i signaling NaN output reg
56
);
57
 
58
  /*
59
     Any stage's output is registered.
60
     Definitions:
61
       s??o_name - "S"tage number "??", "O"utput
62
       s??t_name - "S"tage number "??", "T"emporary (internally)
63
  */
64
 
65
  // exponent after moving binary point at the end of mantissa
66
  // bias is also removed
67
  wire [9:0] s1t_exp10m = exp10a_i - 10'd150; // (- 127 - 23)
68
 
69
  // detect if now shift right is required
70
  wire [9:0] s1t_shr_t = {10{s1t_exp10m[9]}} & (10'd150 - exp10a_i);
71
  // limit right shift by 31
72
  wire [4:0] s1t_shr = s1t_shr_t[4:0] | {5{|s1t_shr_t[9:5]}};
73
 
74
  // detect if left shift required for mantissa
75
  // (limited by 15)
76
  wire [3:0] s1t_shl = {4{~s1t_exp10m[9]}} & (s1t_exp10m[3:0] | {4{|s1t_exp10m[9:4]}});
77
  // check overflow
78
  wire s1t_is_shl_gt8 = s1t_shl[3] & (|s1t_shl[2:0]);
79
  wire s1t_is_shl_eq8 = s1t_shl[3] & (~(|s1t_shl[2:0]));
80
  wire s1t_is_shl_ovf =
81
     s1t_is_shl_gt8 |
82
    (s1t_is_shl_eq8 & (~signa_i)) |
83
    (s1t_is_shl_eq8 &   signa_i & (|fract24a_i[22:0]));
84
 
85
 
86
  // registering output
87
  always @(posedge clk) begin
88
    if(adv_i) begin
89
        // input related
90
      f2i_snan_o  <= snan_i;
91
        // computation related
92
      f2i_sign_o  <= signa_i & (!(qnan_i | snan_i)); // if 'a' is a NaN than ouput is max. positive
93
      f2i_int24_o <= fract24a_i;
94
      f2i_shr_o   <= s1t_shr;
95
      f2i_shl_o   <= s1t_shl;
96
      f2i_ovf_o   <= s1t_is_shl_ovf;
97
    end // (reset or flush) / advance
98
  end // posedge clock
99
 
100
  // ready is special case
101
  always @(posedge clk `OR_ASYNC_RST) begin
102
    if (rst)
103
      f2i_rdy_o <= 1'b0;
104
    else if(flush_i)
105
      f2i_rdy_o <= 1'b0;
106
    else if(adv_i)
107
      f2i_rdy_o <= start_i;
108
  end // posedge clock
109
 
110
endmodule // pfpu32_f2i

powered by: WebSVN 2.1.0

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