|
| 1 | +package kernel.alu |
| 2 | + |
| 3 | +import chisel3._ |
| 4 | +import chisel3.util._ |
| 5 | +import hardfloat._ |
| 6 | +object FPU { |
| 7 | + def equivRecFN(expWidth: Int, sigWidth: Int, a: UInt, b: UInt) = { |
| 8 | + val top4A = a(expWidth + sigWidth, expWidth + sigWidth - 3) |
| 9 | + val top4B = b(expWidth + sigWidth, expWidth + sigWidth - 3) |
| 10 | + Mux( |
| 11 | + (top4A(2, 0) === 0.U) || (top4A(2, 0) === 7.U), |
| 12 | + (top4A === top4B) && (a(sigWidth - 2, 0) === b(sigWidth - 2, 0)), |
| 13 | + Mux((top4A(2, 0) === 6.U), (top4A === top4B), (a === b)) |
| 14 | + ) |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +class ValExec_MulRecFN(expWidth: Int, sigWidth: Int) extends Module { |
| 19 | + val io = IO(new Bundle { |
| 20 | + val a = Input(Bits((expWidth + sigWidth).W)) |
| 21 | + val b = Input(Bits((expWidth + sigWidth).W)) |
| 22 | + val roundingMode = Input(UInt(3.W)) |
| 23 | + val detectTininess = Input(UInt(1.W)) |
| 24 | + |
| 25 | + val expected = new Bundle { |
| 26 | + val out = Input(Bits((expWidth + sigWidth).W)) |
| 27 | + val exceptionFlags = Input(Bits(5.W)) |
| 28 | + val recOut = Output(Bits((expWidth + sigWidth + 1).W)) |
| 29 | + } |
| 30 | + |
| 31 | + val actual = new Bundle { |
| 32 | + val out = Output(Bits((expWidth + sigWidth + 1).W)) |
| 33 | + val exceptionFlags = Output(Bits(5.W)) |
| 34 | + } |
| 35 | + |
| 36 | + val check = Output(Bool()) |
| 37 | + val pass = Output(Bool()) |
| 38 | + }) |
| 39 | + |
| 40 | + val mulRecFN = Module(new MulRecFN(expWidth, sigWidth)) |
| 41 | + mulRecFN.io.a := recFNFromFN(expWidth, sigWidth, io.a) |
| 42 | + mulRecFN.io.b := recFNFromFN(expWidth, sigWidth, io.b) |
| 43 | + mulRecFN.io.roundingMode := io.roundingMode |
| 44 | + mulRecFN.io.detectTininess := io.detectTininess |
| 45 | + |
| 46 | + io.expected.recOut := recFNFromFN(expWidth, sigWidth, io.expected.out) |
| 47 | + |
| 48 | + io.actual.out := mulRecFN.io.out |
| 49 | + io.actual.exceptionFlags := mulRecFN.io.exceptionFlags |
| 50 | + |
| 51 | + io.check := true.B |
| 52 | + io.pass := |
| 53 | + FPU.equivRecFN(expWidth, sigWidth, io.actual.out, io.expected.recOut) && |
| 54 | + (io.actual.exceptionFlags === io.expected.exceptionFlags) |
| 55 | +} |
0 commit comments