fix some int arithmetic problems

This commit is contained in:
Brian
2007-03-06 14:07:48 -07:00
parent 28ab1125c2
commit e10a1457e8
3 changed files with 791 additions and 755 deletions
+77 -53
View File
@@ -537,116 +537,140 @@ mat4 __constructor(const vec4 r0, const vec4 r1, const vec4 r2, const vec4 r3)
int __operator + (const int a, const int b)
{
float x, y;
int c;
__asm int_to_float x, a;
__asm int_to_float y, b;
__asm vec4_add x.x, x.x, y.x;
__asm float_to_int c, x;
return c;
// XXX If we ever have int registers, we'll do something like this:
// XXX For now, mostly treat ints as floats.
// float x, y;
// __asm int_to_float x, a;
// __asm int_to_float y, b;
// __asm vec4_add x.x, x.x, y.x;
// __asm float_to_int __retVal, x;
float x;
__asm vec4_add x, a, b;
__asm float_to_int __retVal, x;
}
int __operator - (const int a, const int b)
{
float x, y;
int c;
__asm int_to_float x, a;
__asm int_to_float y, b;
__asm float_negate y, y;
__asm vec4_add x.x, x.x, y.x;
__asm float_to_int c, x;
return c;
float x;
__asm vec4_subtract x, a, b;
__asm float_to_int __retVal, x;
}
int __operator * (const int a, const int b)
{
float x, y;
int c;
__asm int_to_float x, a;
__asm int_to_float y, b;
__asm float_multiply x, x, y;
__asm float_to_int c, x;
return c;
float x;
__asm vec4_multiply x, a, b;
__asm float_to_int __retVal, x;
}
int __operator / (const int a, const int b)
{
float x, y;
int c;
__asm int_to_float x, a;
__asm int_to_float y, b;
__asm float_divide x, x, y;
__asm float_to_int c, x;
return c;
float bInv, x;
__asm float_rcp bInv, b;
__asm vec4_multiply x, a, bInv;
__asm float_to_int __retVal, x;
}
//// Basic ivec2 operators
ivec2 __operator + (const ivec2 v, const ivec2 u)
ivec2 __operator + (const ivec2 a, const ivec2 b)
{
return ivec2 (v.x + u.x, v.y + u.y);
vec2 x;
__asm vec4_add x, a, b;
__asm float_to_int __retVal, x;
}
ivec2 __operator - (const ivec2 v, const ivec2 u)
ivec2 __operator - (const ivec2 a, const ivec2 b)
{
return ivec2 (v.x - u.x, v.y - u.y);
vec2 x;
__asm vec4_subtract x, a, b;
__asm float_to_int __retVal, x;
}
ivec2 __operator * (const ivec2 v, const ivec2 u)
ivec2 __operator * (const ivec2 a, const ivec2 b)
{
return ivec2 (v.x * u.x, v.y * u.y);
vec2 x;
__asm vec4_multiply x, a, b;
__asm float_to_int __retVal, x;
}
ivec2 __operator / (const ivec2 v, const ivec2 u)
ivec2 __operator / (const ivec2 a, const ivec2 b)
{
return ivec2 (v.x / u.x, v.y / u.y);
vec2 bInv, x;
__asm float_rcp bInv.x, b.x;
__asm float_rcp bInv.y, b.y;
__asm vec4_multiply x, a, bInv;
__asm float_to_int __retVal, x;
}
//// Basic ivec3 operators
ivec3 __operator + (const ivec3 v, const ivec3 u)
ivec3 __operator + (const ivec3 a, const ivec3 b)
{
return ivec3 (v.x + u.x, v.y + u.y, v.z + u.z);
vec3 x;
__asm vec4_add x, a, b;
__asm float_to_int __retVal, x;
}
ivec3 __operator - (const ivec3 v, const ivec3 u)
ivec3 __operator - (const ivec3 a, const ivec3 b)
{
return ivec3 (v.x - u.x, v.y - u.y, v.z - u.z);
vec3 x;
__asm vec4_subtract x, a, b;
__asm float_to_int __retVal, x;
}
ivec3 __operator * (const ivec3 v, const ivec3 u)
ivec3 __operator * (const ivec3 a, const ivec3 b)
{
return ivec3 (v.x * u.x, v.y * u.y, v.z * u.z);
vec3 x;
__asm vec4_multiply x, a, b;
__asm float_to_int __retVal, x;
}
ivec3 __operator / (const ivec3 v, const ivec3 u)
ivec3 __operator / (const ivec3 a, const ivec3 b)
{
return ivec3 (v.x / u.x, v.y / u.y, v.z / u.z);
vec3 bInv, x;
__asm float_rcp bInv.x, b.x;
__asm float_rcp bInv.y, b.y;
__asm float_rcp bInv.z, b.z;
__asm vec4_multiply x, a, bInv;
__asm float_to_int __retVal, x;
}
//// Basic ivec4 operators
ivec4 __operator + (const ivec4 v, const ivec4 u)
ivec4 __operator + (const ivec4 a, const ivec4 b)
{
return ivec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
vec3 x;
__asm vec4_add x, a, b;
__asm float_to_int __retVal, x;
}
ivec4 __operator - (const ivec4 v, const ivec4 u)
ivec4 __operator - (const ivec4 a, const ivec4 b)
{
return ivec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
vec4 x;
__asm vec4_subtract x, a, b;
__asm float_to_int __retVal, x;
}
ivec4 __operator * (const ivec4 v, const ivec4 u)
ivec4 __operator * (const ivec4 a, const ivec4 b)
{
return ivec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
vec4 x;
__asm vec4_multiply x, a, b;
__asm float_to_int __retVal, x;
}
ivec4 __operator / (const ivec4 v, const ivec4 u)
ivec4 __operator / (const ivec4 a, const ivec4 b)
{
return ivec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
vec4 bInv, x;
__asm float_rcp bInv.x, b.x;
__asm float_rcp bInv.y, b.y;
__asm float_rcp bInv.z, b.z;
__asm float_rcp bInv.w, b.w;
__asm vec4_multiply x, a, bInv;
__asm float_to_int __retVal, x;
}
File diff suppressed because it is too large Load Diff
+7 -3
View File
@@ -1482,9 +1482,13 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n)
return emit_swizzle(emitInfo, n);
case IR_I_TO_F:
{
n->Store = n->Children[0]->Store;
}
/* just move */
emit(emitInfo, n->Children[0]);
inst = new_instruction(emitInfo, OPCODE_MOV);
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
if (emitInfo->EmitComments)
inst->Comment = _mesa_strdup("int to float");
return NULL;
/* Simple arithmetic */