fatal("Over!\n"); \
} while (0)
+#define VOODOO_OFFSETOF_ARRAY(type, field, index) \
+ (offsetof(type, field[0]) + \
+ ((index) * sizeof(((type *)0)->field[0])))
+
+#define VOODOO_OFFSETOF_ARRAY_MEMBER(type, field, index, member) \
+ (offsetof(type, field[0].member) + \
+ ((index) * sizeof(((type *)0)->field[0])))
+
static __m128i xmm_01_w;// = 0x0001000100010001ull;
static __m128i xmm_ff_w;// = 0x00ff00ff00ff00ffull;
addbyte(0xd0);
addbyte(0x03); /*ADD EAX, state->lod*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, tmu[tmu].lod));
+ addlong(VOODOO_OFFSETOF_ARRAY_MEMBER(voodoo_state_t, tmu, tmu, lod));
addbyte(0x3b); /*CMP EAX, state->lod_min*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_min[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_min, tmu));
addbyte(0x0f); /*CMOVL EAX, state->lod_min*/
addbyte(0x4c);
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_min[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_min, tmu));
addbyte(0x3b); /*CMP EAX, state->lod_max*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_max[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_max, tmu));
addbyte(0x0f); /*CMOVNL EAX, state->lod_max*/
addbyte(0x4d);
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_max[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_max, tmu));
addbyte(0xc1); /*SHR EAX, 8*/
addbyte(0xe8);
addbyte(8);
addbyte(28);
addbyte(0x8b); /*MOV EBX, state->lod_min*/
addbyte(0x9f);
- addlong(offsetof(voodoo_state_t, lod_min[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_min, tmu));
addbyte(0x48); /*SHR RCX, 28*/
addbyte(0xc1);
addbyte(0xe9);
addbyte(0x8b);
addbyte(0xac);
addbyte(0xcf);
- addlong(offsetof(voodoo_state_t, tex[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, tex, tmu));
addbyte(0x88); /*MOV CL, DL*/
addbyte(0xd1);
addbyte(0x89); /*MOV EDX, EBX*/
{
addbyte(0x23); /*AND EAX, params->tex_w_mask[ESI]*/
addbyte(0x86);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu));
}
addbyte(0x83); /*ADD EDX, 1*/
addbyte(0xc2);
addbyte(0x12);
addbyte(0x3b); /*CMP EDX, params->tex_h_mask[ESI]*/
addbyte(0x96);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x0f); /*CMOVA EDX, params->tex_h_mask[ESI]*/
addbyte(0x47);
addbyte(0x96);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x85); /*TEST EBX,EBX*/
addbyte(0xdb);
addbyte(0x41); /*CMOVS EBX, R10(alookup[0](zero))*/
addbyte(0x1a);
addbyte(0x3b); /*CMP EBX, params->tex_h_mask[ESI]*/
addbyte(0x9e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x0f); /*CMOVA EBX, params->tex_h_mask[ESI]*/
addbyte(0x47);
addbyte(0x9e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
}
else
{
addbyte(0x23); /*AND EDX, params->tex_h_mask[ESI]*/
addbyte(0x96);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x23); /*AND EBX, params->tex_h_mask[ESI]*/
addbyte(0x9e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
}
/*EAX = S, EBX = T0, EDX = T1*/
addbyte(0xd3); /*SHL EBX, CL*/
{
addbyte(0x8b); /*MOV EBP, params->tex_w_mask[ESI]*/
addbyte(0xae);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu));
addbyte(0x85); /*TEST EAX, EAX*/
addbyte(0xc0);
addbyte(0x8b); /*MOV ebp_store2, RSI*/
{
addbyte(0x3b); /*CMP EAX, params->tex_w_mask[ESI] - is S at texture edge (ie will wrap/clamp)?*/
addbyte(0x86);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu));
addbyte(0x8b); /*MOV ebp_store2, ESI*/
addbyte(0xb7);
addlong(offsetof(voodoo_state_t, ebp_store));
addbyte(0x8b);
addbyte(0xac);
addbyte(0xcf);
- addlong(offsetof(voodoo_state_t, tex[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, tex, tmu));
addbyte(0x28); /*SUB DL, CL*/
addbyte(0xca);
addbyte(0x80); /*ADD CL, 4*/
addbyte(0x3b); /*CMP EAX, params->tex_w_mask[ESI+ECX*4]*/
addbyte(0x84);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu) - 0x10);
addbyte(0x0f); /*CMOVAE EAX, params->tex_w_mask[ESI+ECX*4]*/
addbyte(0x43);
addbyte(0x84);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu) - 0x10);
}
else
addbyte(0x23); /*AND EAX, params->tex_w_mask-0x10[ESI+ECX*4]*/
addbyte(0x84);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu) - 0x10);
}
if (state->clamp_t[tmu])
{
addbyte(0x3b); /*CMP EBX, params->tex_h_mask[ESI+ECX*4]*/
addbyte(0x9c);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu) - 0x10);
addbyte(0x0f); /*CMOVAE EBX, params->tex_h_mask[ESI+ECX*4]*/
addbyte(0x43);
addbyte(0x9c);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu) - 0x10);
}
else
{
addbyte(0x23); /*AND EBX, params->tex_h_mask-0x10[ESI+ECX*4]*/
addbyte(0x9c);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu) - 0x10);
}
addbyte(0x88); /*MOV CL, DL*/
addbyte(0xd1);
munmap(voodoo->codegen_data, sizeof(voodoo_x86_data_t) * BLOCK_NUM*4);
#endif
}
-
fatal("Over!\n"); \
} while (0)
+#define VOODOO_OFFSETOF_ARRAY(type, field, index) \
+ (offsetof(type, field[0]) + \
+ ((index) * sizeof(((type *)0)->field[0])))
+
+#define VOODOO_OFFSETOF_ARRAY_MEMBER(type, field, index, member) \
+ (offsetof(type, field[0].member) + \
+ ((index) * sizeof(((type *)0)->field[0])))
+
static __m128i xmm_01_w;// = 0x0001000100010001ull;
static __m128i xmm_ff_w;// = 0x00ff00ff00ff00ffull;
addbyte(0xd8);
addbyte(0x03); /*ADD EAX, state->lod*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, tmu[tmu].lod));
+ addlong(VOODOO_OFFSETOF_ARRAY_MEMBER(voodoo_state_t, tmu, tmu, lod));
addbyte(0x3b); /*CMP EAX, state->lod_min*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_min[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_min, tmu));
addbyte(0x0f); /*CMOVL EAX, state->lod_min*/
addbyte(0x4c);
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_min[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_min, tmu));
addbyte(0x3b); /*CMP EAX, state->lod_max*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_max[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_max, tmu));
addbyte(0x0f); /*CMOVNL EAX, state->lod_max*/
addbyte(0x4d);
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_max[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_max, tmu));
addbyte(0x0f); /*MOVZX EBX, AL*/
addbyte(0xb6);
addbyte(0xd8);
addbyte(8);
addbyte(0x89); /*MOV state->lod_frac[tmu], EBX*/
addbyte(0x9f);
- addlong(offsetof(voodoo_state_t, lod_frac[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_frac, tmu));
addbyte(0x89); /*MOV state->lod, EAX*/
addbyte(0x87);
addlong(offsetof(voodoo_state_t, lod));
addlong(tmu ? offsetof(voodoo_state_t, tmu1_t) : offsetof(voodoo_state_t, tmu0_t));
addbyte(0xc7); /*MOV state->lod[tmu], 0*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_frac[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_frac, tmu));
addlong(0);
addbyte(0x8b); /*MOV EAX, state->lod_min*/
addbyte(0x87);
- addlong(offsetof(voodoo_state_t, lod_min[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_min, tmu));
addbyte(0x66); /*SHRQ XMM4, 28*/
addbyte(0x0f);
addbyte(0x73);
addlong(offsetof(voodoo_state_t, tex_t));
addbyte(0x89); /*MOV state->lod_frac[tmu], EBX*/
addbyte(0x9f);
- addlong(offsetof(voodoo_state_t, lod_frac[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, lod_frac, tmu));
addbyte(0x89); /*MOV state->lod, EAX*/
addbyte(0x87);
addlong(offsetof(voodoo_state_t, lod));
{
addbyte(0x8b); /*MOV ECX, state->tex_lod[tmu]*/
addbyte(0x8f);
- addlong(offsetof(voodoo_state_t, tex_lod[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, tex_lod, tmu));
addbyte(0xb2); /*MOV DL, 8*/
addbyte(8);
addbyte(0x8b); /*MOV ECX, [ECX+EAX*4]*/
addbyte(0x8b); /*MOV EBP, state->tex[EDI+ECX*4]*/
addbyte(0xac);
addbyte(0x8f);
- addlong(offsetof(voodoo_state_t, tex[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, tex, tmu));
addbyte(0x88); /*MOV CL, DL*/
addbyte(0xd1);
addbyte(0x89); /*MOV EDX, EBX*/
{
addbyte(0x23); /*AND EAX, params->tex_w_mask[ESI]*/
addbyte(0x86);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu));
}
addbyte(0x83); /*ADD EDX, 1*/
addbyte(0xc2);
addlong((uint32_t)&zero);
addbyte(0x3b); /*CMP EDX, params->tex_h_mask[ESI]*/
addbyte(0x96);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x0f); /*CMOVA EDX, params->tex_h_mask[ESI]*/
addbyte(0x47);
addbyte(0x96);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x85); /*TEST EBX,EBX*/
addbyte(0xdb);
addbyte(0x0f); /*CMOVS EBX, zero*/
addlong((uint32_t)&zero);
addbyte(0x3b); /*CMP EBX, params->tex_h_mask[ESI]*/
addbyte(0x9e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x0f); /*CMOVA EBX, params->tex_h_mask[ESI]*/
addbyte(0x47);
addbyte(0x9e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
}
else
{
addbyte(0x23); /*AND EDX, params->tex_h_mask[ESI]*/
addbyte(0x96);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
addbyte(0x23); /*AND EBX, params->tex_h_mask[ESI]*/
addbyte(0x9e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu));
}
/*EAX = S, EBX = T0, EDX = T1*/
addbyte(0xd3); /*SHL EBX, CL*/
{
addbyte(0x8b); /*MOV EBP, params->tex_w_mask[ESI]*/
addbyte(0xae);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu));
addbyte(0x85); /*TEST EAX, EAX*/
addbyte(0xc0);
addbyte(0x8b); /*MOV ESI, ebp_store*/
{
addbyte(0x3b); /*CMP EAX, params->tex_w_mask[ESI] - is S at texture edge (ie will wrap/clamp)?*/
addbyte(0x86);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu));
addbyte(0x8b); /*MOV ESI, ebp_store*/
addbyte(0xb7);
addlong(offsetof(voodoo_state_t, ebp_store));
{
addbyte(0x8b); /*MOV ECX, state->tex_lod[tmu]*/
addbyte(0x8f);
- addlong(offsetof(voodoo_state_t, tex_lod[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, tex_lod, tmu));
addbyte(0xb2); /*MOV DL, 8*/
addbyte(8);
addbyte(0x8b); /*MOV ECX, [ECX+EAX*4]*/
addbyte(0x8b); /*MOV EBP, state->tex[EDI+ECX*4]*/
addbyte(0xac);
addbyte(0x8f);
- addlong(offsetof(voodoo_state_t, tex[tmu]));
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_state_t, tex, tmu));
addbyte(0x28); /*SUB DL, CL*/
addbyte(0xca);
addbyte(0x80); /*ADD CL, 4*/
addbyte(0x3b); /*CMP EAX, params->tex_w_mask[ESI+ECX*4]*/
addbyte(0x84);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu) - 0x10);
addbyte(0x0f); /*CMOVAE EAX, params->tex_w_mask[ESI+ECX*4]*/
addbyte(0x43);
addbyte(0x84);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu) - 0x10);
}
else
addbyte(0x23); /*AND EAX, params->tex_w_mask-0x10[ESI+ECX*4]*/
addbyte(0x84);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_w_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_w_mask, tmu) - 0x10);
}
if (state->clamp_t[tmu])
{
addbyte(0x3b); /*CMP EBX, params->tex_h_mask[ESI+ECX*4]*/
addbyte(0x9c);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu) - 0x10);
addbyte(0x0f); /*CMOVAE EBX, params->tex_h_mask[ESI+ECX*4]*/
addbyte(0x43);
addbyte(0x9c);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu) - 0x10);
}
else
{
addbyte(0x23); /*AND EBX, params->tex_h_mask-0x10[ESI+ECX*4]*/
addbyte(0x9c);
addbyte(0x8e);
- addlong(offsetof(voodoo_params_t, tex_h_mask[tmu]) - 0x10);
+ addlong(VOODOO_OFFSETOF_ARRAY(voodoo_params_t, tex_h_mask, tmu) - 0x10);
}
addbyte(0x88); /*MOV CL, DL*/
addbyte(0xd1);