return x86_make_reg( reg.file, reg.idx );
}
-unsigned char *x86_get_label( struct x86_function *p )
+int x86_get_label( struct x86_function *p )
{
- return p->csr;
+ return p->csr - p->store;
}
void x86_jcc( struct x86_function *p,
enum x86_cc cc,
- unsigned char *label )
+ int label )
{
- intptr_t offset = pointer_to_intptr( label ) - (pointer_to_intptr( x86_get_label(p) ) + 2);
+ int offset = label - (x86_get_label(p) + 2);
DUMP_I(cc);
+ if (offset < 0) {
+ int amt = p->csr - p->store;
+ assert(amt > -offset);
+ }
+
if (offset <= 127 && offset >= -128) {
emit_1ub(p, 0x70 + cc);
emit_1b(p, (char) offset);
}
else {
- offset = pointer_to_intptr( label ) - (pointer_to_intptr( x86_get_label(p) ) + 6);
+ offset = label - (x86_get_label(p) + 6);
emit_2ub(p, 0x0f, 0x80 + cc);
emit_1i(p, offset);
}
/* Always use a 32bit offset for forward jumps:
*/
-unsigned char *x86_jcc_forward( struct x86_function *p,
- enum x86_cc cc )
+int x86_jcc_forward( struct x86_function *p,
+ enum x86_cc cc )
{
DUMP_I(cc);
emit_2ub(p, 0x0f, 0x80 + cc);
return x86_get_label(p);
}
-unsigned char *x86_jmp_forward( struct x86_function *p)
+int x86_jmp_forward( struct x86_function *p)
{
DUMP();
emit_1ub(p, 0xe9);
return x86_get_label(p);
}
-unsigned char *x86_call_forward( struct x86_function *p)
+int x86_call_forward( struct x86_function *p)
{
DUMP();
/* Fixup offset from forward jump:
*/
void x86_fixup_fwd_jump( struct x86_function *p,
- unsigned char *fixup )
+ int fixup )
{
- *(int *)(fixup - 4) = pointer_to_intptr( x86_get_label(p) ) - pointer_to_intptr( fixup );
+ *(int *)(p->store + fixup - 4) = x86_get_label(p) - fixup;
}
-void x86_jmp( struct x86_function *p, unsigned char *label)
+void x86_jmp( struct x86_function *p, int label)
{
DUMP_I( label );
emit_1ub(p, 0xe9);
- emit_1i(p, pointer_to_intptr( label ) - pointer_to_intptr( x86_get_label(p) ) - 4);
-}
-
-#if 0
-static unsigned char *cptr( void (*label)() )
-{
- return (unsigned char *) label;
+ emit_1i(p, label - x86_get_label(p) - 4);
}
-/* This doesn't work once we start reallocating & copying the
- * generated code on buffer fills, because the call is relative to the
- * current pc.
- */
-void x86_call( struct x86_function *p, void (*label)())
-{
- DUMP_I( label );
- emit_1ub(p, 0xe8);
- emit_1i(p, cptr(label) - x86_get_label(p) - 4);
-}
-#else
void x86_call( struct x86_function *p, struct x86_reg reg)
{
DUMP_R( reg );
emit_1ub(p, 0xff);
emit_modrm_noreg(p, 2, reg);
}
-#endif
/* michal:
/* Labels, jumps and fixup:
*/
-unsigned char *x86_get_label( struct x86_function *p );
+int x86_get_label( struct x86_function *p );
void x86_jcc( struct x86_function *p,
enum x86_cc cc,
- unsigned char *label );
+ int label );
-unsigned char *x86_jcc_forward( struct x86_function *p,
+int x86_jcc_forward( struct x86_function *p,
enum x86_cc cc );
-unsigned char *x86_jmp_forward( struct x86_function *p);
+int x86_jmp_forward( struct x86_function *p);
-unsigned char *x86_call_forward( struct x86_function *p);
+int x86_call_forward( struct x86_function *p);
void x86_fixup_fwd_jump( struct x86_function *p,
- unsigned char *fixup );
+ int fixup );
-void x86_jmp( struct x86_function *p, unsigned char *label );
+void x86_jmp( struct x86_function *p, int label );
/* void x86_call( struct x86_function *p, void (*label)() ); */
void x86_call( struct x86_function *p, struct x86_reg reg);
struct x86_reg aos_input;
struct x86_reg num_inputs;
struct x86_reg temp;
- unsigned char *inner_loop;
+ int inner_loop;
soa_input = x86_make_reg( file_REG32, reg_AX );
aos_input = get_temp_base(); /* BX or SI */
struct x86_reg aos_output;
struct x86_reg num_outputs;
struct x86_reg temp;
- unsigned char *inner_loop;
+ int inner_loop;
soa_output = x86_make_reg( file_REG32, reg_AX );
aos_output = get_temp_base(); /* BX or SI */