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

Subversion Repositories thor

[/] [thor/] [trunk/] [rtl/] [verilog/] [Thor_execute_combo.v] - Blame information for rev 42

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 robfinch
// ============================================================================
2
//        __
3 37 robfinch
//   \\__/ o\    (C) 2013-2016  Robert Finch, Stratford
4 3 robfinch
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// This source file is free software: you can redistribute it and/or modify 
9
// it under the terms of the GNU Lesser General Public License as published 
10
// by the Free Software Foundation, either version 3 of the License, or     
11
// (at your option) any later version.                                      
12
//                                                                          
13
// This source file is distributed in the hope that it will be useful,      
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
16
// GNU General Public License for more details.                             
17
//                                                                          
18
// You should have received a copy of the GNU General Public License        
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
20
//
21
//
22
// Thor SuperScalar
23
// Execute combinational logic
24
//
25
// ============================================================================
26
//
27
wire [DBW-1:0] alu0_out, alu1_out;
28
wire alu0_done,alu1_done;
29 13 robfinch
wire alu0_idle,alu1_idle;
30 3 robfinch
wire alu0_divByZero, alu1_divByZero;
31 13 robfinch
wire alu0_abort,alu1_abort;
32 3 robfinch
 
33
Thor_alu #(.DBW(DBW),.BIG(1)) ualu0
34
(
35
    .corenum(corenum),
36 13 robfinch
    .rst(rst_i),
37 3 robfinch
    .clk(clk),
38
    .alu_ld(alu0_ld),
39 13 robfinch
    .alu_abort(alu0_abort),
40 3 robfinch
        .alu_op(alu0_op),
41
        .alu_fn(alu0_fn),
42
        .alu_argA(alu0_argA),
43
        .alu_argB(alu0_argB),
44
        .alu_argC(alu0_argC),
45
        .alu_argI(alu0_argI),
46
        .alu_pc(alu0_pc),
47
        .insnsz(alu0_insnsz),
48
        .o(alu0_out),
49
        .alu_done(alu0_done),
50 13 robfinch
        .alu_idle(alu0_idle),
51 3 robfinch
        .alu_divByZero(alu0_divByZero)
52
);
53
 
54
Thor_alu #(.DBW(DBW),.BIG(ALU1BIG)) ualu1
55
(
56
    .corenum(corenum),
57 13 robfinch
    .rst(rst_i),
58 3 robfinch
    .clk(clk),
59
    .alu_ld(alu1_ld),
60 13 robfinch
    .alu_abort(alu1_abort),
61 3 robfinch
        .alu_op(alu1_op),
62
        .alu_fn(alu1_fn),
63
        .alu_argA(alu1_argA),
64
        .alu_argB(alu1_argB),
65
        .alu_argC(alu1_argC),
66
        .alu_argI(alu1_argI),
67
        .alu_pc(alu1_pc),
68
        .insnsz(alu1_insnsz),
69
        .o(alu1_out),
70
        .alu_done(alu1_done),
71 13 robfinch
        .alu_idle(alu1_idle),
72 3 robfinch
    .alu_divByZero(alu1_divByZero)
73
);
74
 
75
function fnPredicate;
76
input [3:0] pr;
77
input [3:0] cond;
78
 
79
case(cond)
80
PF:             fnPredicate = 1'b0;
81
PT:             fnPredicate = 1'b1;
82
PEQ:    fnPredicate =  pr[0];
83
PNE:    fnPredicate = !pr[0];
84
PLE:    fnPredicate =  pr[0]|pr[1];
85
PGT:    fnPredicate = !(pr[0]|pr[1]);
86
PLT:    fnPredicate =  pr[1];
87
PGE:    fnPredicate = !pr[1];
88
PLEU:   fnPredicate =  pr[0]|pr[2];
89
PGTU:   fnPredicate = !(pr[0]|pr[2]);
90
PLTU:   fnPredicate =  pr[2];
91
PGEU:   fnPredicate = !pr[2];
92
default:        fnPredicate = 1'b1;
93
endcase
94
 
95
endfunction
96
 
97
wire alu0_cmtw = fnPredicate(alu0_pred, alu0_cond);
98
wire alu1_cmtw = fnPredicate(alu1_pred, alu1_cond);
99
 
100
always @*
101
begin
102
    alu0_cmt <= alu0_cmtw;
103
    alu1_cmt <= alu1_cmtw;
104
 
105
    alu0_bus <= alu0_cmtw ? alu0_out : alu0_argT;
106
    alu1_bus <= alu1_cmtw ? alu1_out : alu1_argT;
107
 
108
    alu0_v <= alu0_dataready;
109
        alu1_v <= alu1_dataready;
110
 
111
    alu0_id <= alu0_sourceid;
112
        alu1_id <= alu1_sourceid;
113
end
114 13 robfinch
assign alu0_abort = !alu0_cmt;
115
assign alu1_abort = !alu1_cmt;
116 3 robfinch
 
117 37 robfinch
// Special flag bit is used for INT and SYS instructions in order to turn off
118 3 robfinch
// segmentation while the vector jump is taking place.
119
 
120
always @(alu0_op or alu0_fn or alu0_argA or alu0_argI or alu0_insnsz or alu0_pc or alu0_bt)
121
    case(alu0_op)
122 13 robfinch
    `JSR,`JSRS,`JSRZ,`RTD,`RTE,`RTI,`RTS2:
123 3 robfinch
        alu0_misspc <= alu0_argA + alu0_argI;
124
    `LOOP,`SYNC:
125
        alu0_misspc <= alu0_pc + alu0_insnsz;
126 13 robfinch
    `RTS:
127 3 robfinch
        alu0_misspc <= alu0_argA + alu0_fn[3:0];
128 42 robfinch
    `SYS,`INT,`RTF,`JSF:
129 13 robfinch
        alu0_misspc <= {1'b1,alu0_argA + alu0_argI};
130 3 robfinch
    default:
131
        alu0_misspc <= (alu0_bt ? alu0_pc + alu0_insnsz : alu0_pc + alu0_insnsz + alu0_argI);
132
    endcase
133
 
134
always @(alu1_op or alu1_fn or alu1_argA or alu1_argI or alu1_insnsz or alu1_pc or alu1_bt)
135
    case(alu1_op)
136 13 robfinch
    `JSR,`JSRS,`JSRZ,`RTD,`RTE,`RTI,`RTS2:
137 3 robfinch
        alu1_misspc <= alu1_argA + alu1_argI;
138
    `LOOP,`SYNC:
139
        alu1_misspc <= alu1_pc + alu1_insnsz;
140 13 robfinch
    `RTS:
141 3 robfinch
        alu1_misspc <= alu1_argA + alu1_fn[3:0];
142 42 robfinch
    `SYS,`INT,`RTF,`JSF:
143 13 robfinch
        alu1_misspc <= {1'b1,alu1_argA + alu1_argI};
144 3 robfinch
    default:
145
        alu1_misspc <= (alu1_bt ? alu1_pc + alu1_insnsz : alu1_pc + alu1_insnsz + alu1_argI);
146
    endcase
147 10 robfinch
 
148
always @(dram0_fn or dram0_misspc or dram_bus)
149
    case (dram0_fn[1:0])
150
    2'd1:   jmpi_misspc <= {dram0_misspc[DBW-1:16],dram_bus[15:0]};
151
    2'd2:   jmpi_misspc <= (DBW==32) ? dram_bus[31:0] : {dram0_misspc[63:32],dram_bus[31:0]};
152
    2'd3:   jmpi_misspc <= dram_bus[DBW-1:0];
153
    default:    jmpi_misspc <= 32'h00000FA0;    // unimplemented instruction vector 
154
    endcase
155 3 robfinch
 
156 42 robfinch
wire dbze0 = alu0_op==`DIVI || alu0_op==`MODI || (alu0_op==`RR && (alu0_fn==`DIV || alu0_fn==`MOD));
157
wire dbze1 = alu1_op==`DIVI || alu1_op==`MODI || (alu1_op==`RR && (alu1_fn==`DIV || alu1_fn==`MOD));
158 3 robfinch
 
159 42 robfinch
assign  alu0_exc =  (fnIsKMOnly(alu0_op) && !km && alu0_cmt) ? `EX_PRIV :
160
                    (alu0_done && dbze0 && alu0_divByZero && alu0_cmt) ? `EX_DBZ :
161
                    ((alu0_op==`CHKXI||(alu0_op==`RR && alu0_fn==`CHKX)) && !alu0_out && alu0_cmt) ? `EX_CHK :
162
                    (((alu0_op==`MTSPR && alu0_fn==0)|| alu0_op==`LDIS) && iqentry_tgt[alu0_id[2:0]][7:3]==5'h6) ?
163
                      {6'h20,iqentry_tgt[alu0_id[2:0]][2:0]} :
164
                      `EX_NONE;
165 3 robfinch
 
166 42 robfinch
assign  alu1_exc =  (fnIsKMOnly(alu1_op) && !km && alu1_cmt) ? `EX_PRIV :
167
                    (alu1_done && dbze1 && alu1_divByZero && alu1_cmt) ? `EX_DBZ :
168
                    ((alu1_op==`CHKXI ||(alu1_op==`RR && alu1_fn==`CHKX)) && !alu1_out && alu1_cmt) ? `EX_CHK :
169
                    (((alu1_op==`MTSPR && alu1_fn==0)|| alu1_op==`LDIS) && iqentry_tgt[alu1_id[2:0]][7:3]==5'h6) ?
170
                      {6'h20,iqentry_tgt[alu1_id[2:0]][2:0]} :
171
                      `EX_NONE;
172
 
173 3 robfinch
assign alu0_branchmiss = alu0_dataready &&
174
                   ((fnIsBranch(alu0_op))  ? ((alu0_cmt && !alu0_bt) || (!alu0_cmt && alu0_bt))
175 13 robfinch
                  : !alu0_cmt ? (alu0_op==`LOOP)
176
                  : (alu0_cmt && (alu0_op==`SYNC || alu0_op == `JSR || alu0_op == `JSRS || alu0_op == `JSRZ ||
177 42 robfinch
                     alu0_op==`SYS || alu0_op==`INT || alu0_op==`RTF || alu0_op==`JSF ||
178 10 robfinch
                  alu0_op==`RTS || alu0_op==`RTS2 || alu0_op==`RTD || alu0_op == `RTE || alu0_op==`RTI || ((alu0_op==`LOOP) && (alu0_argA == 64'd0)))));
179 3 robfinch
 
180
assign alu1_branchmiss = alu1_dataready &&
181
                   ((fnIsBranch(alu1_op))  ? ((alu1_cmt && !alu1_bt) || (!alu1_cmt && alu1_bt))
182 13 robfinch
                  : !alu1_cmt ? (alu1_op==`LOOP)
183
                  : (alu1_cmt && (alu1_op==`SYNC || alu1_op == `JSR || alu1_op == `JSRS || alu1_op == `JSRZ ||
184 42 robfinch
                     alu1_op==`SYS || alu1_op==`INT || alu1_op==`RTF || alu1_op==`JSF ||
185 10 robfinch
                  alu1_op==`RTS || alu1_op==`RTS2 || alu1_op==`RTD || alu1_op == `RTE || alu1_op==`RTI || ((alu1_op==`LOOP) && (alu1_argA == 64'd0)))));
186 3 robfinch
 
187 10 robfinch
assign  branchmiss = (alu0_branchmiss | alu1_branchmiss | mem_stringmiss | jmpi_miss),
188
        misspc = (jmpi_miss ? jmpi_misspc : mem_stringmiss ? dram0_misspc : alu0_branchmiss ? alu0_misspc : alu1_misspc),
189
        missid = (jmpi_miss ? dram0_id : mem_stringmiss ? dram0_id : alu0_branchmiss ? alu0_sourceid : alu1_sourceid);
190 3 robfinch
 
191
`ifdef FLOATING_POINT
192
 wire fp0_exception;
193
 
194
fpUnit ufp0
195
(
196
        .rst(rst_i),
197
        .clk(clk),
198
        .ce(1'b1),
199
        .op(fp0_op),
200
        .fn(fp0_fn),
201
        .ld(fp0_ld),
202
        .a(fp0_argA),
203
        .b(fp0_argB),
204
        .o(fp0_bus),
205
        .exception(fp0_exception)
206
);
207
 
208
reg [7:0] cnt;
209
always @(posedge clk)
210
if (rst_i)
211
    cnt <= 8'h00;
212
else begin
213
    if (fp0_ld)
214
           cnt <= 8'h00;
215
    else begin
216
           if (cnt < 8'hff)
217
                  cnt <= cnt + 8'd1;
218
    end
219
end
220
 
221
always @*
222
begin
223
        case(fp0_op)
224
        `FLOAT:
225
        case(fp0_fn)
226
        `FCMP,`FCMPS:    fp0_done = 1'b1;        // These ops are done right away
227
        `FADD,`FSUB,`FMUL,`FADDS,`FSUBS,`FMULS:
228
                               fp0_done = cnt > 8'd4;
229
        `FDIV:                fp0_done = cnt > 8'h70;
230
        `FDIVS:                fp0_done = cnt > 8'h37;
231
        default:       fp0_done = 1'b1;
232
        endcase
233
        `SINGLE_R:
234
        case(fp0_fn)
235
        `FNEGS,`FABSS,`FSIGNS,`FMOVS,
236
        `FNABSS,`FMANS:
237
                                    fp0_done = 1'b1;        // These ops are done right away
238
        `FTOIS,`ITOFS:    fp0_done = cnt > 8'd1;
239
        default:       fp0_done = 1'b1;
240
        endcase
241
        `DOUBLE_R:
242
        case(fp0_fn)
243
        `FMOV,`FNEG,`FABS,`FNABS,`FSIGN,`FMAN:
244
                                    fp0_done = 1'b1;        // These ops are done right away
245
        `FTOI,`ITOF:    fp0_done = cnt > 8'd1;
246
        default:       fp0_done = 1'b1;
247
        endcase
248
        default:       fp0_done = 1'b1;
249
        endcase
250
end
251
 
252
assign fp0_cmt = fnPredicate(fp0_pred, fp0_cond);
253 42 robfinch
assign fp0_exc = fp0_exception ? `EX_FP : 9'd0;
254 3 robfinch
 
255
assign  fp0_v = fp0_dataready;
256
assign  fp0_id = fp0_sourceid;
257
`endif
258
 

powered by: WebSVN 2.1.0

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