summaryrefslogtreecommitdiff
path: root/tests/inlineasm
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2020-03-22 21:26:08 -0500
committerDamien George <damien.p.george@gmail.com>2020-03-30 13:21:58 +1100
commit3dc324d3f1312e40d3a8ed87e7244966bb756f26 (patch)
tree94ff44f8eabba0039582c245b901173597edd11e /tests/inlineasm
parent488613bca6c460340ed2995ae5cafafe22d0bfff (diff)
tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
Diffstat (limited to 'tests/inlineasm')
-rw-r--r--tests/inlineasm/asmargs.py15
-rw-r--r--tests/inlineasm/asmbcc.py2
-rw-r--r--tests/inlineasm/asmbitops.py7
-rw-r--r--tests/inlineasm/asmblbx.py2
-rw-r--r--tests/inlineasm/asmconst.py7
-rw-r--r--tests/inlineasm/asmdiv.py6
-rw-r--r--tests/inlineasm/asmfpaddsub.py4
-rw-r--r--tests/inlineasm/asmfpcmp.py9
-rw-r--r--tests/inlineasm/asmfpldrstr.py6
-rw-r--r--tests/inlineasm/asmfpmuldiv.py4
-rw-r--r--tests/inlineasm/asmfpsqrt.py4
-rw-r--r--tests/inlineasm/asmit.py6
-rw-r--r--tests/inlineasm/asmpushpop.py1
-rw-r--r--tests/inlineasm/asmrettype.py12
-rw-r--r--tests/inlineasm/asmshift.py17
-rw-r--r--tests/inlineasm/asmspecialregs.py3
-rw-r--r--tests/inlineasm/asmsum.py8
17 files changed, 91 insertions, 22 deletions
diff --git a/tests/inlineasm/asmargs.py b/tests/inlineasm/asmargs.py
index 047d9ed42..3b03f1510 100644
--- a/tests/inlineasm/asmargs.py
+++ b/tests/inlineasm/asmargs.py
@@ -1,29 +1,44 @@
# test passing arguments
+
@micropython.asm_thumb
def arg0():
mov(r0, 1)
+
+
print(arg0())
+
@micropython.asm_thumb
def arg1(r0):
add(r0, r0, 1)
+
+
print(arg1(1))
+
@micropython.asm_thumb
def arg2(r0, r1):
add(r0, r0, r1)
+
+
print(arg2(1, 2))
+
@micropython.asm_thumb
def arg3(r0, r1, r2):
add(r0, r0, r1)
add(r0, r0, r2)
+
+
print(arg3(1, 2, 3))
+
@micropython.asm_thumb
def arg4(r0, r1, r2, r3):
add(r0, r0, r1)
add(r0, r0, r2)
add(r0, r0, r3)
+
+
print(arg4(1, 2, 3, 4))
diff --git a/tests/inlineasm/asmbcc.py b/tests/inlineasm/asmbcc.py
index 540fa6591..08967d48c 100644
--- a/tests/inlineasm/asmbcc.py
+++ b/tests/inlineasm/asmbcc.py
@@ -1,6 +1,7 @@
# test bcc instructions
# at the moment only tests beq, narrow and wide versions
+
@micropython.asm_thumb
def f(r0):
mov(r1, r0)
@@ -21,6 +22,7 @@ def f(r0):
label(end)
+
print(f(0))
print(f(1))
print(f(2))
diff --git a/tests/inlineasm/asmbitops.py b/tests/inlineasm/asmbitops.py
index 8cf92b301..d1c8a9823 100644
--- a/tests/inlineasm/asmbitops.py
+++ b/tests/inlineasm/asmbitops.py
@@ -2,12 +2,15 @@
def clz(r0):
clz(r0, r0)
-print(clz(0xf0))
+
+print(clz(0xF0))
print(clz(0x8000))
+
@micropython.asm_thumb
def rbit(r0):
rbit(r0, r0)
-print(hex(rbit(0xf0)))
+
+print(hex(rbit(0xF0)))
print(hex(rbit(0x8000)))
diff --git a/tests/inlineasm/asmblbx.py b/tests/inlineasm/asmblbx.py
index d08c0ed6b..43585dddc 100644
--- a/tests/inlineasm/asmblbx.py
+++ b/tests/inlineasm/asmblbx.py
@@ -1,5 +1,6 @@
# test bl and bx instructions
+
@micropython.asm_thumb
def f(r0):
# jump over the internal functions
@@ -17,5 +18,6 @@ def f(r0):
bl(func1)
bl(func2)
+
print(f(0))
print(f(1))
diff --git a/tests/inlineasm/asmconst.py b/tests/inlineasm/asmconst.py
index 299a25093..8412dd2c7 100644
--- a/tests/inlineasm/asmconst.py
+++ b/tests/inlineasm/asmconst.py
@@ -1,8 +1,11 @@
# test constants in assembler
+
@micropython.asm_thumb
def c1():
- movwt(r0, 0xffffffff)
- movwt(r1, 0xf0000000)
+ movwt(r0, 0xFFFFFFFF)
+ movwt(r1, 0xF0000000)
sub(r0, r0, r1)
+
+
print(hex(c1()))
diff --git a/tests/inlineasm/asmdiv.py b/tests/inlineasm/asmdiv.py
index b97d566eb..c27846384 100644
--- a/tests/inlineasm/asmdiv.py
+++ b/tests/inlineasm/asmdiv.py
@@ -2,15 +2,17 @@
def sdiv(r0, r1):
sdiv(r0, r0, r1)
+
@micropython.asm_thumb
def udiv(r0, r1):
udiv(r0, r0, r1)
+
print(sdiv(1234, 3))
print(sdiv(-1234, 3))
print(sdiv(1234, -3))
print(sdiv(-1234, -3))
print(udiv(1234, 3))
-print(udiv(0xffffffff, 0x7fffffff))
-print(udiv(0xffffffff, 0xffffffff))
+print(udiv(0xFFFFFFFF, 0x7FFFFFFF))
+print(udiv(0xFFFFFFFF, 0xFFFFFFFF))
diff --git a/tests/inlineasm/asmfpaddsub.py b/tests/inlineasm/asmfpaddsub.py
index b5fcecb6c..f69c89cdc 100644
--- a/tests/inlineasm/asmfpaddsub.py
+++ b/tests/inlineasm/asmfpaddsub.py
@@ -1,4 +1,4 @@
-@micropython.asm_thumb # r0 = r0+r1-r2
+@micropython.asm_thumb # r0 = r0+r1-r2
def add_sub(r0, r1, r2):
vmov(s0, r0)
vcvt_f32_s32(s0, s0)
@@ -11,5 +11,5 @@ def add_sub(r0, r1, r2):
vcvt_s32_f32(s31, s0)
vmov(r0, s31)
-print(add_sub(100, 20, 30))
+print(add_sub(100, 20, 30))
diff --git a/tests/inlineasm/asmfpcmp.py b/tests/inlineasm/asmfpcmp.py
index d4fa1f241..47fd99a34 100644
--- a/tests/inlineasm/asmfpcmp.py
+++ b/tests/inlineasm/asmfpcmp.py
@@ -1,4 +1,4 @@
-@micropython.asm_thumb # test vcmp, vmrs
+@micropython.asm_thumb # test vcmp, vmrs
def f(r0, r1):
vmov(s0, r0)
vcvt_f32_s32(s0, s0)
@@ -9,6 +9,7 @@ def f(r0, r1):
mov(r1, 28)
lsr(r0, r1)
-print(f(0,1))
-print(f(1,1))
-print(f(1,0))
+
+print(f(0, 1))
+print(f(1, 1))
+print(f(1, 0))
diff --git a/tests/inlineasm/asmfpldrstr.py b/tests/inlineasm/asmfpldrstr.py
index 0efb50bb0..96cd0c23e 100644
--- a/tests/inlineasm/asmfpldrstr.py
+++ b/tests/inlineasm/asmfpldrstr.py
@@ -1,12 +1,14 @@
import uarray as array
-@micropython.asm_thumb # test vldr, vstr
+
+
+@micropython.asm_thumb # test vldr, vstr
def arrayadd(r0):
vldr(s0, [r0, 0])
vldr(s1, [r0, 4])
vadd(s2, s0, s1)
vstr(s2, [r0, 8])
+
z = array.array("f", [2, 4, 10])
arrayadd(z)
print(z[2])
-
diff --git a/tests/inlineasm/asmfpmuldiv.py b/tests/inlineasm/asmfpmuldiv.py
index edf9511bc..930ddd053 100644
--- a/tests/inlineasm/asmfpmuldiv.py
+++ b/tests/inlineasm/asmfpmuldiv.py
@@ -1,4 +1,4 @@
-@micropython.asm_thumb # r0 = (int)(r0*r1/r2)
+@micropython.asm_thumb # r0 = (int)(r0*r1/r2)
def muldiv(r0, r1, r2):
vmov(s0, r0)
vcvt_f32_s32(s0, s0)
@@ -11,5 +11,5 @@ def muldiv(r0, r1, r2):
vcvt_s32_f32(s31, s8)
vmov(r0, s31)
-print(muldiv(100, 10, 50))
+print(muldiv(100, 10, 50))
diff --git a/tests/inlineasm/asmfpsqrt.py b/tests/inlineasm/asmfpsqrt.py
index f2c2d3a95..519fde4fc 100644
--- a/tests/inlineasm/asmfpsqrt.py
+++ b/tests/inlineasm/asmfpsqrt.py
@@ -1,5 +1,5 @@
# test vsqrt, vneg
-@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
+@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
@@ -11,5 +11,5 @@ def sqrt_test(r0, r1):
vcvt_s32_f32(s31, s7)
vmov(r0, s31)
-print(sqrt_test(256, 10))
+print(sqrt_test(256, 10))
diff --git a/tests/inlineasm/asmit.py b/tests/inlineasm/asmit.py
index 57bfcc7f9..640258e7c 100644
--- a/tests/inlineasm/asmit.py
+++ b/tests/inlineasm/asmit.py
@@ -1,16 +1,22 @@
# test it instruction
+
@micropython.asm_thumb
def f(r0, r1):
cmp(r0, r1)
it(eq)
mov(r0, 100)
+
+
print(f(0, 0), f(1, 2))
+
@micropython.asm_thumb
def g(r0, r1):
cmp(r0, r1)
ite(eq)
mov(r0, 100)
mov(r0, 200)
+
+
print(g(0, 0), g(0, 1))
diff --git a/tests/inlineasm/asmpushpop.py b/tests/inlineasm/asmpushpop.py
index c9005434b..74e729dfa 100644
--- a/tests/inlineasm/asmpushpop.py
+++ b/tests/inlineasm/asmpushpop.py
@@ -5,4 +5,5 @@ def f(r0, r1, r2):
pop({r0})
pop({r1, r2})
+
print(f(0, 1, 2))
diff --git a/tests/inlineasm/asmrettype.py b/tests/inlineasm/asmrettype.py
index f1918696e..95068795d 100644
--- a/tests/inlineasm/asmrettype.py
+++ b/tests/inlineasm/asmrettype.py
@@ -1,21 +1,33 @@
# test return type of inline asm
+
@micropython.asm_thumb
def ret_obj(r0) -> object:
pass
+
+
ret_obj(print)(1)
+
@micropython.asm_thumb
def ret_bool(r0) -> bool:
pass
+
+
print(ret_bool(0), ret_bool(1))
+
@micropython.asm_thumb
def ret_int(r0) -> int:
lsl(r0, r0, 29)
+
+
print(ret_int(0), hex(ret_int(1)), hex(ret_int(2)), hex(ret_int(4)))
+
@micropython.asm_thumb
def ret_uint(r0) -> uint:
lsl(r0, r0, 29)
+
+
print(ret_uint(0), hex(ret_uint(1)), hex(ret_uint(2)), hex(ret_uint(4)))
diff --git a/tests/inlineasm/asmshift.py b/tests/inlineasm/asmshift.py
index 0df218734..ba4c21b3f 100644
--- a/tests/inlineasm/asmshift.py
+++ b/tests/inlineasm/asmshift.py
@@ -1,29 +1,46 @@
@micropython.asm_thumb
def lsl1(r0):
lsl(r0, r0, 1)
+
+
print(hex(lsl1(0x123)))
+
@micropython.asm_thumb
def lsl23(r0):
lsl(r0, r0, 23)
+
+
print(hex(lsl23(1)))
+
@micropython.asm_thumb
def lsr1(r0):
lsr(r0, r0, 1)
+
+
print(hex(lsr1(0x123)))
+
@micropython.asm_thumb
def lsr31(r0):
lsr(r0, r0, 31)
+
+
print(hex(lsr31(0x80000000)))
+
@micropython.asm_thumb
def asr1(r0):
asr(r0, r0, 1)
+
+
print(hex(asr1(0x123)))
+
@micropython.asm_thumb
def asr31(r0):
asr(r0, r0, 31)
+
+
print(hex(asr31(0x80000000)))
diff --git a/tests/inlineasm/asmspecialregs.py b/tests/inlineasm/asmspecialregs.py
index edfe4c2bd..053ae29a4 100644
--- a/tests/inlineasm/asmspecialregs.py
+++ b/tests/inlineasm/asmspecialregs.py
@@ -2,10 +2,11 @@
def getIPSR():
mrs(r0, IPSR)
+
@micropython.asm_thumb
def getBASEPRI():
mrs(r0, BASEPRI)
+
print(getBASEPRI())
print(getIPSR())
-
diff --git a/tests/inlineasm/asmsum.py b/tests/inlineasm/asmsum.py
index 93d8eec8d..6535a495d 100644
--- a/tests/inlineasm/asmsum.py
+++ b/tests/inlineasm/asmsum.py
@@ -22,6 +22,7 @@ def asm_sum_words(r0, r1):
mov(r0, r2)
+
@micropython.asm_thumb
def asm_sum_bytes(r0, r1):
@@ -46,16 +47,17 @@ def asm_sum_bytes(r0, r1):
mov(r0, r2)
+
import uarray as array
-b = array.array('l', (100, 200, 300, 400))
+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))
+b = array.array("b", (10, 20, 30, 40, 50, 60, 70, 80))
n = asm_sum_bytes(len(b), b)
print(b, n)
-b = b'\x01\x02\x03\x04'
+b = b"\x01\x02\x03\x04"
n = asm_sum_bytes(len(b), b)
print(b, n)