mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Speed up the div-mod test case
Test various explicit cases, not nested `for` loops over thousands of cases
This commit is contained in:
@@ -1,36 +1,62 @@
|
|||||||
_ASM equ 0
|
def _ASM equ 0
|
||||||
|
|
||||||
test: MACRO
|
test: MACRO
|
||||||
; Test RGBASM
|
; Test RGBASM
|
||||||
V equs "_ASM +"
|
redef V equs "_ASM +"
|
||||||
static_assert \#
|
static_assert \#
|
||||||
PURGE V
|
; Test RGBLINK
|
||||||
; Test RGBLINK
|
redef V equs "_LINK +"
|
||||||
V equs "_LINK +"
|
|
||||||
assert \#
|
assert \#
|
||||||
PURGE V
|
|
||||||
ENDM
|
ENDM
|
||||||
|
|
||||||
for x, -300, 301
|
test_mod: MACRO
|
||||||
for y, -x - 1, x + 2
|
def x = \1 ; dividend
|
||||||
if y != 0
|
def y = \2 ; divisor
|
||||||
q = x / y
|
shift 2
|
||||||
r = x % y
|
def q = x / y ; quotient
|
||||||
|
def r = x % y ; remainder
|
||||||
|
; identity laws
|
||||||
test (V (q * y + r)) == (V x)
|
test (V (q * y + r)) == (V x)
|
||||||
test (V (x + y) % y) == (V r)
|
test (V (x + y) % y) == (V r)
|
||||||
test (V (x - y) % y) == (V r)
|
test (V (x - y) % y) == (V r)
|
||||||
endc
|
ENDM
|
||||||
endr
|
|
||||||
endr
|
|
||||||
|
|
||||||
for x, -300, 301
|
test_each_mod: MACRO
|
||||||
for p, 31
|
test_mod (\1), (\2)
|
||||||
y = 2 ** p
|
test_mod (\1), -(\2)
|
||||||
r = x % y
|
test_mod -(\1), (\2)
|
||||||
m = x & (y - 1)
|
test_mod -(\1), -(\2)
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
test_pow: MACRO
|
||||||
|
def x = \1 ; dividend
|
||||||
|
def y = 2 ** \2 ; divisor
|
||||||
|
def r = x % y ; remainder
|
||||||
|
def m = x & (y - 1) ; mask
|
||||||
|
; identity law
|
||||||
test (V r) == (V m)
|
test (V r) == (V m)
|
||||||
endr
|
ENDM
|
||||||
endr
|
|
||||||
|
test_each_pow: MACRO
|
||||||
|
test_pow (\1), (\2)
|
||||||
|
test_pow -(\1), (\2)
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
test_each_mod 0, 1
|
||||||
|
test_each_mod 7, 5
|
||||||
|
test_each_mod 42, 256
|
||||||
|
test_each_mod 567, 256
|
||||||
|
test_each_mod 256, 512
|
||||||
|
test_each_mod 1, 65535
|
||||||
|
test_each_mod 100, 65535
|
||||||
|
test_each_mod 10000, 65535
|
||||||
|
test_each_mod 1000000, 65535
|
||||||
|
|
||||||
|
test_each_pow 5, 1
|
||||||
|
test_each_pow 42, 8
|
||||||
|
test_each_pow 567, 8
|
||||||
|
test_each_pow 12345, 16
|
||||||
|
test_each_pow 99999, 16
|
||||||
|
|
||||||
SECTION "LINK", ROM0
|
SECTION "LINK", ROM0
|
||||||
_LINK::
|
_LINK::
|
||||||
|
|||||||
Reference in New Issue
Block a user