pike.git / src / code / amd64.c

version» Context lines:

pike.git/src/code/amd64.c:1:   /*    * Machine code generator for AMD64.    */      #include "operators.h"   #include "constants.h"   #include "object.h"   #include "builtin_functions.h"       - /* This is defined on windows */ - #ifdef REG_NONE - #undef REG_NONE - #endif -  -  +    /* Register encodings */   enum amd64_reg {REG_RAX = 0, REG_RBX = 3, REG_RCX = 1, REG_RDX = 2,    REG_RSP = 4, REG_RBP = 5, REG_RSI = 6, REG_RDI = 7,    REG_R8 = 8, REG_R9 = 9, REG_R10 = 10, REG_R11 = 11,    REG_R12 = 12, REG_R13 = 13, REG_R14 = 14, REG_R15 = 15, -  REG_NONE = 4}; +  REG_INVALID = -1};      /* We reserve register r12 and above (as well as RSP, RBP and RBX). */   #define REG_BITMASK ((1 << REG_MAX) - 1)   #define REG_RESERVED (REG_RSP|REG_RBP|REG_RBX)   #define REG_MAX REG_R12   #define PIKE_MARK_SP_REG REG_R12   #define PIKE_SP_REG REG_R13   #define PIKE_FP_REG REG_R14   #define Pike_interpreter_reg REG_R15   
pike.git/src/code/amd64.c:96:    add_to_program( (x>>16)&0xff );    add_to_program( (x>>24)&0xff );   }      /* x86 opcodes */   #define opcode(X) ib(X)         static void modrm( int mod, int r, int m )   { +  if (r < 0) Pike_fatal("Using an invalid register(1)!\n"); +  if (m < 0) Pike_fatal("Using an invalid register(2)!\n");    ib( ((mod<<6) | ((r&0x7)<<3) | (m&0x7)) );   }      static void sib( int scale, int index, enum amd64_reg base )   {    ib( (scale<<6) | ((index&0x7)<<3) | (base&0x7) );   }         static void modrm_sib( int mod, int r, int m )
pike.git/src/code/amd64.c:151:    }   }      static void ret()   {    opcode(0xc3);   }      static void push(enum amd64_reg reg )   { +  if (reg < 0) Pike_fatal("Pushing invalid register.\n");    if (reg & 0x08) add_to_program(0x41);    add_to_program(0x50 + (reg & 0x07));   }      static void pop(enum amd64_reg reg )   { -  +  if (reg < 0) Pike_fatal("Popping invalid register.\n");    if (reg & 0x08) add_to_program(0x41);    add_to_program(0x58 + (reg & 0x07));   }      static void mov_reg_reg(enum amd64_reg from_reg, enum amd64_reg to_reg )   {    rex( 1, from_reg, 0, to_reg );    opcode( 0x89 );    modrm( 3, from_reg, to_reg );   }
pike.git/src/code/amd64.c:745:    push(REG_R13);    push(REG_R12);    push(REG_RBX);    sub_reg_imm(REG_RSP, 8); /* Align on 16 bytes. */       mov_reg_reg(ARG1_REG, Pike_interpreter_reg);       amd64_flush_code_generator_state();   }    - static enum amd64_reg sp_reg = 0, fp_reg = 0, mark_sp_reg = 0; + static enum amd64_reg sp_reg = -1, fp_reg = -1, mark_sp_reg = -1;   static int dirty_regs = 0, ret_for_func = 0;   ptrdiff_t amd64_prev_stored_pc = -1; /* PROG_PC at the last point Pike_fp->pc was updated. */   static int branch_check_threads_update_etc = -1;         void amd64_flush_code_generator_state(void)   { -  sp_reg = 0; -  fp_reg = 0; -  mark_sp_reg = 0; +  sp_reg = -1; +  fp_reg = -1; +  mark_sp_reg = -1;    dirty_regs = 0;    ret_for_func = 0;    amd64_prev_stored_pc = -1;    branch_check_threads_update_etc = -1;   }      static void flush_dirty_regs(void)   {    /* NB: PIKE_FP_REG is currently never dirty. */    if (dirty_regs & (1 << PIKE_SP_REG)) {
pike.git/src/code/amd64.c:783:    dirty_regs &= ~(1 << PIKE_MARK_SP_REG);    }   }         /* NB: We load Pike_fp et al into registers that    * are persistent across function calls.    */   void amd64_load_fp_reg(void)   { -  if (!fp_reg) { +  if (fp_reg < 0) {    mov_mem_reg(Pike_interpreter_reg,    OFFSETOF(Pike_interpreter_struct, frame_pointer),    PIKE_FP_REG);    fp_reg = PIKE_FP_REG;    }   }      void amd64_load_sp_reg(void)   { -  if (!sp_reg) { +  if (sp_reg < 0) {    mov_mem_reg(Pike_interpreter_reg,    OFFSETOF(Pike_interpreter_struct, stack_pointer),    PIKE_SP_REG);    sp_reg = PIKE_SP_REG;    }   }      void amd64_load_mark_sp_reg(void)   { -  if (!mark_sp_reg) { +  if (mark_sp_reg < 0) {    mov_mem_reg(Pike_interpreter_reg,    OFFSETOF(Pike_interpreter_struct, mark_stack_pointer),    PIKE_MARK_SP_REG);    mark_sp_reg = PIKE_MARK_SP_REG;    }   }      static void update_arg1(INT32 value)   {    mov_imm_reg(value, ARG1_REG);
pike.git/src/code/amd64.c:1107:    last_num_linenumbers = Pike_compiler->new_program->num_linenumbers;    UPDATE_PC();    }   }      static void sync_registers(int flags)   {    maybe_update_pc();    flush_dirty_regs();    -  if (flags & I_UPDATE_SP) sp_reg = 0; -  if (flags & I_UPDATE_M_SP) mark_sp_reg = 0; -  if (flags & I_UPDATE_FP) fp_reg = 0; +  if (flags & I_UPDATE_SP) sp_reg = REG_INVALID; +  if (flags & I_UPDATE_M_SP) mark_sp_reg = REG_INVALID; +  if (flags & I_UPDATE_FP) fp_reg = REG_INVALID;   }      static void amd64_call_c_opcode(void *addr, int flags)   {    sync_registers(flags);    call_imm( addr );   }         #ifdef PIKE_DEBUG