int __constructor(const float f)
{
- __asm float_to_int __retVal, f;
+ __asm vec4_to_ivec4 __retVal, f;
}
int __constructor(const bool b)
bool __constructor(const int i)
{
- const float zero = 0.0;
- __asm vec4_sne __retVal, i, zero;
+ __asm vec4_sne __retVal, i, 0.0;
}
bool __constructor(const float f)
{
- const float zero = 0.0;
- __asm vec4_sne __retVal, f, zero;
+ __asm vec4_sne __retVal, f, 0.0;
}
bool __constructor(const bool b)
float __constructor(const int i)
{
- __asm int_to_float __retVal, i;
+ __asm ivec4_to_vec4 __retVal, i;
}
float __constructor(const bool b)
{
- __retVal = b;
+ __asm ivec4_to_vec4 __retVal, b;
}
float __constructor(const float f)
vec2 __constructor(const float f)
{
- __retVal.xy = f.xx;
+ __asm vec4_move __retVal.xy, f;
}
vec2 __constructor(const int i)
{
- __retVal.xy = i.xx;
+ __asm ivec4_to_vec4 __retVal.xy, i;
}
vec2 __constructor(const bool b)
{
- __retVal.xy = b.xx;
+ __asm ivec4_to_vec4 __retVal.xy, b;
}
vec2 __constructor(const bvec2 b)
{
- __retVal = b;
+// __retVal = b;
+ __asm ivec4_to_vec4 __retVal.xy, b;
}
vec2 __constructor(const vec3 v)
{
- __retVal.xy = v.xy;
+ __asm vec4_move __retVal.xy, v.xy;
}
vec2 __constructor(const vec4 v)
{
- __retVal.st = v.xy;
+ __asm vec4_move __retVal.xy, v.xy;
}
vec3 __constructor(const float f)
{
- __retVal.xyz = f.xxx;
+ // Note: this could be "__retVal.xyz = f" but that's an illegal assignment
+ __asm vec4_move __retVal.xyz, f;
}
vec3 __constructor(const int i)
{
- __asm int_to_float __retVal.xyz, i.xxx;
+ __asm ivec4_to_vec4 __retVal.xyz, i;
}
vec3 __constructor(const bool b)
{
- __retVal.xyz = b.xxx;
+ __asm ivec4_to_vec4 __retVal.xyz, b;
}
vec3 __constructor(const bvec3 b)
{
- __retVal = b;
+ __asm ivec4_to_vec4 __retVal.xyz, b;
}
vec3 __constructor(const vec4 v)
{
- __retVal.xyz = v.xyz;
+ __asm vec4_move __retVal.xyz, v;
}
vec4 __constructor(const float f)
{
- __retVal = f.xxxx;
+ // Note: this could be "__retVal = f" but that's an illegal assignment
+ __asm vec4_move __retVal, f;
}
vec4 __constructor(const int i)
{
- __retVal = i.xxxx;
+ __asm ivec4_to_vec4 __retVal, i;
}
vec4 __constructor(const bool b)
{
- __retVal = b.xxxx;
+ __asm ivec4_to_vec4 __retVal, b;
}
vec4 __constructor(const bvec4 b)
{
- __retVal = b;
+ __asm ivec4_to_vec4 __retVal, b;
}
vec4 __constructor(const ivec4 i)
{
- __retVal = i;
+ __asm ivec4_to_vec4 __retVal, i;
}
vec4 __constructor(const vec3 v3, const float f)
ivec2 __constructor(const int i)
{
- __retVal.xy = i.xx;
+ __asm vec4_move __retVal.xy, i;
}
ivec2 __constructor(const float f)
{
- __asm float_to_int __retVal.xy, f.xx;
+ __asm vec4_to_ivec4 __retVal.xy, f;
}
ivec2 __constructor(const bool b)
{
- __asm float_to_int __retVal.xy, b.xx;
+ __asm vec4_to_ivec4 __retVal.xy, b;
}
ivec3 __constructor(const int i)
{
- __retVal.xyz = i.xxx;
+ __asm vec4_move __retVal.xyz, i;
}
ivec3 __constructor(const float f)
{
- __retVal.xyz = f.xxx;
+ __asm vec4_to_ivec4 __retVal.xyz, f;
}
ivec3 __constructor(const bool b)
{
- __retVal.xyz = b.xxx;
+ __asm vec4_move __retVal.xyz, b;
}
ivec4 __constructor(const int i)
{
- __retVal = i.xxxx;
+ __asm vec4_move __retVal, i;
}
ivec4 __constructor(const float f)
{
- __asm float_to_int __retVal, f.xxxx;
+ __asm vec4_to_ivec4 __retVal, f;
}
ivec4 __constructor(const bool b)
{
- __retVal = b.xxxx;
+ __asm vec4_to_ivec4 __retVal, b;
}
bvec2 __constructor(const bool b)
{
- __retVal.xy = b.xx;
+ __asm vec4_move __retVal.xy, b;
}
bvec2 __constructor(const float f)
{
- const vec2 zero = vec2(0.0, 0.0);
- __asm vec4_sne __retVal.xy, f.xx, zero;
+ __asm vec4_sne __retVal.xy, f, 0.0;
}
bvec2 __constructor(const int i)
{
- const ivec2 zero = ivec2(0, 0);
- __asm vec4_sne __retVal.xy, i.xx, zero;
+ __asm vec4_sne __retVal.xy, i, 0.0;
}
bvec2 __constructor(const vec2 v)
bvec2 __constructor(const ivec2 v)
{
- const ivec2 zero = ivec2(0, 0);
- __asm vec4_sne __retVal.xy, v, zero;
+ __asm vec4_sne __retVal.xy, v, 0.0;
}
bvec3 __constructor(const bool b)
{
- __retVal.xyz = b.xxx;
+ __asm vec4_move __retVal.xyz, b;
}
bvec3 __constructor(const float f)
{
- const vec3 zero = vec3(0.0, 0.0, 0.0);
- __asm vec4_sne __retVal.xyz, f.xxx, zero;
+ __asm vec4_sne __retVal.xyz, f, 0.0;
}
bvec3 __constructor(const int i)
{
- const ivec3 zero = ivec3(0, 0, 0);
- __asm vec4_sne __retVal.xyz, i.xxx, zero;
+ __asm vec4_sne __retVal.xyz, i, 0.0;
}
bvec3 __constructor(const vec3 v)
{
- const vec3 zero = vec3(0.0, 0.0, 0.0);
- __asm vec4_sne __retVal.xyz, v, zero;
+ __asm vec4_sne __retVal.xyz, v, 0.0;
}
bvec3 __constructor(const ivec3 v)
{
- const ivec3 zero = ivec3(0, 0, 0);
- __asm vec4_sne __retVal.xyz, v, zero;
+ __asm vec4_sne __retVal.xyz, v, 0.0;
}
bvec4 __constructor(const bool b)
{
- __retVal.xyzw = b.xxxx;
+ __asm vec4_move __retVal.xyzw, b;
}
bvec4 __constructor(const float f)
{
- const vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);
- __asm vec4_sne __retVal, f.xxxx, zero;
+ __asm vec4_sne __retVal.xyzw, f, 0.0;
}
bvec4 __constructor(const int i)
{
- const ivec4 zero = ivec4(0, 0, 0, 0);
- __asm vec4_sne __retVal, i.xxxx, zero;
+ __asm vec4_sne __retVal.xyzw, i, 0.0;
}
bvec4 __constructor(const vec4 v)
{
- const vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);
- __asm vec4_sne __retVal, v, zero;
+ __asm vec4_sne __retVal.xyzw, v, 0.0;
}
bvec4 __constructor(const ivec4 v)
{
- const ivec4 zero = ivec4(0, 0, 0, 0);
- __asm vec4_sne __retVal, v, zero;
+ __asm vec4_sne __retVal.xyzw, v, 0.0;
}
int __operator + (const int a, const int b)
{
-// 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;
+ __asm vec4_add __retVal, a, b;
}
int __operator - (const int a, const int b)
{
- float x;
- __asm vec4_subtract x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_subtract __retVal, a, b;
}
int __operator * (const int a, const int b)
{
- float x;
- __asm vec4_multiply x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_multiply __retVal, a, b;
}
int __operator / (const int a, const int b)
float bInv, x;
__asm float_rcp bInv, b;
__asm vec4_multiply x, a, bInv;
- __asm float_to_int __retVal, x;
+ __asm vec4_to_ivec4 __retVal, x;
}
ivec2 __operator + (const ivec2 a, const ivec2 b)
{
- vec2 x;
- __asm vec4_add x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_add __retVal, a, b;
}
ivec2 __operator - (const ivec2 a, const ivec2 b)
{
- vec2 x;
- __asm vec4_subtract x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_subtract __retVal, a, b;
}
ivec2 __operator * (const ivec2 a, const ivec2 b)
{
- vec2 x;
- __asm vec4_multiply x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_multiply __retVal, a, b;
}
ivec2 __operator / (const ivec2 a, const ivec2 b)
__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;
+ __asm vec4_to_ivec4 __retVal, x;
}
ivec3 __operator + (const ivec3 a, const ivec3 b)
{
- vec3 x;
- __asm vec4_add x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_add __retVal, a, b;
}
ivec3 __operator - (const ivec3 a, const ivec3 b)
{
- vec3 x;
- __asm vec4_subtract x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_subtract __retVal, a, b;
}
ivec3 __operator * (const ivec3 a, const ivec3 b)
{
- vec3 x;
- __asm vec4_multiply x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_multiply __retVal, a, b;
}
ivec3 __operator / (const ivec3 a, const ivec3 b)
__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;
+ __asm vec4_to_ivec4 __retVal, x;
}
ivec4 __operator + (const ivec4 a, const ivec4 b)
{
- vec3 x;
- __asm vec4_add x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_add __retVal, a, b;
}
ivec4 __operator - (const ivec4 a, const ivec4 b)
{
- vec4 x;
- __asm vec4_subtract x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_subtract __retVal, a, b;
}
ivec4 __operator * (const ivec4 a, const ivec4 b)
{
- vec4 x;
- __asm vec4_multiply x, a, b;
- __asm float_to_int __retVal, x;
+ __asm vec4_multiply __retVal, a, b;
}
ivec4 __operator / (const ivec4 a, const ivec4 b)
__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;
+ __asm vec4_to_ivec4 __retVal, x;
}
float __operator + (const float a, const float b)
{
- __asm vec4_add __retVal.x, a, b;
+ __asm vec4_add __retVal, a, b;
}
float __operator - (const float a, const float b)
{
- __asm vec4_subtract __retVal.x, a, b;
+ __asm vec4_subtract __retVal, a, b;
}
float __operator * (const float a, const float b)
{
- __asm vec4_multiply __retVal.x, a, b;
+ __asm vec4_multiply __retVal, a, b;
}
float __operator / (const float a, const float b)
{
float bInv;
- __asm float_rcp bInv.x, b.x;
- __asm vec4_multiply __retVal.x, a, bInv;
+ __asm float_rcp bInv.x, b;
+ __asm vec4_multiply __retVal, a, bInv;
}
vec2 __operator + (const float a, const vec2 u)
{
- __asm vec4_add __retVal.xy, a.xx, u.xy;
+ __asm vec4_add __retVal.xy, a, u.xy;
}
vec2 __operator + (const vec2 v, const float b)
{
- __asm vec4_add __retVal.xy, v.xy, b.xx;
+ __asm vec4_add __retVal.xy, v.xy, b;
}
vec2 __operator - (const float a, const vec2 u)
{
- __asm vec4_subtract __retVal.xy, a.xx, u.xy;
+ __asm vec4_subtract __retVal.xy, a, u.xy;
}
vec2 __operator - (const vec2 v, const float b)
{
- __asm vec4_subtract __retVal.xy, v.xy, b.xx;
+ __asm vec4_subtract __retVal.xy, v.xy, b;
}
vec2 __operator * (const float a, const vec2 u)
{
- __asm vec4_multiply __retVal.xy, a.xx, u.xy;
+ __asm vec4_multiply __retVal.xy, a, u.xy;
}
vec2 __operator * (const vec2 v, const float b)
{
- __asm vec4_multiply __retVal.xy, v.xy, b.xx;
+ __asm vec4_multiply __retVal.xy, v.xy, b;
}
vec2 __operator / (const float a, const vec2 u)
vec2 invU;
__asm float_rcp invU.x, u.x;
__asm float_rcp invU.y, u.y;
- __asm vec4_multiply __retVal.xy, a.xx, invU.xy;
+ __asm vec4_multiply __retVal.xy, a, invU.xy;
}
vec2 __operator / (const vec2 v, const float b)
{
float invB;
__asm float_rcp invB, b;
- __asm vec4_multiply __retVal.xy, v.xy, invB.xx;
+ __asm vec4_multiply __retVal.xy, v.xy, invB;
}
vec3 __operator + (const float a, const vec3 u)
{
- __asm vec4_add __retVal.xyz, a.xxx, u.xyz;
+ __asm vec4_add __retVal.xyz, a, u.xyz;
}
vec3 __operator + (const vec3 v, const float b)
{
- __asm vec4_add __retVal.xyz, v.xyz, b.xxx;
+ __asm vec4_add __retVal.xyz, v.xyz, b;
}
vec3 __operator - (const float a, const vec3 u)
{
- __asm vec4_subtract __retVal.xyz, a.xxx, u.xyz;
+ __asm vec4_subtract __retVal.xyz, a, u.xyz;
}
vec3 __operator - (const vec3 v, const float b)
{
- __asm vec4_subtract __retVal.xyz, v.xyz, b.xxx;
+ __asm vec4_subtract __retVal.xyz, v.xyz, b;
}
vec3 __operator * (const float a, const vec3 u)
{
- __asm vec4_multiply __retVal.xyz, a.xxx, u.xyz;
+ __asm vec4_multiply __retVal.xyz, a, u.xyz;
}
vec3 __operator * (const vec3 v, const float b)
{
- __asm vec4_multiply __retVal.xyz, v.xyz, b.xxx;
+ __asm vec4_multiply __retVal.xyz, v.xyz, b;
}
vec3 __operator / (const float a, const vec3 u)
__asm float_rcp invU.x, u.x;
__asm float_rcp invU.y, u.y;
__asm float_rcp invU.z, u.z;
- __asm vec4_multiply __retVal.xyz, a.xxx, invU.xyz;
+ __asm vec4_multiply __retVal.xyz, a, invU.xyz;
}
vec3 __operator / (const vec3 v, const float b)
{
float invB;
__asm float_rcp invB, b;
- __asm vec4_multiply __retVal.xyz, v.xyz, invB.xxx;
+ __asm vec4_multiply __retVal.xyz, v.xyz, invB;
}
vec4 __operator + (const float a, const vec4 u)
{
- __asm vec4_add __retVal, a.xxxx, u;
+ __asm vec4_add __retVal, a, u;
}
vec4 __operator + (const vec4 v, const float b)
{
- __asm vec4_add __retVal, v, b.xxxx;
+ __asm vec4_add __retVal, v, b;
}
vec4 __operator - (const float a, const vec4 u)
{
- __asm vec4_subtract __retVal, a.xxxx, u;
+ __asm vec4_subtract __retVal, a, u;
}
vec4 __operator - (const vec4 v, const float b)
{
- __asm vec4_subtract __retVal, v, b.xxxx;
+ __asm vec4_subtract __retVal, v, b;
}
vec4 __operator * (const float a, const vec4 u)
{
- __asm vec4_multiply __retVal, a.xxxx, u;
+ __asm vec4_multiply __retVal, a, u;
}
vec4 __operator * (const vec4 v, const float b)
{
- __asm vec4_multiply __retVal, v, b.xxxx;
+ __asm vec4_multiply __retVal, v, b;
}
vec4 __operator / (const float a, const vec4 u)
__asm float_rcp invU.y, u.y;
__asm float_rcp invU.z, u.z;
__asm float_rcp invU.w, u.w;
- __asm vec4_multiply __retVal, a.xxxx, invU;
+ __asm vec4_multiply __retVal, a, invU;
}
vec4 __operator / (const vec4 v, const float b)
{
float invB;
__asm float_rcp invB, b;
- __asm vec4_multiply __retVal, v, invB.xxxx;
+ __asm vec4_multiply __retVal, v, invB;
}
float invB;
__asm float_rcp invB, b;
__asm vec4_multiply a, a, invB;
- __asm float_to_int a, a;
+ __asm vec4_to_ivec4 a, a;
}
__asm float_rcp inv.x, u.x;
__asm float_rcp inv.y, u.y;
__asm vec4_multiply z, v, inv;
- __asm float_to_int v, z;
+ __asm vec4_to_ivec4 v, z;
}
__asm float_rcp inv.x, u.x;
__asm float_rcp inv.y, u.y;
__asm vec4_multiply z, v, inv;
- __asm float_to_int v, z;
+ __asm vec4_to_ivec4 v, z;
}
__asm float_rcp inv.x, u.x;
__asm float_rcp inv.y, u.y;
__asm vec4_multiply z, v, inv;
- __asm float_to_int v, z;
+ __asm vec4_to_ivec4 v, z;
}
void __operator += (inout ivec2 v, const int a)
{
- __asm vec4_add v.xy, v.xy, a.xx;
+ __asm vec4_add v.xy, v.xy, a;
}
void __operator -= (inout ivec2 v, const int a)
{
- __asm vec4_subtract v.xy, v.xy, a.xx;
+ __asm vec4_subtract v.xy, v.xy, a;
}
void __operator *= (inout ivec2 v, const int a)
{
- __asm vec4_multiply v.xy, v.xy, a.xx;
+ __asm vec4_multiply v.xy, v.xy, a;
v.x *= a;
v.y *= a;
}
void __operator += (inout ivec3 v, const int a)
{
- __asm vec4_add v.xyz, v.xyz, a.xxx;
+ __asm vec4_add v.xyz, v.xyz, a;
}
void __operator -= (inout ivec3 v, const int a)
{
- __asm vec4_subtract v.xyz, v.xyz, a.xxx;
+ __asm vec4_subtract v.xyz, v.xyz, a;
}
void __operator *= (inout ivec3 v, const int a)
{
- __asm vec4_multiply v.xyz, v.xyz, a.xxx;
+ __asm vec4_multiply v.xyz, v.xyz, a;
}
void __operator /= (inout ivec3 v, const int a)
void __operator += (inout ivec4 v, const int a)
{
- __asm vec4_add v, v, a.xxxx;
+ __asm vec4_add v, v, a;
}
void __operator -= (inout ivec4 v, const int a)
{
- __asm vec4_subtract v, v, a.xxxx;
+ __asm vec4_subtract v, v, a;
}
void __operator *= (inout ivec4 v, const int a)
{
- __asm vec4_multiply v, v, a.xxxx;
+ __asm vec4_multiply v, v, a;
}
void __operator /= (inout ivec4 v, const int a)
void __operator += (inout vec2 v, const float a)
{
- __asm vec4_add v.xy, v, a.xx;
+ __asm vec4_add v.xy, v, a;
}
void __operator -= (inout vec2 v, const float a)
{
- __asm vec4_subtract v.xy, v, a.xx;
+ __asm vec4_subtract v.xy, v, a;
}
void __operator *= (inout vec2 v, const float a)
{
- __asm vec4_multiply v.xy, v, a.xx;
+ __asm vec4_multiply v.xy, v, a;
}
void __operator /= (inout vec2 v, const float a)
{
float invA;
__asm float_rcp invA, a;
- __asm vec4_multiply v.xy, v.xy, invA.xx;
+ __asm vec4_multiply v.xy, v.xy, invA;
}
void __operator += (inout vec3 v, const float a)
{
- __asm vec4_add v.xyz, v, a.xxx;
+ __asm vec4_add v.xyz, v, a;
}
void __operator -= (inout vec3 v, const float a)
{
- __asm vec4_subtract v.xyz, v, a.xxx;
+ __asm vec4_subtract v.xyz, v, a;
}
void __operator *= (inout vec3 v, const float a)
{
- __asm vec4_multiply v.xyz, v, a.xxx;
+ __asm vec4_multiply v.xyz, v, a;
}
void __operator /= (inout vec3 v, const float a)
{
float invA;
__asm float_rcp invA, a;
- __asm vec4_multiply v.xyz, v.xyz, invA.xxx;
+ __asm vec4_multiply v.xyz, v.xyz, invA;
}
void __operator += (inout vec4 v, const float a)
{
- __asm vec4_add v, v, a.xxxx;
+ __asm vec4_add v, v, a;
}
void __operator -= (inout vec4 v, const float a)
{
- __asm vec4_subtract v, v, a.xxxx;
+ __asm vec4_subtract v, v, a;
}
void __operator *= (inout vec4 v, const float a)
{
- __asm vec4_multiply v, v, a.xxxx;
+ __asm vec4_multiply v, v, a;
}
void __operator /= (inout vec4 v, const float a)
{
float invA;
__asm float_rcp invA, a;
- __asm vec4_multiply v, v, invA.xxxx;
+ __asm vec4_multiply v, v, invA;
}
{ "vec4_sle", IR_SLE, 1, 2 },
{ "vec4_slt", IR_SLT, 1, 2 },
/* vec4 unary */
+ { "vec4_move", IR_MOVE, 1, 1 },
{ "vec4_floor", IR_FLOOR, 1, 1 },
{ "vec4_frac", IR_FRAC, 1, 1 },
{ "vec4_abs", IR_ABS, 1, 1 },
{ "vec4_texp_rect", IR_TEX, 1, 2 },/* rectangle w/ projection */
/* unary op */
- { "int_to_float", IR_I_TO_F, 1, 1 },
- { "float_to_int", IR_F_TO_I, 1, 1 },
+ { "ivec4_to_vec4", IR_I_TO_F, 1, 1 }, /* int[4] to float[4] */
+ { "vec4_to_ivec4", IR_F_TO_I, 1, 1 }, /* float[4] to int[4] */
{ "float_exp", IR_EXP, 1, 1 },
{ "float_exp2", IR_EXP2, 1, 1 },
{ "float_log2", IR_LOG2, 1, 1 },
return NULL;
assert(!n->Store);
- n->Store = get_store(n0);
- n->Writemask = writemask;
+ n->Store = n0->Store;
- assert(n->Store->File != PROGRAM_UNDEFINED ||
- n->Store->Parent);
+ assert(n->Store->File != PROGRAM_UNDEFINED || n->Store->Parent);
_slang_free(n0);
}
slang_atom atom;
slang_function *fun;
GLboolean error;
+ slang_ir_node *n;
atom = slang_atom_pool_atom(A->atoms, name);
if (atom == SLANG_ATOM_NULL)
assert(fun);
}
- return _slang_gen_function_call(A, fun, oper, dest);
+ n = _slang_gen_function_call(A, fun, oper, dest);
+
+ if (n && !n->Store && !dest
+ && fun->header.type.specifier.type != SLANG_SPEC_VOID) {
+ /* setup n->Store for the result of the function call */
+ GLint size = _slang_sizeof_type_specifier(&fun->header.type.specifier);
+ n->Store = _slang_new_ir_storage(PROGRAM_TEMPORARY, -1, size);
+ /*printf("Alloc storage for function result, size %d \n", size);*/
+ }
+
+ return n;
}
tmpVar = new_node0(IR_VAR);
tmpVar->Store = tmpDecl->Store;
trueExpr = _slang_gen_operation(A, &oper->children[1]);
- trueNode = new_node2(IR_MOVE, tmpVar, trueExpr);
+ trueNode = new_node2(IR_COPY, tmpVar, trueExpr);
/* if-false body (child 2) */
tmpVar = new_node0(IR_VAR);
tmpVar->Store = tmpDecl->Store;
falseExpr = _slang_gen_operation(A, &oper->children[2]);
- falseNode = new_node2(IR_MOVE, tmpVar, falseExpr);
+ falseNode = new_node2(IR_COPY, tmpVar, falseExpr);
ifNode = new_if(cond, trueNode, falseNode);
assert(oper->num_children == 0 || oper->num_children == 1);
v = _slang_locate_variable(oper->locals, oper->a_id, GL_TRUE);
- /*printf("Declare %s at %p\n", varName, v);*/
+ /*printf("Declare %s at %p\n", varName, (void *) v);*/
assert(v);
#if 0
rhs = _slang_gen_operation(A, &oper->children[0]);
if (!rhs)
return NULL; /* must have found an error */
- init = new_node2(IR_MOVE, var, rhs);
+ init = new_node2(IR_COPY, var, rhs);
+
/*assert(rhs->Opcode != IR_SEQ);*/
n = new_seq(varDecl, init);
}
if (!rhs)
return NULL;
+ /*assert(rhs->Store);*/
+
if (rhs->Store && var->Store->Size != rhs->Store->Size) {
slang_info_log_error(A->log, "invalid assignment (wrong types)");
return NULL;
}
- init = new_node2(IR_MOVE, var, rhs);
+ init = new_node2(IR_COPY, var, rhs);
n = new_seq(varDecl, init);
}
else {
const slang_typeinfo *t1)
{
-#if 0
+#if 1
GLuint sz0 = _slang_sizeof_type_specifier(&t0->spec);
GLuint sz1 = _slang_sizeof_type_specifier(&t1->spec);
- if (sz0 != sz1)
+ if (sz0 != sz1) {
+ printf("size mismatch %u vs %u\n", sz0, sz1);
return GL_FALSE;
+ }
#endif
if (t0->spec.type == SLANG_SPEC_STRUCT &&
*/
rhs = _slang_gen_swizzle(rhs, newSwizzle);
}
- n = new_node2(IR_MOVE, lhs, rhs);
+ n = new_node2(IR_COPY, lhs, rhs);
n->Writemask = writemask;
return n;
}
slang_ir_opcode opcode)
{
slang_typeinfo t0, t1;
+ slang_ir_node *n;
slang_typeinfo_construct(&t0);
_slang_typeof_operation(A, &oper->children[0], &t0);
return NULL;
}
- return new_node2(opcode,
- _slang_gen_operation(A, &oper->children[0]),
- _slang_gen_operation(A, &oper->children[1]));
+ n = new_node2(opcode,
+ _slang_gen_operation(A, &oper->children[0]),
+ _slang_gen_operation(A, &oper->children[1]));
+
+ /* result is a bool (size 1) */
+ n->Store = _slang_new_ir_storage(PROGRAM_TEMPORARY, -1, 1);
+
+ return n;
}
if (var->initializer) {
slang_ir_node *lhs, *rhs, *init;
- /* Generate IR_MOVE instruction to initialize the variable */
+ /* Generate IR_COPY instruction to initialize the variable */
lhs = new_node0(IR_VAR);
lhs->Var = var;
lhs->Store = n->Store;
rhs = _slang_gen_operation(A, var->initializer);
assert(rhs);
- init = new_node2(IR_MOVE, lhs, rhs);
+ init = new_node2(IR_COPY, lhs, rhs);
n = new_seq(n, init);
}
/**
- * Allocate temporary storage for an intermediate result (such as for
- * a multiply or add, etc.
+ * Allocate storage for the given node (if it hasn't already been allocated).
+ *
+ * Typically this is temporary storage for an intermediate result (such as
+ * for a multiply or add, etc).
+ *
+ * If n->Store does not exist it will be created and will be of the size
+ * specified by defaultSize.
*/
static GLboolean
-alloc_temp_storage(slang_emit_info *emitInfo, slang_ir_node *n, GLint size)
+alloc_node_storage(slang_emit_info *emitInfo, slang_ir_node *n,
+ GLint defaultSize)
{
assert(!n->Var);
- assert(!n->Store);
- assert(size > 0);
- n->Store = _slang_new_ir_storage(PROGRAM_TEMPORARY, -1, size);
- if (!_slang_alloc_temp(emitInfo->vt, n->Store)) {
- slang_info_log_error(emitInfo->log,
- "Ran out of registers, too many temporaries");
- _slang_free(n->Store);
- n->Store = NULL;
- return GL_FALSE;
+ if (!n->Store) {
+ assert(defaultSize > 0);
+ n->Store = _slang_new_ir_storage(PROGRAM_TEMPORARY, -1, defaultSize);
+ }
+
+ /* now allocate actual register(s). I.e. set n->Store->Index >= 0 */
+ if (n->Store->Index < 0) {
+ if (!_slang_alloc_temp(emitInfo->vt, n->Store)) {
+ slang_info_log_error(emitInfo->log,
+ "Ran out of registers, too many temporaries");
+ _slang_free(n->Store);
+ n->Store = NULL;
+ return GL_FALSE;
+ }
}
return GL_TRUE;
}
* Otherwise, no-op.
*/
static void
-free_temp_storage(slang_var_table *vt, slang_ir_node *n)
+free_node_storage(slang_var_table *vt, slang_ir_node *n)
{
if (n->Store->File == PROGRAM_TEMPORARY &&
n->Store->Index >= 0 &&
}
+/**
+ * Helper function to allocate a short-term temporary.
+ * Free it with _slang_free_temp().
+ */
+static GLboolean
+alloc_local_temp(slang_emit_info *emitInfo, slang_ir_storage *temp, GLint size)
+{
+ assert(size >= 1);
+ assert(size <= 4);
+ _mesa_bzero(temp, sizeof(*temp));
+ temp->Size = size;
+ temp->File = PROGRAM_TEMPORARY;
+ temp->Index = -1;
+ return _slang_alloc_temp(emitInfo->vt, temp);
+}
+
/**
* Remove any SWIZZLE_NIL terms from given swizzle mask.
}
/* result storage */
- if (!n->Store) {
- GLint size = info->ResultSize;
- if (!alloc_temp_storage(emitInfo, n, size))
- return NULL;
-#if 0000 /* this should work, but doesn't yet */
- if (size == 2)
- n->Writemask = WRITEMASK_XY;
- else if (size == 3)
- n->Writemask = WRITEMASK_XYZ;
- else if (size == 1)
- n->Writemask = WRITEMASK_X << GET_SWZ(n->Store->Swizzle,0);
-#endif
- }
+ alloc_node_storage(emitInfo, n, -1);
+ assert(n->Store->Index >= 0);
+ if (n->Store->Size == 2)
+ n->Writemask = WRITEMASK_XY;
+ else if (n->Store->Size == 3)
+ n->Writemask = WRITEMASK_XYZ;
+ else if (n->Store->Size == 1)
+ n->Writemask = WRITEMASK_X << GET_SWZ(n->Store->Swizzle, 0);
+
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
/* really free temps now */
for (i = 0; i < 3; i++)
if (temps[i])
- free_temp_storage(emitInfo->vt, temps[i]);
+ free_node_storage(emitInfo->vt, temps[i]);
/*_mesa_print_instruction(inst);*/
return inst;
return NULL;
}
+ /* final result is 1 bool */
+ if (!alloc_node_storage(emitInfo, n, 1))
+ return NULL;
+
size = n->Children[0]->Store->Size;
if (size == 1) {
gl_inst_opcode opcode;
- if (!n->Store) {
- if (!alloc_temp_storage(emitInfo, n, 1)) /* 1 bool */
- return NULL;
- }
-
opcode = n->Opcode == IR_EQUAL ? OPCODE_SEQ : OPCODE_SNE;
inst = new_instruction(emitInfo, opcode);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
else if (size <= 4) {
GLuint swizzle;
gl_inst_opcode dotOp;
-
- assert(!n->Store);
- if (!n->Store) {
- if (!alloc_temp_storage(emitInfo, n, size)) /* 'size' bools */
- return NULL;
+ slang_ir_storage tempStore;
+
+ if (!alloc_local_temp(emitInfo, &tempStore, 4)) {
+ return NULL;
+ /* out of temps */
}
if (size == 4) {
swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y);
}
- /* Compute equality, inequality (tmp1 = (A ?= B)) */
+ /* Compute inequality (temp = (A != B)) */
inst = new_instruction(emitInfo, OPCODE_SNE);
+ storage_to_dst_reg(&inst->DstReg, &tempStore, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
storage_to_src_reg(&inst->SrcReg[1], n->Children[1]->Store);
- storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
inst->Comment = _mesa_strdup("Compare values");
- /* Compute tmp2 = DOT(tmp1, tmp1) (reduction) */
+ /* Compute val = DOT(temp, temp) (reduction) */
inst = new_instruction(emitInfo, dotOp);
- storage_to_src_reg(&inst->SrcReg[0], n->Store);
- storage_to_src_reg(&inst->SrcReg[1], n->Store);
- inst->SrcReg[0].Swizzle = inst->SrcReg[1].Swizzle = swizzle; /*override*/
- free_temp_storage(emitInfo->vt, n); /* free tmp1 */
- if (!alloc_temp_storage(emitInfo, n, 1)) /* alloc tmp2 */
- return NULL;
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
+ storage_to_src_reg(&inst->SrcReg[0], &tempStore);
+ storage_to_src_reg(&inst->SrcReg[1], &tempStore);
+ inst->SrcReg[0].Swizzle = inst->SrcReg[1].Swizzle = swizzle; /*override*/
inst->Comment = _mesa_strdup("Reduce vec to bool");
+ _slang_free_temp(emitInfo->vt, &tempStore); /* free temp */
+
if (n->Opcode == IR_EQUAL) {
- /* compute tmp2.x = !tmp2.x via tmp2.x = (tmp2.x == 0) */
+ /* compute val = !val.x with SEQ val, val, 0; */
inst = new_instruction(emitInfo, OPCODE_SEQ);
storage_to_src_reg(&inst->SrcReg[0], n->Store);
constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
* XXX this won't work reliably for structs with padding!!
*/
GLint i, num = (n->Children[0]->Store->Size + 3) / 4;
- slang_ir_storage accTemp;
+ slang_ir_storage accTemp, sneTemp;
- if (!n->Store) {
- if (!alloc_temp_storage(emitInfo, n, 4))
- return NULL;
- }
+ if (!alloc_local_temp(emitInfo, &accTemp, 4))
+ return NULL;
- accTemp.Size = 4;
- accTemp.File = PROGRAM_TEMPORARY;
- if (!_slang_alloc_temp(emitInfo->vt, &accTemp)) {
+ if (!alloc_local_temp(emitInfo, &sneTemp, 4))
return NULL;
- /* out of temps */
- }
for (i = 0; i < num; i++) {
- /* SNE t0, left[i], right[i] */
+ /* SNE sneTemp, left[i], right[i] */
inst = new_instruction(emitInfo, OPCODE_SNE);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
storage_to_src_reg(&inst->SrcReg[1], n->Children[1]->Store);
inst->SrcReg[0].Index += i;
inst->SrcReg[1].Index += i;
if (i == 0) {
- inst->DstReg.File = accTemp.File;
- inst->DstReg.Index = accTemp.Index;
+ storage_to_dst_reg(&inst->DstReg, &accTemp, WRITEMASK_XYZW);
inst->Comment = _mesa_strdup("Begin struct/array comparison");
}
else {
- inst->DstReg.File = n->Store->File;
- inst->DstReg.Index = n->Store->Index;
- }
- if (i > 0) {
- /* ADD accTemp, accTemp, temp; # like logical-OR */
+ storage_to_dst_reg(&inst->DstReg, &sneTemp, WRITEMASK_XYZW);
+
+ /* ADD accTemp, accTemp, sneTemp; # like logical-OR */
inst = new_instruction(emitInfo, OPCODE_ADD);
- inst->SrcReg[0].File = accTemp.File;
- inst->SrcReg[0].Index = accTemp.Index;
- inst->SrcReg[1].File = n->Store->File;
- inst->SrcReg[1].Index = n->Store->Index;
- inst->DstReg.File = accTemp.File;
- inst->DstReg.Index = accTemp.Index;
+ storage_to_dst_reg(&inst->DstReg, &accTemp, WRITEMASK_XYZW);
+ storage_to_src_reg(&inst->SrcReg[0], &accTemp);
+ storage_to_src_reg(&inst->SrcReg[1], &sneTemp);
}
}
/* compute accTemp.x || accTemp.y || accTemp.z || accTemp.w with DOT4 */
inst = new_instruction(emitInfo, OPCODE_DP4);
- inst->SrcReg[0].File = accTemp.File;
- inst->SrcReg[0].Index = accTemp.Index;
- inst->SrcReg[1].File = accTemp.File;
- inst->SrcReg[1].Index = accTemp.Index;
- inst->DstReg.File = n->Store->File;
- inst->DstReg.Index = n->Store->Index;
+ storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
+ storage_to_src_reg(&inst->SrcReg[0], &accTemp);
+ storage_to_src_reg(&inst->SrcReg[1], &accTemp);
inst->Comment = _mesa_strdup("End struct/array comparison");
if (n->Opcode == IR_EQUAL) {
/* compute tmp.x = !tmp.x via tmp.x = (tmp.x == 0) */
inst = new_instruction(emitInfo, OPCODE_SEQ);
+ storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], n->Store);
constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
- storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
inst->Comment = _mesa_strdup("Invert true/false");
}
_slang_free_temp(emitInfo->vt, &accTemp);
+ _slang_free_temp(emitInfo->vt, &sneTemp);
}
/* free temps */
- free_temp_storage(emitInfo->vt, n->Children[0]);
- free_temp_storage(emitInfo->vt, n->Children[1]);
+ free_node_storage(emitInfo->vt, n->Children[0]);
+ free_node_storage(emitInfo->vt, n->Children[1]);
return inst;
}
}
#endif
- if (!n->Store)
- if (!alloc_temp_storage(emitInfo, n, n->Children[0]->Store->Size))
- return NULL;
+ if (!alloc_node_storage(emitInfo, n, n->Children[0]->Store->Size))
+ return NULL;
emit(emitInfo, n->Children[1]);
emit(emitInfo, n->Children[2]);
* the intermediate result. Use a temp register instead.
*/
_mesa_bzero(&tmpNode, sizeof(tmpNode));
- alloc_temp_storage(emitInfo, &tmpNode, n->Store->Size);
+ alloc_node_storage(emitInfo, &tmpNode, n->Store->Size);
/* tmp = max(ch[0], ch[1]) */
inst = new_instruction(emitInfo, OPCODE_MAX);
storage_to_src_reg(&inst->SrcReg[0], tmpNode.Store);
storage_to_src_reg(&inst->SrcReg[1], n->Children[2]->Store);
- free_temp_storage(emitInfo->vt, &tmpNode);
+ free_node_storage(emitInfo->vt, &tmpNode);
return inst;
}
emit(emitInfo, n->Children[0]);
- if (!n->Store)
- if (!alloc_temp_storage(emitInfo, n, n->Children[0]->Store->Size))
- return NULL;
+ if (!alloc_node_storage(emitInfo, n, n->Children[0]->Store->Size))
+ return NULL;
inst = new_instruction(emitInfo, OPCODE_MOV);
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
inst = new_instruction(emitInfo, OPCODE_TXP);
}
- if (!n->Store)
- if (!alloc_temp_storage(emitInfo, n, 4))
- return NULL;
+ if (!alloc_node_storage(emitInfo, n, 4))
+ return NULL;
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
}
+/**
+ * Assignment/copy
+ */
static struct prog_instruction *
-emit_move(slang_emit_info *emitInfo, slang_ir_node *n)
+emit_copy(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct prog_instruction *inst;
- assert(n->Opcode == IR_MOVE);
+ assert(n->Opcode == IR_COPY);
/* lhs */
emit(emitInfo, n->Children[0]);
srcStore.Size = 4;
while (size >= 4) {
inst = new_instruction(emitInfo, OPCODE_MOV);
- inst->Comment = _mesa_strdup("IR_MOVE block");
+ inst->Comment = _mesa_strdup("IR_COPY block");
storage_to_dst_reg(&inst->DstReg, &dstStore, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], &srcStore);
srcStore.Index++;
inst->Comment = instruction_annotation(inst->Opcode, dstAnnot,
srcAnnot, NULL, NULL);
}
- free_temp_storage(emitInfo->vt, n->Children[1]);
+ free_node_storage(emitInfo->vt, n->Children[1]);
return inst;
}
}
* is normally generated for the expression "i".
* Generate a move instruction just to set condition codes.
*/
- if (!alloc_temp_storage(emitInfo, n, 1))
+ if (!alloc_node_storage(emitInfo, n, 1))
return NULL;
inst = new_instruction(emitInfo, OPCODE_MOV);
inst->CondUpdate = GL_TRUE;
#endif
/* else, invert using SEQ (v = v == 0) */
- if (!n->Store)
- if (!alloc_temp_storage(emitInfo, n, n->Children[0]->Store->Size))
- return NULL;
+ if (!alloc_node_storage(emitInfo, n, n->Children[0]->Store->Size))
+ return NULL;
inst = new_instruction(emitInfo, OPCODE_SEQ);
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
constant_to_src_reg(&inst->SrcReg[1], 0.0, emitInfo);
- free_temp_storage(emitInfo->vt, n->Children[0]);
+ free_node_storage(emitInfo->vt, n->Children[0]);
inst->Comment = _mesa_strdup("NOT");
return inst;
case IR_SWIZZLE:
return emit_swizzle(emitInfo, n);
- case IR_I_TO_F:
- /* just move */
- emit(emitInfo, n->Children[0]);
- inst = new_instruction(emitInfo, OPCODE_MOV);
- if (!n->Store) {
- if (!alloc_temp_storage(emitInfo, n, 1))
- return NULL;
- }
- 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 */
/* unary */
+ case IR_MOVE:
case IR_RSQ:
case IR_RCP:
case IR_FLOOR:
case IR_FRAC:
case IR_F_TO_I:
+ case IR_I_TO_F:
case IR_ABS:
case IR_SIN:
case IR_COS:
}
return NULL;
- case IR_MOVE:
- return emit_move(emitInfo, n);
+ case IR_COPY:
+ return emit_copy(emitInfo, n);
case IR_COND:
return emit_cond(emitInfo, n);