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

Subversion Repositories thor

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

Go to most recent revision | 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
    `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 37 robfinch
assign  alu0_exc =  (fnIsKMOnly(alu0_op) && !km && alu0_cmt) ? `EXC_PRIV :
157
                    (alu0_done && alu0_divByZero && alu0_cmt) ? `EXC_DBZ :
158
                    ((alu0_op==`CHKI||(alu0_op==`RR && alu0_fn==`CHK)) && !alu0_out && alu0_cmt) ? `EXC_CHK :
159
                    `EXC_NONE;
160 3 robfinch
 
161 37 robfinch
assign  alu1_exc =  (fnIsKMOnly(alu1_op) && !km && alu1_cmt) ? `EXC_PRIV :
162
                    (alu1_done && alu1_divByZero && alu1_cmt) ? `EXC_DBZ :
163
                    ((alu1_op==`CHKI ||(alu1_op==`RR && alu1_fn==`CHK)) && !alu1_out && alu1_cmt) ? `EXC_CHK :
164
                    `EXC_NONE;
165 3 robfinch
 
166
assign alu0_branchmiss = alu0_dataready &&
167
                   ((fnIsBranch(alu0_op))  ? ((alu0_cmt && !alu0_bt) || (!alu0_cmt && alu0_bt))
168 13 robfinch
                  : !alu0_cmt ? (alu0_op==`LOOP)
169
                  : (alu0_cmt && (alu0_op==`SYNC || alu0_op == `JSR || alu0_op == `JSRS || alu0_op == `JSRZ ||
170 3 robfinch
                     alu0_op==`SYS || alu0_op==`INT ||
171 10 robfinch
                  alu0_op==`RTS || alu0_op==`RTS2 || alu0_op==`RTD || alu0_op == `RTE || alu0_op==`RTI || ((alu0_op==`LOOP) && (alu0_argA == 64'd0)))));
172 3 robfinch
 
173
assign alu1_branchmiss = alu1_dataready &&
174
                   ((fnIsBranch(alu1_op))  ? ((alu1_cmt && !alu1_bt) || (!alu1_cmt && alu1_bt))
175 13 robfinch
                  : !alu1_cmt ? (alu1_op==`LOOP)
176
                  : (alu1_cmt && (alu1_op==`SYNC || alu1_op == `JSR || alu1_op == `JSRS || alu1_op == `JSRZ ||
177 3 robfinch
                     alu1_op==`SYS || alu1_op==`INT ||
178 10 robfinch
                  alu1_op==`RTS || alu1_op==`RTS2 || alu1_op==`RTD || alu1_op == `RTE || alu1_op==`RTI || ((alu1_op==`LOOP) && (alu1_argA == 64'd0)))));
179 3 robfinch
 
180 10 robfinch
assign  branchmiss = (alu0_branchmiss | alu1_branchmiss | mem_stringmiss | jmpi_miss),
181
        misspc = (jmpi_miss ? jmpi_misspc : mem_stringmiss ? dram0_misspc : alu0_branchmiss ? alu0_misspc : alu1_misspc),
182
        missid = (jmpi_miss ? dram0_id : mem_stringmiss ? dram0_id : alu0_branchmiss ? alu0_sourceid : alu1_sourceid);
183 3 robfinch
 
184
`ifdef FLOATING_POINT
185
 wire fp0_exception;
186
 
187
fpUnit ufp0
188
(
189
        .rst(rst_i),
190
        .clk(clk),
191
        .ce(1'b1),
192
        .op(fp0_op),
193
        .fn(fp0_fn),
194
        .ld(fp0_ld),
195
        .a(fp0_argA),
196
        .b(fp0_argB),
197
        .o(fp0_bus),
198
        .exception(fp0_exception)
199
);
200
 
201
reg [7:0] cnt;
202
always @(posedge clk)
203
if (rst_i)
204
    cnt <= 8'h00;
205
else begin
206
    if (fp0_ld)
207
           cnt <= 8'h00;
208
    else begin
209
           if (cnt < 8'hff)
210
                  cnt <= cnt + 8'd1;
211
    end
212
end
213
 
214
always @*
215
begin
216
        case(fp0_op)
217
        `FLOAT:
218
        case(fp0_fn)
219
        `FCMP,`FCMPS:    fp0_done = 1'b1;        // These ops are done right away
220
        `FADD,`FSUB,`FMUL,`FADDS,`FSUBS,`FMULS:
221
                               fp0_done = cnt > 8'd4;
222
        `FDIV:                fp0_done = cnt > 8'h70;
223
        `FDIVS:                fp0_done = cnt > 8'h37;
224
        default:       fp0_done = 1'b1;
225
        endcase
226
        `SINGLE_R:
227
        case(fp0_fn)
228
        `FNEGS,`FABSS,`FSIGNS,`FMOVS,
229
        `FNABSS,`FMANS:
230
                                    fp0_done = 1'b1;        // These ops are done right away
231
        `FTOIS,`ITOFS:    fp0_done = cnt > 8'd1;
232
        default:       fp0_done = 1'b1;
233
        endcase
234
        `DOUBLE_R:
235
        case(fp0_fn)
236
        `FMOV,`FNEG,`FABS,`FNABS,`FSIGN,`FMAN:
237
                                    fp0_done = 1'b1;        // These ops are done right away
238
        `FTOI,`ITOF:    fp0_done = cnt > 8'd1;
239
        default:       fp0_done = 1'b1;
240
        endcase
241
        default:       fp0_done = 1'b1;
242
        endcase
243
end
244
 
245
assign fp0_cmt = fnPredicate(fp0_pred, fp0_cond);
246
assign fp0_exc = fp0_exception ? 8'd242 : 8'd0;
247
 
248
assign  fp0_v = fp0_dataready;
249
assign  fp0_id = fp0_sourceid;
250
`endif
251
 

powered by: WebSVN 2.1.0

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