summaryrefslogtreecommitdiff
path: root/tests/inlineasm/rv32/asmarith.py
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2024-08-25 16:28:35 +0200
committerDamien George <damien@micropython.org>2025-01-02 11:49:10 +1100
commit268acb714dd79fa5eeeb82c1fca022bc4ea126b7 (patch)
tree428ed75070ee89847fd5087095e3d7331d5f9b26 /tests/inlineasm/rv32/asmarith.py
parent3044233ea3726e9d8727d8f6a76f32c48e6fae5e (diff)
py/emitinlinerv32: Add inline assembler support for RV32.
This commit adds support for writing inline assembler functions when targeting a RV32IMC processor. Given that this takes up a bit of rodata space due to its large instruction decoding table and its extensive error messages, it is enabled by default only on offline targets such as mpy-cross and the qemu port. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Diffstat (limited to 'tests/inlineasm/rv32/asmarith.py')
-rw-r--r--tests/inlineasm/rv32/asmarith.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/inlineasm/rv32/asmarith.py b/tests/inlineasm/rv32/asmarith.py
new file mode 100644
index 000000000..8b864c0b3
--- /dev/null
+++ b/tests/inlineasm/rv32/asmarith.py
@@ -0,0 +1,79 @@
+# test arithmetic opcodes
+
+
+@micropython.asm_rv32
+def f1():
+ li(a0, 0x100)
+ li(a1, 1)
+ add(a0, a0, a1)
+ addi(a0, a0, 1)
+ addi(a0, a0, -2)
+ sub(a0, a0, a1)
+ c_add(a0, a1)
+ c_addi(a0, -1)
+ c_sub(a0, a1)
+
+
+print(hex(f1()))
+
+
+@micropython.asm_rv32
+def f2():
+ li(a0, 0x10FF)
+ li(a1, 1)
+ and_(a2, a0, a1)
+ andi(a3, a0, 0x10)
+ or_(a2, a2, a3)
+ ori(a2, a2, 8)
+ li(a1, 0x200)
+ c_or(a2, a1)
+ li(a1, 0xF0)
+ mv(a0, a2)
+ c_and(a0, a1)
+ li(a1, 0x101)
+ xor(a0, a0, a1)
+ xori(a0, a0, 0x101)
+ c_xor(a0, a1)
+
+
+print(hex(f2()))
+
+
+@micropython.asm_rv32
+def f3(a0, a1):
+ slt(a0, a0, a1)
+
+
+print(f3(0xFFFFFFF0, 0xFFFFFFF1))
+print(f3(0x0, 0xFFFFFFF1))
+print(f3(0xFFFFFFF1, 0xFFFFFFF1))
+print(f3(0xFFFFFFF1, 0xFFFFFFF0))
+
+
+@micropython.asm_rv32
+def f4(a0, a1):
+ sltu(a0, a0, a1)
+
+
+print(f3(0xFFFFFFF0, 0xFFFFFFF1))
+print(f3(0x0, 0xFFFFFFF1))
+print(f3(0xFFFFFFF1, 0xFFFFFFF1))
+print(f3(0xFFFFFFF1, 0xFFFFFFF0))
+
+
+@micropython.asm_rv32
+def f5(a0):
+ slti(a0, a0, -2)
+
+
+print(f5(-1))
+print(f5(-3))
+
+
+@micropython.asm_rv32
+def f6(a0):
+ sltiu(a0, a0, -2)
+
+
+print(f6(-1))
+print(f6(-3))