tests: Add inline assembler test for pyboard.
This commit is contained in:
parent
a32c1e41cc
commit
c4ccb078a5
57
tests/inlineasm/asmsum.py
Normal file
57
tests/inlineasm/asmsum.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
@micropython.asm_thumb
|
||||||
|
def asm_sum_words(r0, r1):
|
||||||
|
|
||||||
|
# r0 = len
|
||||||
|
# r1 = ptr
|
||||||
|
# r2 = sum
|
||||||
|
# r3 = dummy
|
||||||
|
mov(r2, 0)
|
||||||
|
|
||||||
|
b(loop_entry)
|
||||||
|
|
||||||
|
label(loop1)
|
||||||
|
ldr(r3, [r1, 0])
|
||||||
|
add(r2, r2, r3)
|
||||||
|
|
||||||
|
add(r1, r1, 4)
|
||||||
|
sub(r0, r0, 1)
|
||||||
|
|
||||||
|
label(loop_entry)
|
||||||
|
cmp(r0, 0)
|
||||||
|
bgt(loop1)
|
||||||
|
|
||||||
|
mov(r0, r2)
|
||||||
|
|
||||||
|
@micropython.asm_thumb
|
||||||
|
def asm_sum_bytes(r0, r1):
|
||||||
|
|
||||||
|
# r0 = len
|
||||||
|
# r1 = ptr
|
||||||
|
# r2 = sum
|
||||||
|
# r3 = dummy
|
||||||
|
mov(r2, 0)
|
||||||
|
|
||||||
|
b(loop_entry)
|
||||||
|
|
||||||
|
label(loop1)
|
||||||
|
ldrb(r3, [r1, 0])
|
||||||
|
add(r2, r2, r3)
|
||||||
|
|
||||||
|
add(r1, r1, 1)
|
||||||
|
sub(r0, r0, 1)
|
||||||
|
|
||||||
|
label(loop_entry)
|
||||||
|
cmp(r0, 0)
|
||||||
|
bgt(loop1)
|
||||||
|
|
||||||
|
mov(r0, r2)
|
||||||
|
|
||||||
|
import array
|
||||||
|
|
||||||
|
b = array.array('l', (100, 200, 300, 400))
|
||||||
|
n = asm_sum_words(len(b), b)
|
||||||
|
print(b, n)
|
||||||
|
|
||||||
|
b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80))
|
||||||
|
n = asm_sum_bytes(len(b), b)
|
||||||
|
print(b, n)
|
2
tests/inlineasm/asmsum.py.exp
Normal file
2
tests/inlineasm/asmsum.py.exp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
array('l', [100, 200, 300, 400]) 1000
|
||||||
|
array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360
|
@ -115,7 +115,7 @@ def main():
|
|||||||
test_dirs = ('basics', 'float', 'import', 'io', 'misc')
|
test_dirs = ('basics', 'float', 'import', 'io', 'misc')
|
||||||
else:
|
else:
|
||||||
# run pyboard tests
|
# run pyboard tests
|
||||||
test_dirs = ('basics', 'float', 'pyb')
|
test_dirs = ('basics', 'float', 'pyb', 'inlineasm')
|
||||||
tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files)
|
tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files)
|
||||||
else:
|
else:
|
||||||
# tests explicitly given
|
# tests explicitly given
|
||||||
|
Loading…
x
Reference in New Issue
Block a user