egg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 6085296c4563c526b14d0eda189059008eb50f00
parent 78d62319df4cf4d7fa4a1b0be9d7fe32b711bfe7
Author: Gabriel G. de Brito <gabrielgbrito@icloud.com>
Date:   Fri,  5 Jan 2024 14:50:02 -0300

Added tests for remaining multiplication extension for RISC-V

Diffstat:
Mriscv/riscv.go | 10++++++++--
Mriscv/riscv_test.go | 10++++++++++
Mriscv/test-instructions.asm | 12++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/riscv/riscv.go b/riscv/riscv.go @@ -144,9 +144,15 @@ func (m *RiscV) execArithmetic(rd uint8, rs1 uint8, rs2 uint8, func3 uint8, func tmp := rs1v64 * rs2v64 r = int32(tmp >> 32) case 0x2: - r = int32((int64(signExtend64(uint32(rs1v))) * int64(rs2v)) >> 32) + rs1v64 := int64(signExtend64(uint32(rs1v))) + rs2v64 := int64(uint64(rs2v)) & 0x00000000ffffffff + tmp := int64(rs1v64 * rs2v64) >> 32 + r = int32(tmp) case 0x3: - r = int32(uint64(rs1v) * uint64(rs2v) >> 32) + rs1v64 := uint64(rs1v) & 0x00000000ffffffff + rs2v64 := uint64(rs2v) & 0x00000000ffffffff + tmp := (rs1v64 * rs2v64) >> 32 + r = int32(tmp) case 0x4: if rs2v == 0 { r = 0 diff --git a/riscv/riscv_test.go b/riscv/riscv_test.go @@ -432,4 +432,14 @@ func TestInstructions(t *testing.T) { m.NextInstruction() // -536869545 but without the 4 top bytes. m.assertRegister(t, "t2", uint64(3758097750), "div t2, t0, t1 (neg)") + + m.NextInstruction() + m.NextInstruction() + + m.NextInstruction() + m.assertRegister(t, "t2", uint64(4294965248), "mulsu t2, t0, t1") + m.NextInstruction() + m.assertRegister(t, "t2", uint64(0x7FFFF800), "mulu t2, t0, t1") + m.NextInstruction() + m.assertRegister(t, "t2", uint64(0x7FFFF000), "remu t2, t0, t1") } diff --git a/riscv/test-instructions.asm b/riscv/test-instructions.asm @@ -207,5 +207,17 @@ bgeu2: mulh t2, t0, t1 ;; t2 == 0xF5556555 div t2, t0, t1 + + ;; Load 0xFFFFF000 to t0 (-0x1000). + lui t0, 0xFFFFF + ;; Load 0x80000000 to t1. + lui t1, 0x80000 + + ;; t2 == 0xFFFF8000 + mulsu t2, t0, t1 + ;; t2 == 0x7FFFF800 + mulu t2, t0, t1 + ;; t2 == 0x70000000 + remu t2, t0, t1 func: jalr zero, ra, 0