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

Subversion Repositories thor

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2013,2015  Robert Finch, Stratford
4
//    \  __ /    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
// Special flag nybble is used for INT and SYS instructions in order to turn off
118
// 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
    `SYS,`INT:
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
    `SYS,`INT:
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
assign  alu0_misspc = (alu0_op == `JSR || alu0_op==`JSRS || alu0_op==`JSRZ ||
157
                       alu0_op==`RTS || alu0_op==`RTS2 || alu0_op == `RTE || alu0_op==`RTI || alu0_op==`LOOP) ? alu0_argA + alu0_argI :
158
                                          (alu0_op == `SYS || alu0_op==`INT) ? alu0_argA + {alu0_argI[DBW-5:0],4'b0} :
159
                                          (alu0_bt ? alu0_pc + alu0_insnsz : alu0_pc + alu0_insnsz + alu0_argI),
160
                alu1_misspc = (alu1_op == `JSR || alu1_op==`JSRS || alu1_op==`JSRZ ||
161
                               alu1_op==`RTS || alu1_op == `RTE || alu1_op==`RTI || alu1_op==`LOOP) ? alu1_argA + alu1_argI :
162
                                          (alu1_op == `SYS || alu1_op==`INT) ? alu1_argA + {alu1_argI[DBW-5:0],4'b0} :
163
                                          (alu1_bt ? alu1_pc + alu1_insnsz : alu1_pc + alu1_insnsz + alu1_argI);
164
*/
165
assign  alu0_exc =  (fnIsKMOnly(alu0_op) && !km) ? `EXC_PRIV :
166
                    (alu0_done && alu0_divByZero) ? `EXC_DBZ : `EXC_NONE;
167
 
168
//                      ? `EXC_NONE
169
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_NONE)     ? `EXC_NONE
170
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_CALL)     ? alu0_argB[`INSTRUCTION_S2]
171
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_MFSR)     ? `EXC_NONE
172
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_MTSR)     ? `EXC_NONE
173
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_RFU1)     ? `EXC_INVALID
174
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_RFU2)     ? `EXC_INVALID
175
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_RFU3)     ? `EXC_INVALID
176
//                      : (alu0_argB[`INSTRUCTION_S1] == `SYS_EXC)      ? alu0_argB[`INSTRUCTION_S2]
177
//                      : `EXC_INVALID;
178
 
179
assign  alu1_exc =  (fnIsKMOnly(alu1_op) && !km) ? `EXC_PRIV :
180
                    (alu1_done && alu1_divByZero) ? `EXC_DBZ : `EXC_NONE;
181
 
182
//                      ? `EXC_NONE
183
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_NONE)     ? `EXC_NONE
184
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_CALL)     ? alu1_argB[`INSTRUCTION_S2]
185
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_MFSR)     ? `EXC_NONE
186
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_MTSR)     ? `EXC_NONE
187
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_RFU1)     ? `EXC_INVALID
188
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_RFU2)     ? `EXC_INVALID
189
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_RFU3)     ? `EXC_INVALID
190
//                      : (alu1_argB[`INSTRUCTION_S1] == `SYS_EXC)      ? alu1_argB[`INSTRUCTION_S2]
191
//                      : `EXC_INVALID;
192
 
193
assign alu0_branchmiss = alu0_dataready &&
194
                   ((fnIsBranch(alu0_op))  ? ((alu0_cmt && !alu0_bt) || (!alu0_cmt && alu0_bt))
195 13 robfinch
                  : !alu0_cmt ? (alu0_op==`LOOP)
196
                  : (alu0_cmt && (alu0_op==`SYNC || alu0_op == `JSR || alu0_op == `JSRS || alu0_op == `JSRZ ||
197 3 robfinch
                     alu0_op==`SYS || alu0_op==`INT ||
198 10 robfinch
                  alu0_op==`RTS || alu0_op==`RTS2 || alu0_op==`RTD || alu0_op == `RTE || alu0_op==`RTI || ((alu0_op==`LOOP) && (alu0_argA == 64'd0)))));
199 3 robfinch
 
200
assign alu1_branchmiss = alu1_dataready &&
201
                   ((fnIsBranch(alu1_op))  ? ((alu1_cmt && !alu1_bt) || (!alu1_cmt && alu1_bt))
202 13 robfinch
                  : !alu1_cmt ? (alu1_op==`LOOP)
203
                  : (alu1_cmt && (alu1_op==`SYNC || alu1_op == `JSR || alu1_op == `JSRS || alu1_op == `JSRZ ||
204 3 robfinch
                     alu1_op==`SYS || alu1_op==`INT ||
205 10 robfinch
                  alu1_op==`RTS || alu1_op==`RTS2 || alu1_op==`RTD || alu1_op == `RTE || alu1_op==`RTI || ((alu1_op==`LOOP) && (alu1_argA == 64'd0)))));
206 3 robfinch
 
207 10 robfinch
assign  branchmiss = (alu0_branchmiss | alu1_branchmiss | mem_stringmiss | jmpi_miss),
208
        misspc = (jmpi_miss ? jmpi_misspc : mem_stringmiss ? dram0_misspc : alu0_branchmiss ? alu0_misspc : alu1_misspc),
209
        missid = (jmpi_miss ? dram0_id : mem_stringmiss ? dram0_id : alu0_branchmiss ? alu0_sourceid : alu1_sourceid);
210 3 robfinch
 
211
`ifdef FLOATING_POINT
212
 wire fp0_exception;
213
 
214
fpUnit ufp0
215
(
216
        .rst(rst_i),
217
        .clk(clk),
218
        .ce(1'b1),
219
        .op(fp0_op),
220
        .fn(fp0_fn),
221
        .ld(fp0_ld),
222
        .a(fp0_argA),
223
        .b(fp0_argB),
224
        .o(fp0_bus),
225
        .exception(fp0_exception)
226
);
227
 
228
reg [7:0] cnt;
229
always @(posedge clk)
230
if (rst_i)
231
    cnt <= 8'h00;
232
else begin
233
    if (fp0_ld)
234
           cnt <= 8'h00;
235
    else begin
236
           if (cnt < 8'hff)
237
                  cnt <= cnt + 8'd1;
238
    end
239
end
240
 
241
always @*
242
begin
243
        case(fp0_op)
244
        `FLOAT:
245
        case(fp0_fn)
246
        `FCMP,`FCMPS:    fp0_done = 1'b1;        // These ops are done right away
247
        `FADD,`FSUB,`FMUL,`FADDS,`FSUBS,`FMULS:
248
                               fp0_done = cnt > 8'd4;
249
        `FDIV:                fp0_done = cnt > 8'h70;
250
        `FDIVS:                fp0_done = cnt > 8'h37;
251
        default:       fp0_done = 1'b1;
252
        endcase
253
        `SINGLE_R:
254
        case(fp0_fn)
255
        `FNEGS,`FABSS,`FSIGNS,`FMOVS,
256
        `FNABSS,`FMANS:
257
                                    fp0_done = 1'b1;        // These ops are done right away
258
        `FTOIS,`ITOFS:    fp0_done = cnt > 8'd1;
259
        default:       fp0_done = 1'b1;
260
        endcase
261
        `DOUBLE_R:
262
        case(fp0_fn)
263
        `FMOV,`FNEG,`FABS,`FNABS,`FSIGN,`FMAN:
264
                                    fp0_done = 1'b1;        // These ops are done right away
265
        `FTOI,`ITOF:    fp0_done = cnt > 8'd1;
266
        default:       fp0_done = 1'b1;
267
        endcase
268
        default:       fp0_done = 1'b1;
269
        endcase
270
end
271
 
272
assign fp0_cmt = fnPredicate(fp0_pred, fp0_cond);
273
assign fp0_exc = fp0_exception ? 8'd242 : 8'd0;
274
 
275
assign  fp0_v = fp0_dataready;
276
assign  fp0_id = fp0_sourceid;
277
`endif
278
 

powered by: WebSVN 2.1.0

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