diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-04-14 17:20:34 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-04-14 17:20:34 +0300 |
| commit | 367813568d723e598a38a7327fc2bb4abcfc598c (patch) | |
| tree | f4c72a5e3f3992d8b43ed0a5e695c8e9aa790ecf /test | |
| parent | 2f69a9ac8c2de9d37248baa5c774c2813f070ba0 (diff) | |
Add data_segment feature, refactor
Diffstat (limited to 'test')
| -rw-r--r-- | test/e2e/call_stack/lib.atk16 | 92 | ||||
| -rw-r--r-- | test/e2e/call_stack/run_fact.atk16 | 2 | ||||
| -rw-r--r-- | test/e2e/call_stack/run_mul.atk16 | 8 | ||||
| -rw-r--r-- | test/e2e/fibo/fibo.atk16 | 3 | ||||
| -rw-r--r-- | test/e2e/std_bump_alloc/run_bump_alloc_overlap.atk16 | 3 | ||||
| -rw-r--r-- | test/e2e/std_mem/run_memcopy.atk16 | 6 | ||||
| -rw-r--r-- | test/e2e/std_mem/run_memset.atk16 | 3 |
7 files changed, 9 insertions, 108 deletions
diff --git a/test/e2e/call_stack/lib.atk16 b/test/e2e/call_stack/lib.atk16 deleted file mode 100644 index 58b9cdb..0000000 --- a/test/e2e/call_stack/lib.atk16 +++ /dev/null @@ -1,92 +0,0 @@ -@label mul_sign_mask - ${2 ** 15} -@label mul_not_mask - 0xFFFF - -@label mul - ; multiply a signed (a) and a signed (b) - ; parameters RA = a - ; RB = b - ; return RG = a * b - - stack_stash RA RB RC RD - ldi 0 RG ; initialize return value in RG to 0 - - ldi mul_sign_mask RD - ldr RD RD ; RD := 2 ** 16 - and RA RD RC ; RC := 2 ** 16 if a is negative, 0 otherwise - and RB RD RD ; RD := 2 ** 16 if b is negative, 0 otherwise - xor RC RD RC ; RC := 2 ** 16 if exactly one of a or b is negative, 0 otherwise - - ldi mul_not_mask RD - ldr RD RD ; RD := 0xFFFF - - ; RA := abs(a) - subi RA 0 RA - bri sign mul_a_negative - jpi mul_a_negative_done -@label mul_a_negative - xor RA RD RA ; RA := ~a - inc RA ; negate twos complement a -@label mul_a_negative_done - - ; RB := abs(b) - subi RB 0 RB - bri sign mul_b_negative - jpi mul_b_negative_done -@label mul_b_negative - xor RB RD RB ; RB := ~b - inc RB ; negate twos complement b -@label mul_b_negative_done - - ; the algorithms iterates b times, adding a to RG each time - ; so b should be as small as possible - sub RB RA RD ; if a <= b, swap a and b - bri sign mul_loop - - mov RA RD - mov RB RA - mov RD RB -@label mul_loop - ; if b == 0, we are done - subi RB 0 RB - bri zero mul_done - ; RG += RA - add RA RG RG - dec RB - jpi mul_loop -@label mul_done - ; set the most significant bit to the precomputed sign - subi RC 0 RC - bri sign mul_negate_result - jpi mul_return -@label mul_negate_result - ldi mul_not_mask RD - ldr RD RD ; RD := 0xFFFF - xor RG RD RG - inc RG -@label mul_return - stack_restore RA RB RC RD - return - -; Recursive impl of the factorial -; Calling convention is that arguments are in registers RA..RG (max 7 arguments since RH = SP) -; and the return value is in RG (note: overwriting arg in RG) - -@label fact - ; parameters RA = n - ; return RG = factorial(n) - subi RA 0 RA - bri zero fact_basecase -@label fact_reccase - stack_stash RA RB - mov RA RB ; RB := n - subi RA 1 RA ; RA := n - 1 - calli fact ; RG := fact(n - 1) - mov RG RA ; RA := fact(n - 1) - calli mul ; RG := n * fact(n - 1) - stack_restore RA RB - return -@label fact_basecase - ldi 1 RG - return diff --git a/test/e2e/call_stack/run_fact.atk16 b/test/e2e/call_stack/run_fact.atk16 index e0b8bf1..9a282ff 100644 --- a/test/e2e/call_stack/run_fact.atk16 +++ b/test/e2e/call_stack/run_fact.atk16 @@ -1,5 +1,5 @@ @include %bootstrap -@include lib +@include %std_math @let INPUT %INPUT% ; value replaced by test driver code diff --git a/test/e2e/call_stack/run_mul.atk16 b/test/e2e/call_stack/run_mul.atk16 index 377e61c..f47e19b 100644 --- a/test/e2e/call_stack/run_mul.atk16 +++ b/test/e2e/call_stack/run_mul.atk16 @@ -1,11 +1,9 @@ @include %bootstrap -@include lib +@include %std_math ; values replaced by test driver code -@label INPUT_A - %INPUT_A% -@label INPUT_B - %INPUT_B% +@data INPUT_A %INPUT_A% +@data INPUT_B %INPUT_B% @label main ldi INPUT_A RA diff --git a/test/e2e/fibo/fibo.atk16 b/test/e2e/fibo/fibo.atk16 index a817a1c..5b9030b 100644 --- a/test/e2e/fibo/fibo.atk16 +++ b/test/e2e/fibo/fibo.atk16 @@ -1,7 +1,6 @@ @include %bootstrap -@label iters - 51 +@data iters 51 @label main ldi iters RA diff --git a/test/e2e/std_bump_alloc/run_bump_alloc_overlap.atk16 b/test/e2e/std_bump_alloc/run_bump_alloc_overlap.atk16 index 8dcc6fa..08ced49 100644 --- a/test/e2e/std_bump_alloc/run_bump_alloc_overlap.atk16 +++ b/test/e2e/std_bump_alloc/run_bump_alloc_overlap.atk16 @@ -1,8 +1,7 @@ @include %bootstrap @include %std_bump_alloc -@label n - 0x8000 +@data n 0x8000 @label main calli bump_reset diff --git a/test/e2e/std_mem/run_memcopy.atk16 b/test/e2e/std_mem/run_memcopy.atk16 index 66f3c1d..a011cb9 100644 --- a/test/e2e/std_mem/run_memcopy.atk16 +++ b/test/e2e/std_mem/run_memcopy.atk16 @@ -1,10 +1,8 @@ @include %bootstrap @include %std_mem -@label mem_offset_from - 0x9000 -@label mem_offset_to - 0x9100 +@data mem_offset_from 0x9000 +@data mem_offset_to 0x9100 @label main ; set values 0x0000..0x0004 to 3 diff --git a/test/e2e/std_mem/run_memset.atk16 b/test/e2e/std_mem/run_memset.atk16 index 07e7666..b6a012c 100644 --- a/test/e2e/std_mem/run_memset.atk16 +++ b/test/e2e/std_mem/run_memset.atk16 @@ -1,8 +1,7 @@ @include %bootstrap @include %std_mem -@label mem_offset - 0x9000 +@data mem_offset 0x9000 @label main ; set 0x9005 to value 4 |
