mesa: glsl: re-order some constructors
[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
105
106 //// Basic, scalar constructors/casts
107
108 int __constructor(const float f)
109 {
110 __asm float_to_int __retVal, f;
111 }
112
113 int __constructor(const bool b)
114 {
115 __retVal = b;
116 }
117
118 int __constructor(const int i)
119 {
120 __retVal = i;
121 }
122
123 bool __constructor(const int i)
124 {
125 const float zero = 0.0;
126 __asm vec4_sne __retVal, i, zero;
127 }
128
129 bool __constructor(const float f)
130 {
131 const float zero = 0.0;
132 __asm vec4_sne __retVal, f, zero;
133 }
134
135 bool __constructor(const bool b)
136 {
137 __retVal = b;
138 }
139
140 float __constructor(const int i)
141 {
142 __asm int_to_float __retVal, i;
143 }
144
145 float __constructor(const bool b)
146 {
147 __retVal = b;
148 }
149
150 float __constructor(const float f)
151 {
152 __retVal = f;
153 }
154
155
156 //// vec2 constructors
157
158 vec2 __constructor(const float x, const float y)
159 {
160 __retVal.x = x;
161 __retVal.y = y;
162 }
163
164 vec2 __constructor(const float f)
165 {
166 __retVal.xy = f.xx;
167 }
168
169 vec2 __constructor(const int i)
170 {
171 __retVal.xy = i.xx;
172 }
173
174 vec2 __constructor(const bool b)
175 {
176 __retVal.xy = b.xx;
177 }
178
179 vec2 __constructor(const bvec2 b)
180 {
181 __retVal = b;
182 }
183
184 vec2 __constructor(const vec3 v)
185 {
186 __retVal.xy = v.xy;
187 }
188
189 vec2 __constructor(const vec4 v)
190 {
191 __retVal.st = v.xy;
192 }
193
194
195 //// vec3 constructors
196
197 vec3 __constructor(const float x, const float y, const float z)
198 {
199 __retVal.x = x;
200 __retVal.y = y;
201 __retVal.z = z;
202 }
203
204 vec3 __constructor(const float f)
205 {
206 __retVal.xyz = f.xxx;
207 }
208
209 vec3 __constructor(const int i)
210 {
211 __asm int_to_float __retVal.xyz, i.xxx;
212 }
213
214 vec3 __constructor(const bool b)
215 {
216 __retVal.xyz = b.xxx;
217 }
218
219 vec3 __constructor(const bvec3 b)
220 {
221 __retVal = b;
222 }
223
224 vec3 __constructor(const vec4 v)
225 {
226 __retVal.xyz = v.xyz;
227 }
228
229
230 //// vec4 constructors
231
232 vec4 __constructor(const float x, const float y, const float z, const float w)
233 {
234 __retVal.x = x;
235 __retVal.y = y;
236 __retVal.z = z;
237 __retVal.w = w;
238 }
239
240 vec4 __constructor(const float f)
241 {
242 __retVal = f.xxxx;
243 }
244
245 vec4 __constructor(const int i)
246 {
247 __retVal = i.xxxx;
248 }
249
250 vec4 __constructor(const bool b)
251 {
252 __retVal = b.xxxx;
253 }
254
255 vec4 __constructor(const bvec4 b)
256 {
257 __retVal = b;
258 }
259
260 vec4 __constructor(const vec3 v3, const float f)
261 {
262 // XXX this constructor shouldn't be needed anymore
263 __retVal.xyz = v3;
264 __retVal.w = f;
265 }
266
267 vec4 __constructor(const vec2 v2, const float f1, const float f2)
268 {
269 // XXX this constructor shouldn't be needed anymore
270 __retVal.xy = v2;
271 __retVal.z = f1;
272 __retVal.w = f2;
273 }
274
275
276 //// ivec2 constructors
277
278 ivec2 __constructor(const int i, const int j)
279 {
280 __retVal.x = i;
281 __retVal.y = j;
282 }
283
284 ivec2 __constructor(const int i)
285 {
286 __retVal.xy = i.xx;
287 }
288
289 ivec2 __constructor(const float f)
290 {
291 __asm float_to_int __retVal.xy, f.xx;
292 }
293
294 ivec2 __constructor(const bool b)
295 {
296 __asm float_to_int __retVal.xy, b.xx;
297 }
298
299
300 //// ivec3 constructors
301
302 ivec3 __constructor(const int i, const int j, const int k)
303 {
304 __retVal.x = i;
305 __retVal.y = j;
306 __retVal.z = k;
307 }
308
309 ivec3 __constructor(const int i)
310 {
311 __retVal.xyz = i.xxx;
312 }
313
314 ivec3 __constructor(const float f)
315 {
316 __retVal.xyz = f.xxx;
317 }
318
319 ivec3 __constructor(const bool b)
320 {
321 __retVal.xyz = b.xxx;
322 }
323
324
325 //// ivec4 constructors
326
327 ivec4 __constructor(const int x, const int y, const int z, const int w)
328 {
329 __retVal.x = x;
330 __retVal.y = y;
331 __retVal.z = z;
332 __retVal.w = w;
333 }
334
335 ivec4 __constructor(const int i)
336 {
337 __retVal = i.xxxx;
338 }
339
340 ivec4 __constructor(const float f)
341 {
342 __asm float_to_int __retVal, f.xxxx;
343 }
344
345 ivec4 __constructor(const bool b)
346 {
347 __retVal = b.xxxx;
348 }
349
350
351 //// bvec2 constructors
352
353 bvec2 __constructor(const bool b1, const bool b2)
354 {
355 __retVal.x = b1;
356 __retVal.y = b2;
357 }
358
359 bvec2 __constructor(const bool b)
360 {
361 __retVal.xy = b.xx;
362 }
363
364 bvec2 __constructor(const float f)
365 {
366 const vec2 zero = vec2(0.0, 0.0);
367 __asm vec4_sne __retVal.xy, f.xx, zero;
368 }
369
370 bvec2 __constructor(const int i)
371 {
372 const ivec2 zero = ivec2(0, 0);
373 __asm vec4_sne __retVal.xy, i.xx, zero;
374 }
375
376 bvec2 __constructor(const vec2 v)
377 {
378 __asm vec4_sne __retVal.xy, v, 0.0;
379 }
380
381 bvec2 __constructor(const ivec2 v)
382 {
383 const ivec2 zero = ivec2(0, 0);
384 __asm vec4_sne __retVal.xy, v, zero;
385 }
386
387
388
389 //// bvec3 constructors
390
391 bvec3 __constructor(const bool b1, const bool b2, const bool b3)
392 {
393 __retVal.x = b1;
394 __retVal.y = b2;
395 __retVal.z = b3;
396 }
397
398 bvec3 __constructor(const bool b)
399 {
400 __retVal.xyz = b.xxx;
401 }
402
403 bvec3 __constructor(const float f)
404 {
405 const vec3 zero = vec3(0.0, 0.0, 0.0);
406 __asm vec4_sne __retVal.xyz, f.xxx, zero;
407 }
408
409 bvec3 __constructor(const int i)
410 {
411 const ivec3 zero = ivec3(0, 0, 0);
412 __asm vec4_sne __retVal.xyz, i.xxx, zero;
413 }
414
415 bvec3 __constructor(const vec3 v)
416 {
417 const vec3 zero = vec3(0.0, 0.0, 0.0);
418 __asm vec4_sne __retVal.xyz, v, zero;
419 }
420
421 bvec3 __constructor(const ivec3 v)
422 {
423 const ivec3 zero = ivec3(0, 0, 0);
424 __asm vec4_sne __retVal.xyz, v, zero;
425 }
426
427
428
429 //// bvec4 constructors
430
431 bvec4 __constructor(const bool b1, const bool b2, const bool b3, const bool b4)
432 {
433 __retVal.x = b1;
434 __retVal.y = b2;
435 __retVal.z = b3;
436 __retVal.w = b4;
437 }
438
439 bvec4 __constructor(const bool b)
440 {
441 __retVal.xyzw = b.xxxx;
442 }
443
444 bvec4 __constructor(const float f)
445 {
446 const vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);
447 __asm vec4_sne __retVal, f.xxxx, zero;
448 }
449
450 bvec4 __constructor(const int i)
451 {
452 const ivec4 zero = ivec4(0, 0, 0, 0);
453 __asm vec4_sne __retVal, i.xxxx, zero;
454 }
455
456 bvec4 __constructor(const vec4 v)
457 {
458 const vec4 zero = vec4(0.0, 0.0, 0.0, 0.0);
459 __asm vec4_sne __retVal, v, zero;
460 }
461
462 bvec4 __constructor(const ivec4 v)
463 {
464 const ivec4 zero = ivec4(0, 0, 0, 0);
465 __asm vec4_sne __retVal, v, zero;
466 }
467
468
469
470 //// mat2 constructors
471
472 mat2 __constructor(const float m00, const float m10,
473 const float m01, const float m11)
474 {
475 __retVal[0].x = m00;
476 __retVal[0].y = m10;
477 __retVal[1].x = m01;
478 __retVal[1].y = m11;
479 }
480
481 mat2 __constructor(const float f)
482 {
483 __retVal[0].x = f;
484 __retVal[0].y = 0.0;
485 __retVal[1].x = 0.0;
486 __retVal[1].y = f;
487 }
488
489 mat2 __constructor(const int i)
490 {
491 return mat2(float(i));
492 }
493
494 mat2 __constructor(const bool b)
495 {
496 return mat2(float(b));
497 }
498
499 mat2 __constructor(const vec2 c0, const vec2 c1)
500 {
501 __retVal[0] = c0;
502 __retVal[1] = c1;
503 }
504
505
506 //// mat3 constructors
507
508 mat3 __constructor(const float m00, const float m10, const float m20,
509 const float m01, const float m11, const float m21,
510 const float m02, const float m12, const float m22)
511 {
512 __retVal[0].x = m00;
513 __retVal[0].y = m10;
514 __retVal[0].z = m20;
515 __retVal[1].x = m01;
516 __retVal[1].y = m11;
517 __retVal[1].z = m21;
518 __retVal[2].x = m02;
519 __retVal[2].y = m12;
520 __retVal[2].z = m22;
521 }
522
523 mat3 __constructor(const float f)
524 {
525 vec2 v = vec2(f, 0.0);
526 __retVal[0] = v.xyy;
527 __retVal[1] = v.yxy;
528 __retVal[2] = v.yyx;
529 }
530
531 mat3 __constructor(const int i)
532 {
533 return mat3(float(i));
534 }
535
536 mat3 __constructor(const bool b)
537 {
538 return mat3(float(b));
539 }
540
541 mat3 __constructor(const vec3 c0, const vec3 c1, const vec3 c2)
542 {
543 __retVal[0] = c0;
544 __retVal[1] = c1;
545 __retVal[2] = c2;
546 }
547
548
549 //// mat4 constructors
550
551 mat4 __constructor(const float m00, const float m10, const float m20, const float m30,
552 const float m01, const float m11, const float m21, const float m31,
553 const float m02, const float m12, const float m22, const float m32,
554 const float m03, const float m13, const float m23, const float m33)
555 {
556 __retVal[0].x = m00;
557 __retVal[0].y = m10;
558 __retVal[0].z = m20;
559 __retVal[0].w = m30;
560 __retVal[1].x = m01;
561 __retVal[1].y = m11;
562 __retVal[1].z = m21;
563 __retVal[1].w = m31;
564 __retVal[2].x = m02;
565 __retVal[2].y = m12;
566 __retVal[2].z = m22;
567 __retVal[2].w = m32;
568 __retVal[3].x = m03;
569 __retVal[3].y = m13;
570 __retVal[3].z = m23;
571 __retVal[3].w = m33;
572 }
573
574
575 mat4 __constructor(const float f)
576 {
577 vec2 v = vec2(f, 0.0);
578 __retVal[0] = v.xyyy;
579 __retVal[1] = v.yxyy;
580 __retVal[2] = v.yyxy;
581 __retVal[3] = v.yyyx;
582 }
583
584 mat4 __constructor(const int i)
585 {
586 return mat4(float(i));
587 }
588
589 mat4 __constructor(const bool b)
590 {
591 return mat4(float(b));
592 }
593
594 mat4 __constructor(const vec4 c0, const vec4 c1, const vec4 c2, const vec4 c3)
595 {
596 __retVal[0] = c0;
597 __retVal[1] = c1;
598 __retVal[2] = c2;
599 __retVal[3] = c3;
600 }
601
602
603
604 //// Basic int operators
605
606 int __operator + (const int a, const int b)
607 {
608 // XXX If we ever have int registers, we'll do something like this:
609 // XXX For now, mostly treat ints as floats.
610 // float x, y;
611 // __asm int_to_float x, a;
612 // __asm int_to_float y, b;
613 // __asm vec4_add x.x, x.x, y.x;
614 // __asm float_to_int __retVal, x;
615 float x;
616 __asm vec4_add x, a, b;
617 __asm float_to_int __retVal, x;
618 }
619
620 int __operator - (const int a, const int b)
621 {
622 float x;
623 __asm vec4_subtract x, a, b;
624 __asm float_to_int __retVal, x;
625 }
626
627 int __operator * (const int a, const int b)
628 {
629 float x;
630 __asm vec4_multiply x, a, b;
631 __asm float_to_int __retVal, x;
632 }
633
634 int __operator / (const int a, const int b)
635 {
636 float bInv, x;
637 __asm float_rcp bInv, b;
638 __asm vec4_multiply x, a, bInv;
639 __asm float_to_int __retVal, x;
640 }
641
642
643 //// Basic ivec2 operators
644
645 ivec2 __operator + (const ivec2 a, const ivec2 b)
646 {
647 vec2 x;
648 __asm vec4_add x, a, b;
649 __asm float_to_int __retVal, x;
650 }
651
652 ivec2 __operator - (const ivec2 a, const ivec2 b)
653 {
654 vec2 x;
655 __asm vec4_subtract x, a, b;
656 __asm float_to_int __retVal, x;
657 }
658
659 ivec2 __operator * (const ivec2 a, const ivec2 b)
660 {
661 vec2 x;
662 __asm vec4_multiply x, a, b;
663 __asm float_to_int __retVal, x;
664 }
665
666 ivec2 __operator / (const ivec2 a, const ivec2 b)
667 {
668 vec2 bInv, x;
669 __asm float_rcp bInv.x, b.x;
670 __asm float_rcp bInv.y, b.y;
671 __asm vec4_multiply x, a, bInv;
672 __asm float_to_int __retVal, x;
673 }
674
675
676 //// Basic ivec3 operators
677
678 ivec3 __operator + (const ivec3 a, const ivec3 b)
679 {
680 vec3 x;
681 __asm vec4_add x, a, b;
682 __asm float_to_int __retVal, x;
683 }
684
685 ivec3 __operator - (const ivec3 a, const ivec3 b)
686 {
687 vec3 x;
688 __asm vec4_subtract x, a, b;
689 __asm float_to_int __retVal, x;
690 }
691
692 ivec3 __operator * (const ivec3 a, const ivec3 b)
693 {
694 vec3 x;
695 __asm vec4_multiply x, a, b;
696 __asm float_to_int __retVal, x;
697 }
698
699 ivec3 __operator / (const ivec3 a, const ivec3 b)
700 {
701 vec3 bInv, x;
702 __asm float_rcp bInv.x, b.x;
703 __asm float_rcp bInv.y, b.y;
704 __asm float_rcp bInv.z, b.z;
705 __asm vec4_multiply x, a, bInv;
706 __asm float_to_int __retVal, x;
707 }
708
709
710 //// Basic ivec4 operators
711
712 ivec4 __operator + (const ivec4 a, const ivec4 b)
713 {
714 vec3 x;
715 __asm vec4_add x, a, b;
716 __asm float_to_int __retVal, x;
717 }
718
719 ivec4 __operator - (const ivec4 a, const ivec4 b)
720 {
721 vec4 x;
722 __asm vec4_subtract x, a, b;
723 __asm float_to_int __retVal, x;
724 }
725
726 ivec4 __operator * (const ivec4 a, const ivec4 b)
727 {
728 vec4 x;
729 __asm vec4_multiply x, a, b;
730 __asm float_to_int __retVal, x;
731 }
732
733 ivec4 __operator / (const ivec4 a, const ivec4 b)
734 {
735 vec4 bInv, x;
736 __asm float_rcp bInv.x, b.x;
737 __asm float_rcp bInv.y, b.y;
738 __asm float_rcp bInv.z, b.z;
739 __asm float_rcp bInv.w, b.w;
740 __asm vec4_multiply x, a, bInv;
741 __asm float_to_int __retVal, x;
742 }
743
744
745 //// Basic float operators
746
747 float __operator + (const float a, const float b)
748 {
749 __asm vec4_add __retVal.x, a, b;
750 }
751
752 float __operator - (const float a, const float b)
753 {
754 __asm vec4_subtract __retVal.x, a, b;
755 }
756
757 float __operator * (const float a, const float b)
758 {
759 __asm vec4_multiply __retVal.x, a, b;
760 }
761
762 float __operator / (const float a, const float b)
763 {
764 float bInv;
765 __asm float_rcp bInv.x, b.x;
766 __asm vec4_multiply __retVal.x, a, bInv;
767 }
768
769
770 //// Basic vec2 operators
771
772 vec2 __operator + (const vec2 v, const vec2 u)
773 {
774 __asm vec4_add __retVal.xy, v, u;
775 }
776
777 vec2 __operator - (const vec2 v, const vec2 u)
778 {
779 __asm vec4_subtract __retVal.xy, v, u;
780 }
781
782 vec2 __operator * (const vec2 v, const vec2 u)
783 {
784 __asm vec4_multiply __retVal.xy, v, u;
785 }
786
787 vec2 __operator / (const vec2 v, const vec2 u)
788 {
789 vec2 w; // = 1 / u
790 __asm float_rcp w.x, u.x;
791 __asm float_rcp w.y, u.y;
792 __asm vec4_multiply __retVal.xy, v, w;
793 }
794
795
796 //// Basic vec3 operators
797
798 vec3 __operator + (const vec3 v, const vec3 u)
799 {
800 __asm vec4_add __retVal.xyz, v, u;
801 }
802
803 vec3 __operator - (const vec3 v, const vec3 u)
804 {
805 __asm vec4_subtract __retVal.xyz, v, u;
806 }
807
808 vec3 __operator * (const vec3 v, const vec3 u)
809 {
810 __asm vec4_multiply __retVal.xyz, v, u;
811 }
812
813 vec3 __operator / (const vec3 v, const vec3 u)
814 {
815 vec3 w; // = 1 / u
816 __asm float_rcp w.x, u.x;
817 __asm float_rcp w.y, u.y;
818 __asm float_rcp w.z, u.z;
819 __asm vec4_multiply __retVal.xyz, v, w;
820 }
821
822
823 //// Basic vec4 operators
824
825 vec4 __operator + (const vec4 v, const vec4 u)
826 {
827 __asm vec4_add __retVal, v, u;
828 }
829
830 vec4 __operator - (const vec4 v, const vec4 u)
831 {
832 __asm vec4_subtract __retVal, v, u;
833 }
834
835 vec4 __operator * (const vec4 v, const vec4 u)
836 {
837 __asm vec4_multiply __retVal, v, u;
838 }
839
840 vec4 __operator / (const vec4 v, const vec4 u)
841 {
842 vec4 w; // = 1 / u
843 __asm float_rcp w.x, u.x;
844 __asm float_rcp w.y, u.y;
845 __asm float_rcp w.z, u.z;
846 __asm float_rcp w.w, u.w;
847 __asm vec4_multiply __retVal, v, w;
848 }
849
850
851
852
853 //// Basic vec2/float operators
854
855 vec2 __operator + (const float a, const vec2 u)
856 {
857 __asm vec4_add __retVal.xy, a.xx, u.xy;
858 }
859
860 vec2 __operator + (const vec2 v, const float b)
861 {
862 __asm vec4_add __retVal.xy, v.xy, b.xx;
863 }
864
865 vec2 __operator - (const float a, const vec2 u)
866 {
867 __asm vec4_subtract __retVal.xy, a.xx, u.xy;
868 }
869
870 vec2 __operator - (const vec2 v, const float b)
871 {
872 __asm vec4_subtract __retVal.xy, v.xy, b.xx;
873 }
874
875 vec2 __operator * (const float a, const vec2 u)
876 {
877 __asm vec4_multiply __retVal.xy, a.xx, u.xy;
878 }
879
880 vec2 __operator * (const vec2 v, const float b)
881 {
882 __asm vec4_multiply __retVal.xy, v.xy, b.xx;
883 }
884
885 vec2 __operator / (const float a, const vec2 u)
886 {
887 vec2 invU;
888 __asm float_rcp invU.x, u.x;
889 __asm float_rcp invU.y, u.y;
890 __asm vec4_multiply __retVal.xy, a.xx, invU.xy;
891 }
892
893 vec2 __operator / (const vec2 v, const float b)
894 {
895 float invB;
896 __asm float_rcp invB, b;
897 __asm vec4_multiply __retVal.xy, v.xy, invB.xx;
898 }
899
900
901 //// Basic vec3/float operators
902
903 vec3 __operator + (const float a, const vec3 u)
904 {
905 __asm vec4_add __retVal.xyz, a.xxx, u.xyz;
906 }
907
908 vec3 __operator + (const vec3 v, const float b)
909 {
910 __asm vec4_add __retVal.xyz, v.xyz, b.xxx;
911 }
912
913 vec3 __operator - (const float a, const vec3 u)
914 {
915 __asm vec4_subtract __retVal.xyz, a.xxx, u.xyz;
916 }
917
918 vec3 __operator - (const vec3 v, const float b)
919 {
920 __asm vec4_subtract __retVal.xyz, v.xyz, b.xxx;
921 }
922
923 vec3 __operator * (const float a, const vec3 u)
924 {
925 __asm vec4_multiply __retVal.xyz, a.xxx, u.xyz;
926 }
927
928 vec3 __operator * (const vec3 v, const float b)
929 {
930 __asm vec4_multiply __retVal.xyz, v.xyz, b.xxx;
931 }
932
933 vec3 __operator / (const float a, const vec3 u)
934 {
935 vec3 invU;
936 __asm float_rcp invU.x, u.x;
937 __asm float_rcp invU.y, u.y;
938 __asm float_rcp invU.z, u.z;
939 __asm vec4_multiply __retVal.xyz, a.xxx, invU.xyz;
940 }
941
942 vec3 __operator / (const vec3 v, const float b)
943 {
944 float invB;
945 __asm float_rcp invB, b;
946 __asm vec4_multiply __retVal.xyz, v.xyz, invB.xxx;
947 }
948
949
950 //// Basic vec4/float operators
951
952 vec4 __operator + (const float a, const vec4 u)
953 {
954 __asm vec4_add __retVal, a.xxxx, u;
955 }
956
957 vec4 __operator + (const vec4 v, const float b)
958 {
959 __asm vec4_add __retVal, v, b.xxxx;
960 }
961
962 vec4 __operator - (const float a, const vec4 u)
963 {
964 __asm vec4_subtract __retVal, a.xxxx, u;
965 }
966
967 vec4 __operator - (const vec4 v, const float b)
968 {
969 __asm vec4_subtract __retVal, v, b.xxxx;
970 }
971
972 vec4 __operator * (const float a, const vec4 u)
973 {
974 __asm vec4_multiply __retVal, a.xxxx, u;
975 }
976
977 vec4 __operator * (const vec4 v, const float b)
978 {
979 __asm vec4_multiply __retVal, v, b.xxxx;
980 }
981
982 vec4 __operator / (const float a, const vec4 u)
983 {
984 vec4 invU;
985 __asm float_rcp invU.x, u.x;
986 __asm float_rcp invU.y, u.y;
987 __asm float_rcp invU.z, u.z;
988 __asm float_rcp invU.w, u.w;
989 __asm vec4_multiply __retVal, a.xxxx, invU;
990 }
991
992 vec4 __operator / (const vec4 v, const float b)
993 {
994 float invB;
995 __asm float_rcp invB, b;
996 __asm vec4_multiply __retVal, v, invB.xxxx;
997 }
998
999
1000
1001 //// Basic ivec2/int operators
1002
1003 ivec2 __operator + (const int a, const ivec2 u)
1004 {
1005 __retVal = ivec2(a) + u;
1006 }
1007
1008 ivec2 __operator + (const ivec2 v, const int b)
1009 {
1010 __retVal = v + ivec2(b);
1011 }
1012
1013 ivec2 __operator - (const int a, const ivec2 u)
1014 {
1015 __retVal = ivec2(a) - u;
1016 }
1017
1018 ivec2 __operator - (const ivec2 v, const int b)
1019 {
1020 __retVal = v - ivec2(b);
1021 }
1022
1023 ivec2 __operator * (const int a, const ivec2 u)
1024 {
1025 __retVal = ivec2(a) * u;
1026 }
1027
1028 ivec2 __operator * (const ivec2 v, const int b)
1029 {
1030 __retVal = v * ivec2(b);
1031 }
1032
1033 ivec2 __operator / (const int a, const ivec2 u)
1034 {
1035 __retVal = ivec2(a) / u;
1036 }
1037
1038 ivec2 __operator / (const ivec2 v, const int b)
1039 {
1040 __retVal = v / ivec2(b);
1041 }
1042
1043
1044 //// Basic ivec3/int operators
1045
1046 ivec3 __operator + (const int a, const ivec3 u)
1047 {
1048 __retVal = ivec3(a) + u;
1049 }
1050
1051 ivec3 __operator + (const ivec3 v, const int b)
1052 {
1053 __retVal = v + ivec3(b);
1054 }
1055
1056 ivec3 __operator - (const int a, const ivec3 u)
1057 {
1058 __retVal = ivec3(a) - u;
1059 }
1060
1061 ivec3 __operator - (const ivec3 v, const int b)
1062 {
1063 __retVal = v - ivec3(b);
1064 }
1065
1066 ivec3 __operator * (const int a, const ivec3 u)
1067 {
1068 __retVal = ivec3(a) * u;
1069 }
1070
1071 ivec3 __operator * (const ivec3 v, const int b)
1072 {
1073 __retVal = v * ivec3(b);
1074 }
1075
1076 ivec3 __operator / (const int a, const ivec3 u)
1077 {
1078 __retVal = ivec3(a) / u;
1079 }
1080
1081 ivec3 __operator / (const ivec3 v, const int b)
1082 {
1083 __retVal = v / ivec3(b);
1084 }
1085
1086
1087 //// Basic ivec4/int operators
1088
1089 ivec4 __operator + (const int a, const ivec4 u)
1090 {
1091 __retVal = ivec4(a) + u;
1092 }
1093
1094 ivec4 __operator + (const ivec4 v, const int b)
1095 {
1096 __retVal = v + ivec4(b);
1097 }
1098
1099 ivec4 __operator - (const int a, const ivec4 u)
1100 {
1101 __retVal = ivec4(a) - u;
1102 }
1103
1104 ivec4 __operator - (const ivec4 v, const int b)
1105 {
1106 __retVal = v - ivec4(b);
1107 }
1108
1109 ivec4 __operator * (const int a, const ivec4 u)
1110 {
1111 __retVal = ivec4(a) * u;
1112 }
1113
1114 ivec4 __operator * (const ivec4 v, const int b)
1115 {
1116 __retVal = v * ivec4(b);
1117 }
1118
1119 ivec4 __operator / (const int a, const ivec4 u)
1120 {
1121 __retVal = ivec4(a) / u;
1122 }
1123
1124 ivec4 __operator / (const ivec4 v, const int b)
1125 {
1126 __retVal = v / ivec4(b);
1127 }
1128
1129
1130
1131
1132 //// Unary negation operator
1133
1134 int __operator - (const int a)
1135 {
1136 __asm vec4_negate __retVal.x, a;
1137 }
1138
1139 ivec2 __operator - (const ivec2 v)
1140 {
1141 __asm vec4_negate __retVal, v;
1142 }
1143
1144 ivec3 __operator - (const ivec3 v)
1145 {
1146 __asm vec4_negate __retVal, v;
1147 }
1148
1149 ivec4 __operator - (const ivec4 v)
1150 {
1151 __asm vec4_negate __retVal, v;
1152 }
1153
1154 float __operator - (const float a)
1155 {
1156 __asm vec4_negate __retVal.x, a;
1157 }
1158
1159 vec2 __operator - (const vec2 v)
1160 {
1161 __asm vec4_negate __retVal.xy, v.xy;
1162 }
1163
1164 vec3 __operator - (const vec3 v)
1165 {
1166 __asm vec4_negate __retVal.xyz, v.xyz;
1167 }
1168
1169 vec4 __operator - (const vec4 v)
1170 {
1171 __asm vec4_negate __retVal, v;
1172 }
1173
1174 mat2 __operator - (const mat2 m)
1175 {
1176 __retVal[0] = -m[0];
1177 __retVal[1] = -m[1];
1178 }
1179
1180 mat3 __operator - (const mat3 m)
1181 {
1182 __retVal[0] = -m[0];
1183 __retVal[1] = -m[1];
1184 __retVal[2] = -m[2];
1185 }
1186
1187 mat4 __operator - (const mat4 m)
1188 {
1189 __retVal[0] = -m[0];
1190 __retVal[1] = -m[1];
1191 __retVal[2] = -m[2];
1192 __retVal[3] = -m[3];
1193 }
1194
1195
1196
1197 //// dot product
1198
1199 float dot(const float a, const float b)
1200 {
1201 __retVal = a * b;
1202 }
1203
1204 float dot(const vec2 a, const vec2 b)
1205 {
1206 __retVal = a.x * b.x + a.y * b.y;
1207 }
1208
1209 float dot(const vec3 a, const vec3 b)
1210 {
1211 __asm vec3_dot __retVal, a, b;
1212 }
1213
1214 float dot(const vec4 a, const vec4 b)
1215 {
1216 __asm vec4_dot __retVal, a, b;
1217 }
1218
1219
1220
1221 //// int assignment operators
1222
1223 void __operator += (inout int a, const int b)
1224 {
1225 __asm vec4_add a, a, b;
1226 }
1227
1228 void __operator -= (inout int a, const int b)
1229 {
1230 __asm vec4_subtract a, a, b;
1231 }
1232
1233 void __operator *= (inout int a, const int b)
1234 {
1235 __asm vec4_multiply a, a, b;
1236 }
1237
1238 void __operator /= (inout int a, const int b)
1239 {
1240 float invB;
1241 __asm float_rcp invB, b;
1242 __asm vec4_multiply a, a, invB;
1243 __asm float_to_int a, a;
1244 }
1245
1246
1247 //// ivec2 assignment operators
1248
1249 void __operator += (inout ivec2 v, const ivec2 u)
1250 {
1251 __asm vec4_add v, v, u;
1252 }
1253
1254 void __operator -= (inout ivec2 v, const ivec2 u)
1255 {
1256 __asm vec4_subtract v, v, u;
1257 }
1258
1259 void __operator *= (inout ivec2 v, const ivec2 u)
1260 {
1261 __asm vec4_multiply v, v, u;
1262 }
1263
1264 void __operator /= (inout ivec2 v, const ivec2 u)
1265 {
1266 ivec2 inv, z;
1267 __asm float_rcp inv.x, u.x;
1268 __asm float_rcp inv.y, u.y;
1269 __asm vec4_multiply z, v, inv;
1270 __asm float_to_int v, z;
1271 }
1272
1273
1274 //// ivec3 assignment operators
1275
1276 void __operator += (inout ivec3 v, const ivec3 u)
1277 {
1278 __asm vec4_add v, v, u;
1279 }
1280
1281 void __operator -= (inout ivec3 v, const ivec3 u)
1282 {
1283 __asm vec4_subtract v, v, u;
1284 }
1285
1286 void __operator *= (inout ivec3 v, const ivec3 u)
1287 {
1288 __asm vec4_multiply v, v, u;
1289 }
1290
1291 void __operator /= (inout ivec3 v, const ivec3 u)
1292 {
1293 ivec3 inv, z;
1294 __asm float_rcp inv.x, u.x;
1295 __asm float_rcp inv.y, u.y;
1296 __asm vec4_multiply z, v, inv;
1297 __asm float_to_int v, z;
1298 }
1299
1300
1301 //// ivec4 assignment operators
1302
1303 void __operator += (inout ivec4 v, const ivec4 u)
1304 {
1305 __asm vec4_add v, v, u;
1306 }
1307
1308 void __operator -= (inout ivec4 v, const ivec4 u)
1309 {
1310 __asm vec4_subtract v, v, u;
1311 }
1312
1313 void __operator *= (inout ivec4 v, const ivec4 u)
1314 {
1315 __asm vec4_multiply v, v, u;
1316 }
1317
1318 void __operator /= (inout ivec4 v, const ivec4 u)
1319 {
1320 ivec4 inv, z;
1321 __asm float_rcp inv.x, u.x;
1322 __asm float_rcp inv.y, u.y;
1323 __asm vec4_multiply z, v, inv;
1324 __asm float_to_int v, z;
1325 }
1326
1327
1328 //// float assignment operators
1329
1330 void __operator += (inout float a, const float b)
1331 {
1332 __asm vec4_add a.x, a.x, b.x;
1333 }
1334
1335 void __operator -= (inout float a, const float b)
1336 {
1337 __asm vec4_subtract a.x, a, b;
1338 }
1339
1340 void __operator *= (inout float a, const float b)
1341 {
1342 __asm vec4_multiply a.x, a, b;
1343 }
1344
1345 void __operator /= (inout float a, const float b)
1346 {
1347 float w; // = 1 / b
1348 __asm float_rcp w.x, b;
1349 __asm vec4_multiply a.x, a, w;
1350 }
1351
1352
1353 //// vec2 assignment operators
1354
1355 void __operator += (inout vec2 v, const vec2 u)
1356 {
1357 __asm vec4_add v.xy, v.xy, u.xy;
1358 }
1359
1360 void __operator -= (inout vec2 v, const vec2 u)
1361 {
1362 __asm vec4_subtract v.xy, v.xy, u.xy;
1363 }
1364
1365 void __operator *= (inout vec2 v, const vec2 u)
1366 {
1367 __asm vec4_multiply v.xy, v.xy, u.xy;
1368 }
1369
1370 void __operator /= (inout vec2 v, const vec2 u)
1371 {
1372 vec2 w;
1373 __asm float_rcp w.x, u.x;
1374 __asm float_rcp w.y, u.y;
1375 __asm vec4_multiply v.xy, v.xy, w.xy;
1376 }
1377
1378
1379 //// vec3 assignment operators
1380
1381 void __operator += (inout vec3 v, const vec3 u)
1382 {
1383 __asm vec4_add v.xyz, v, u;
1384 }
1385
1386 void __operator -= (inout vec3 v, const vec3 u)
1387 {
1388 __asm vec4_subtract v.xyz, v, u;
1389 }
1390
1391 void __operator *= (inout vec3 v, const vec3 u)
1392 {
1393 __asm vec4_multiply v.xyz, v, u;
1394 }
1395
1396 void __operator /= (inout vec3 v, const vec3 u)
1397 {
1398 vec3 w;
1399 __asm float_rcp w.x, u.x;
1400 __asm float_rcp w.y, u.y;
1401 __asm float_rcp w.z, u.z;
1402 __asm vec4_multiply v.xyz, v.xyz, w.xyz;
1403 }
1404
1405
1406 //// vec4 assignment operators
1407
1408 void __operator += (inout vec4 v, const vec4 u)
1409 {
1410 __asm vec4_add v, v, u;
1411 }
1412
1413 void __operator -= (inout vec4 v, const vec4 u)
1414 {
1415 __asm vec4_subtract v, v, u;
1416 }
1417
1418 void __operator *= (inout vec4 v, const vec4 u)
1419 {
1420 __asm vec4_multiply v, v, u;
1421 }
1422
1423 void __operator /= (inout vec4 v, const vec4 u)
1424 {
1425 vec4 w;
1426 __asm float_rcp w.x, u.x;
1427 __asm float_rcp w.y, u.y;
1428 __asm float_rcp w.z, u.z;
1429 __asm float_rcp w.w, u.w;
1430 __asm vec4_multiply v, v, w;
1431 }
1432
1433
1434
1435 //// ivec2/int assignment operators
1436
1437 void __operator += (inout ivec2 v, const int a)
1438 {
1439 __asm vec4_add v.xy, v.xy, a.xx;
1440 }
1441
1442 void __operator -= (inout ivec2 v, const int a)
1443 {
1444 __asm vec4_subtract v.xy, v.xy, a.xx;
1445 }
1446
1447 void __operator *= (inout ivec2 v, const int a)
1448 {
1449 __asm vec4_multiply v.xy, v.xy, a.xx;
1450 v.x *= a;
1451 v.y *= a;
1452 }
1453
1454 void __operator /= (inout ivec2 v, const int a)
1455 {
1456 // XXX rcp
1457 v.x /= a;
1458 v.y /= a;
1459 }
1460
1461
1462 //// ivec3/int assignment operators
1463
1464 void __operator += (inout ivec3 v, const int a)
1465 {
1466 __asm vec4_add v.xyz, v.xyz, a.xxx;
1467 }
1468
1469 void __operator -= (inout ivec3 v, const int a)
1470 {
1471 __asm vec4_subtract v.xyz, v.xyz, a.xxx;
1472 }
1473
1474 void __operator *= (inout ivec3 v, const int a)
1475 {
1476 __asm vec4_multiply v.xyz, v.xyz, a.xxx;
1477 }
1478
1479 void __operator /= (inout ivec3 v, const int a)
1480 {
1481 // XXX rcp
1482 v.x /= a;
1483 v.y /= a;
1484 v.z /= a;
1485 }
1486
1487
1488 //// ivec4/int assignment operators
1489
1490 void __operator += (inout ivec4 v, const int a)
1491 {
1492 __asm vec4_add v, v, a.xxxx;
1493 }
1494
1495 void __operator -= (inout ivec4 v, const int a)
1496 {
1497 __asm vec4_subtract v, v, a.xxxx;
1498 }
1499
1500 void __operator *= (inout ivec4 v, const int a)
1501 {
1502 __asm vec4_multiply v, v, a.xxxx;
1503 }
1504
1505 void __operator /= (inout ivec4 v, const int a)
1506 {
1507 v.x /= a;
1508 v.y /= a;
1509 v.z /= a;
1510 v.w /= a;
1511 }
1512
1513
1514
1515 //// vec2/float assignment operators
1516
1517 void __operator += (inout vec2 v, const float a)
1518 {
1519 __asm vec4_add v.xy, v, a.xx;
1520 }
1521
1522 void __operator -= (inout vec2 v, const float a)
1523 {
1524 __asm vec4_subtract v.xy, v, a.xx;
1525 }
1526
1527 void __operator *= (inout vec2 v, const float a)
1528 {
1529 __asm vec4_multiply v.xy, v, a.xx;
1530 }
1531
1532 void __operator /= (inout vec2 v, const float a)
1533 {
1534 float invA;
1535 __asm float_rcp invA, a;
1536 __asm vec4_multiply v.xy, v.xy, invA.xx;
1537 }
1538
1539
1540 //// vec3/float assignment operators
1541
1542 void __operator += (inout vec3 v, const float a)
1543 {
1544 __asm vec4_add v.xyz, v, a.xxx;
1545 }
1546
1547 void __operator -= (inout vec3 v, const float a)
1548 {
1549 __asm vec4_subtract v.xyz, v, a.xxx;
1550 }
1551
1552 void __operator *= (inout vec3 v, const float a)
1553 {
1554 __asm vec4_multiply v.xyz, v, a.xxx;
1555 }
1556
1557 void __operator /= (inout vec3 v, const float a)
1558 {
1559 float invA;
1560 __asm float_rcp invA, a;
1561 __asm vec4_multiply v.xyz, v.xyz, invA.xxx;
1562 }
1563
1564
1565 //// vec4/float assignment operators
1566
1567 void __operator += (inout vec4 v, const float a)
1568 {
1569 __asm vec4_add v, v, a.xxxx;
1570 }
1571
1572 void __operator -= (inout vec4 v, const float a)
1573 {
1574 __asm vec4_subtract v, v, a.xxxx;
1575 }
1576
1577 void __operator *= (inout vec4 v, const float a)
1578 {
1579 __asm vec4_multiply v, v, a.xxxx;
1580 }
1581
1582 void __operator /= (inout vec4 v, const float a)
1583 {
1584 float invA;
1585 __asm float_rcp invA, a;
1586 __asm vec4_multiply v, v, invA.xxxx;
1587 }
1588
1589
1590
1591
1592
1593 //// Basic mat2 operations
1594
1595 mat2 __operator + (const mat2 m, const mat2 n)
1596 {
1597 __retVal[0] = m[0] + n[0];
1598 __retVal[1] = m[1] + n[1];
1599 }
1600
1601 mat2 __operator - (const mat2 m, const mat2 n)
1602 {
1603 __retVal[0] = m[0] - n[0];
1604 __retVal[1] = m[1] - n[1];
1605 }
1606
1607 mat2 __operator * (const mat2 m, const mat2 n)
1608 {
1609 __retVal[0] = m[0] * n[0].xx + m[1] * n[0].yy;
1610 __retVal[1] = m[0] * n[1].xx + m[1] * n[1].yy;
1611 }
1612
1613 mat2 __operator / (const mat2 m, const mat2 n)
1614 {
1615 __retVal[0] = m[0] / n[0];
1616 __retVal[1] = m[1] / n[1];
1617 }
1618
1619
1620 //// Basic mat3 operations
1621
1622 mat3 __operator + (const mat3 m, const mat3 n)
1623 {
1624 __retVal[0] = m[0] + n[0];
1625 __retVal[1] = m[1] + n[1];
1626 __retVal[2] = m[2] + n[2];
1627 }
1628
1629 mat3 __operator - (const mat3 m, const mat3 n)
1630 {
1631 __retVal[0] = m[0] - n[0];
1632 __retVal[1] = m[1] - n[1];
1633 __retVal[2] = m[2] - n[2];
1634 }
1635
1636 mat3 __operator * (const mat3 m, const mat3 n)
1637 {
1638 __retVal[0] = m[0] * n[0].xxx + m[1] * n[0].yyy + m[2] * n[0].zzz;
1639 __retVal[1] = m[0] * n[1].xxx + m[1] * n[1].yyy + m[2] * n[1].zzz;
1640 __retVal[2] = m[0] * n[2].xxx + m[1] * n[2].yyy + m[2] * n[2].zzz;
1641 }
1642
1643 mat3 __operator / (const mat3 m, const mat3 n)
1644 {
1645 __retVal[0] = m[0] / n[0];
1646 __retVal[1] = m[1] / n[1];
1647 __retVal[2] = m[2] / n[2];
1648 }
1649
1650
1651 //// Basic mat4 operations
1652
1653 mat4 __operator + (const mat4 m, const mat4 n)
1654 {
1655 __retVal[0] = m[0] + n[0];
1656 __retVal[1] = m[1] + n[1];
1657 __retVal[2] = m[2] + n[2];
1658 __retVal[3] = m[3] + n[3];
1659 }
1660
1661 mat4 __operator - (const mat4 m, const mat4 n)
1662 {
1663 __retVal[0] = m[0] - n[0];
1664 __retVal[1] = m[1] - n[1];
1665 __retVal[2] = m[2] - n[2];
1666 __retVal[3] = m[3] - n[3];
1667 }
1668
1669 mat4 __operator * (const mat4 m, const mat4 n)
1670 {
1671 __retVal[0] = m[0] * n[0].xxxx + m[1] * n[0].yyyy + m[2] * n[0].zzzz + m[3] * n[0].wwww;
1672 __retVal[1] = m[0] * n[1].xxxx + m[1] * n[1].yyyy + m[2] * n[1].zzzz + m[3] * n[1].wwww;
1673 __retVal[2] = m[0] * n[2].xxxx + m[1] * n[2].yyyy + m[2] * n[2].zzzz + m[3] * n[2].wwww;
1674 __retVal[3] = m[0] * n[3].xxxx + m[1] * n[3].yyyy + m[2] * n[3].zzzz + m[3] * n[3].wwww;
1675 }
1676
1677 mat4 __operator / (const mat4 m, const mat4 n)
1678 {
1679 __retVal[0] = m[0] / n[0];
1680 __retVal[1] = m[1] / n[1];
1681 __retVal[2] = m[2] / n[2];
1682 __retVal[3] = m[3] / n[3];
1683 }
1684
1685
1686 //// mat2/float operations
1687
1688 mat2 __operator + (const float a, const mat2 n)
1689 {
1690 __retVal[0] = a + n[0];
1691 __retVal[1] = a + n[1];
1692 }
1693
1694 mat2 __operator + (const mat2 m, const float b)
1695 {
1696 __retVal[0] = m[0] + b;
1697 __retVal[1] = m[1] + b;
1698 }
1699
1700 mat2 __operator - (const float a, const mat2 n)
1701 {
1702 __retVal[0] = a - n[0];
1703 __retVal[1] = a - n[1];
1704 }
1705
1706 mat2 __operator - (const mat2 m, const float b)
1707 {
1708 __retVal[0] = m[0] - b;
1709 __retVal[1] = m[1] - b;
1710 }
1711
1712 mat2 __operator * (const float a, const mat2 n)
1713 {
1714 __retVal[0] = a * n[0];
1715 __retVal[1] = a * n[1];
1716 }
1717
1718 mat2 __operator * (const mat2 m, const float b)
1719 {
1720 __retVal[0] = m[0] * b;
1721 __retVal[1] = m[1] * b;
1722 }
1723
1724 mat2 __operator / (const float a, const mat2 n)
1725 {
1726 __retVal[0] = a / n[0];
1727 __retVal[1] = a / n[1];
1728 }
1729
1730 mat2 __operator / (const mat2 m, const float b)
1731 {
1732 __retVal[0] = m[0] / b;
1733 __retVal[1] = m[1] / b;
1734 }
1735
1736
1737 //// mat3/float operations
1738
1739 mat3 __operator + (const float a, const mat3 n)
1740 {
1741 __retVal[0] = a + n[0];
1742 __retVal[1] = a + n[1];
1743 __retVal[2] = a + n[2];
1744 }
1745
1746 mat3 __operator + (const mat3 m, const float b)
1747 {
1748 __retVal[0] = m[0] + b;
1749 __retVal[1] = m[1] + b;
1750 __retVal[2] = m[2] + b;
1751 }
1752
1753 mat3 __operator - (const float a, const mat3 n)
1754 {
1755 __retVal[0] = a - n[0];
1756 __retVal[1] = a - n[1];
1757 __retVal[2] = a - n[2];
1758 }
1759
1760 mat3 __operator - (const mat3 m, const float b)
1761 {
1762 __retVal[0] = m[0] - b;
1763 __retVal[1] = m[1] - b;
1764 __retVal[2] = m[2] - b;
1765 }
1766
1767 mat3 __operator * (const float a, const mat3 n)
1768 {
1769 __retVal[0] = a * n[0];
1770 __retVal[1] = a * n[1];
1771 __retVal[2] = a * n[2];
1772 }
1773
1774 mat3 __operator * (const mat3 m, const float b)
1775 {
1776 __retVal[0] = m[0] * b;
1777 __retVal[1] = m[1] * b;
1778 __retVal[2] = m[2] * b;
1779 }
1780
1781 mat3 __operator / (const float a, const mat3 n)
1782 {
1783 __retVal[0] = a / n[0];
1784 __retVal[1] = a / n[1];
1785 __retVal[2] = a / n[2];
1786 }
1787
1788 mat3 __operator / (const mat3 m, const float b)
1789 {
1790 __retVal[0] = m[0] / b;
1791 __retVal[1] = m[1] / b;
1792 __retVal[2] = m[2] / b;
1793 }
1794
1795
1796 //// mat4/float operations
1797
1798 mat4 __operator + (const float a, const mat4 n)
1799 {
1800 __retVal[0] = a + n[0];
1801 __retVal[1] = a + n[1];
1802 __retVal[2] = a + n[2];
1803 __retVal[3] = a + n[3];
1804 }
1805
1806 mat4 __operator + (const mat4 m, const float b)
1807 {
1808 __retVal[0] = m[0] + b;
1809 __retVal[1] = m[1] + b;
1810 __retVal[2] = m[2] + b;
1811 __retVal[3] = m[3] + b;
1812 }
1813
1814 mat4 __operator - (const float a, const mat4 n)
1815 {
1816 __retVal[0] = a - n[0];
1817 __retVal[1] = a - n[1];
1818 __retVal[2] = a - n[2];
1819 __retVal[3] = a - n[3];
1820 }
1821
1822 mat4 __operator - (const mat4 m, const float b)
1823 {
1824 __retVal[0] = m[0] - b;
1825 __retVal[1] = m[1] - b;
1826 __retVal[2] = m[2] - b;
1827 __retVal[3] = m[3] - b;
1828 }
1829
1830 mat4 __operator * (const float a, const mat4 n)
1831 {
1832 __retVal[0] = a * n[0];
1833 __retVal[1] = a * n[1];
1834 __retVal[2] = a * n[2];
1835 __retVal[3] = a * n[3];
1836 }
1837
1838 mat4 __operator * (const mat4 m, const float b)
1839 {
1840 __retVal[0] = m[0] * b;
1841 __retVal[1] = m[1] * b;
1842 __retVal[2] = m[2] * b;
1843 __retVal[3] = m[3] * b;
1844 }
1845
1846 mat4 __operator / (const float a, const mat4 n)
1847 {
1848 __retVal[0] = a / n[0];
1849 __retVal[1] = a / n[1];
1850 __retVal[2] = a / n[2];
1851 __retVal[3] = a / n[3];
1852 }
1853
1854 mat4 __operator / (const mat4 m, const float b)
1855 {
1856 __retVal[0] = m[0] / b;
1857 __retVal[1] = m[1] / b;
1858 __retVal[2] = m[2] / b;
1859 __retVal[3] = m[3] / b;
1860 }
1861
1862
1863
1864 //// matrix / vector products
1865
1866 vec2 __operator * (const mat2 m, const vec2 v)
1867 {
1868 __retVal = m[0] * v.xx
1869 + m[1] * v.yy;
1870 }
1871
1872 vec2 __operator * (const vec2 v, const mat2 m)
1873 {
1874 __retVal.x = dot(v, m[0]);
1875 __retVal.y = dot(v, m[1]);
1876 }
1877
1878 vec3 __operator * (const mat3 m, const vec3 v)
1879 {
1880 __retVal = m[0] * v.xxx
1881 + m[1] * v.yyy
1882 + m[2] * v.zzz;
1883 }
1884
1885 vec3 __operator * (const vec3 v, const mat3 m)
1886 {
1887 __retVal.x = dot(v, m[0]);
1888 __retVal.y = dot(v, m[1]);
1889 __retVal.z = dot(v, m[2]);
1890 }
1891
1892 vec4 __operator * (const mat4 m, const vec4 v)
1893 {
1894 __retVal = m[0] * v.xxxx
1895 + m[1] * v.yyyy
1896 + m[2] * v.zzzz
1897 + m[3] * v.wwww;
1898 }
1899
1900 vec4 __operator * (const vec4 v, const mat4 m)
1901 {
1902 __retVal.x = dot(v, m[0]);
1903 __retVal.y = dot(v, m[1]);
1904 __retVal.z = dot(v, m[2]);
1905 __retVal.w = dot(v, m[3]);
1906 }
1907
1908
1909
1910 //// mat2 assignment operators
1911
1912 void __operator += (inout mat2 m, const mat2 n)
1913 {
1914 m[0] += n[0];
1915 m[1] += n[1];
1916 }
1917
1918 void __operator -= (inout mat2 m, const mat2 n)
1919 {
1920 m[0] -= n[0];
1921 m[1] -= n[1];
1922 }
1923
1924 void __operator *= (inout mat2 m, const mat2 n)
1925 {
1926 m = m * n;
1927 }
1928
1929 void __operator /= (inout mat2 m, const mat2 n)
1930 {
1931 m[0] /= n[0];
1932 m[1] /= n[1];
1933 }
1934
1935
1936 //// mat3 assignment operators
1937
1938 void __operator += (inout mat3 m, const mat3 n)
1939 {
1940 m[0] += n[0];
1941 m[1] += n[1];
1942 m[2] += n[2];
1943 }
1944
1945 void __operator -= (inout mat3 m, const mat3 n)
1946 {
1947 m[0] -= n[0];
1948 m[1] -= n[1];
1949 m[2] -= n[2];
1950 }
1951
1952 void __operator *= (inout mat3 m, const mat3 n)
1953 {
1954 m = m * n;
1955 }
1956
1957 void __operator /= (inout mat3 m, const mat3 n)
1958 {
1959 m[0] /= n[0];
1960 m[1] /= n[1];
1961 m[2] /= n[2];
1962 }
1963
1964
1965 // mat4 assignment operators
1966
1967 void __operator += (inout mat4 m, const mat4 n)
1968 {
1969 m[0] += n[0];
1970 m[1] += n[1];
1971 m[2] += n[2];
1972 m[3] += n[3];
1973 }
1974
1975 void __operator -= (inout mat4 m, const mat4 n) {
1976 m[0] -= n[0];
1977 m[1] -= n[1];
1978 m[2] -= n[2];
1979 m[3] -= n[3];
1980 }
1981
1982 void __operator *= (inout mat4 m, const mat4 n)
1983 {
1984 m = m * n;
1985 }
1986
1987 void __operator /= (inout mat4 m, const mat4 n)
1988 {
1989 m[0] /= n[0];
1990 m[1] /= n[1];
1991 m[2] /= n[2];
1992 m[3] /= n[3];
1993 }
1994
1995
1996 //// mat2/float assignment operators
1997
1998 void __operator += (inout mat2 m, const float a) {
1999 m[0] += a;
2000 m[1] += a;
2001 }
2002
2003 void __operator -= (inout mat2 m, const float a) {
2004 m[0] -= a;
2005 m[1] -= a;
2006 }
2007
2008 void __operator *= (inout mat2 m, const float a) {
2009 m[0] *= a;
2010 m[1] *= a;
2011 }
2012
2013 void __operator /= (inout mat2 m, const float a) {
2014 m[0] /= a;
2015 m[1] /= a;
2016 }
2017
2018
2019 //// mat3/float assignment operators
2020
2021 void __operator += (inout mat3 m, const float a) {
2022 m[0] += a;
2023 m[1] += a;
2024 m[2] += a;
2025 }
2026
2027 void __operator -= (inout mat3 m, const float a) {
2028 m[0] -= a;
2029 m[1] -= a;
2030 m[2] -= a;
2031 }
2032
2033 void __operator *= (inout mat3 m, const float a) {
2034 m[0] *= a;
2035 m[1] *= a;
2036 m[2] *= a;
2037 }
2038
2039 void __operator /= (inout mat3 m, const float a) {
2040 m[0] /= a;
2041 m[1] /= a;
2042 m[2] /= a;
2043 }
2044
2045
2046 //// mat4/float assignment operators
2047
2048 void __operator += (inout mat4 m, const float a) {
2049 m[0] += a;
2050 m[1] += a;
2051 m[2] += a;
2052 m[3] += a;
2053 }
2054
2055 void __operator -= (inout mat4 m, const float a) {
2056 m[0] -= a;
2057 m[1] -= a;
2058 m[2] -= a;
2059 m[3] -= a;
2060 }
2061
2062 void __operator *= (inout mat4 m, const float a) {
2063 m[0] *= a;
2064 m[1] *= a;
2065 m[2] *= a;
2066 m[3] *= a;
2067 }
2068
2069 void __operator /= (inout mat4 m, const float a) {
2070 m[0] /= a;
2071 m[1] /= a;
2072 m[2] /= a;
2073 m[3] /= a;
2074 }
2075
2076
2077
2078 //// vec/mat assignment operators
2079
2080 void __operator *= (inout vec2 v, const mat2 m)
2081 {
2082 v = v * m;
2083 }
2084
2085 void __operator *= (inout vec3 v, const mat3 m)
2086 {
2087 v = v * m;
2088 }
2089
2090 void __operator *= (inout vec4 v, const mat4 m)
2091 {
2092 v = v * m;
2093 }
2094
2095
2096
2097 //// pre-decrement operators
2098
2099 int __operator --(inout int a)
2100 {
2101 a = a - 1;
2102 __retVal = a;
2103 }
2104
2105 ivec2 __operator --(inout ivec2 v)
2106 {
2107 v = v - ivec2(1);
2108 __retVal = v;
2109 }
2110
2111 ivec3 __operator --(inout ivec3 v)
2112 {
2113 v = v - ivec3(1);
2114 __retVal = v;
2115 }
2116
2117 ivec4 __operator --(inout ivec4 v)
2118 {
2119 v = v - ivec4(1);
2120 __retVal = v;
2121 }
2122
2123
2124 float __operator --(inout float a)
2125 {
2126 a = a - 1.0;
2127 __retVal = a;
2128 }
2129
2130 vec2 __operator --(inout vec2 v)
2131 {
2132 v = v - vec2(1.0);
2133 __retVal = v;
2134 }
2135
2136 vec3 __operator --(inout vec3 v)
2137 {
2138 v = v - vec3(1.0);
2139 __retVal = v;
2140 }
2141
2142 vec4 __operator --(inout vec4 v)
2143 {
2144 v = v - vec4(1.0);
2145 __retVal = v;
2146 }
2147
2148
2149 mat2 __operator --(inout mat2 m)
2150 {
2151 m[0] = m[0] - vec2(1.0);
2152 m[1] = m[1] - vec2(1.0);
2153 __retVal = m;
2154 }
2155
2156 mat3 __operator --(inout mat3 m)
2157 {
2158 m[0] = m[0] - vec3(1.0);
2159 m[1] = m[1] - vec3(1.0);
2160 m[2] = m[2] - vec3(1.0);
2161 __retVal = m;
2162 }
2163
2164 mat4 __operator --(inout mat4 m)
2165 {
2166 m[0] = m[0] - vec4(1.0);
2167 m[1] = m[1] - vec4(1.0);
2168 m[2] = m[2] - vec4(1.0);
2169 m[3] = m[3] - vec4(1.0);
2170 __retVal = m;
2171 }
2172
2173
2174 //// pre-increment operators
2175
2176 int __operator ++(inout int a)
2177 {
2178 a = a + 1;
2179 __retVal = a;
2180 }
2181
2182 ivec2 __operator ++(inout ivec2 v)
2183 {
2184 v = v + ivec2(1);
2185 __retVal = v;
2186 }
2187
2188 ivec3 __operator ++(inout ivec3 v)
2189 {
2190 v = v + ivec3(1);
2191 __retVal = v;
2192 }
2193
2194 ivec4 __operator ++(inout ivec4 v)
2195 {
2196 v = v + ivec4(1);
2197 __retVal = v;
2198 }
2199
2200
2201 float __operator ++(inout float a)
2202 {
2203 a = a + 1.0;
2204 __retVal = a;
2205 }
2206
2207 vec2 __operator ++(inout vec2 v)
2208 {
2209 v = v + vec2(1.0);
2210 __retVal = v;
2211 }
2212
2213 vec3 __operator ++(inout vec3 v)
2214 {
2215 v = v + vec3(1.0);
2216 __retVal = v;
2217 }
2218
2219 vec4 __operator ++(inout vec4 v)
2220 {
2221 v = v + vec4(1.0);
2222 __retVal = v;
2223 }
2224
2225
2226 mat2 __operator ++(inout mat2 m)
2227 {
2228 m[0] = m[0] + vec2(1.0);
2229 m[1] = m[1] + vec2(1.0);
2230 __retVal = m;
2231 }
2232
2233 mat3 __operator ++(inout mat3 m)
2234 {
2235 m[0] = m[0] + vec3(1.0);
2236 m[1] = m[1] + vec3(1.0);
2237 m[2] = m[2] + vec3(1.0);
2238 __retVal = m;
2239 }
2240
2241 mat4 __operator ++(inout mat4 m)
2242 {
2243 m[0] = m[0] + vec4(1.0);
2244 m[1] = m[1] + vec4(1.0);
2245 m[2] = m[2] + vec4(1.0);
2246 m[3] = m[3] + vec4(1.0);
2247 __retVal = m;
2248 }
2249
2250
2251
2252 //// post-decrement
2253
2254 int __postDecr(inout int a)
2255 {
2256 __retVal = a;
2257 a = a - 1;
2258 }
2259
2260 ivec2 __postDecr(inout ivec2 v)
2261 {
2262 __retVal = v;
2263 v = v - ivec2(1);
2264 }
2265
2266 ivec3 __postDecr(inout ivec3 v)
2267 {
2268 __retVal = v;
2269 v = v - ivec3(1);
2270 }
2271
2272 ivec4 __postDecr(inout ivec4 v)
2273 {
2274 __retVal = v;
2275 v = v - ivec4(1);
2276 }
2277
2278
2279 float __postDecr(inout float a)
2280 {
2281 __retVal = a;
2282 a = a - 1.0;
2283 }
2284
2285 vec2 __postDecr(inout vec2 v)
2286 {
2287 __retVal = v;
2288 v = v - vec2(1.0);
2289 }
2290
2291 vec3 __postDecr(inout vec3 v)
2292 {
2293 __retVal = v;
2294 v = v - vec3(1.0);
2295 }
2296
2297 vec4 __postDecr(inout vec4 v)
2298 {
2299 __retVal = v;
2300 v = v - vec4(1.0);
2301 }
2302
2303
2304 mat2 __postDecr(inout mat2 m)
2305 {
2306 __retVal = m;
2307 m[0] = m[0] - vec2(1.0);
2308 m[1] = m[1] - vec2(1.0);
2309 }
2310
2311 mat3 __postDecr(inout mat3 m)
2312 {
2313 __retVal = m;
2314 m[0] = m[0] - vec3(1.0);
2315 m[1] = m[1] - vec3(1.0);
2316 m[2] = m[2] - vec3(1.0);
2317 }
2318
2319 mat4 __postDecr(inout mat4 m)
2320 {
2321 __retVal = m;
2322 m[0] = m[0] - vec4(1.0);
2323 m[1] = m[1] - vec4(1.0);
2324 m[2] = m[2] - vec4(1.0);
2325 m[3] = m[3] - vec4(1.0);
2326 }
2327
2328
2329 //// post-increment
2330
2331 float __postIncr(inout float a)
2332 {
2333 __retVal = a;
2334 a = a + 1;
2335 }
2336
2337 vec2 __postIncr(inout vec2 v)
2338 {
2339 __retVal = v;
2340 v = v + vec2(1.0);
2341 }
2342
2343 vec3 __postIncr(inout vec3 v)
2344 {
2345 __retVal = v;
2346 v = v + vec3(1.0);
2347 }
2348
2349 vec4 __postIncr(inout vec4 v)
2350 {
2351 __retVal = v;
2352 v = v + vec4(1.0);
2353 }
2354
2355
2356 int __postIncr(inout int a)
2357 {
2358 __retVal = a;
2359 a = a + 1;
2360 }
2361
2362 ivec2 __postIncr(inout ivec2 v)
2363 {
2364 __retVal = v;
2365 v = v + ivec2(1);
2366 }
2367
2368 ivec3 __postIncr(inout ivec3 v)
2369 {
2370 __retVal = v;
2371 v = v + ivec3(1);
2372 }
2373
2374 ivec4 __postIncr(inout ivec4 v)
2375 {
2376 __retVal = v;
2377 v = v + ivec3(1);
2378 }
2379
2380
2381 mat2 __postIncr(inout mat2 m)
2382 {
2383 mat2 n = m;
2384 m[0] = m[0] + vec2(1.0);
2385 m[1] = m[1] + vec2(1.0);
2386 return n;
2387 }
2388
2389 mat3 __postIncr(inout mat3 m)
2390 {
2391 mat3 n = m;
2392 m[0] = m[0] + vec3(1.0);
2393 m[1] = m[1] + vec3(1.0);
2394 m[2] = m[2] + vec3(1.0);
2395 return n;
2396 }
2397
2398 mat4 __postIncr(inout mat4 m)
2399 {
2400 mat4 n = m;
2401 m[0] = m[0] + vec4(1.0);
2402 m[1] = m[1] + vec4(1.0);
2403 m[2] = m[2] + vec4(1.0);
2404 m[3] = m[3] + vec4(1.0);
2405 return n;
2406 }
2407
2408
2409
2410 //// inequality operators
2411
2412
2413 // XXX are the inequality operators for floats/ints really needed????
2414 bool __operator < (const float a, const float b)
2415 {
2416 __asm vec4_sgt __retVal.x, b, a;
2417 }
2418
2419
2420 bool __operator < (const int a, const int b) {
2421 return float (a) < float (b);
2422 }
2423
2424 bool __operator > (const float a, const float b) {
2425 bool c;
2426 __asm float_less c, b, a;
2427 return c;
2428 }
2429
2430 bool __operator > (const int a, const int b) {
2431 return float (a) > float (b);
2432 }
2433
2434 bool __operator >= (const float a, const float b) {
2435 bool g, e;
2436 __asm float_less g, b, a;
2437 __asm float_equal e, a, b;
2438 return g || e;
2439 }
2440
2441 bool __operator >= (const int a, const int b) {
2442 return float (a) >= float (b);
2443 }
2444
2445 bool __operator <= (const float a, const float b) {
2446 bool g, e;
2447 __asm float_less g, a, b;
2448 __asm float_equal e, a, b;
2449 return g || e;
2450 }
2451
2452 bool __operator <= (const int a, const int b) {
2453 return float (a) <= float (b);
2454 }
2455
2456
2457
2458 //
2459 // MESA-specific extension functions.
2460 //
2461
2462 void printMESA (const float f) {
2463 __asm float_print f;
2464 }
2465
2466 void printMESA (const int i) {
2467 __asm int_print i;
2468 }
2469
2470 void printMESA (const bool b) {
2471 __asm bool_print b;
2472 }
2473
2474 void printMESA (const vec2 v) {
2475 printMESA (v.x);
2476 printMESA (v.y);
2477 }
2478
2479 void printMESA (const vec3 v) {
2480 printMESA (v.x);
2481 printMESA (v.y);
2482 printMESA (v.z);
2483 }
2484
2485 void printMESA (const vec4 v) {
2486 printMESA (v.x);
2487 printMESA (v.y);
2488 printMESA (v.z);
2489 printMESA (v.w);
2490 }
2491
2492 void printMESA (const ivec2 v) {
2493 printMESA (v.x);
2494 printMESA (v.y);
2495 }
2496
2497 void printMESA (const ivec3 v) {
2498 printMESA (v.x);
2499 printMESA (v.y);
2500 printMESA (v.z);
2501 }
2502
2503 void printMESA (const ivec4 v) {
2504 printMESA (v.x);
2505 printMESA (v.y);
2506 printMESA (v.z);
2507 printMESA (v.w);
2508 }
2509
2510 void printMESA (const bvec2 v) {
2511 printMESA (v.x);
2512 printMESA (v.y);
2513 }
2514
2515 void printMESA (const bvec3 v) {
2516 printMESA (v.x);
2517 printMESA (v.y);
2518 printMESA (v.z);
2519 }
2520
2521 void printMESA (const bvec4 v) {
2522 printMESA (v.x);
2523 printMESA (v.y);
2524 printMESA (v.z);
2525 printMESA (v.w);
2526 }
2527
2528 void printMESA (const mat2 m) {
2529 printMESA (m[0]);
2530 printMESA (m[1]);
2531 }
2532
2533 void printMESA (const mat3 m) {
2534 printMESA (m[0]);
2535 printMESA (m[1]);
2536 printMESA (m[2]);
2537 }
2538
2539 void printMESA (const mat4 m) {
2540 printMESA (m[0]);
2541 printMESA (m[1]);
2542 printMESA (m[2]);
2543 printMESA (m[3]);
2544 }
2545
2546 void printMESA (const sampler1D e) {
2547 __asm int_print e;
2548 }
2549
2550 void printMESA (const sampler2D e) {
2551 __asm int_print e;
2552 }
2553
2554 void printMESA (const sampler3D e) {
2555 __asm int_print e;
2556 }
2557
2558 void printMESA (const samplerCube e) {
2559 __asm int_print e;
2560 }
2561
2562 void printMESA (const sampler1DShadow e) {
2563 __asm int_print e;
2564 }
2565
2566 void printMESA (const sampler2DShadow e) {
2567 __asm int_print e;
2568 }
2569