From f88ec3c7eb546609186ad17222da31d34218f66f Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Sun, 9 Mar 2025 17:50:08 +0100 Subject: [PATCH] test branch --- shell.nix | 1 - tests/check/branch.S | 62 ++++++++++++++++++++++++++++++++++++++++++++ tests/helper.S | 4 +++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index eb6eaec..9cbaea1 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,4 @@ { pkgs ? import { } }: pkgs.mkShell { - nativeBuildInputs = with pkgs; [ cmake ninja ]; packages = with pkgs; [ llvmPackages_18.clang-unwrapped llvmPackages_18.lld diff --git a/tests/check/branch.S b/tests/check/branch.S index ce5497b..1938d67 100644 --- a/tests/check/branch.S +++ b/tests/check/branch.S @@ -3,4 +3,66 @@ #include "../helper.S" START_TEST + j unconditional + FAIL +unconditional: + +# Test branching instructions + li t0, 10 + li t1, 10 + beq t0, t1, branch2 + FAIL +branch2: + bge t0, t1, branch3 + FAIL +branch3: + bne t0, t1, fail + blt t0, t1, fail + bltu t0, t1, fail + + li t0, -1 + li t1, 1 + blt t1, t0, fail + bltu t0, t1, fail + bge t0, t1, fail + bgeu t1, t0, fail + + blt t0, t1, branch4 + FAIL +branch4: + bltu t1, t0, branch5 + FAIL +branch5: + bge t1, t0, branch6 + FAIL +branch6: + bgeu t0, t1, branch7 + FAIL +branch7: + +# Test link registers being set correctly: + auipc t1, 0 + jal t0, link2 + j fail +link2: + addi t1, t1, 8 # the instruction following the jump + bne t1, t0, fail + + auipc t1, 0 + jalr t0, 12(t1) # 12 is the three instructions, so to the addi + j fail + + addi t1, t1, 8 # the instruction following the jump + bne t0, t1, fail + +# Test a loop (t0=counter, t1=expected) + li t0, 0 + li t1, 100 +loop1: + addi t0, t0, 1 + blt t0, t1, loop1 + + ASSERT_EQ t0, 100 + +# End PASS diff --git a/tests/helper.S b/tests/helper.S index e8fedbf..de1e7ca 100644 --- a/tests/helper.S +++ b/tests/helper.S @@ -15,6 +15,10 @@ ecall .endm +.macro FAIL + j fail +.endm + fail: li a7, -1 li a0, 0