From 7e5f31bcd72b56a77c722ba6687d4dd34afda892 Mon Sep 17 00:00:00 2001 From: Angelo Jacobo Date: Thu, 23 Jun 2022 17:52:45 +0800 Subject: [PATCH] added testfiles for pipeline hazards --- test/extra/branch_hazard.s | 90 +++++++++++++++++++++++++++++ test/extra/data_hazard.s | 112 +++++++++++++++++++++++++++++++++++++ test/extra/no_hazard.s | 68 ++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 test/extra/branch_hazard.s create mode 100644 test/extra/data_hazard.s create mode 100644 test/extra/no_hazard.s diff --git a/test/extra/branch_hazard.s b/test/extra/branch_hazard.s new file mode 100644 index 0000000..9f0ee00 --- /dev/null +++ b/test/extra/branch_hazard.s @@ -0,0 +1,90 @@ +# +# TEST CODE FOR ADD +# + # ----------------------------------------- + # Program section (known as text) + # ----------------------------------------- + .text + +# Start symbol (must be present), exported as a global symbol. +_start: .global _start + +# Export main as a global symbol + .global main + +# Label for entry point of test code +main: + ### TEST CODE STARTS HERE ### + + # 100 + 150 = 250 (positive answer) + li x1, 100 # set x1 to 100 (0x00000064) + nop + nop + nop + nop + nop + nop + li x2, 150 # set x2 to 150 (0x00000096) + nop + nop + nop + nop + nop + nop + add x3, x1, x2 # add x1(100) to x2(150), x3=250 (0x000000FA) + nop + nop + nop + nop + nop + nop + j pass + ### END OF TEST CODE ### + + # Exit test using RISC-V International's riscv-tests pass/fail criteria + +fail: + li a0, 2 # set a0 (x10) to 0 to indicate a pass code + nop + nop + nop + nop + nop + nop + li a7, 93 # set a7 (x17) to 93 (5dh) to indicate reached the end of the test + nop + nop + nop + nop + nop + nop + ebreak + pass: + li a0, 0 # set a0 (x10) to 0 to indicate a pass code + nop + nop + nop + nop + nop + nop + li a7, 93 # set a7 (x17) to 93 (5dh) to indicate reached the end of the test + nop + nop + nop + nop + nop + nop + ebreak + + + + + # ----------------------------------------- + # Data section. Note starts at 0x1000, as + # set by DATAADDR variable in rv_asm.bat. + # ----------------------------------------- + .data + + # Data section +data: + diff --git a/test/extra/data_hazard.s b/test/extra/data_hazard.s new file mode 100644 index 0000000..d9216ca --- /dev/null +++ b/test/extra/data_hazard.s @@ -0,0 +1,112 @@ +# +# TEST CODE FOR ADD +# + # ----------------------------------------- + # Program section (known as text) + # ----------------------------------------- + .text + +# Start symbol (must be present), exported as a global symbol. +_start: .global _start + +# Export main as a global symbol + .global main + +# Label for entry point of test code +main: + ### TEST CODE STARTS HERE ### + + # 1 NOP margin between dependent instructions + + li x1, 100 # set x1 to 100 (0x00000064) + li x2, 150 # set x2 to 150 (0x00000096) + add x3, x1, x2 # add x1(100) to x2(150), x3=250 (0x000000FA) + nop + nop + nop + nop + nop + nop + li x4, 0xFA # set x4 to 0xFA (expected value for x3) + nop + nop + nop + nop + nop + nop + beqz x4, fail0 # make sure x4 has value + nop + nop + nop + nop + nop + nop + bne x3, x4, fail1 # branch to fail if not equal to expected value + + # 2 NOP margin between dependent instructions + li x1, 100 # set x1 to 100 (0x00000064) + li x2, 150 # set x2 to 150 (0x00000096) + nop + nop + add x3, x1, x2 # add x1(100) to x2(150), x3=250 (0x000000FA) + nop + nop + nop + nop + nop + nop + bne x3, x4, fail2 # branch to fail if not equal to expected value + + # 3 NOP margin between dependent instructions + li x1, 100 # set x1 to 100 (0x00000064) + li x2, 150 # set x2 to 150 (0x00000096) + nop + nop + nop + add x3, x1, x2 # add x1(100) to x2(150), x3=250 (0x000000FA) + nop + nop + nop + nop + nop + nop + bne x3, x4, fail3 # branch to fail if not equal to expected value + + ### END OF TEST CODE ### + pass: + li a0, 0 # set a0 (x10) to 0 to indicate a pass code + li a7, 93 # set a7 (x17) to 93 (5dh) to indicate reached the end of the test + ebreak + + fail0: + li a0, 1 # fail code + li a7, 93 # reached end of code + ebreak + + fail1: + li a0, 2 # fail code + li a7, 93 # reached end of code + ebreak + + fail2: + li a0, 4 # fail code + li a7, 93 # reached end of code + ebreak + + fail3: + li a0, 6 # fail code + li a7, 93 # reached end of code + ebreak + + + + + # ----------------------------------------- + # Data section. Note starts at 0x1000, as + # set by DATAADDR variable in rv_asm.bat. + # ----------------------------------------- + .data + + # Data section +data: + diff --git a/test/extra/no_hazard.s b/test/extra/no_hazard.s new file mode 100644 index 0000000..087ea0a --- /dev/null +++ b/test/extra/no_hazard.s @@ -0,0 +1,68 @@ +# +# TEST CODE FOR ADD +# + # ----------------------------------------- + # Program section (known as text) + # ----------------------------------------- + .text + +# Start symbol (must be present), exported as a global symbol. +_start: .global _start + +# Export main as a global symbol + .global main + +# Label for entry point of test code +main: + ### TEST CODE STARTS HERE ### + + # 100 + 150 = 250 (positive answer) + li x1, 100 # set x1 to 100 (0x00000064) + nop + nop + nop + nop + nop + nop + li x2, 150 # set x2 to 150 (0x00000096) + nop + nop + nop + nop + nop + nop + add x3, x1, x2 # add x1(100) to x2(150), x3=250 (0x000000FA) + nop + nop + nop + nop + nop + nop + ### END OF TEST CODE ### + + # Exit test using RISC-V International's riscv-tests pass/fail criteria + li a0, 0 # set a0 (x10) to 0 to indicate a pass code + nop + nop + nop + nop + nop + nop + li a7, 93 # set a7 (x17) to 93 (5dh) to indicate reached the end of the test + nop + nop + nop + nop + nop + nop + ebreak + + # ----------------------------------------- + # Data section. Note starts at 0x1000, as + # set by DATAADDR variable in rv_asm.bat. + # ----------------------------------------- + .data + + # Data section +data: +