8000 py/emitnative: Fix x86-64 emitter to generate correct 8/16-bit stores. · salewski/micropython@5176a2d · GitHub
[go: up one dir, main page]

Skip to content

Commit 5176a2d

Browse files
committed
py/emitnative: Fix x86-64 emitter to generate correct 8/16-bit stores.
Fixes issue micropython#6643. Signed-off-by: Damien George <damien@micropython.org>
1 parent f49d47c commit 5176a2d

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

py/emitnative.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
17691769
int reg_index = REG_ARG_2;
17701770
int reg_value = REG_ARG_3;
17711771
emit_pre_pop_reg_flexible(emit, &vtype_base, &reg_base, reg_index, reg_value);
1772-
#if N_X86
1772+
#if N_X64 || N_X86
17731773
// special case: x86 needs byte stores to be from lower 4 regs (REG_ARG_3 is EDX)
17741774
emit_pre_pop_reg(emit, &vtype_value, reg_value);
17751775
#else
@@ -1856,7 +1856,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
18561856
EMIT_NATIVE_VIPER_TYPE_ERROR(emit,
18571857
MP_ERROR_TEXT("can't store with '%q' index"), vtype_to_qstr(vtype_index));
18581858
}
1859-
#if N_X86
1859+
#if N_X64 || N_X86
18601860
// special case: x86 needs byte stores to be from lower 4 regs (REG_ARG_3 is EDX)
18611861
emit_pre_pop_reg(emit, &vtype_value, reg_value);
18621862
#else

tests/micropython/viper_misc2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Miscellaneous viper tests
2+
3+
# Test correct use of registers in load and store
4+
@micropython.viper
5+
def expand(dest: ptr8, source: ptr8, length: int):
6+
n = 0
7+
for x in range(0, length, 2):
8+
c = source[x]
9+
d = source[x + 1]
10+
dest[n] = (c & 0xE0) | ((c & 0x1C) >> 1)
11+
n += 1
12+
dest[n] = ((c & 3) << 6) | ((d & 0xE0) >> 4)
13+
n += 1
14+
dest[n] = ((d & 0x1C) << 3) | ((d & 3) << 2)
15+
n += 1
16+
17+
18+
source = b"\xaa\xaa\xff\xff"
19+
dest = bytearray(len(source) // 2 * 3)
20+
expand(dest, source, len(source))
21+
print(dest)

tests/micropython/viper_misc2.py.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bytearray(b'\xa4\x8aH\xee\xce\xec')

0 commit comments

Comments
 (0)
0