mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 21:11:12 +02:00
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>
64 lines
990 B
Python
64 lines
990 B
Python
@micropython.asm_rv32
|
|
def sdiv(a0, a1):
|
|
div(a0, a0, a1)
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def udiv(a0, a1):
|
|
divu(a0, a0, a1)
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def srem(a0, a1):
|
|
rem(a0, a0, a1)
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def urem(a0, a1):
|
|
remu(a0, a0, a1)
|
|
|
|
|
|
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(srem(1234, 3))
|
|
print(srem(-1234, 3))
|
|
print(srem(1234, -3))
|
|
print(srem(-1234, -3))
|
|
|
|
print(urem(1234, 3))
|
|
print(urem(0xFFFFFFFF, 0x7FFFFFFF))
|
|
print(urem(0xFFFFFFFF, 0xFFFFFFFF))
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def m1(a0, a1):
|
|
mul(a0, a0, a1)
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def m2(a0, a1):
|
|
mulh(a0, a0, a1)
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def m3(a0, a1):
|
|
mulhu(a0, a0, a1)
|
|
|
|
|
|
@micropython.asm_rv32
|
|
def m4(a0, a1):
|
|
mulhsu(a0, a0, a1)
|
|
|
|
|
|
print(m1(0xFFFFFFFF, 2))
|
|
print(m2(0xFFFFFFFF, 0xFFFFFFF0))
|
|
print(m3(0xFFFFFFFF, 0xFFFFFFF0))
|
|
print(m4(0xFFFFFFFF, 0xFFFFFFF0))
|