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/] [mor1kx_utils.vh] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
/******************************************************************************
2
 This Source Code Form is subject to the terms of the
3
 Open Hardware Description License, v. 1.0. If a copy
4
 of the OHDL was not distributed with this file, You
5
 can obtain one at http://juliusbaxter.net/ohdl/ohdl.txt
6
 Copyright (C) 2014 Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
7
 
8
 ******************************************************************************/
9
 
10
`ifndef _MOR1KX_UTILS_VH_
11
`define _MOR1KX_UTILS_VH_ 1
12
//
13
// clog2 - replacement for $clog for tools that doesn't support verilog 2005.
14
// However, icarus doesn't support constant user functions, so it has to be
15
// implemened with a bit of `define trickery.
16
//
17
`ifdef __ICARUS__
18
`define clog2 $clog2
19
`else
20
`define clog2 clog2
21
`endif
22
 
23
`endif // _MOR1KX_UTILS_VH_
24
 
25
function integer clog2;
26
input integer in;
27
begin
28
        in = in - 1;
29
        for (clog2 = 0; in > 0; clog2=clog2+1)
30
                in = in >> 1;
31
end
32
endfunction
33
 
34
//
35
// Find First 1 - Start from MSB and count downwards, returns 0 when no bit set
36
//
37
function integer ff1;
38
input integer in;
39
input integer width;
40
integer i;
41
begin
42
        ff1 = 0;
43
        for (i = width-1; i >= 0; i=i-1) begin
44
                if (in[i])
45
                        ff1 = i;
46
        end
47
end
48
endfunction
49
 
50
//
51
// Find Last 1 -  Start from LSB and count upwards, returns 0 when no bit set
52
//
53
function integer fl1;
54
input integer in;
55
input integer width;
56
integer i;
57
begin
58
        fl1 = 0;
59
        for (i = 0; i < width; i=i+1) begin
60
                if (in[i])
61
                        fl1 = i;
62
        end
63
end
64
endfunction
65
 
66
//
67
// Reverse bits in a vector
68
//
69
function integer reverse_bits;
70
input integer in;
71
input integer width;
72
integer i;
73
begin
74
        for (i = 0; i < width; i=i+1) begin
75
                reverse_bits[width-i] = in[i];
76
        end
77
end
78
endfunction
79
 
80
//
81
// Reverse bytes in a vector
82
//
83
function integer reverse_bytes;
84
input integer in;
85
input integer width;
86
integer i;
87
begin
88
        for (i = 0; i < width; i=i+8) begin
89
                reverse_bytes[(width-1)-i-:8] = in[i+:8];
90
        end
91
end
92
endfunction
93
 
94
//
95
// Calculate register file address width, considers shadow registers, used in
96
// rf and cpu.
97
//
98
function integer calc_rf_addr_width;
99
input integer rf_addr_width;
100
input integer rf_num_shadow_gpr;
101
begin
102
        if (rf_num_shadow_gpr == 0)
103
                calc_rf_addr_width = rf_addr_width;
104
        else
105
                calc_rf_addr_width = rf_addr_width
106
                        + ((rf_num_shadow_gpr == 1) ? 1 : `clog2(rf_num_shadow_gpr));
107
end
108
endfunction
109
 
110
 

powered by: WebSVN 2.1.0

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