2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // This file defines nearly all constructors and operators for built-in data
27 // types, using extended language syntax. In general, compiler treats
28 // constructors and operators as ordinary functions with some exceptions.
29 // For example, the language does not allow functions to be called in
30 // constant expressions - here the exception is made to allow it.
32 // Each implementation provides its own version of this file. Each
33 // implementation can define the required set of operators and constructors
34 // in its own fashion.
36 // The extended language syntax is only present when compiling this file.
37 // It is implicitly included at the very beginning of the compiled shader,
38 // so no built-in functions can be used.
40 // To communicate with the implementation, a special extended "__asm" keyword
41 // is used, followed by an instruction name (any valid identifier), a
42 // destination variable identifier and a list of zero or more source
43 // variable identifiers.
45 // A variable identifier is a variable name declared earlier in the code
46 // (as a function parameter, local or global variable).
48 // An instruction name designates an instruction that must be exported
49 // by the implementation. Each instruction receives data from source
50 // variable identifiers and returns data in the destination variable
53 // It is up to the implementation how to define a particular operator
54 // or constructor. If it is expected to being used rarely, it can be
55 // defined in terms of other operators and constructors,
58 // ivec2 __operator + (const ivec2 x, const ivec2 y) {
59 // return ivec2 (x[0] + y[0], x[1] + y[1]);
62 // If a particular operator or constructor is expected to be used very
63 // often or is an atomic operation (that is, an operation that cannot be
64 // expressed in terms of other operations or would create a dependency
65 // cycle) it must be defined using one or more __asm constructs.
67 // Each implementation must define constructors for all scalar types
68 // (bool, float, int). There are 9 scalar-to-scalar constructors
69 // (including identity constructors). However, since the language
70 // introduces special constructors (like matrix constructor with a single
71 // scalar value), implementations must also implement these cases.
72 // The compiler provides the following algorithm when resolving a constructor:
73 // - try to find a constructor with a prototype matching ours,
74 // - if no constructor is found and this is a scalar-to-scalar constructor,
76 // - if a constructor is found, execute it and return,
77 // - count the size of the constructor parameter list - if it is less than
78 // the size of our constructor's type, raise an error,
79 // - for each parameter in the list do a recursive constructor matching for
80 // appropriate scalar fields in the constructed variable,
82 // Each implementation must also define a set of operators that deal with
83 // built-in data types.
84 // There are four kinds of operators:
85 // 1) Operators that are implemented only by the compiler: "()" (function
86 // call), "," (sequence) and "?:" (selection).
87 // 2) Operators that are implemented by the compiler by expressing it in
88 // terms of other operators:
89 // - "." (field selection) - translated to subscript access,
90 // - "&&" (logical and) - translated to "<left_expr> ? <right_expr> :
92 // - "||" (logical or) - translated to "<left_expr> ? true : <right_expr>",
93 // 3) Operators that can be defined by the implementation and if the required
94 // prototype is not found, standard behaviour is used:
95 // - "==", "!=", "=" (equality, assignment) - compare or assign
96 // matching fields one-by-one;
97 // note that at least operators for scalar data types must be defined
98 // by the implementation to get it work,
99 // 4) All other operators not mentioned above. If no required prototype is
100 // found, an error is raised. An implementation must follow the language
101 // specification to provide all valid operator prototypes.
105 vec4 vec4(const float a1, const float b1, const float c1, const float d1)
113 int __constructor (const float f) {
115 __asm float_to_int i, f;
119 bool __constructor (const int i) {
123 bool __constructor (const float f) {
127 int __constructor (const bool b) {
131 float __constructor (const bool b) {
132 return b ? 1.0 : 0.0;
135 float __constructor (const int i) {
137 __asm int_to_float f, i;
141 bool __constructor (const bool b) {
145 int __constructor (const int i) {
149 float __constructor (const float f) {
153 vec2 __constructor (const float f) {
157 vec2 __constructor (const int i) {
159 __asm int_to_float x, i;
163 vec2 __constructor (const bool b) {
164 return vec2 (b ? 1.0 : 0.0);
167 vec3 __constructor (const float f) {
168 return vec3 (f, f, f);
171 vec3 __constructor (const int i) {
173 __asm int_to_float x, i;
177 vec3 __constructor (const bool b) {
178 return vec3 (b ? 1.0 : 0.0);
181 //bp: TODO replace with asm == f.xxxx
182 vec4 __constructor (const float f) {
183 return vec4 (f, f, f, f);
186 vec4 __constructor (const int i) {
188 __asm int_to_float x, i;
192 vec4 __constructor (const bool b) {
193 return vec4 (b ? 1.0 : 0.0);
196 ivec2 __constructor (const int i) {
200 ivec2 __constructor (const float f) {
201 return ivec2 (int (f));
204 ivec2 __constructor (const bool b) {
205 return ivec2 (int (b));
208 ivec3 __constructor (const int i) {
209 return ivec3 (i, i, i);
212 ivec3 __constructor (const float f) {
213 return ivec3 (int (f));
216 ivec3 __constructor (const bool b) {
217 return ivec3 (int (b));
220 ivec4 __constructor (const int i) {
221 return ivec4 (i, i, i, i);
224 ivec4 __constructor (const float f) {
225 return ivec4 (int (f));
228 ivec4 __constructor (const bool b) {
229 return ivec4 (int (b));
232 bvec2 __constructor (const bool b) {
236 bvec2 __constructor (const float f) {
237 return bvec2 (bool (f));
240 bvec2 __constructor (const int i) {
241 return bvec2 (bool (i));
244 bvec3 __constructor (const bool b) {
245 return bvec3 (b, b, b);
248 bvec3 __constructor (const float f) {
249 return bvec3 (bool (f));
252 bvec3 __constructor (const int i) {
253 return bvec3 (bool (i));
256 bvec4 __constructor (const bool b) {
257 return bvec4 (b, b, b, b);
260 bvec4 __constructor (const float f) {
261 return bvec4 (bool (f));
264 bvec4 __constructor (const int i) {
265 return bvec4 (bool (i));
270 //// mat2 constructors
272 mat2 __constructor (const float f) {
273 return mat2 (f, 0.0, 0.0, f);
276 mat2 __constructor (const int i) {
278 __asm int_to_float x, i;
282 mat2 __constructor (const bool b) {
283 return mat2 (b ? 1.0 : 0.0);
287 //// mat3 constructors
289 mat3 __constructor (const float f) {
290 return mat3 (f, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, f);
293 mat3 __constructor (const int i) {
295 __asm int_to_float x, i;
299 mat3 __constructor (const bool b) {
300 return mat3 (b ? 1.0 : 0.0);
304 //// mat4 constructors
306 mat4 __constructor (const float f) {
307 return mat4 (f, 0.0, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, 0.0, f);
310 mat4 __constructor (const int i) {
312 __asm int_to_float x, i;
316 mat4 __constructor (const bool b) {
317 return mat4 (b ? 1.0 : 0.0);
320 mat4 __constructor (const vec4 r0, const vec4 r1, const vec4 r2, const vec4 r3)
331 void __operator += (inout float a, const float b)
333 __asm vec4_add a.x, a, b;
336 void __operator -= (inout float a, const float b)
338 __asm vec4_subtract a.x, a, b;
341 void __operator *= (inout float a, const float b)
343 __asm vec4_multiply a.x, a, b;
346 void __operator /= (inout float a, const float b)
349 __asm float_rcp w.x, b;
350 __asm vec4_multiply a.x, a, w;
355 float __operator - (const float a) {
357 __asm float_negate b, a;
361 float __operator + (const float a, const float b) {
363 // __asm float_add c, a, b;
366 __asm float_add __retVal, a, b;
369 void __operator += (inout int a, const int b) {
370 a = int (float (a) + float (b));
373 int __operator - (const int a) {
376 __asm int_to_float x, a;
377 __asm float_negate x, x;
378 __asm float_to_int b, x;
382 void __operator -= (inout int a, const int b) {
386 float __operator * (const float a, const float b) {
388 // __asm float_multiply c, a, b;
391 __asm float_multiply __retVal, a, b;
394 void __operator *= (inout int a, const int b) {
395 a = int (float (a) * float (b));
398 float __operator / (const float a, const float b) {
400 // __asm float_divide c, a, b;
403 __asm float_divide __retVal, a, b;
406 void __operator /= (inout int a, const int b) {
407 a = int (float (a) / float (b));
410 void __operator += (inout vec2 v, const vec2 u) {
415 void __operator -= (inout vec2 v, const vec2 u) {
420 void __operator *= (inout vec2 v, const vec2 u) {
425 void __operator /= (inout vec2 v, const vec2 u) {
430 void __operator += (inout vec3 v, const vec3 u) {
436 void __operator -= (inout vec3 v, const vec3 u) {
442 void __operator *= (inout vec3 v, const vec3 u) {
448 void __operator /= (inout vec3 v, const vec3 u) {
454 void __operator += (inout vec4 v, const vec4 u) {
461 void __operator -= (inout vec4 v, const vec4 u) {
468 void __operator *= (inout vec4 v, const vec4 u) {
475 void __operator /= (inout vec4 v, const vec4 u) {
482 void __operator += (inout ivec2 v, const ivec2 u) {
487 void __operator -= (inout ivec2 v, const ivec2 u) {
492 void __operator *= (inout ivec2 v, const ivec2 u) {
497 void __operator /= (inout ivec2 v, const ivec2 u) {
502 void __operator += (inout ivec3 v, const ivec3 u) {
508 void __operator -= (inout ivec3 v, const ivec3 u) {
514 void __operator *= (inout ivec3 v, const ivec3 u) {
520 void __operator /= (inout ivec3 v, const ivec3 u) {
526 void __operator += (inout ivec4 v, const ivec4 u) {
533 void __operator -= (inout ivec4 v, const ivec4 u) {
540 void __operator *= (inout ivec4 v, const ivec4 u) {
547 void __operator /= (inout ivec4 v, const ivec4 u) {
554 void __operator += (inout mat2 m, const mat2 n) {
559 void __operator -= (inout mat2 m, const mat2 n) {
564 vec2 __operator * (const mat2 m, const vec2 v) {
566 v.x * m[0].x + v.y * m[1].x,
567 v.x * m[0].y + v.y * m[1].y
574 mat2 __operator * (const mat2 m, const mat2 n) {
575 return mat2 (m * n[0], m * n[1]);
578 void __operator *= (inout mat2 m, const mat2 n) {
582 void __operator /= (inout mat2 m, const mat2 n) {
587 void __operator += (inout mat3 m, const mat3 n) {
593 void __operator -= (inout mat3 m, const mat3 n) {
600 //// dot (formerly in slang_common_builtin.gc)
602 float dot(const float a, const float b)
607 float dot(const vec2 a, const vec2 b)
609 return a.x * b.x + a.y * b.y;
612 float dot(const vec3 a, const vec3 b)
614 __asm vec3_dot __retVal, a, b;
617 float dot(const vec4 a, const vec4 b)
619 __asm vec4_dot __retVal, a, b;
625 mat3 __operator * (const mat3 m, const mat3 n) {
626 // return mat3 (m * n[0], m * n[1], m * n[2]);
629 void __operator *= (inout mat3 m, const mat3 n) {
633 void __operator /= (inout mat3 m, const mat3 n) {
639 void __operator += (inout mat4 m, const mat4 n) {
646 void __operator -= (inout mat4 m, const mat4 n) {
655 vec4 __operator * (const mat4 mx, const vec4 v)
657 __retVal.x = dot(v, mx[0]);
658 __retVal.y = dot(v, mx[1]);
659 __retVal.z = dot(v, mx[2]);
660 __retVal.w = dot(v, mx[3]);
664 vec3 __operator * (const mat3 m, const vec3 v)
666 __retVal.x = dot(v, m[0]);
667 __retVal.y = dot(v, m[1]);
668 __retVal.z = dot(v, m[2]);
673 mat4 __operator * (const mat4 m, const mat4 n) {
674 return mat4 (m * n[0], m * n[1], m * n[2], m * n[3]);
677 void __operator *= (inout mat4 m, const mat4 n) {
681 void __operator /= (inout mat4 m, const mat4 n) {
688 void __operator += (inout vec2 v, const float a) {
693 void __operator -= (inout vec2 v, const float a) {
698 void __operator *= (inout vec2 v, const float a) {
703 void __operator /= (inout vec2 v, const float a) {
708 void __operator += (inout vec3 v, const float a) {
714 void __operator -= (inout vec3 v, const float a) {
720 void __operator *= (inout vec3 v, const float a) {
726 void __operator /= (inout vec3 v, const float a) {
732 void __operator += (inout vec4 v, const float a) {
739 void __operator -= (inout vec4 v, const float a) {
746 void __operator *= (inout vec4 v, const float a) {
753 void __operator /= (inout vec4 v, const float a) {
760 void __operator += (inout mat2 m, const float a) {
765 void __operator -= (inout mat2 m, const float a) {
770 void __operator *= (inout mat2 m, const float a) {
775 void __operator /= (inout mat2 m, const float a) {
780 void __operator += (inout mat3 m, const float a) {
786 void __operator -= (inout mat3 m, const float a) {
792 void __operator *= (inout mat3 m, const float a) {
798 void __operator /= (inout mat3 m, const float a) {
804 void __operator += (inout mat4 m, const float a) {
811 void __operator -= (inout mat4 m, const float a) {
818 void __operator *= (inout mat4 m, const float a) {
825 void __operator /= (inout mat4 m, const float a) {
832 vec2 __operator * (const vec2 v, const mat2 m) {
834 v.x * m[0].x + v.y * m[0].y,
835 v.x * m[1].x + v.y * m[1].y
839 void __operator *= (inout vec2 v, const mat2 m) {
843 void __operator *= (inout vec3 v, const mat3 m) {
849 vec4 __operator * (const vec4 v, const mat4 m)
868 __asm vec4_dot __retVal.x, r1, v;
869 __asm vec4_dot __retVal.y, r2, v;
870 __asm vec4_dot __retVal.z, r3, v;
871 __asm vec4_dot __retVal.w, r4, v;
875 vec3 __operator * (const vec3 v, const mat3 m)
887 __asm vec3_dot __retVal.x, r1, v;
888 __asm vec3_dot __retVal.y, r2, v;
889 __asm vec3_dot __retVal.z, r3, v;
901 void __operator *= (inout vec4 v, const mat4 m)
903 // xxx improve codegen for this case
908 float __operator - (const float a, const float b)
910 __asm vec4_subtract __retVal.x, a, b;
914 int __operator + (const int a, const int b) {
917 __asm int_to_float x, a;
918 __asm int_to_float y, b;
919 __asm float_add x, x, y;
920 __asm float_to_int c, x;
924 int __operator - (const int a, const int b) {
927 __asm int_to_float x, a;
928 __asm int_to_float y, b;
929 __asm float_negate y, y;
930 __asm float_add x, x, y;
931 __asm float_to_int c, x;
935 int __operator * (const int a, const int b) {
938 __asm int_to_float x, a;
939 __asm int_to_float y, b;
940 __asm float_multiply x, x, y;
941 __asm float_to_int c, x;
945 int __operator / (const int a, const int b) {
948 __asm int_to_float x, a;
949 __asm int_to_float y, b;
950 __asm float_divide x, x, y;
951 __asm float_to_int c, x;
959 vec2 __operator + (const vec2 v, const vec2 u)
961 __asm vec4_add __retVal.xy, v, u;
964 vec2 __operator - (const vec2 v, const vec2 u)
966 __asm vec4_subtract __retVal.xy, v, u;
969 vec2 __operator * (const vec2 v, const vec2 u)
971 __asm vec4_multiply __retVal.xy, v, u;
974 vec2 __operator / (const vec2 v, const vec2 u)
977 __asm float_rcp w.x, u.x;
978 __asm float_rcp w.y, u.y;
979 __asm vec4_multiply __retVal.xy, v, w;
985 vec3 __operator + (const vec3 v, const vec3 u)
987 __asm vec4_add __retVal.xyz, v, u;
990 vec3 __operator - (const vec3 v, const vec3 u)
992 __asm vec4_subtract __retVal.xyz, v, u;
995 vec3 __operator * (const vec3 v, const vec3 u)
997 __asm vec4_multiply __retVal.xyz, v, u;
1000 vec3 __operator / (const vec3 v, const vec3 u)
1003 __asm float_rcp w.x, u.x;
1004 __asm float_rcp w.y, u.y;
1005 __asm float_rcp w.z, u.z;
1006 __asm vec4_multiply __retVal.xyz, v, w;
1012 vec4 __operator + (const vec4 v, const vec4 u)
1014 __asm vec4_add __retVal, v, u;
1017 vec4 __operator - (const vec4 v, const vec4 u)
1019 __asm vec4_subtract __retVal, v, u;
1022 vec4 __operator * (const vec4 v, const vec4 u)
1024 __asm vec4_multiply __retVal, v, u;
1027 vec4 __operator / (const vec4 v, const vec4 u)
1030 __asm float_rcp w.x, u.x;
1031 __asm float_rcp w.y, u.y;
1032 __asm float_rcp w.z, u.z;
1033 __asm float_rcp w.w, u.w;
1034 __asm vec4_multiply __retVal, v, w;
1039 ivec2 __operator + (const ivec2 v, const ivec2 u) {
1040 return ivec2 (v.x + u.x, v.y + u.y);
1043 ivec2 __operator - (const ivec2 v, const ivec2 u) {
1044 return ivec2 (v.x - u.x, v.y - u.y);
1047 ivec2 __operator * (const ivec2 v, const ivec2 u) {
1048 return ivec2 (v.x * u.x, v.y * u.y);
1051 ivec2 __operator / (const ivec2 v, const ivec2 u) {
1052 return ivec2 (v.x / u.x, v.y / u.y);
1055 ivec3 __operator + (const ivec3 v, const ivec3 u) {
1056 return ivec3 (v.x + u.x, v.y + u.y, v.z + u.z);
1059 ivec3 __operator - (const ivec3 v, const ivec3 u) {
1060 return ivec3 (v.x - u.x, v.y - u.y, v.z - u.z);
1063 ivec3 __operator * (const ivec3 v, const ivec3 u) {
1064 return ivec3 (v.x * u.x, v.y * u.y, v.z * u.z);
1067 ivec3 __operator / (const ivec3 v, const ivec3 u) {
1068 return ivec3 (v.x / u.x, v.y / u.y, v.z / u.z);
1071 ivec4 __operator + (const ivec4 v, const ivec4 u) {
1072 return ivec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
1075 ivec4 __operator - (const ivec4 v, const ivec4 u) {
1076 return ivec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
1079 ivec4 __operator * (const ivec4 v, const ivec4 u) {
1080 return ivec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
1083 ivec4 __operator / (const ivec4 v, const ivec4 u) {
1084 return ivec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
1087 mat2 __operator + (const mat2 m, const mat2 n) {
1088 return mat2 (m[0] + n[0], m[1] + n[1]);
1091 mat2 __operator - (const mat2 m, const mat2 n) {
1092 return mat2 (m[0] - n[0], m[1] - n[1]);
1095 mat2 __operator / (const mat2 m, const mat2 n) {
1096 return mat2 (m[0] / n[0], m[1] / n[1]);
1100 mat3 __operator + (const mat3 m, const mat3 n)
1102 __retVal[0] = m[0] + n[0];
1103 __retVal[1] = m[1] + n[1];
1104 __retVal[2] = m[2] + n[2];
1107 mat3 __operator - (const mat3 m, const mat3 n)
1109 __retVal[0] = m[0] - n[0];
1110 __retVal[1] = m[1] - n[1];
1111 __retVal[2] = m[2] - n[2];
1114 mat3 __operator / (const mat3 m, const mat3 n)
1116 __retVal[0] = m[0] / n[0];
1117 __retVal[0] = m[1] / n[1];
1118 __retVal[0] = m[2] / n[2];
1122 mat4 __operator + (const mat4 m, const mat4 n)
1124 __retVal[0] = m[0] + n[0];
1125 __retVal[1] = m[1] + n[1];
1126 __retVal[2] = m[2] + n[2];
1127 __retVal[3] = m[3] + n[3];
1130 mat4 __operator - (const mat4 m, const mat4 n)
1132 __retVal[0] = m[0] - n[0];
1133 __retVal[1] = m[1] - n[1];
1134 __retVal[2] = m[2] - n[2];
1135 __retVal[3] = m[3] - n[3];
1140 mat4 __operator / (const mat4 m, const mat4 n)
1142 __retVal[0] = m[0] / n[0];
1143 __retVal[0] = m[1] / n[1];
1144 __retVal[0] = m[2] / n[2];
1145 __retVal[0] = m[3] / n[3];
1148 vec2 __operator + (const float a, const vec2 u) {
1149 return vec2 (a + u.x, a + u.y);
1152 vec2 __operator + (const vec2 v, const float b) {
1153 return vec2 (v.x + b, v.y + b);
1156 vec2 __operator - (const float a, const vec2 u) {
1157 return vec2 (a - u.x, a - u.y);
1160 vec2 __operator - (const vec2 v, const float b) {
1161 return vec2 (v.x - b, v.y - b);
1164 vec2 __operator * (const float a, const vec2 u) {
1165 return vec2 (a * u.x, a * u.y);
1168 vec2 __operator * (const vec2 v, const float b) {
1169 return vec2 (v.x * b, v.y * b);
1172 vec2 __operator / (const float a, const vec2 u) {
1173 return vec2 (a / u.x, a / u.y);
1176 vec2 __operator / (const vec2 v, const float b) {
1177 return vec2 (v.x / b, v.y / b);
1180 vec3 __operator + (const float a, const vec3 u) {
1181 return vec3 (a + u.x, a + u.y, a + u.z);
1184 vec3 __operator + (const vec3 v, const float b) {
1185 return vec3 (v.x + b, v.y + b, v.z + b);
1188 vec3 __operator - (const float a, const vec3 u) {
1189 return vec3 (a - u.x, a - u.y, a - u.z);
1192 vec3 __operator - (const vec3 v, const float b) {
1193 return vec3 (v.x - b, v.y - b, v.z - b);
1196 vec3 __operator * (const float a, const vec3 u) {
1197 return vec3 (a * u.x, a * u.y, a * u.z);
1201 vec3 __operator * (const vec3 v, const float b)
1203 __retVal.xyz = v.xyz * b.xxx;
1206 vec3 __operator / (const float a, const vec3 u) {
1207 return vec3 (a / u.x, a / u.y, a / u.z);
1210 vec3 __operator / (const vec3 v, const float b) {
1211 return vec3 (v.x / b, v.y / b, v.z / b);
1214 vec4 __operator + (const float a, const vec4 u) {
1215 return vec4 (a + u.x, a + u.y, a + u.z, a + u.w);
1218 vec4 __operator + (const vec4 v, const float b) {
1219 return vec4 (v.x + b, v.y + b, v.z + b, v.w + b);
1222 vec4 __operator - (const float a, const vec4 u) {
1223 return vec4 (a - u.x, a - u.y, a - u.z, a - u.w);
1226 vec4 __operator - (const vec4 v, const float b) {
1227 return vec4 (v.x - b, v.y - b, v.z - b, v.w - b);
1230 vec4 __operator * (const float a, const vec4 u) {
1231 return vec4 (a * u.x, a * u.y, a * u.z, a * u.w);
1235 vec4 __operator * (const vec4 v, const float b)
1237 __asm vec4_multiply __retVal.xyzw, v.xyzw, b.xxxx;
1240 vec4 __operator / (const float a, const vec4 u) {
1241 return vec4 (a / u.x, a / u.y, a / u.z, a / u.w);
1244 vec4 __operator / (const vec4 v, const float b) {
1245 return vec4 (v.x / b, v.y / b, v.z / b, v.w / b);
1248 mat2 __operator + (const float a, const mat2 n) {
1249 return mat2 (a + n[0], a + n[1]);
1252 mat2 __operator + (const mat2 m, const float b) {
1253 return mat2 (m[0] + b, m[1] + b);
1256 mat2 __operator - (const float a, const mat2 n) {
1257 return mat2 (a - n[0], a - n[1]);
1260 mat2 __operator - (const mat2 m, const float b) {
1261 return mat2 (m[0] - b, m[1] - b);
1264 mat2 __operator * (const float a, const mat2 n) {
1265 return mat2 (a * n[0], a * n[1]);
1268 mat2 __operator * (const mat2 m, const float b) {
1269 return mat2 (m[0] * b, m[1] * b);
1272 mat2 __operator / (const float a, const mat2 n) {
1273 return mat2 (a / n[0], a / n[1]);
1276 mat2 __operator / (const mat2 m, const float b) {
1277 return mat2 (m[0] / b, m[1] / b);
1280 mat3 __operator + (const float a, const mat3 n) {
1281 return mat3 (a + n[0], a + n[1], a + n[2]);
1284 mat3 __operator + (const mat3 m, const float b) {
1285 return mat3 (m[0] + b, m[1] + b, m[2] + b);
1288 mat3 __operator - (const float a, const mat3 n) {
1289 return mat3 (a - n[0], a - n[1], a - n[2]);
1292 mat3 __operator - (const mat3 m, const float b) {
1293 return mat3 (m[0] - b, m[1] - b, m[2] - b);
1296 mat3 __operator * (const float a, const mat3 n) {
1297 return mat3 (a * n[0], a * n[1], a * n[2]);
1300 mat3 __operator * (const mat3 m, const float b) {
1301 return mat3 (m[0] * b, m[1] * b, m[2] * b);
1304 mat3 __operator / (const float a, const mat3 n) {
1305 return mat3 (a / n[0], a / n[1], a / n[2]);
1308 mat3 __operator / (const mat3 m, const float b) {
1309 return mat3 (m[0] / b, m[1] / b, m[2] / b);
1312 mat4 __operator + (const float a, const mat4 n) {
1313 return mat4 (a + n[0], a + n[1], a + n[2], a + n[3]);
1316 mat4 __operator + (const mat4 m, const float b) {
1317 return mat4 (m[0] + b, m[1] + b, m[2] + b, m[3] + b);
1320 mat4 __operator - (const float a, const mat4 n) {
1321 return mat4 (a - n[0], a - n[1], a - n[2], a - n[3]);
1324 mat4 __operator - (const mat4 m, const float b) {
1325 return mat4 (m[0] - b, m[1] - b, m[2] - b, m[3] - b);
1328 mat4 __operator * (const float a, const mat4 n) {
1329 return mat4 (a * n[0], a * n[1], a * n[2], a * n[3]);
1332 mat4 __operator * (const mat4 m, const float b) {
1333 return mat4 (m[0] * b, m[1] * b, m[2] * b, m[3] * b);
1336 mat4 __operator / (const float a, const mat4 n) {
1337 return mat4 (a / n[0], a / n[1], a / n[2], a / n[3]);
1340 mat4 __operator / (const mat4 m, const float b) {
1341 return mat4 (m[0] / b, m[1] / b, m[2] / b, m[3] / b);
1344 ivec2 __operator + (const int a, const ivec2 u) {
1345 return ivec2 (a) + u;
1348 ivec2 __operator + (const ivec2 v, const int b) {
1349 return v + ivec2 (b);
1352 ivec2 __operator - (const int a, const ivec2 u) {
1353 return ivec2 (a) - u;
1356 ivec2 __operator - (const ivec2 v, const int b) {
1357 return v - ivec2 (b);
1360 ivec2 __operator * (const int a, const ivec2 u) {
1361 return ivec2 (a) * u;
1364 ivec2 __operator * (const ivec2 v, const int b) {
1365 return v * ivec2 (b);
1368 ivec2 __operator / (const int a, const ivec2 u) {
1369 return ivec2 (a) / u;
1372 ivec2 __operator / (const ivec2 v, const int b) {
1373 return v / ivec2 (b);
1376 ivec3 __operator + (const int a, const ivec3 u) {
1377 return ivec3 (a) + u;
1380 ivec3 __operator + (const ivec3 v, const int b) {
1381 return v + ivec3 (b);
1384 ivec3 __operator - (const int a, const ivec3 u) {
1385 return ivec3 (a) - u;
1388 ivec3 __operator - (const ivec3 v, const int b) {
1389 return v - ivec3 (b);
1392 ivec3 __operator * (const int a, const ivec3 u) {
1393 return ivec3 (a) * u;
1396 ivec3 __operator * (const ivec3 v, const int b) {
1397 return v * ivec3 (b);
1400 ivec3 __operator / (const int a, const ivec3 u) {
1401 return ivec3 (a) / u;
1404 ivec3 __operator / (const ivec3 v, const int b) {
1405 return v / ivec3 (b);
1408 ivec4 __operator + (const int a, const ivec4 u) {
1409 return ivec4 (a) + u;
1412 ivec4 __operator + (const ivec4 v, const int b) {
1413 return v + ivec4 (b);
1416 ivec4 __operator - (const int a, const ivec4 u) {
1417 return ivec4 (a) - u;
1420 ivec4 __operator - (const ivec4 v, const int b) {
1421 return v - ivec4 (b);
1424 ivec4 __operator * (const int a, const ivec4 u) {
1425 return ivec4 (a) * u;
1428 ivec4 __operator * (const ivec4 v, const int b) {
1429 return v * ivec4 (b);
1432 ivec4 __operator / (const int a, const ivec4 u) {
1433 return ivec4 (a) / u;
1436 ivec4 __operator / (const ivec4 v, const int b) {
1437 return v / ivec4 (b);
1440 vec2 __operator - (const vec2 v) {
1441 return vec2 (-v.x, -v.y);
1444 vec3 __operator - (const vec3 v) {
1445 return vec3 (-v.x, -v.y, -v.z);
1448 vec4 __operator - (const vec4 v) {
1449 return vec4 (-v.x, -v.y, -v.z, -v.w);
1452 ivec2 __operator - (const ivec2 v) {
1453 return ivec2 (-v.x, -v.y);
1456 ivec3 __operator - (const ivec3 v) {
1457 return ivec3 (-v.x, -v.y, -v.z);
1460 ivec4 __operator - (const ivec4 v) {
1461 return ivec4 (-v.x, -v.y, -v.z, -v.w);
1464 mat2 __operator - (const mat2 m) {
1465 return mat2 (-m[0], -m[1]);
1468 mat3 __operator - (const mat3 m) {
1469 return mat3 (-m[0], -m[1], -m[2]);
1472 mat4 __operator - (const mat4 m) {
1473 return mat4 (-m[0], -m[1], -m[2], -m[3]);
1476 void __operator -- (inout float a) {
1480 void __operator -- (inout int a) {
1484 void __operator -- (inout vec2 v) {
1489 void __operator -- (inout vec3 v) {
1495 void __operator -- (inout vec4 v) {
1502 void __operator -- (inout ivec2 v) {
1507 void __operator -- (inout ivec3 v) {
1513 void __operator -- (inout ivec4 v) {
1520 void __operator -- (inout mat2 m) {
1525 void __operator -- (inout mat3 m) {
1531 void __operator -- (inout mat4 m) {
1538 void __operator ++ (inout float a) {
1542 void __operator ++ (inout int a) {
1546 void __operator ++ (inout vec2 v) {
1551 void __operator ++ (inout vec3 v) {
1557 void __operator ++ (inout vec4 v) {
1564 void __operator ++ (inout ivec2 v) {
1569 void __operator ++ (inout ivec3 v) {
1575 void __operator ++ (inout ivec4 v) {
1582 void __operator ++ (inout mat2 m) {
1587 void __operator ++ (inout mat3 m) {
1593 void __operator ++ (inout mat4 m) {
1601 // NOTE: postfix increment and decrement operators take additional dummy int parameter to
1602 // distinguish their prototypes from prefix ones.
1605 float __operator -- (inout float a, const int) {
1611 int __operator -- (inout int a, const int) {
1617 vec2 __operator -- (inout vec2 v, const int) {
1618 return vec2 (v.x--, v.y--);
1621 vec3 __operator -- (inout vec3 v, const int) {
1622 return vec3 (v.x--, v.y--, v.z--);
1625 vec4 __operator -- (inout vec4 v, const int) {
1626 return vec4 (v.x--, v.y--, v.z--, v.w--);
1629 ivec2 __operator -- (inout ivec2 v, const int) {
1630 return ivec2 (v.x--, v.y--);
1633 ivec3 __operator -- (inout ivec3 v, const int) {
1634 return ivec3 (v.x--, v.y--, v.z--);
1637 ivec4 __operator -- (inout ivec4 v, const int) {
1638 return ivec4 (v.x--, v.y--, v.z--, v.w--);
1641 mat2 __operator -- (inout mat2 m, const int) {
1642 return mat2 (m[0]--, m[1]--);
1645 mat3 __operator -- (inout mat3 m, const int) {
1646 return mat3 (m[0]--, m[1]--, m[2]--);
1649 mat4 __operator -- (inout mat4 m, const int) {
1650 return mat4 (m[0]--, m[1]--, m[2]--, m[3]--);
1653 float __operator ++ (inout float a, const int) {
1659 int __operator ++ (inout int a, const int) {
1665 vec2 __operator ++ (inout vec2 v, const int) {
1666 return vec2 (v.x++, v.y++);
1669 vec3 __operator ++ (inout vec3 v, const int) {
1670 return vec3 (v.x++, v.y++, v.z++);
1673 vec4 __operator ++ (inout vec4 v, const int) {
1674 return vec4 (v.x++, v.y++, v.z++, v.w++);
1677 ivec2 __operator ++ (inout ivec2 v, const int) {
1678 return ivec2 (v.x++, v.y++);
1681 ivec3 __operator ++ (inout ivec3 v, const int) {
1682 return ivec3 (v.x++, v.y++, v.z++);
1685 ivec4 __operator ++ (inout ivec4 v, const int) {
1686 return ivec4 (v.x++, v.y++, v.z++, v.w++);
1689 mat2 __operator ++ (inout mat2 m, const int) {
1690 return mat2 (m[0]++, m[1]++);
1693 mat3 __operator ++ (inout mat3 m, const int) {
1694 return mat3 (m[0]++, m[1]++, m[2]++);
1697 mat4 __operator ++ (inout mat4 m, const int) {
1698 return mat4 (m[0]++, m[1]++, m[2]++, m[3]++);
1702 // XXX are the inequality operators for floats/ints really needed????
1703 bool __operator < (const float a, const float b)
1705 __asm vec4_sgt __retVal.x, b, a;
1709 bool __operator < (const int a, const int b) {
1710 return float (a) < float (b);
1713 bool __operator > (const float a, const float b) {
1715 __asm float_less c, b, a;
1719 bool __operator > (const int a, const int b) {
1720 return float (a) > float (b);
1723 bool __operator >= (const float a, const float b) {
1725 __asm float_less g, b, a;
1726 __asm float_equal e, a, b;
1730 bool __operator >= (const int a, const int b) {
1731 return float (a) >= float (b);
1734 bool __operator <= (const float a, const float b) {
1736 __asm float_less g, a, b;
1737 __asm float_equal e, a, b;
1741 bool __operator <= (const int a, const int b) {
1742 return float (a) <= float (b);
1745 bool __operator ^^ (const bool a, const bool b) {
1750 // These operators are handled internally by the compiler:
1752 // bool __operator && (bool a, bool b) {
1753 // return a ? b : false;
1755 // bool __operator || (bool a, bool b) {
1756 // return a ? true : b;
1760 bool __operator ! (const bool a) {
1765 // MESA-specific extension functions.
1768 void printMESA (const float f) {
1769 __asm float_print f;
1772 void printMESA (const int i) {
1776 void printMESA (const bool b) {
1780 void printMESA (const vec2 v) {
1785 void printMESA (const vec3 v) {
1791 void printMESA (const vec4 v) {
1798 void printMESA (const ivec2 v) {
1803 void printMESA (const ivec3 v) {
1809 void printMESA (const ivec4 v) {
1816 void printMESA (const bvec2 v) {
1821 void printMESA (const bvec3 v) {
1827 void printMESA (const bvec4 v) {
1834 void printMESA (const mat2 m) {
1839 void printMESA (const mat3 m) {
1845 void printMESA (const mat4 m) {
1852 void printMESA (const sampler1D e) {
1856 void printMESA (const sampler2D e) {
1860 void printMESA (const sampler3D e) {
1864 void printMESA (const samplerCube e) {
1868 void printMESA (const sampler1DShadow e) {
1872 void printMESA (const sampler2DShadow e) {