diff options
| author | Keith Whitwell <keith@tungstengraphics.com> | 2008-05-01 20:41:03 +0100 | 
|---|---|---|
| committer | Keith Whitwell <keith@tungstengraphics.com> | 2008-05-01 20:49:45 +0100 | 
| commit | fb3623b235f5caa9d76e656b1e5eda797c7c73eb (patch) | |
| tree | 0e51644fe7b0d5de341c9439f28aec3b6813162e /src/gallium/auxiliary/rtasm | |
| parent | b8936ca1c22de7b0cb695ee3b392e4473fd17aa0 (diff) | |
rtasm: fix labels after (not so) recent change to allow dynamic fn growth
Using char * for labels doesn't work if you realloc the function
during assembly and free the old storage...
Diffstat (limited to 'src/gallium/auxiliary/rtasm')
| -rw-r--r-- | src/gallium/auxiliary/rtasm/rtasm_x86sse.c | 49 | ||||
| -rw-r--r-- | src/gallium/auxiliary/rtasm/rtasm_x86sse.h | 14 | 
2 files changed, 25 insertions, 38 deletions
diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c index 40f6f973d6..e69251f072 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c @@ -347,9 +347,9 @@ struct x86_reg x86_get_base_reg( struct x86_reg reg )     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;  } @@ -361,17 +361,22 @@ unsigned char *x86_get_label( struct x86_function *p )  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);     } @@ -379,8 +384,8 @@ void x86_jcc( struct x86_function *p,  /* 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); @@ -388,7 +393,7 @@ unsigned char *x86_jcc_forward( struct x86_function *p,     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); @@ -396,7 +401,7 @@ unsigned char *x86_jmp_forward( struct x86_function *p)     return x86_get_label(p);  } -unsigned char *x86_call_forward( struct x86_function *p) +int x86_call_forward( struct x86_function *p)  {     DUMP(); @@ -408,42 +413,24 @@ unsigned char *x86_call_forward( struct x86_function *p)  /* 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: diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h index ad79b1facf..eacaeeaf6f 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h @@ -124,23 +124,23 @@ struct x86_reg x86_get_base_reg( struct x86_reg reg );  /* 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);  | 
