Branch: Tag:

2012-07-13

2012-07-13 15:43:29 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler (amd64): Load fp_reg more consistently.

Background:
Some of the opcode implementations use the C-implementation as
a fallback for the more complex cases. These typically use
amd64_call_c_opcode(), which calls maybe_update_pc(), which may
call UPDATE_PC(), which calls amd64_load_fp_reg(), which loads
fp_reg if it isn't thought to be loaded.

Problem:
This means that the opcodes in question sometimes will enter
with fp_reg not loaded, and exit with fp_reg thought to be
loaded even though it isn't loaded on all code-paths for the
opcode.

Solution:
This patch loads fp_reg in the instruction prologue under
the same circumstances where maybe_update_pc() would have
loaded it.

1262:    }   }    + static void maybe_load_fp(void) + { +  static int last_prog_id=-1; +  static size_t last_num_linenumbers=-1; +  +  if( + #ifdef PIKE_DEBUG +  /* Update the pc more often for the sake of the opcode level trace. */ +  d_flag || + #endif +  (amd64_prev_stored_pc == -1) || +  last_prog_id != Pike_compiler->new_program->id || +  last_num_linenumbers != Pike_compiler->new_program->num_linenumbers +  ) { +  amd64_load_fp_reg(); +  } + } +    static void sync_registers(int flags)   {    maybe_update_pc();
1284: Inside #if defined(PIKE_DEBUG)
  {    int flags = instrs[instr].flags;    +  /* Note: maybe_update_pc() is called by amd64_call_c_opcode() above, +  * which has the side-effect of loading fp_reg. Some of the +  * opcodes use amd64_call_c_opcode() in conditional segments. +  * This is to make sure that fp_reg is always loaded on exit +  * from such opcodes. +  */ +  +  maybe_load_fp(); +    /* For now: It is very hard to read the disassembled source when    this is inserted */    if( !d_flag )