OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber23/] [a23_functions.vh] - Blame information for rev 82

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Functions for Amber 2 Core                                  //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Functions used in more than one module                      //
10
//                                                              //
11
//  Author(s):                                                  //
12
//      - Conor Santifort, csantifort.amber@gmail.com           //
13
//                                                              //
14
//////////////////////////////////////////////////////////////////
15
//                                                              //
16
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
17
//                                                              //
18
// This source file may be used and distributed without         //
19
// restriction provided that this copyright statement is not    //
20
// removed from the file and that any derivative work contains  //
21
// the original copyright notice and the associated disclaimer. //
22
//                                                              //
23
// This source file is free software; you can redistribute it   //
24
// and/or modify it under the terms of the GNU Lesser General   //
25
// Public License as published by the Free Software Foundation; //
26
// either version 2.1 of the License, or (at your option) any   //
27
// later version.                                               //
28
//                                                              //
29
// This source is distributed in the hope that it will be       //
30
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
31
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
32
// PURPOSE.  See the GNU Lesser General Public License for more //
33
// details.                                                     //
34
//                                                              //
35
// You should have received a copy of the GNU Lesser General    //
36
// Public License along with this source; if not, download it   //
37
// from http://www.opencores.org/lgpl.shtml                     //
38
//                                                              //
39
//////////////////////////////////////////////////////////////////
40
 
41
 
42
// ========================================================
43
// PC Filter - Remove the status bits 
44
// ========================================================
45
function [31:0] pcf;
46
input [31:0] pc_reg;
47
    begin
48
    pcf = {6'd0, pc_reg[25:2], 2'd0};
49
    end
50
endfunction
51
 
52
 
53
// ========================================================
54
// 4-bit to 16-bit 1-hot decode
55
// ========================================================
56
function [14:0] decode;
57
input [3:0] reg_sel;
58
begin
59
case ( reg_sel )
60
    4'h0:    decode = 15'h0001;
61
    4'h1:    decode = 15'h0002;
62
    4'h2:    decode = 15'h0004;
63
    4'h3:    decode = 15'h0008;
64
    4'h4:    decode = 15'h0010;
65
    4'h5:    decode = 15'h0020;
66
    4'h6:    decode = 15'h0040;
67
    4'h7:    decode = 15'h0080;
68
    4'h8:    decode = 15'h0100;
69
    4'h9:    decode = 15'h0200;
70
    4'ha:    decode = 15'h0400;
71
    4'hb:    decode = 15'h0800;
72
    4'hc:    decode = 15'h1000;
73
    4'hd:    decode = 15'h2000;
74
    4'he:    decode = 15'h4000;
75
    default: decode = 15'h0000;
76
endcase
77
end
78
endfunction
79
 
80
 
81
// ========================================================
82
// Convert Stats Bits Mode to one-hot encoded version
83
// ========================================================
84
function [3:0] oh_status_bits_mode;
85
input [1:0] fn_status_bits_mode;
86
begin
87
oh_status_bits_mode =
88
    fn_status_bits_mode == SVC  ? 1'd1 << OH_SVC  :
89
    fn_status_bits_mode == IRQ  ? 1'd1 << OH_IRQ  :
90
    fn_status_bits_mode == FIRQ ? 1'd1 << OH_FIRQ :
91
                                  1'd1 << OH_USR  ;
92
end
93
endfunction
94
 
95
// ========================================================
96
// Convert mode into ascii name
97
// ========================================================
98
function [(14*8)-1:0]  mode_name;
99
input [4:0] mode;
100
begin
101
 
102
mode_name    = mode == USR  ? "User          " :
103
               mode == SVC  ? "Supervisor    " :
104
               mode == IRQ  ? "Interrupt     " :
105
               mode == FIRQ ? "Fast Interrupt" :
106
                              "UNKNOWN       " ;
107
end
108
endfunction
109
 
110
 
111
// ========================================================
112
// Conditional Execution Function
113
// ========================================================
114
// EQ Z set
115
// NE Z clear
116
// CS C set
117
// CC C clear
118
// MI N set
119
// PL N clear
120
// VS V set
121
// VC V clear
122
// HI C set and Z clear
123
// LS C clear or Z set
124
// GE N == V
125
// LT N != V
126
// GT Z == 0,N == V
127
// LE Z == 1 or N != V
128
// AL Always (unconditional)
129
// NV Never
130
 
131
function conditional_execute;
132
input [3:0] condition;
133
input [3:0] flags;
134
begin
135
conditional_execute
136
               = ( condition == AL                                        ) ||
137
                 ( condition == EQ  &&  flags[2]                          ) ||
138
                 ( condition == NE  && !flags[2]                          ) ||
139
                 ( condition == CS  &&  flags[1]                          ) ||
140
                 ( condition == CC  && !flags[1]                          ) ||
141
                 ( condition == MI  &&  flags[3]                          ) ||
142
                 ( condition == PL  && !flags[3]                          ) ||
143
                 ( condition == VS  &&  flags[0]                          ) ||
144
                 ( condition == VC  && !flags[0]                          ) ||
145
 
146
                 ( condition == HI  &&    flags[1] && !flags[2]           ) ||
147
                 ( condition == LS  &&  (!flags[1] ||  flags[2])          ) ||
148
 
149
                 ( condition == GE  &&  flags[3] == flags[0]              ) ||
150
                 ( condition == LT  &&  flags[3] != flags[0]              ) ||
151
 
152
                 ( condition == GT  &&  !flags[2] && flags[3] == flags[0] ) ||
153
                 ( condition == LE  &&  (flags[2] || flags[3] != flags[0])) ;
154
 
155
end
156
endfunction
157
 
158
 
159
// ========================================================
160
// Log 2
161
// ========================================================
162
 
163
function [31:0] log2;
164
input    [31:0] num;
165
integer i;
166 63 csantifort
integer out;
167 2 csantifort
begin
168 63 csantifort
  out = 32'd0;
169 2 csantifort
  for (i=0; i<30; i=i+1)
170 63 csantifort
    if ((2**i > num) && (out == 0))
171
      out = i-1;
172
  log2 = out;
173 2 csantifort
end
174
endfunction

powered by: WebSVN 2.1.0

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