circuitpython/tests/micropython/viper_misc2.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
558 B
Python
Raw Normal View History

# Miscellaneous viper tests
2023-02-01 03:08:41 -05:00
# Test correct use of registers in load and store
@micropython.viper
def expand(dest: ptr8, source: ptr8, length: int):
n = 0
for x in range(0, length, 2):
c = source[x]
d = source[x + 1]
dest[n] = (c & 0xE0) | ((c & 0x1C) >> 1)
n += 1
dest[n] = ((c & 3) << 6) | ((d & 0xE0) >> 4)
n += 1
dest[n] = ((d & 0x1C) << 3) | ((d & 3) << 2)
n += 1
source = b"\xaa\xaa\xff\xff"
dest = bytearray(len(source) // 2 * 3)
expand(dest, source, len(source))
print(dest)