Commit dfef4249 authored by Damien George's avatar Damien George
Browse files

py: Fix viper store on x86; add tests for viper ptr16.

parent e9dac3b4
......@@ -1391,7 +1391,10 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
assert(vtype_value == VTYPE_PYOBJ);
emit_call(emit, MP_F_OBJ_SUBSCR);
} else {
// viper call
// viper store
// TODO The different machine architectures have very different
// capabilities and requirements for stores, so probably best to
// write a completely separate store-optimiser for each one.
stack_info_t *top = peek_stack(emit, 0);
if (top->vtype == VTYPE_INT && top->kind == STACK_IMM) {
// index is an immediate
......@@ -1402,7 +1405,12 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
int reg_index = REG_ARG_2;
int reg_value = REG_ARG_3;
emit_pre_pop_reg_flexible(emit, &vtype_base, &reg_base, reg_index, reg_value);
#if N_X86
// special case: x86 needs byte stores to be from lower 4 regs (REG_ARG_3 is EDX)
emit_pre_pop_reg(emit, &vtype_value, reg_value);
#else
emit_pre_pop_reg_flexible(emit, &vtype_value, &reg_value, reg_base, reg_index);
#endif
switch (vtype_base) {
case VTYPE_PTR8: {
// pointer to 8-bit memory
......@@ -1449,7 +1457,12 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
int reg_value = REG_ARG_3;
emit_pre_pop_reg_flexible(emit, &vtype_index, &reg_index, REG_ARG_1, reg_value);
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1);
#if N_X86
// special case: x86 needs byte stores to be from lower 4 regs (REG_ARG_3 is EDX)
emit_pre_pop_reg(emit, &vtype_value, reg_value);
#else
emit_pre_pop_reg_flexible(emit, &vtype_value, &reg_value, REG_ARG_1, reg_index);
#endif
switch (vtype_base) {
case VTYPE_PTR8: {
// pointer to 8-bit memory
......
# test ptr16 type
@micropython.viper
def set(dest:ptr16, val:int):
dest[0] = val
@micropython.viper
def memset(dest:ptr16, val:int, n:int):
for i in range(n):
dest[i] = val
b = bytearray(4)
print(b)
set(b, 0x4242)
print(b)
memset(b, 0x4343, len(b) // 2)
print(b)
bytearray(b'\x00\x00\x00\x00')
bytearray(b'BB\x00\x00')
bytearray(b'CCCC')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment