1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * This file is compiled with clang into the LLVM bitcode
32 * Zack Rusin zack@tungstengraphics.com
34 typedef __attribute__(( ext_vector_type(4) )) float float4
;
37 extern float fabsf(float val
);
39 float4
absvec(float4 vec
)
51 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
)
53 res
[0] = absvec(tmp0x
);
54 res
[1] = absvec(tmp0y
);
55 res
[2] = absvec(tmp0z
);
56 res
[3] = absvec(tmp0w
);
60 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
,
61 float4 tmp1x
, float4 tmp1y
, float4 tmp1z
, float4 tmp1w
)
63 float4 dot
= (tmp0x
* tmp1x
) + (tmp0y
* tmp1y
) +
74 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
,
75 float4 tmp1x
, float4 tmp1y
, float4 tmp1z
, float4 tmp1w
)
77 float4 dot
= (tmp0x
* tmp1x
) + (tmp0y
* tmp1y
) +
78 (tmp0z
* tmp1z
) + (tmp0w
* tmp1w
);
86 extern float powf(float num
, float p
);
87 extern float sqrtf(float x
);
89 float4
powvec(float4 vec
, float4 q
)
92 p
.x
= powf(vec
.x
, q
.x
);
93 p
.y
= powf(vec
.y
, q
.y
);
94 p
.z
= powf(vec
.z
, q
.z
);
95 p
.w
= powf(vec
.w
, q
.w
);
100 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
,
101 float4 tmp1x
, float4 tmp1y
, float4 tmp1z
, float4 tmp1w
)
103 res
[0] = powvec(tmp0x
, tmp1x
);
109 float4
minvec(float4 a
, float4 b
)
111 return (float4
){(a
.x
< b
.x
) ? a
.x
: b
.x
,
112 (a
.y
< b
.y
) ? a
.y
: b
.y
,
113 (a
.z
< b
.z
) ? a
.z
: b
.z
,
114 (a
.w
< b
.w
) ? a
.w
: b
.w
};
117 void min(float4
*res
,
118 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
,
119 float4 tmp1x
, float4 tmp1y
, float4 tmp1z
, float4 tmp1w
)
121 res
[0] = minvec(tmp0x
, tmp1x
);
122 res
[1] = minvec(tmp0y
, tmp1y
);
123 res
[2] = minvec(tmp0z
, tmp1z
);
124 res
[3] = minvec(tmp0w
, tmp1w
);
128 float4
maxvec(float4 a
, float4 b
)
130 return (float4
){(a
.x
> b
.x
) ? a
.x
: b
.x
,
131 (a
.y
> b
.y
) ? a
.y
: b
.y
,
132 (a
.z
> b
.z
) ? a
.z
: b
.z
,
133 (a
.w
> b
.w
) ? a
.w
: b
.w
};
136 void max(float4
*res
,
137 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
,
138 float4 tmp1x
, float4 tmp1y
, float4 tmp1z
, float4 tmp1w
)
140 res
[0] = maxvec(tmp0x
, tmp1x
);
141 res
[1] = maxvec(tmp0y
, tmp1y
);
142 res
[2] = maxvec(tmp0z
, tmp1z
);
143 res
[3] = maxvec(tmp0w
, tmp1w
);
147 void lit(float4
*res
,
148 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
)
150 const float4 zerovec
= (float4
) {0.0, 0.0, 0.0, 0.0};
151 const float4 min128
= (float4
) {-128.f
, -128.f
, -128.f
, -128.f
};
152 const float4 plus128
= (float4
) {128.f
, 128.f
, 128.f
, 128.f
};
154 res
[0] = (float4
){1.0, 1.0, 1.0, 1.0};
156 float4 tmpy
= maxvec(tmp0y
, zerovec
);
157 float4 tmpw
= minvec(tmp0w
, plus128
);
158 tmpw
= maxvec(tmpw
, min128
);
160 res
[2] = powvec(tmpy
, tmpw
);
165 res
[3] = (float4
){1.0, 1.0, 1.0, 1.0};
169 float4
sqrtvec(float4 vec
)
179 void rsq(float4
*res
,
180 float4 tmp0x
, float4 tmp0y
, float4 tmp0z
, float4 tmp0w
)
182 const float4 onevec
= (float4
) {1., 1., 1., 1.};
183 res
[0] = onevec
/sqrtvec(absvec(tmp0x
));
184 res
[1] = onevec
/sqrtvec(absvec(tmp0y
));
185 res
[2] = onevec
/sqrtvec(absvec(tmp0z
));
186 res
[3] = onevec
/sqrtvec(absvec(tmp0w
));