mirror of
https://github.com/Noratrieb/rustv32i.git
synced 2026-01-15 13:55:01 +01:00
many improvements
- fix a decode bug for C.ADDI16SP - improve test suite (to test that bug) - improve debugging - clean up code
This commit is contained in:
parent
fdb4968c8b
commit
b2c3c9fc80
8 changed files with 290 additions and 64 deletions
|
|
@ -2,36 +2,75 @@
|
|||
|
||||
#include "../helper.S"
|
||||
|
||||
.macro CASER inst a b expected
|
||||
.macro CASER inst:req a:req b:req expected:req
|
||||
li t0, \a
|
||||
li t1, \b
|
||||
\inst t2, t0, t1
|
||||
ASSERT_EQ t2, \expected
|
||||
.endm
|
||||
|
||||
.macro CASE_IMM inst a b expected
|
||||
.macro CASE_IMM inst:req a:req b:req expected:req
|
||||
li t0, \a
|
||||
\inst t2, t0, \b
|
||||
ASSERT_EQ t2, \expected
|
||||
.endm
|
||||
|
||||
.macro CASE_BOTH inst insti a b expected
|
||||
.macro CASE_BOTH inst:req insti:req a:req b:req expected:req
|
||||
CASER \inst, \a, \b, \expected
|
||||
CASE_IMM \insti, \a, \b, \expected
|
||||
.endm
|
||||
|
||||
|
||||
.macro CASE inst a b expected
|
||||
.macro CASE inst:req a:req b:req expected:req
|
||||
CASE_BOTH \inst, \inst\()i, \a, \b, \expected
|
||||
.endm
|
||||
|
||||
.macro WITH_SINGLE_TEST_NUMBERS macro
|
||||
\macro a, 0
|
||||
\macro c, 1
|
||||
\macro d, 2
|
||||
\macro u, 3
|
||||
\macro e, 4
|
||||
\macro v, 5
|
||||
\macro f, 8
|
||||
\macro t, 10
|
||||
\macro g, 16
|
||||
\macro h, 32
|
||||
\macro i, 64
|
||||
\macro s, 100
|
||||
\macro j, 128
|
||||
\macro k, 256
|
||||
\macro l, 512
|
||||
\macro w, 1000
|
||||
\macro m, 1024
|
||||
\macro n, 2047
|
||||
\macro b, -1
|
||||
\macro o, -2
|
||||
\macro p, -16
|
||||
\macro q, -1024
|
||||
\macro r, -1000
|
||||
|
||||
.endm
|
||||
|
||||
.macro WITH_TWO_TEST_NUMBERS macro
|
||||
.macro \macro\()_TMP namea:req a:req
|
||||
.macro \macro\()_TMP_\namea nameb:req b:req
|
||||
\macro \a, \b
|
||||
.endm
|
||||
|
||||
WITH_SINGLE_TEST_NUMBERS \macro\()_TMP_\namea
|
||||
.endm
|
||||
|
||||
WITH_SINGLE_TEST_NUMBERS \macro\()_TMP
|
||||
.endm
|
||||
|
||||
START_TEST
|
||||
# Base instructions
|
||||
|
||||
CASE add 10, 20, 30
|
||||
CASE add 10, -2, 8
|
||||
CASE add 10, 0, 10
|
||||
CASE add 0, 0, 0
|
||||
.macro CASE_ADD a:req, b:req
|
||||
CASE add, \a, \b, \a + \b
|
||||
.endm
|
||||
|
||||
WITH_TWO_TEST_NUMBERS CASE_ADD
|
||||
|
||||
CASE slt 10 20 1
|
||||
CASE slt 20 10 0
|
||||
|
|
@ -52,15 +91,33 @@ START_TEST
|
|||
CASE and, -1, 40, 40
|
||||
CASE and, 0b101, 0b100, 0b100
|
||||
|
||||
.macro CASE_AND a:req, b:req
|
||||
CASE and, \a, \b, \a & \b
|
||||
.endm
|
||||
|
||||
WITH_TWO_TEST_NUMBERS CASE_AND
|
||||
|
||||
CASE or, -1, 0, -1
|
||||
CASE or, -1, 40, -1
|
||||
CASE or, 0, 0, 0
|
||||
CASE or, 0b101, 0b110, 0b111
|
||||
|
||||
.macro CASE_OR a:req, b:req
|
||||
CASE or, \a, \b, \a | \b
|
||||
.endm
|
||||
|
||||
WITH_TWO_TEST_NUMBERS CASE_OR
|
||||
|
||||
CASE xor, -1, 0, -1
|
||||
CASE xor, -1, -1, 0
|
||||
CASE xor 0b101, 0b100, 0b001
|
||||
|
||||
.macro CASE_XOR a:req, b:req
|
||||
CASE xor, \a, \b, \a ^ \b
|
||||
.endm
|
||||
|
||||
WITH_TWO_TEST_NUMBERS CASE_XOR
|
||||
|
||||
CASE sll, 2, 1, 4
|
||||
CASE sll, 2, 20, 2097152
|
||||
CASE sll, 2, 30, 2147483648
|
||||
|
|
@ -84,6 +141,12 @@ START_TEST
|
|||
CASER sub, -1, -2, 1
|
||||
CASER sub, 0, 4294967295, 1
|
||||
|
||||
.macro CASE_SUB a:req, b:req
|
||||
CASER sub, \a, \b, \a - \b
|
||||
.endm
|
||||
|
||||
WITH_TWO_TEST_NUMBERS CASE_SUB
|
||||
|
||||
CASE sra, 4, 1, 2
|
||||
CASE sra, 0, 10, 0
|
||||
CASE sra, 10, 0, 10
|
||||
|
|
@ -100,6 +163,12 @@ START_TEST
|
|||
CASER mul, -1, -1, 1
|
||||
CASER mul, 25252566, 5225225, 353909638
|
||||
|
||||
.macro CASE_MUL a:req, b:req
|
||||
CASER mul, \a, \b, \a * \b
|
||||
.endm
|
||||
|
||||
WITH_TWO_TEST_NUMBERS CASE_MUL
|
||||
|
||||
CASER mulh 4, 4, 0
|
||||
CASER mulh, -1, -1, 0
|
||||
CASER mulh, 25252566, 5225225, 30722
|
||||
|
|
|
|||
57
tests/check/stack.S
Normal file
57
tests/check/stack.S
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Stack Pointer Addition (special-cased by compressed instructions)
|
||||
# I've had two bugs in this area before...
|
||||
|
||||
#include "../helper.S"
|
||||
|
||||
.macro CASE_FOR_REGISTER reg:req number:req
|
||||
li \reg, 0
|
||||
addi \reg, \reg, \number
|
||||
ASSERT_EQ \reg, \number
|
||||
.endm
|
||||
|
||||
# The goal is sp addition, but why not test some other registers as well while we're at it :)
|
||||
|
||||
.macro CASE number
|
||||
CASE_FOR_REGISTER sp, \number
|
||||
CASE_FOR_REGISTER ra, \number
|
||||
CASE_FOR_REGISTER a0, \number
|
||||
CASE_FOR_REGISTER s0, \number
|
||||
CASE_FOR_REGISTER t0, \number
|
||||
.endm
|
||||
|
||||
START_TEST
|
||||
CASE 0
|
||||
CASE 1
|
||||
CASE 2
|
||||
CASE 4
|
||||
CASE 8
|
||||
CASE 10
|
||||
CASE 16
|
||||
CASE 32
|
||||
CASE 64
|
||||
CASE 100
|
||||
CASE 128
|
||||
CASE 200
|
||||
CASE 256
|
||||
CASE 512
|
||||
CASE 1024
|
||||
CASE 2047
|
||||
|
||||
CASE -1
|
||||
CASE -2
|
||||
CASE -4
|
||||
CASE -8
|
||||
CASE -10
|
||||
CASE -16
|
||||
CASE -32
|
||||
CASE -64
|
||||
CASE -100
|
||||
CASE -128
|
||||
CASE -200
|
||||
CASE -256
|
||||
CASE -512
|
||||
CASE -1024
|
||||
CASE -2047
|
||||
CASE -2048
|
||||
|
||||
PASS
|
||||
Loading…
Add table
Add a link
Reference in a new issue