Uniform matrix support.
[mesa.git] / src / mesa / shader / slang / library / slang_core.gc
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 //
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.
31 //
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.
35 //
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.
39 //
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.
44 //
45 // A variable identifier is a variable name declared earlier in the code
46 // (as a function parameter, local or global variable).
47 //
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
51 // identifier.
52 //
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,
56 // for example:
57 //
58 // ivec2 __operator + (const ivec2 x, const ivec2 y) {
59 // return ivec2 (x[0] + y[0], x[1] + y[1]);
60 // }
61 //
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.
66 //
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,
75 // raise an error,
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,
81 //
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> :
91 // false",
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.
102 //
103
104 //bp:
105 vec4 vec4(const float a1, const float b1, const float c1, const float d1)
106 {
107 __retVal.x = a1;
108 __retVal.y = b1;
109 __retVal.z = c1;
110 __retVal.w = d1;
111 }
112
113 int __constructor (const float f) {
114 int i;
115 __asm float_to_int i, f;
116 return i;
117 }
118
119 bool __constructor (const int i) {
120 return i != 0;
121 }
122
123 bool __constructor (const float f) {
124 return f != 0.0;
125 }
126
127 int __constructor (const bool b) {
128 return b ? 1 : 0;
129 }
130
131 float __constructor (const bool b) {
132 return b ? 1.0 : 0.0;
133 }
134
135 float __constructor (const int i) {
136 float f;
137 __asm int_to_float f, i;
138 return f;
139 }
140
141 bool __constructor (const bool b) {
142 return b;
143 }
144
145 int __constructor (const int i) {
146 return i;
147 }
148
149 float __constructor (const float f) {
150 return f;
151 }
152
153 vec2 __constructor (const float f) {
154 return vec2 (f, f);
155 }
156
157 vec2 __constructor (const int i) {
158 float x;
159 __asm int_to_float x, i;
160 return vec2 (x);
161 }
162
163 vec2 __constructor (const bool b) {
164 return vec2 (b ? 1.0 : 0.0);
165 }
166
167 vec3 __constructor (const float f) {
168 return vec3 (f, f, f);
169 }
170
171 vec3 __constructor (const int i) {
172 float x;
173 __asm int_to_float x, i;
174 return vec3 (x);
175 }
176
177 vec3 __constructor (const bool b) {
178 return vec3 (b ? 1.0 : 0.0);
179 }
180
181 //bp: TODO replace with asm == f.xxxx
182 vec4 __constructor (const float f) {
183 return vec4 (f, f, f, f);
184 }
185
186 vec4 __constructor (const int i) {
187 float x;
188 __asm int_to_float x, i;
189 return vec4 (x);
190 }
191
192 vec4 __constructor (const bool b) {
193 return vec4 (b ? 1.0 : 0.0);
194 }
195
196 ivec2 __constructor (const int i) {
197 return ivec2 (i, i);
198 }
199
200 ivec2 __constructor (const float f) {
201 return ivec2 (int (f));
202 }
203
204 ivec2 __constructor (const bool b) {
205 return ivec2 (int (b));
206 }
207
208 ivec3 __constructor (const int i) {
209 return ivec3 (i, i, i);
210 }
211
212 ivec3 __constructor (const float f) {
213 return ivec3 (int (f));
214 }
215
216 ivec3 __constructor (const bool b) {
217 return ivec3 (int (b));
218 }
219
220 ivec4 __constructor (const int i) {
221 return ivec4 (i, i, i, i);
222 }
223
224 ivec4 __constructor (const float f) {
225 return ivec4 (int (f));
226 }
227
228 ivec4 __constructor (const bool b) {
229 return ivec4 (int (b));
230 }
231
232 bvec2 __constructor (const bool b) {
233 return bvec2 (b, b);
234 }
235
236 bvec2 __constructor (const float f) {
237 return bvec2 (bool (f));
238 }
239
240 bvec2 __constructor (const int i) {
241 return bvec2 (bool (i));
242 }
243
244 bvec3 __constructor (const bool b) {
245 return bvec3 (b, b, b);
246 }
247
248 bvec3 __constructor (const float f) {
249 return bvec3 (bool (f));
250 }
251
252 bvec3 __constructor (const int i) {
253 return bvec3 (bool (i));
254 }
255
256 bvec4 __constructor (const bool b) {
257 return bvec4 (b, b, b, b);
258 }
259
260 bvec4 __constructor (const float f) {
261 return bvec4 (bool (f));
262 }
263
264 bvec4 __constructor (const int i) {
265 return bvec4 (bool (i));
266 }
267
268
269
270 //// mat2 constructors
271
272 mat2 __constructor (const float f) {
273 return mat2 (f, 0.0, 0.0, f);
274 }
275
276 mat2 __constructor (const int i) {
277 float x;
278 __asm int_to_float x, i;
279 return mat2 (x);
280 }
281
282 mat2 __constructor (const bool b) {
283 return mat2 (b ? 1.0 : 0.0);
284 }
285
286
287 //// mat3 constructors
288
289 mat3 __constructor (const float f) {
290 return mat3 (f, 0.0, 0.0, 0.0, f, 0.0, 0.0, 0.0, f);
291 }
292
293 mat3 __constructor (const int i) {
294 float x;
295 __asm int_to_float x, i;
296 return mat3 (x);
297 }
298
299 mat3 __constructor (const bool b) {
300 return mat3 (b ? 1.0 : 0.0);
301 }
302
303
304 //// mat4 constructors
305
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);
308 }
309
310 mat4 __constructor (const int i) {
311 float x;
312 __asm int_to_float x, i;
313 return mat4 (x);
314 }
315
316 mat4 __constructor (const bool b) {
317 return mat4 (b ? 1.0 : 0.0);
318 }
319
320 mat4 __constructor (const vec4 r0, const vec4 r1, const vec4 r2, const vec4 r3)
321 {
322 __retVal[0] = r0;
323 __retVal[1] = r1;
324 __retVal[2] = r2;
325 __retVal[3] = r3;
326 }
327
328
329 //// operator +=
330
331 void __operator += (inout float a, const float b)
332 {
333 __asm vec4_add a.x, a, b;
334 }
335
336 void __operator -= (inout float a, const float b)
337 {
338 __asm vec4_subtract a.x, a, b;
339 }
340
341 void __operator *= (inout float a, const float b)
342 {
343 __asm vec4_multiply a.x, a, b;
344 }
345
346 void __operator /= (inout float a, const float b)
347 {
348 float w; // = 1 / b
349 __asm float_rcp w.x, b;
350 __asm vec4_multiply a.x, a, w;
351 }
352
353
354
355 float __operator - (const float a) {
356 float b;
357 __asm float_negate b, a;
358 return b;
359 }
360
361 float __operator + (const float a, const float b) {
362 // float c;
363 // __asm float_add c, a, b;
364 // return c;
365 //bp:
366 __asm float_add __retVal, a, b;
367 }
368
369 void __operator += (inout int a, const int b) {
370 a = int (float (a) + float (b));
371 }
372
373 int __operator - (const int a) {
374 float x;
375 int b;
376 __asm int_to_float x, a;
377 __asm float_negate x, x;
378 __asm float_to_int b, x;
379 return b;
380 }
381
382 void __operator -= (inout int a, const int b) {
383 a += -b;
384 }
385
386 float __operator * (const float a, const float b) {
387 // float c;
388 // __asm float_multiply c, a, b;
389 // return c;
390 //bp:
391 __asm float_multiply __retVal, a, b;
392 }
393
394 void __operator *= (inout int a, const int b) {
395 a = int (float (a) * float (b));
396 }
397
398 float __operator / (const float a, const float b) {
399 // float c;
400 // __asm float_divide c, a, b;
401 // return c;
402 //bp:
403 __asm float_divide __retVal, a, b;
404 }
405
406 void __operator /= (inout int a, const int b) {
407 a = int (float (a) / float (b));
408 }
409
410 void __operator += (inout vec2 v, const vec2 u) {
411 v.x += u.x;
412 v.y += u.y;
413 }
414
415 void __operator -= (inout vec2 v, const vec2 u) {
416 v.x -= u.x;
417 v.y -= u.y;
418 }
419
420 void __operator *= (inout vec2 v, const vec2 u) {
421 v.x *= u.x;
422 v.y *= u.y;
423 }
424
425 void __operator /= (inout vec2 v, const vec2 u) {
426 v.x /= u.x;
427 v.y /= u.y;
428 }
429
430 void __operator += (inout vec3 v, const vec3 u) {
431 v.x += u.x;
432 v.y += u.y;
433 v.z += u.z;
434 }
435
436 void __operator -= (inout vec3 v, const vec3 u) {
437 v.x -= u.x;
438 v.y -= u.y;
439 v.z -= u.z;
440 }
441
442 void __operator *= (inout vec3 v, const vec3 u) {
443 v.x *= u.x;
444 v.y *= u.y;
445 v.z *= u.z;
446 }
447
448 void __operator /= (inout vec3 v, const vec3 u) {
449 v.x /= u.x;
450 v.y /= u.y;
451 v.z /= u.z;
452 }
453
454 void __operator += (inout vec4 v, const vec4 u) {
455 v.x += u.x;
456 v.y += u.y;
457 v.z += u.z;
458 v.w += u.w;
459 }
460
461 void __operator -= (inout vec4 v, const vec4 u) {
462 v.x -= u.x;
463 v.y -= u.y;
464 v.z -= u.z;
465 v.w -= u.w;
466 }
467
468 void __operator *= (inout vec4 v, const vec4 u) {
469 v.x *= u.x;
470 v.y *= u.y;
471 v.z *= u.z;
472 v.w *= u.w;
473 }
474
475 void __operator /= (inout vec4 v, const vec4 u) {
476 v.x /= u.x;
477 v.y /= u.y;
478 v.z /= u.z;
479 v.w /= u.w;
480 }
481
482 void __operator += (inout ivec2 v, const ivec2 u) {
483 v.x += u.x;
484 v.y += u.y;
485 }
486
487 void __operator -= (inout ivec2 v, const ivec2 u) {
488 v.x -= u.x;
489 v.y -= u.y;
490 }
491
492 void __operator *= (inout ivec2 v, const ivec2 u) {
493 v.x *= u.x;
494 v.y *= u.y;
495 }
496
497 void __operator /= (inout ivec2 v, const ivec2 u) {
498 v.x /= u.x;
499 v.y /= u.y;
500 }
501
502 void __operator += (inout ivec3 v, const ivec3 u) {
503 v.x += u.x;
504 v.y += u.y;
505 v.z += u.z;
506 }
507
508 void __operator -= (inout ivec3 v, const ivec3 u) {
509 v.x -= u.x;
510 v.y -= u.y;
511 v.z -= u.z;
512 }
513
514 void __operator *= (inout ivec3 v, const ivec3 u) {
515 v.x *= u.x;
516 v.y *= u.y;
517 v.z *= u.z;
518 }
519
520 void __operator /= (inout ivec3 v, const ivec3 u) {
521 v.x /= u.x;
522 v.y /= u.y;
523 v.z /= u.z;
524 }
525
526 void __operator += (inout ivec4 v, const ivec4 u) {
527 v.x += u.x;
528 v.y += u.y;
529 v.z += u.z;
530 v.w += u.w;
531 }
532
533 void __operator -= (inout ivec4 v, const ivec4 u) {
534 v.x -= u.x;
535 v.y -= u.y;
536 v.z -= u.z;
537 v.w -= u.w;
538 }
539
540 void __operator *= (inout ivec4 v, const ivec4 u) {
541 v.x *= u.x;
542 v.y *= u.y;
543 v.z *= u.z;
544 v.w *= u.w;
545 }
546
547 void __operator /= (inout ivec4 v, const ivec4 u) {
548 v.x /= u.x;
549 v.y /= u.y;
550 v.z /= u.z;
551 v.w /= u.w;
552 }
553
554 void __operator += (inout mat2 m, const mat2 n) {
555 m[0] += n[0];
556 m[1] += n[1];
557 }
558
559 void __operator -= (inout mat2 m, const mat2 n) {
560 m[0] -= n[0];
561 m[1] -= n[1];
562 }
563
564 vec2 __operator * (const mat2 m, const vec2 v) {
565 return vec2 (
566 v.x * m[0].x + v.y * m[1].x,
567 v.x * m[0].y + v.y * m[1].y
568 );
569 }
570
571
572
573
574 mat2 __operator * (const mat2 m, const mat2 n) {
575 return mat2 (m * n[0], m * n[1]);
576 }
577
578 void __operator *= (inout mat2 m, const mat2 n) {
579 m = m * n;
580 }
581
582 void __operator /= (inout mat2 m, const mat2 n) {
583 m[0] /= n[0];
584 m[1] /= n[1];
585 }
586
587 void __operator += (inout mat3 m, const mat3 n) {
588 m[0] += n[0];
589 m[1] += n[1];
590 m[2] += n[2];
591 }
592
593 void __operator -= (inout mat3 m, const mat3 n) {
594 m[0] -= n[0];
595 m[1] -= n[1];
596 m[2] -= n[2];
597 }
598
599
600 //// dot (formerly in slang_common_builtin.gc)
601
602 float dot(const float a, const float b)
603 {
604 return a * b;
605 }
606
607 float dot(const vec2 a, const vec2 b)
608 {
609 return a.x * b.x + a.y * b.y;
610 }
611
612 float dot(const vec3 a, const vec3 b)
613 {
614 __asm vec3_dot __retVal, a, b;
615 }
616
617 float dot(const vec4 a, const vec4 b)
618 {
619 __asm vec4_dot __retVal, a, b;
620 }
621
622
623
624
625 mat3 __operator * (const mat3 m, const mat3 n) {
626 // return mat3 (m * n[0], m * n[1], m * n[2]);
627 }
628
629 void __operator *= (inout mat3 m, const mat3 n) {
630 m = m * n;
631 }
632
633 void __operator /= (inout mat3 m, const mat3 n) {
634 m[0] /= n[0];
635 m[1] /= n[1];
636 m[2] /= n[2];
637 }
638
639 void __operator += (inout mat4 m, const mat4 n) {
640 m[0] += n[0];
641 m[1] += n[1];
642 m[2] += n[2];
643 m[3] += n[3];
644 }
645
646 void __operator -= (inout mat4 m, const mat4 n) {
647 m[0] -= n[0];
648 m[1] -= n[1];
649 m[2] -= n[2];
650 m[3] -= n[3];
651 }
652
653
654
655 vec4 __operator * (const mat4 mx, const vec4 v)
656 {
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]);
661 }
662
663 //matmul
664 vec3 __operator * (const mat3 m, const vec3 v)
665 {
666 __retVal.x = dot(v, m[0]);
667 __retVal.y = dot(v, m[1]);
668 __retVal.z = dot(v, m[2]);
669 }
670
671
672 // xxx move this
673 mat4 __operator * (const mat4 m, const mat4 n) {
674 return mat4 (m * n[0], m * n[1], m * n[2], m * n[3]);
675 }
676
677 void __operator *= (inout mat4 m, const mat4 n) {
678 m = m * n;
679 }
680
681 void __operator /= (inout mat4 m, const mat4 n) {
682 m[0] /= n[0];
683 m[1] /= n[1];
684 m[2] /= n[2];
685 m[3] /= n[3];
686 }
687
688 void __operator += (inout vec2 v, const float a) {
689 v.x += a;
690 v.y += a;
691 }
692
693 void __operator -= (inout vec2 v, const float a) {
694 v.x -= a;
695 v.y -= a;
696 }
697
698 void __operator *= (inout vec2 v, const float a) {
699 v.x *= a;
700 v.y *= a;
701 }
702
703 void __operator /= (inout vec2 v, const float a) {
704 v.x /= a;
705 v.y /= a;
706 }
707
708 void __operator += (inout vec3 v, const float a) {
709 v.x += a;
710 v.y += a;
711 v.z += a;
712 }
713
714 void __operator -= (inout vec3 v, const float a) {
715 v.x -= a;
716 v.y -= a;
717 v.z -= a;
718 }
719
720 void __operator *= (inout vec3 v, const float a) {
721 v.x *= a;
722 v.y *= a;
723 v.z *= a;
724 }
725
726 void __operator /= (inout vec3 v, const float a) {
727 v.x /= a;
728 v.y /= a;
729 v.z /= a;
730 }
731
732 void __operator += (inout vec4 v, const float a) {
733 v.x += a;
734 v.y += a;
735 v.z += a;
736 v.w += a;
737 }
738
739 void __operator -= (inout vec4 v, const float a) {
740 v.x -= a;
741 v.y -= a;
742 v.z -= a;
743 v.w -= a;
744 }
745
746 void __operator *= (inout vec4 v, const float a) {
747 v.x *= a;
748 v.y *= a;
749 v.z *= a;
750 v.w *= a;
751 }
752
753 void __operator /= (inout vec4 v, const float a) {
754 v.x /= a;
755 v.y /= a;
756 v.z /= a;
757 v.w /= a;
758 }
759
760 void __operator += (inout mat2 m, const float a) {
761 m[0] += a;
762 m[1] += a;
763 }
764
765 void __operator -= (inout mat2 m, const float a) {
766 m[0] -= a;
767 m[1] -= a;
768 }
769
770 void __operator *= (inout mat2 m, const float a) {
771 m[0] *= a;
772 m[1] *= a;
773 }
774
775 void __operator /= (inout mat2 m, const float a) {
776 m[0] /= a;
777 m[1] /= a;
778 }
779
780 void __operator += (inout mat3 m, const float a) {
781 m[0] += a;
782 m[1] += a;
783 m[2] += a;
784 }
785
786 void __operator -= (inout mat3 m, const float a) {
787 m[0] -= a;
788 m[1] -= a;
789 m[2] -= a;
790 }
791
792 void __operator *= (inout mat3 m, const float a) {
793 m[0] *= a;
794 m[1] *= a;
795 m[2] *= a;
796 }
797
798 void __operator /= (inout mat3 m, const float a) {
799 m[0] /= a;
800 m[1] /= a;
801 m[2] /= a;
802 }
803
804 void __operator += (inout mat4 m, const float a) {
805 m[0] += a;
806 m[1] += a;
807 m[2] += a;
808 m[3] += a;
809 }
810
811 void __operator -= (inout mat4 m, const float a) {
812 m[0] -= a;
813 m[1] -= a;
814 m[2] -= a;
815 m[3] -= a;
816 }
817
818 void __operator *= (inout mat4 m, const float a) {
819 m[0] *= a;
820 m[1] *= a;
821 m[2] *= a;
822 m[3] *= a;
823 }
824
825 void __operator /= (inout mat4 m, const float a) {
826 m[0] /= a;
827 m[1] /= a;
828 m[2] /= a;
829 m[3] /= a;
830 }
831
832 vec2 __operator * (const vec2 v, const mat2 m) {
833 return vec2 (
834 v.x * m[0].x + v.y * m[0].y,
835 v.x * m[1].x + v.y * m[1].y
836 );
837 }
838
839 void __operator *= (inout vec2 v, const mat2 m) {
840 v = v * m;
841 }
842
843 void __operator *= (inout vec3 v, const mat3 m) {
844 // v = v * m;
845 }
846
847
848
849 vec4 __operator * (const vec4 v, const mat4 m)
850 {
851 vec4 r1, r2, r3, r4;
852 r1.x = m[0].x;
853 r1.y = m[1].x;
854 r1.z = m[2].x;
855 r1.w = m[3].x;
856 r2.x = m[0].y;
857 r2.y = m[1].y;
858 r2.z = m[2].y;
859 r2.w = m[3].y;
860 r3.x = m[0].z;
861 r3.y = m[1].z;
862 r3.z = m[2].z;
863 r3.w = m[3].z;
864 r4.x = m[0].w;
865 r4.y = m[1].w;
866 r4.z = m[2].w;
867 r4.w = m[3].w;
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;
872 }
873
874 // matmul
875 vec3 __operator * (const vec3 v, const mat3 m)
876 {
877 vec3 r1, r2, r3;
878 r1.x = m[0].x;
879 r1.y = m[1].x;
880 r1.z = m[2].x;
881 r2.x = m[0].y;
882 r2.y = m[1].y;
883 r2.z = m[2].y;
884 r3.x = m[0].z;
885 r3.y = m[1].z;
886 r3.z = m[2].z;
887 __asm vec3_dot __retVal.x, r1, v;
888 __asm vec3_dot __retVal.y, r2, v;
889 __asm vec3_dot __retVal.z, r3, v;
890 }
891
892
893
894
895
896
897
898
899
900
901 void __operator *= (inout vec4 v, const mat4 m)
902 {
903 // xxx improve codegen for this case
904 v = v * m;
905 }
906
907
908 float __operator - (const float a, const float b)
909 {
910 __asm vec4_subtract __retVal.x, a, b;
911 }
912
913
914 int __operator + (const int a, const int b) {
915 float x, y;
916 int c;
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;
921 return c;
922 }
923
924 int __operator - (const int a, const int b) {
925 float x, y;
926 int c;
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;
932 return c;
933 }
934
935 int __operator * (const int a, const int b) {
936 float x, y;
937 int c;
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;
942 return c;
943 }
944
945 int __operator / (const int a, const int b) {
946 float x, y;
947 int c;
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;
952 return c;
953 }
954
955
956
957 //// vec2 +,-,*,/
958
959 vec2 __operator + (const vec2 v, const vec2 u)
960 {
961 __asm vec4_add __retVal.xy, v, u;
962 }
963
964 vec2 __operator - (const vec2 v, const vec2 u)
965 {
966 __asm vec4_subtract __retVal.xy, v, u;
967 }
968
969 vec2 __operator * (const vec2 v, const vec2 u)
970 {
971 __asm vec4_multiply __retVal.xy, v, u;
972 }
973
974 vec2 __operator / (const vec2 v, const vec2 u)
975 {
976 vec2 w; // = 1 / 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;
980 }
981
982
983 //// vec3 +,-,*,/
984
985 vec3 __operator + (const vec3 v, const vec3 u)
986 {
987 __asm vec4_add __retVal.xyz, v, u;
988 }
989
990 vec3 __operator - (const vec3 v, const vec3 u)
991 {
992 __asm vec4_subtract __retVal.xyz, v, u;
993 }
994
995 vec3 __operator * (const vec3 v, const vec3 u)
996 {
997 __asm vec4_multiply __retVal.xyz, v, u;
998 }
999
1000 vec3 __operator / (const vec3 v, const vec3 u)
1001 {
1002 vec3 w; // = 1 / 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;
1007 }
1008
1009
1010 //// vec4 +,-,*,/
1011
1012 vec4 __operator + (const vec4 v, const vec4 u)
1013 {
1014 __asm vec4_add __retVal, v, u;
1015 }
1016
1017 vec4 __operator - (const vec4 v, const vec4 u)
1018 {
1019 __asm vec4_subtract __retVal, v, u;
1020 }
1021
1022 vec4 __operator * (const vec4 v, const vec4 u)
1023 {
1024 __asm vec4_multiply __retVal, v, u;
1025 }
1026
1027 vec4 __operator / (const vec4 v, const vec4 u)
1028 {
1029 vec4 w; // = 1 / 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;
1035 }
1036
1037
1038
1039 ivec2 __operator + (const ivec2 v, const ivec2 u) {
1040 return ivec2 (v.x + u.x, v.y + u.y);
1041 }
1042
1043 ivec2 __operator - (const ivec2 v, const ivec2 u) {
1044 return ivec2 (v.x - u.x, v.y - u.y);
1045 }
1046
1047 ivec2 __operator * (const ivec2 v, const ivec2 u) {
1048 return ivec2 (v.x * u.x, v.y * u.y);
1049 }
1050
1051 ivec2 __operator / (const ivec2 v, const ivec2 u) {
1052 return ivec2 (v.x / u.x, v.y / u.y);
1053 }
1054
1055 ivec3 __operator + (const ivec3 v, const ivec3 u) {
1056 return ivec3 (v.x + u.x, v.y + u.y, v.z + u.z);
1057 }
1058
1059 ivec3 __operator - (const ivec3 v, const ivec3 u) {
1060 return ivec3 (v.x - u.x, v.y - u.y, v.z - u.z);
1061 }
1062
1063 ivec3 __operator * (const ivec3 v, const ivec3 u) {
1064 return ivec3 (v.x * u.x, v.y * u.y, v.z * u.z);
1065 }
1066
1067 ivec3 __operator / (const ivec3 v, const ivec3 u) {
1068 return ivec3 (v.x / u.x, v.y / u.y, v.z / u.z);
1069 }
1070
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);
1073 }
1074
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);
1077 }
1078
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);
1081 }
1082
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);
1085 }
1086
1087 mat2 __operator + (const mat2 m, const mat2 n) {
1088 return mat2 (m[0] + n[0], m[1] + n[1]);
1089 }
1090
1091 mat2 __operator - (const mat2 m, const mat2 n) {
1092 return mat2 (m[0] - n[0], m[1] - n[1]);
1093 }
1094
1095 mat2 __operator / (const mat2 m, const mat2 n) {
1096 return mat2 (m[0] / n[0], m[1] / n[1]);
1097 }
1098
1099
1100 mat3 __operator + (const mat3 m, const mat3 n)
1101 {
1102 __retVal[0] = m[0] + n[0];
1103 __retVal[1] = m[1] + n[1];
1104 __retVal[2] = m[2] + n[2];
1105 }
1106
1107 mat3 __operator - (const mat3 m, const mat3 n)
1108 {
1109 __retVal[0] = m[0] - n[0];
1110 __retVal[1] = m[1] - n[1];
1111 __retVal[2] = m[2] - n[2];
1112 }
1113
1114 mat3 __operator / (const mat3 m, const mat3 n)
1115 {
1116 __retVal[0] = m[0] / n[0];
1117 __retVal[0] = m[1] / n[1];
1118 __retVal[0] = m[2] / n[2];
1119 }
1120
1121
1122 mat4 __operator + (const mat4 m, const mat4 n)
1123 {
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];
1128 }
1129
1130 mat4 __operator - (const mat4 m, const mat4 n)
1131 {
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];
1136 }
1137
1138
1139
1140 mat4 __operator / (const mat4 m, const mat4 n)
1141 {
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];
1146 }
1147
1148 vec2 __operator + (const float a, const vec2 u) {
1149 return vec2 (a + u.x, a + u.y);
1150 }
1151
1152 vec2 __operator + (const vec2 v, const float b) {
1153 return vec2 (v.x + b, v.y + b);
1154 }
1155
1156 vec2 __operator - (const float a, const vec2 u) {
1157 return vec2 (a - u.x, a - u.y);
1158 }
1159
1160 vec2 __operator - (const vec2 v, const float b) {
1161 return vec2 (v.x - b, v.y - b);
1162 }
1163
1164 vec2 __operator * (const float a, const vec2 u) {
1165 return vec2 (a * u.x, a * u.y);
1166 }
1167
1168 vec2 __operator * (const vec2 v, const float b) {
1169 return vec2 (v.x * b, v.y * b);
1170 }
1171
1172 vec2 __operator / (const float a, const vec2 u) {
1173 return vec2 (a / u.x, a / u.y);
1174 }
1175
1176 vec2 __operator / (const vec2 v, const float b) {
1177 return vec2 (v.x / b, v.y / b);
1178 }
1179
1180 vec3 __operator + (const float a, const vec3 u) {
1181 return vec3 (a + u.x, a + u.y, a + u.z);
1182 }
1183
1184 vec3 __operator + (const vec3 v, const float b) {
1185 return vec3 (v.x + b, v.y + b, v.z + b);
1186 }
1187
1188 vec3 __operator - (const float a, const vec3 u) {
1189 return vec3 (a - u.x, a - u.y, a - u.z);
1190 }
1191
1192 vec3 __operator - (const vec3 v, const float b) {
1193 return vec3 (v.x - b, v.y - b, v.z - b);
1194 }
1195
1196 vec3 __operator * (const float a, const vec3 u) {
1197 return vec3 (a * u.x, a * u.y, a * u.z);
1198 }
1199
1200 //bp:
1201 vec3 __operator * (const vec3 v, const float b)
1202 {
1203 __retVal.xyz = v.xyz * b.xxx;
1204 }
1205
1206 vec3 __operator / (const float a, const vec3 u) {
1207 return vec3 (a / u.x, a / u.y, a / u.z);
1208 }
1209
1210 vec3 __operator / (const vec3 v, const float b) {
1211 return vec3 (v.x / b, v.y / b, v.z / b);
1212 }
1213
1214 vec4 __operator + (const float a, const vec4 u) {
1215 return vec4 (a + u.x, a + u.y, a + u.z, a + u.w);
1216 }
1217
1218 vec4 __operator + (const vec4 v, const float b) {
1219 return vec4 (v.x + b, v.y + b, v.z + b, v.w + b);
1220 }
1221
1222 vec4 __operator - (const float a, const vec4 u) {
1223 return vec4 (a - u.x, a - u.y, a - u.z, a - u.w);
1224 }
1225
1226 vec4 __operator - (const vec4 v, const float b) {
1227 return vec4 (v.x - b, v.y - b, v.z - b, v.w - b);
1228 }
1229
1230 vec4 __operator * (const float a, const vec4 u) {
1231 return vec4 (a * u.x, a * u.y, a * u.z, a * u.w);
1232 }
1233
1234 //bp:
1235 vec4 __operator * (const vec4 v, const float b)
1236 {
1237 __asm vec4_multiply __retVal.xyzw, v.xyzw, b.xxxx;
1238 }
1239
1240 vec4 __operator / (const float a, const vec4 u) {
1241 return vec4 (a / u.x, a / u.y, a / u.z, a / u.w);
1242 }
1243
1244 vec4 __operator / (const vec4 v, const float b) {
1245 return vec4 (v.x / b, v.y / b, v.z / b, v.w / b);
1246 }
1247
1248 mat2 __operator + (const float a, const mat2 n) {
1249 return mat2 (a + n[0], a + n[1]);
1250 }
1251
1252 mat2 __operator + (const mat2 m, const float b) {
1253 return mat2 (m[0] + b, m[1] + b);
1254 }
1255
1256 mat2 __operator - (const float a, const mat2 n) {
1257 return mat2 (a - n[0], a - n[1]);
1258 }
1259
1260 mat2 __operator - (const mat2 m, const float b) {
1261 return mat2 (m[0] - b, m[1] - b);
1262 }
1263
1264 mat2 __operator * (const float a, const mat2 n) {
1265 return mat2 (a * n[0], a * n[1]);
1266 }
1267
1268 mat2 __operator * (const mat2 m, const float b) {
1269 return mat2 (m[0] * b, m[1] * b);
1270 }
1271
1272 mat2 __operator / (const float a, const mat2 n) {
1273 return mat2 (a / n[0], a / n[1]);
1274 }
1275
1276 mat2 __operator / (const mat2 m, const float b) {
1277 return mat2 (m[0] / b, m[1] / b);
1278 }
1279
1280 mat3 __operator + (const float a, const mat3 n) {
1281 return mat3 (a + n[0], a + n[1], a + n[2]);
1282 }
1283
1284 mat3 __operator + (const mat3 m, const float b) {
1285 return mat3 (m[0] + b, m[1] + b, m[2] + b);
1286 }
1287
1288 mat3 __operator - (const float a, const mat3 n) {
1289 return mat3 (a - n[0], a - n[1], a - n[2]);
1290 }
1291
1292 mat3 __operator - (const mat3 m, const float b) {
1293 return mat3 (m[0] - b, m[1] - b, m[2] - b);
1294 }
1295
1296 mat3 __operator * (const float a, const mat3 n) {
1297 return mat3 (a * n[0], a * n[1], a * n[2]);
1298 }
1299
1300 mat3 __operator * (const mat3 m, const float b) {
1301 return mat3 (m[0] * b, m[1] * b, m[2] * b);
1302 }
1303
1304 mat3 __operator / (const float a, const mat3 n) {
1305 return mat3 (a / n[0], a / n[1], a / n[2]);
1306 }
1307
1308 mat3 __operator / (const mat3 m, const float b) {
1309 return mat3 (m[0] / b, m[1] / b, m[2] / b);
1310 }
1311
1312 mat4 __operator + (const float a, const mat4 n) {
1313 return mat4 (a + n[0], a + n[1], a + n[2], a + n[3]);
1314 }
1315
1316 mat4 __operator + (const mat4 m, const float b) {
1317 return mat4 (m[0] + b, m[1] + b, m[2] + b, m[3] + b);
1318 }
1319
1320 mat4 __operator - (const float a, const mat4 n) {
1321 return mat4 (a - n[0], a - n[1], a - n[2], a - n[3]);
1322 }
1323
1324 mat4 __operator - (const mat4 m, const float b) {
1325 return mat4 (m[0] - b, m[1] - b, m[2] - b, m[3] - b);
1326 }
1327
1328 mat4 __operator * (const float a, const mat4 n) {
1329 return mat4 (a * n[0], a * n[1], a * n[2], a * n[3]);
1330 }
1331
1332 mat4 __operator * (const mat4 m, const float b) {
1333 return mat4 (m[0] * b, m[1] * b, m[2] * b, m[3] * b);
1334 }
1335
1336 mat4 __operator / (const float a, const mat4 n) {
1337 return mat4 (a / n[0], a / n[1], a / n[2], a / n[3]);
1338 }
1339
1340 mat4 __operator / (const mat4 m, const float b) {
1341 return mat4 (m[0] / b, m[1] / b, m[2] / b, m[3] / b);
1342 }
1343
1344 ivec2 __operator + (const int a, const ivec2 u) {
1345 return ivec2 (a) + u;
1346 }
1347
1348 ivec2 __operator + (const ivec2 v, const int b) {
1349 return v + ivec2 (b);
1350 }
1351
1352 ivec2 __operator - (const int a, const ivec2 u) {
1353 return ivec2 (a) - u;
1354 }
1355
1356 ivec2 __operator - (const ivec2 v, const int b) {
1357 return v - ivec2 (b);
1358 }
1359
1360 ivec2 __operator * (const int a, const ivec2 u) {
1361 return ivec2 (a) * u;
1362 }
1363
1364 ivec2 __operator * (const ivec2 v, const int b) {
1365 return v * ivec2 (b);
1366 }
1367
1368 ivec2 __operator / (const int a, const ivec2 u) {
1369 return ivec2 (a) / u;
1370 }
1371
1372 ivec2 __operator / (const ivec2 v, const int b) {
1373 return v / ivec2 (b);
1374 }
1375
1376 ivec3 __operator + (const int a, const ivec3 u) {
1377 return ivec3 (a) + u;
1378 }
1379
1380 ivec3 __operator + (const ivec3 v, const int b) {
1381 return v + ivec3 (b);
1382 }
1383
1384 ivec3 __operator - (const int a, const ivec3 u) {
1385 return ivec3 (a) - u;
1386 }
1387
1388 ivec3 __operator - (const ivec3 v, const int b) {
1389 return v - ivec3 (b);
1390 }
1391
1392 ivec3 __operator * (const int a, const ivec3 u) {
1393 return ivec3 (a) * u;
1394 }
1395
1396 ivec3 __operator * (const ivec3 v, const int b) {
1397 return v * ivec3 (b);
1398 }
1399
1400 ivec3 __operator / (const int a, const ivec3 u) {
1401 return ivec3 (a) / u;
1402 }
1403
1404 ivec3 __operator / (const ivec3 v, const int b) {
1405 return v / ivec3 (b);
1406 }
1407
1408 ivec4 __operator + (const int a, const ivec4 u) {
1409 return ivec4 (a) + u;
1410 }
1411
1412 ivec4 __operator + (const ivec4 v, const int b) {
1413 return v + ivec4 (b);
1414 }
1415
1416 ivec4 __operator - (const int a, const ivec4 u) {
1417 return ivec4 (a) - u;
1418 }
1419
1420 ivec4 __operator - (const ivec4 v, const int b) {
1421 return v - ivec4 (b);
1422 }
1423
1424 ivec4 __operator * (const int a, const ivec4 u) {
1425 return ivec4 (a) * u;
1426 }
1427
1428 ivec4 __operator * (const ivec4 v, const int b) {
1429 return v * ivec4 (b);
1430 }
1431
1432 ivec4 __operator / (const int a, const ivec4 u) {
1433 return ivec4 (a) / u;
1434 }
1435
1436 ivec4 __operator / (const ivec4 v, const int b) {
1437 return v / ivec4 (b);
1438 }
1439
1440 vec2 __operator - (const vec2 v) {
1441 return vec2 (-v.x, -v.y);
1442 }
1443
1444 vec3 __operator - (const vec3 v) {
1445 return vec3 (-v.x, -v.y, -v.z);
1446 }
1447
1448 vec4 __operator - (const vec4 v) {
1449 return vec4 (-v.x, -v.y, -v.z, -v.w);
1450 }
1451
1452 ivec2 __operator - (const ivec2 v) {
1453 return ivec2 (-v.x, -v.y);
1454 }
1455
1456 ivec3 __operator - (const ivec3 v) {
1457 return ivec3 (-v.x, -v.y, -v.z);
1458 }
1459
1460 ivec4 __operator - (const ivec4 v) {
1461 return ivec4 (-v.x, -v.y, -v.z, -v.w);
1462 }
1463
1464 mat2 __operator - (const mat2 m) {
1465 return mat2 (-m[0], -m[1]);
1466 }
1467
1468 mat3 __operator - (const mat3 m) {
1469 return mat3 (-m[0], -m[1], -m[2]);
1470 }
1471
1472 mat4 __operator - (const mat4 m) {
1473 return mat4 (-m[0], -m[1], -m[2], -m[3]);
1474 }
1475
1476 void __operator -- (inout float a) {
1477 a -= 1.0;
1478 }
1479
1480 void __operator -- (inout int a) {
1481 a -= 1;
1482 }
1483
1484 void __operator -- (inout vec2 v) {
1485 --v.x;
1486 --v.y;
1487 }
1488
1489 void __operator -- (inout vec3 v) {
1490 --v.x;
1491 --v.y;
1492 --v.z;
1493 }
1494
1495 void __operator -- (inout vec4 v) {
1496 --v.x;
1497 --v.y;
1498 --v.z;
1499 --v.w;
1500 }
1501
1502 void __operator -- (inout ivec2 v) {
1503 --v.x;
1504 --v.y;
1505 }
1506
1507 void __operator -- (inout ivec3 v) {
1508 --v.x;
1509 --v.y;
1510 --v.z;
1511 }
1512
1513 void __operator -- (inout ivec4 v) {
1514 --v.x;
1515 --v.y;
1516 --v.z;
1517 --v.w;
1518 }
1519
1520 void __operator -- (inout mat2 m) {
1521 --m[0];
1522 --m[1];
1523 }
1524
1525 void __operator -- (inout mat3 m) {
1526 --m[0];
1527 --m[1];
1528 --m[2];
1529 }
1530
1531 void __operator -- (inout mat4 m) {
1532 --m[0];
1533 --m[1];
1534 --m[2];
1535 --m[3];
1536 }
1537
1538 void __operator ++ (inout float a) {
1539 a += 1.0;
1540 }
1541
1542 void __operator ++ (inout int a) {
1543 a += 1;
1544 }
1545
1546 void __operator ++ (inout vec2 v) {
1547 ++v.x;
1548 ++v.y;
1549 }
1550
1551 void __operator ++ (inout vec3 v) {
1552 ++v.x;
1553 ++v.y;
1554 ++v.z;
1555 }
1556
1557 void __operator ++ (inout vec4 v) {
1558 ++v.x;
1559 ++v.y;
1560 ++v.z;
1561 ++v.w;
1562 }
1563
1564 void __operator ++ (inout ivec2 v) {
1565 ++v.x;
1566 ++v.y;
1567 }
1568
1569 void __operator ++ (inout ivec3 v) {
1570 ++v.x;
1571 ++v.y;
1572 ++v.z;
1573 }
1574
1575 void __operator ++ (inout ivec4 v) {
1576 ++v.x;
1577 ++v.y;
1578 ++v.z;
1579 ++v.w;
1580 }
1581
1582 void __operator ++ (inout mat2 m) {
1583 ++m[0];
1584 ++m[1];
1585 }
1586
1587 void __operator ++ (inout mat3 m) {
1588 ++m[0];
1589 ++m[1];
1590 ++m[2];
1591 }
1592
1593 void __operator ++ (inout mat4 m) {
1594 ++m[0];
1595 ++m[1];
1596 ++m[2];
1597 ++m[3];
1598 }
1599
1600 //
1601 // NOTE: postfix increment and decrement operators take additional dummy int parameter to
1602 // distinguish their prototypes from prefix ones.
1603 //
1604
1605 float __operator -- (inout float a, const int) {
1606 float b = a;
1607 --a;
1608 return b;
1609 }
1610
1611 int __operator -- (inout int a, const int) {
1612 int b = a;
1613 --a;
1614 return b;
1615 }
1616
1617 vec2 __operator -- (inout vec2 v, const int) {
1618 return vec2 (v.x--, v.y--);
1619 }
1620
1621 vec3 __operator -- (inout vec3 v, const int) {
1622 return vec3 (v.x--, v.y--, v.z--);
1623 }
1624
1625 vec4 __operator -- (inout vec4 v, const int) {
1626 return vec4 (v.x--, v.y--, v.z--, v.w--);
1627 }
1628
1629 ivec2 __operator -- (inout ivec2 v, const int) {
1630 return ivec2 (v.x--, v.y--);
1631 }
1632
1633 ivec3 __operator -- (inout ivec3 v, const int) {
1634 return ivec3 (v.x--, v.y--, v.z--);
1635 }
1636
1637 ivec4 __operator -- (inout ivec4 v, const int) {
1638 return ivec4 (v.x--, v.y--, v.z--, v.w--);
1639 }
1640
1641 mat2 __operator -- (inout mat2 m, const int) {
1642 return mat2 (m[0]--, m[1]--);
1643 }
1644
1645 mat3 __operator -- (inout mat3 m, const int) {
1646 return mat3 (m[0]--, m[1]--, m[2]--);
1647 }
1648
1649 mat4 __operator -- (inout mat4 m, const int) {
1650 return mat4 (m[0]--, m[1]--, m[2]--, m[3]--);
1651 }
1652
1653 float __operator ++ (inout float a, const int) {
1654 float b = a;
1655 ++a;
1656 return b;
1657 }
1658
1659 int __operator ++ (inout int a, const int) {
1660 int b = a;
1661 ++a;
1662 return b;
1663 }
1664
1665 vec2 __operator ++ (inout vec2 v, const int) {
1666 return vec2 (v.x++, v.y++);
1667 }
1668
1669 vec3 __operator ++ (inout vec3 v, const int) {
1670 return vec3 (v.x++, v.y++, v.z++);
1671 }
1672
1673 vec4 __operator ++ (inout vec4 v, const int) {
1674 return vec4 (v.x++, v.y++, v.z++, v.w++);
1675 }
1676
1677 ivec2 __operator ++ (inout ivec2 v, const int) {
1678 return ivec2 (v.x++, v.y++);
1679 }
1680
1681 ivec3 __operator ++ (inout ivec3 v, const int) {
1682 return ivec3 (v.x++, v.y++, v.z++);
1683 }
1684
1685 ivec4 __operator ++ (inout ivec4 v, const int) {
1686 return ivec4 (v.x++, v.y++, v.z++, v.w++);
1687 }
1688
1689 mat2 __operator ++ (inout mat2 m, const int) {
1690 return mat2 (m[0]++, m[1]++);
1691 }
1692
1693 mat3 __operator ++ (inout mat3 m, const int) {
1694 return mat3 (m[0]++, m[1]++, m[2]++);
1695 }
1696
1697 mat4 __operator ++ (inout mat4 m, const int) {
1698 return mat4 (m[0]++, m[1]++, m[2]++, m[3]++);
1699 }
1700
1701
1702 // XXX are the inequality operators for floats/ints really needed????
1703 bool __operator < (const float a, const float b)
1704 {
1705 __asm vec4_sgt __retVal.x, b, a;
1706 }
1707
1708
1709 bool __operator < (const int a, const int b) {
1710 return float (a) < float (b);
1711 }
1712
1713 bool __operator > (const float a, const float b) {
1714 bool c;
1715 __asm float_less c, b, a;
1716 return c;
1717 }
1718
1719 bool __operator > (const int a, const int b) {
1720 return float (a) > float (b);
1721 }
1722
1723 bool __operator >= (const float a, const float b) {
1724 bool g, e;
1725 __asm float_less g, b, a;
1726 __asm float_equal e, a, b;
1727 return g || e;
1728 }
1729
1730 bool __operator >= (const int a, const int b) {
1731 return float (a) >= float (b);
1732 }
1733
1734 bool __operator <= (const float a, const float b) {
1735 bool g, e;
1736 __asm float_less g, a, b;
1737 __asm float_equal e, a, b;
1738 return g || e;
1739 }
1740
1741 bool __operator <= (const int a, const int b) {
1742 return float (a) <= float (b);
1743 }
1744
1745 bool __operator ^^ (const bool a, const bool b) {
1746 return a != b;
1747 }
1748
1749 //
1750 // These operators are handled internally by the compiler:
1751 //
1752 // bool __operator && (bool a, bool b) {
1753 // return a ? b : false;
1754 // }
1755 // bool __operator || (bool a, bool b) {
1756 // return a ? true : b;
1757 // }
1758 //
1759
1760 bool __operator ! (const bool a) {
1761 return a == false;
1762 }
1763
1764 //
1765 // MESA-specific extension functions.
1766 //
1767
1768 void printMESA (const float f) {
1769 __asm float_print f;
1770 }
1771
1772 void printMESA (const int i) {
1773 __asm int_print i;
1774 }
1775
1776 void printMESA (const bool b) {
1777 __asm bool_print b;
1778 }
1779
1780 void printMESA (const vec2 v) {
1781 printMESA (v.x);
1782 printMESA (v.y);
1783 }
1784
1785 void printMESA (const vec3 v) {
1786 printMESA (v.x);
1787 printMESA (v.y);
1788 printMESA (v.z);
1789 }
1790
1791 void printMESA (const vec4 v) {
1792 printMESA (v.x);
1793 printMESA (v.y);
1794 printMESA (v.z);
1795 printMESA (v.w);
1796 }
1797
1798 void printMESA (const ivec2 v) {
1799 printMESA (v.x);
1800 printMESA (v.y);
1801 }
1802
1803 void printMESA (const ivec3 v) {
1804 printMESA (v.x);
1805 printMESA (v.y);
1806 printMESA (v.z);
1807 }
1808
1809 void printMESA (const ivec4 v) {
1810 printMESA (v.x);
1811 printMESA (v.y);
1812 printMESA (v.z);
1813 printMESA (v.w);
1814 }
1815
1816 void printMESA (const bvec2 v) {
1817 printMESA (v.x);
1818 printMESA (v.y);
1819 }
1820
1821 void printMESA (const bvec3 v) {
1822 printMESA (v.x);
1823 printMESA (v.y);
1824 printMESA (v.z);
1825 }
1826
1827 void printMESA (const bvec4 v) {
1828 printMESA (v.x);
1829 printMESA (v.y);
1830 printMESA (v.z);
1831 printMESA (v.w);
1832 }
1833
1834 void printMESA (const mat2 m) {
1835 printMESA (m[0]);
1836 printMESA (m[1]);
1837 }
1838
1839 void printMESA (const mat3 m) {
1840 printMESA (m[0]);
1841 printMESA (m[1]);
1842 printMESA (m[2]);
1843 }
1844
1845 void printMESA (const mat4 m) {
1846 printMESA (m[0]);
1847 printMESA (m[1]);
1848 printMESA (m[2]);
1849 printMESA (m[3]);
1850 }
1851
1852 void printMESA (const sampler1D e) {
1853 __asm int_print e;
1854 }
1855
1856 void printMESA (const sampler2D e) {
1857 __asm int_print e;
1858 }
1859
1860 void printMESA (const sampler3D e) {
1861 __asm int_print e;
1862 }
1863
1864 void printMESA (const samplerCube e) {
1865 __asm int_print e;
1866 }
1867
1868 void printMESA (const sampler1DShadow e) {
1869 __asm int_print e;
1870 }
1871
1872 void printMESA (const sampler2DShadow e) {
1873 __asm int_print e;
1874 }
1875