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

This commit is contained in:
Damien George 2014-09-29 21:41:41 +00:00
parent e9dac3b4d0
commit dfef4249eb
3 changed files with 36 additions and 1 deletions

View File

@ -1391,7 +1391,10 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
assert(vtype_value == VTYPE_PYOBJ); assert(vtype_value == VTYPE_PYOBJ);
emit_call(emit, MP_F_OBJ_SUBSCR); emit_call(emit, MP_F_OBJ_SUBSCR);
} else { } 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); stack_info_t *top = peek_stack(emit, 0);
if (top->vtype == VTYPE_INT && top->kind == STACK_IMM) { if (top->vtype == VTYPE_INT && top->kind == STACK_IMM) {
// index is an immediate // 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_index = REG_ARG_2;
int reg_value = REG_ARG_3; int reg_value = REG_ARG_3;
emit_pre_pop_reg_flexible(emit, &vtype_base, &reg_base, reg_index, reg_value); 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); emit_pre_pop_reg_flexible(emit, &vtype_value, &reg_value, reg_base, reg_index);
#endif
switch (vtype_base) { switch (vtype_base) {
case VTYPE_PTR8: { case VTYPE_PTR8: {
// pointer to 8-bit memory // pointer to 8-bit memory
@ -1449,7 +1457,12 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
int reg_value = REG_ARG_3; 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_flexible(emit, &vtype_index, &reg_index, REG_ARG_1, reg_value);
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); 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); emit_pre_pop_reg_flexible(emit, &vtype_value, &reg_value, REG_ARG_1, reg_index);
#endif
switch (vtype_base) { switch (vtype_base) {
case VTYPE_PTR8: { case VTYPE_PTR8: {
// pointer to 8-bit memory // pointer to 8-bit memory

View File

@ -0,0 +1,19 @@
# 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)

View File

@ -0,0 +1,3 @@
bytearray(b'\x00\x00\x00\x00')
bytearray(b'BB\x00\x00')
bytearray(b'CCCC')