2012-02-26 02:09:26 +01:00
|
|
|
package rocket
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import Node._;
|
|
|
|
|
|
|
|
import Constants._
|
|
|
|
import Instructions._
|
|
|
|
|
|
|
|
class ioALU extends Bundle(){
|
2012-01-18 19:28:48 +01:00
|
|
|
val dw = UFix(1, INPUT);
|
|
|
|
val fn = UFix(4, INPUT);
|
|
|
|
val in2 = UFix(64, INPUT);
|
|
|
|
val in1 = UFix(64, INPUT);
|
|
|
|
val out = UFix(64, OUTPUT);
|
|
|
|
val adder_out = UFix(64, OUTPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class rocketDpathALU extends Component
|
|
|
|
{
|
2011-11-10 08:18:14 +01:00
|
|
|
val io = new ioALU();
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2011-12-17 16:20:32 +01:00
|
|
|
// ADD, SUB
|
|
|
|
val sub = (io.fn === FN_SUB) || (io.fn === FN_SLT) || (io.fn === FN_SLTU)
|
|
|
|
val adder_rhs = Mux(sub, ~io.in2, io.in2)
|
2012-01-02 06:28:38 +01:00
|
|
|
val sum = (io.in1 + adder_rhs + sub.toUFix)(63,0)
|
2011-12-17 16:20:32 +01:00
|
|
|
|
|
|
|
// SLT, SLTU
|
2012-02-08 15:47:26 +01:00
|
|
|
val less = Mux(io.in1(63) === io.in2(63), sum(63),
|
|
|
|
Mux(io.fn === FN_SLT, io.in1(63), io.in2(63)))
|
2011-12-17 16:20:32 +01:00
|
|
|
|
|
|
|
// SLL, SRL, SRA
|
|
|
|
val sra = (io.fn === FN_SRA)
|
2012-02-08 15:47:26 +01:00
|
|
|
val shamt = Cat(io.in2(5) & (io.dw === DW_64), io.in2(4,0)).toUFix
|
2011-12-17 16:20:32 +01:00
|
|
|
val shright = sra || (io.fn === FN_SR)
|
|
|
|
val shin_hi_32 = Mux(sra, Fill(32, io.in1(31)), UFix(0,32))
|
|
|
|
val shin_hi = Mux(io.dw === DW_64, io.in1(63,32), shin_hi_32)
|
|
|
|
val shin_r = Cat(shin_hi, io.in1(31,0))
|
|
|
|
val shin = Mux(shright, shin_r, Reverse(shin_r))
|
2012-02-15 04:43:59 +01:00
|
|
|
val shout_r = (Cat(sra & shin_r(63), shin).toFix >> shamt)(63,0)
|
2012-02-08 15:47:26 +01:00
|
|
|
|
2012-03-16 08:44:16 +01:00
|
|
|
val bitwise_logic =
|
2012-02-08 15:47:26 +01:00
|
|
|
Mux(io.fn === FN_AND, io.in1 & io.in2,
|
|
|
|
Mux(io.fn === FN_OR, io.in1 | io.in2,
|
|
|
|
Mux(io.fn === FN_XOR, io.in1 ^ io.in2,
|
|
|
|
io.in2))) // FN_OP2
|
|
|
|
|
|
|
|
val out64 =
|
|
|
|
Mux(io.fn === FN_ADD || io.fn === FN_SUB, sum,
|
|
|
|
Mux(io.fn === FN_SLT || io.fn === FN_SLTU, less,
|
|
|
|
Mux(io.fn === FN_SR || io.fn === FN_SRA, shout_r,
|
|
|
|
Mux(io.fn === FN_SL, Reverse(shout_r),
|
2012-03-16 08:44:16 +01:00
|
|
|
bitwise_logic))))
|
2011-12-17 16:20:32 +01:00
|
|
|
|
|
|
|
val out_hi = Mux(io.dw === DW_64, out64(63,32), Fill(32, out64(31)))
|
|
|
|
io.out := Cat(out_hi, out64(31,0)).toUFix
|
2012-01-02 06:28:38 +01:00
|
|
|
io.adder_out := sum
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|