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