mesa: remove unused/obsolete __NormalMatrixTranspose matrix
[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 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 void __operator += (inout int a, const int b)
1211 {
1212 __asm vec4_add a, a, b;
1213 }
1214
1215 void __operator -= (inout int a, const int b)
1216 {
1217 __asm vec4_subtract a, a, b;
1218 }
1219
1220 void __operator *= (inout int a, const int b)
1221 {
1222 __asm vec4_multiply a, a, b;
1223 }
1224
1225 void __operator /= (inout int a, const int b)
1226 {
1227 float invB;
1228 __asm float_rcp invB, b;
1229 __asm vec4_multiply a, a, invB;
1230 __asm vec4_to_ivec4 a, a;
1231 }
1232
1233
1234 //// ivec2 assignment operators
1235
1236 void __operator += (inout ivec2 v, const ivec2 u)
1237 {
1238 __asm vec4_add v, v, u;
1239 }
1240
1241 void __operator -= (inout ivec2 v, const ivec2 u)
1242 {
1243 __asm vec4_subtract v, v, u;
1244 }
1245
1246 void __operator *= (inout ivec2 v, const ivec2 u)
1247 {
1248 __asm vec4_multiply v, v, u;
1249 }
1250
1251 void __operator /= (inout ivec2 v, const ivec2 u)
1252 {
1253 ivec2 inv, z;
1254 __asm float_rcp inv.x, u.x;
1255 __asm float_rcp inv.y, u.y;
1256 __asm vec4_multiply z, v, inv;
1257 __asm vec4_to_ivec4 v, z;
1258 }
1259
1260
1261 //// ivec3 assignment operators
1262
1263 void __operator += (inout ivec3 v, const ivec3 u)
1264 {
1265 __asm vec4_add v, v, u;
1266 }
1267
1268 void __operator -= (inout ivec3 v, const ivec3 u)
1269 {
1270 __asm vec4_subtract v, v, u;
1271 }
1272
1273 void __operator *= (inout ivec3 v, const ivec3 u)
1274 {
1275 __asm vec4_multiply v, v, u;
1276 }
1277
1278 void __operator /= (inout ivec3 v, const ivec3 u)
1279 {
1280 ivec3 inv, z;
1281 __asm float_rcp inv.x, u.x;
1282 __asm float_rcp inv.y, u.y;
1283 __asm vec4_multiply z, v, inv;
1284 __asm vec4_to_ivec4 v, z;
1285 }
1286
1287
1288 //// ivec4 assignment operators
1289
1290 void __operator += (inout ivec4 v, const ivec4 u)
1291 {
1292 __asm vec4_add v, v, u;
1293 }
1294
1295 void __operator -= (inout ivec4 v, const ivec4 u)
1296 {
1297 __asm vec4_subtract v, v, u;
1298 }
1299
1300 void __operator *= (inout ivec4 v, const ivec4 u)
1301 {
1302 __asm vec4_multiply v, v, u;
1303 }
1304
1305 void __operator /= (inout ivec4 v, const ivec4 u)
1306 {
1307 ivec4 inv, z;
1308 __asm float_rcp inv.x, u.x;
1309 __asm float_rcp inv.y, u.y;
1310 __asm vec4_multiply z, v, inv;
1311 __asm vec4_to_ivec4 v, z;
1312 }
1313
1314
1315 //// float assignment operators
1316
1317 void __operator += (inout float a, const float b)
1318 {
1319 __asm vec4_add a.x, a.x, b.x;
1320 }
1321
1322 void __operator -= (inout float a, const float b)
1323 {
1324 __asm vec4_subtract a.x, a, b;
1325 }
1326
1327 void __operator *= (inout float a, const float b)
1328 {
1329 __asm vec4_multiply a.x, a, b;
1330 }
1331
1332 void __operator /= (inout float a, const float b)
1333 {
1334 float w; // = 1 / b
1335 __asm float_rcp w.x, b;
1336 __asm vec4_multiply a.x, a, w;
1337 }
1338
1339
1340 //// vec2 assignment operators
1341
1342 void __operator += (inout vec2 v, const vec2 u)
1343 {
1344 __asm vec4_add v.xy, v.xy, u.xy;
1345 }
1346
1347 void __operator -= (inout vec2 v, const vec2 u)
1348 {
1349 __asm vec4_subtract v.xy, v.xy, u.xy;
1350 }
1351
1352 void __operator *= (inout vec2 v, const vec2 u)
1353 {
1354 __asm vec4_multiply v.xy, v.xy, u.xy;
1355 }
1356
1357 void __operator /= (inout vec2 v, const vec2 u)
1358 {
1359 vec2 w;
1360 __asm float_rcp w.x, u.x;
1361 __asm float_rcp w.y, u.y;
1362 __asm vec4_multiply v.xy, v.xy, w.xy;
1363 }
1364
1365
1366 //// vec3 assignment operators
1367
1368 void __operator += (inout vec3 v, const vec3 u)
1369 {
1370 __asm vec4_add v.xyz, v, u;
1371 }
1372
1373 void __operator -= (inout vec3 v, const vec3 u)
1374 {
1375 __asm vec4_subtract v.xyz, v, u;
1376 }
1377
1378 void __operator *= (inout vec3 v, const vec3 u)
1379 {
1380 __asm vec4_multiply v.xyz, v, u;
1381 }
1382
1383 void __operator /= (inout vec3 v, const vec3 u)
1384 {
1385 vec3 w;
1386 __asm float_rcp w.x, u.x;
1387 __asm float_rcp w.y, u.y;
1388 __asm float_rcp w.z, u.z;
1389 __asm vec4_multiply v.xyz, v.xyz, w.xyz;
1390 }
1391
1392
1393 //// vec4 assignment operators
1394
1395 void __operator += (inout vec4 v, const vec4 u)
1396 {
1397 __asm vec4_add v, v, u;
1398 }
1399
1400 void __operator -= (inout vec4 v, const vec4 u)
1401 {
1402 __asm vec4_subtract v, v, u;
1403 }
1404
1405 void __operator *= (inout vec4 v, const vec4 u)
1406 {
1407 __asm vec4_multiply v, v, u;
1408 }
1409
1410 void __operator /= (inout vec4 v, const vec4 u)
1411 {
1412 vec4 w;
1413 __asm float_rcp w.x, u.x;
1414 __asm float_rcp w.y, u.y;
1415 __asm float_rcp w.z, u.z;
1416 __asm float_rcp w.w, u.w;
1417 __asm vec4_multiply v, v, w;
1418 }
1419
1420
1421
1422 //// ivec2/int assignment operators
1423
1424 void __operator += (inout ivec2 v, const int a)
1425 {
1426 __asm vec4_add v.xy, v.xy, a;
1427 }
1428
1429 void __operator -= (inout ivec2 v, const int a)
1430 {
1431 __asm vec4_subtract v.xy, v.xy, a;
1432 }
1433
1434 void __operator *= (inout ivec2 v, const int a)
1435 {
1436 __asm vec4_multiply v.xy, v.xy, a;
1437 v.x *= a;
1438 v.y *= a;
1439 }
1440
1441 void __operator /= (inout ivec2 v, const int a)
1442 {
1443 // XXX rcp
1444 v.x /= a;
1445 v.y /= a;
1446 }
1447
1448
1449 //// ivec3/int assignment operators
1450
1451 void __operator += (inout ivec3 v, const int a)
1452 {
1453 __asm vec4_add v.xyz, v.xyz, a;
1454 }
1455
1456 void __operator -= (inout ivec3 v, const int a)
1457 {
1458 __asm vec4_subtract v.xyz, v.xyz, a;
1459 }
1460
1461 void __operator *= (inout ivec3 v, const int a)
1462 {
1463 __asm vec4_multiply v.xyz, v.xyz, a;
1464 }
1465
1466 void __operator /= (inout ivec3 v, const int a)
1467 {
1468 // XXX rcp
1469 v.x /= a;
1470 v.y /= a;
1471 v.z /= a;
1472 }
1473
1474
1475 //// ivec4/int assignment operators
1476
1477 void __operator += (inout ivec4 v, const int a)
1478 {
1479 __asm vec4_add v, v, a;
1480 }
1481
1482 void __operator -= (inout ivec4 v, const int a)
1483 {
1484 __asm vec4_subtract v, v, a;
1485 }
1486
1487 void __operator *= (inout ivec4 v, const int a)
1488 {
1489 __asm vec4_multiply v, v, a;
1490 }
1491
1492 void __operator /= (inout ivec4 v, const int a)
1493 {
1494 v.x /= a;
1495 v.y /= a;
1496 v.z /= a;
1497 v.w /= a;
1498 }
1499
1500
1501
1502 //// vec2/float assignment operators
1503
1504 void __operator += (inout vec2 v, const float a)
1505 {
1506 __asm vec4_add v.xy, v, a;
1507 }
1508
1509 void __operator -= (inout vec2 v, const float a)
1510 {
1511 __asm vec4_subtract v.xy, v, a;
1512 }
1513
1514 void __operator *= (inout vec2 v, const float a)
1515 {
1516 __asm vec4_multiply v.xy, v, a;
1517 }
1518
1519 void __operator /= (inout vec2 v, const float a)
1520 {
1521 float invA;
1522 __asm float_rcp invA, a;
1523 __asm vec4_multiply v.xy, v.xy, invA;
1524 }
1525
1526
1527 //// vec3/float assignment operators
1528
1529 void __operator += (inout vec3 v, const float a)
1530 {
1531 __asm vec4_add v.xyz, v, a;
1532 }
1533
1534 void __operator -= (inout vec3 v, const float a)
1535 {
1536 __asm vec4_subtract v.xyz, v, a;
1537 }
1538
1539 void __operator *= (inout vec3 v, const float a)
1540 {
1541 __asm vec4_multiply v.xyz, v, a;
1542 }
1543
1544 void __operator /= (inout vec3 v, const float a)
1545 {
1546 float invA;
1547 __asm float_rcp invA, a;
1548 __asm vec4_multiply v.xyz, v.xyz, invA;
1549 }
1550
1551
1552 //// vec4/float assignment operators
1553
1554 void __operator += (inout vec4 v, const float a)
1555 {
1556 __asm vec4_add v, v, a;
1557 }
1558
1559 void __operator -= (inout vec4 v, const float a)
1560 {
1561 __asm vec4_subtract v, v, a;
1562 }
1563
1564 void __operator *= (inout vec4 v, const float a)
1565 {
1566 __asm vec4_multiply v, v, a;
1567 }
1568
1569 void __operator /= (inout vec4 v, const float a)
1570 {
1571 float invA;
1572 __asm float_rcp invA, a;
1573 __asm vec4_multiply v, v, invA;
1574 }
1575
1576
1577
1578
1579
1580 //// Basic mat2 operations
1581
1582 mat2 __operator + (const mat2 m, const mat2 n)
1583 {
1584 __retVal[0] = m[0] + n[0];
1585 __retVal[1] = m[1] + n[1];
1586 }
1587
1588 mat2 __operator - (const mat2 m, const mat2 n)
1589 {
1590 __retVal[0] = m[0] - n[0];
1591 __retVal[1] = m[1] - n[1];
1592 }
1593
1594 mat2 __operator * (const mat2 m, const mat2 n)
1595 {
1596 __retVal[0] = m[0] * n[0].xx + m[1] * n[0].yy;
1597 __retVal[1] = m[0] * n[1].xx + m[1] * n[1].yy;
1598 }
1599
1600 mat2 __operator / (const mat2 m, const mat2 n)
1601 {
1602 __retVal[0] = m[0] / n[0];
1603 __retVal[1] = m[1] / n[1];
1604 }
1605
1606
1607 //// Basic mat3 operations
1608
1609 mat3 __operator + (const mat3 m, const mat3 n)
1610 {
1611 __retVal[0] = m[0] + n[0];
1612 __retVal[1] = m[1] + n[1];
1613 __retVal[2] = m[2] + n[2];
1614 }
1615
1616 mat3 __operator - (const mat3 m, const mat3 n)
1617 {
1618 __retVal[0] = m[0] - n[0];
1619 __retVal[1] = m[1] - n[1];
1620 __retVal[2] = m[2] - n[2];
1621 }
1622
1623 mat3 __operator * (const mat3 m, const mat3 n)
1624 {
1625 __retVal[0] = m[0] * n[0].xxx + m[1] * n[0].yyy + m[2] * n[0].zzz;
1626 __retVal[1] = m[0] * n[1].xxx + m[1] * n[1].yyy + m[2] * n[1].zzz;
1627 __retVal[2] = m[0] * n[2].xxx + m[1] * n[2].yyy + m[2] * n[2].zzz;
1628 }
1629
1630 mat3 __operator / (const mat3 m, const mat3 n)
1631 {
1632 __retVal[0] = m[0] / n[0];
1633 __retVal[1] = m[1] / n[1];
1634 __retVal[2] = m[2] / n[2];
1635 }
1636
1637
1638 //// Basic mat4 operations
1639
1640 mat4 __operator + (const mat4 m, const mat4 n)
1641 {
1642 __retVal[0] = m[0] + n[0];
1643 __retVal[1] = m[1] + n[1];
1644 __retVal[2] = m[2] + n[2];
1645 __retVal[3] = m[3] + n[3];
1646 }
1647
1648 mat4 __operator - (const mat4 m, const mat4 n)
1649 {
1650 __retVal[0] = m[0] - n[0];
1651 __retVal[1] = m[1] - n[1];
1652 __retVal[2] = m[2] - n[2];
1653 __retVal[3] = m[3] - n[3];
1654 }
1655
1656 mat4 __operator * (const mat4 m, const mat4 n)
1657 {
1658 __retVal[0] = m[0] * n[0].xxxx + m[1] * n[0].yyyy + m[2] * n[0].zzzz + m[3] * n[0].wwww;
1659 __retVal[1] = m[0] * n[1].xxxx + m[1] * n[1].yyyy + m[2] * n[1].zzzz + m[3] * n[1].wwww;
1660 __retVal[2] = m[0] * n[2].xxxx + m[1] * n[2].yyyy + m[2] * n[2].zzzz + m[3] * n[2].wwww;
1661 __retVal[3] = m[0] * n[3].xxxx + m[1] * n[3].yyyy + m[2] * n[3].zzzz + m[3] * n[3].wwww;
1662 }
1663
1664 mat4 __operator / (const mat4 m, const mat4 n)
1665 {
1666 __retVal[0] = m[0] / n[0];
1667 __retVal[1] = m[1] / n[1];
1668 __retVal[2] = m[2] / n[2];
1669 __retVal[3] = m[3] / n[3];
1670 }
1671
1672
1673 //// mat2/float operations
1674
1675 mat2 __operator + (const float a, const mat2 n)
1676 {
1677 __retVal[0] = a + n[0];
1678 __retVal[1] = a + n[1];
1679 }
1680
1681 mat2 __operator + (const mat2 m, const float b)
1682 {
1683 __retVal[0] = m[0] + b;
1684 __retVal[1] = m[1] + b;
1685 }
1686
1687 mat2 __operator - (const float a, const mat2 n)
1688 {
1689 __retVal[0] = a - n[0];
1690 __retVal[1] = a - n[1];
1691 }
1692
1693 mat2 __operator - (const mat2 m, const float b)
1694 {
1695 __retVal[0] = m[0] - b;
1696 __retVal[1] = m[1] - b;
1697 }
1698
1699 mat2 __operator * (const float a, const mat2 n)
1700 {
1701 __retVal[0] = a * n[0];
1702 __retVal[1] = a * n[1];
1703 }
1704
1705 mat2 __operator * (const mat2 m, const float b)
1706 {
1707 __retVal[0] = m[0] * b;
1708 __retVal[1] = m[1] * b;
1709 }
1710
1711 mat2 __operator / (const float a, const mat2 n)
1712 {
1713 __retVal[0] = a / n[0];
1714 __retVal[1] = a / n[1];
1715 }
1716
1717 mat2 __operator / (const mat2 m, const float b)
1718 {
1719 __retVal[0] = m[0] / b;
1720 __retVal[1] = m[1] / b;
1721 }
1722
1723
1724 //// mat3/float operations
1725
1726 mat3 __operator + (const float a, const mat3 n)
1727 {
1728 __retVal[0] = a + n[0];
1729 __retVal[1] = a + n[1];
1730 __retVal[2] = a + n[2];
1731 }
1732
1733 mat3 __operator + (const mat3 m, const float b)
1734 {
1735 __retVal[0] = m[0] + b;
1736 __retVal[1] = m[1] + b;
1737 __retVal[2] = m[2] + b;
1738 }
1739
1740 mat3 __operator - (const float a, const mat3 n)
1741 {
1742 __retVal[0] = a - n[0];
1743 __retVal[1] = a - n[1];
1744 __retVal[2] = a - n[2];
1745 }
1746
1747 mat3 __operator - (const mat3 m, const float b)
1748 {
1749 __retVal[0] = m[0] - b;
1750 __retVal[1] = m[1] - b;
1751 __retVal[2] = m[2] - b;
1752 }
1753
1754 mat3 __operator * (const float a, const mat3 n)
1755 {
1756 __retVal[0] = a * n[0];
1757 __retVal[1] = a * n[1];
1758 __retVal[2] = a * n[2];
1759 }
1760
1761 mat3 __operator * (const mat3 m, const float b)
1762 {
1763 __retVal[0] = m[0] * b;
1764 __retVal[1] = m[1] * b;
1765 __retVal[2] = m[2] * b;
1766 }
1767
1768 mat3 __operator / (const float a, const mat3 n)
1769 {
1770 __retVal[0] = a / n[0];
1771 __retVal[1] = a / n[1];
1772 __retVal[2] = a / n[2];
1773 }
1774
1775 mat3 __operator / (const mat3 m, const float b)
1776 {
1777 __retVal[0] = m[0] / b;
1778 __retVal[1] = m[1] / b;
1779 __retVal[2] = m[2] / b;
1780 }
1781
1782
1783 //// mat4/float operations
1784
1785 mat4 __operator + (const float a, const mat4 n)
1786 {
1787 __retVal[0] = a + n[0];
1788 __retVal[1] = a + n[1];
1789 __retVal[2] = a + n[2];
1790 __retVal[3] = a + n[3];
1791 }
1792
1793 mat4 __operator + (const mat4 m, const float b)
1794 {
1795 __retVal[0] = m[0] + b;
1796 __retVal[1] = m[1] + b;
1797 __retVal[2] = m[2] + b;
1798 __retVal[3] = m[3] + b;
1799 }
1800
1801 mat4 __operator - (const float a, const mat4 n)
1802 {
1803 __retVal[0] = a - n[0];
1804 __retVal[1] = a - n[1];
1805 __retVal[2] = a - n[2];
1806 __retVal[3] = a - n[3];
1807 }
1808
1809 mat4 __operator - (const mat4 m, const float b)
1810 {
1811 __retVal[0] = m[0] - b;
1812 __retVal[1] = m[1] - b;
1813 __retVal[2] = m[2] - b;
1814 __retVal[3] = m[3] - b;
1815 }
1816
1817 mat4 __operator * (const float a, const mat4 n)
1818 {
1819 __retVal[0] = a * n[0];
1820 __retVal[1] = a * n[1];
1821 __retVal[2] = a * n[2];
1822 __retVal[3] = a * n[3];
1823 }
1824
1825 mat4 __operator * (const mat4 m, const float b)
1826 {
1827 __retVal[0] = m[0] * b;
1828 __retVal[1] = m[1] * b;
1829 __retVal[2] = m[2] * b;
1830 __retVal[3] = m[3] * b;
1831 }
1832
1833 mat4 __operator / (const float a, const mat4 n)
1834 {
1835 __retVal[0] = a / n[0];
1836 __retVal[1] = a / n[1];
1837 __retVal[2] = a / n[2];
1838 __retVal[3] = a / n[3];
1839 }
1840
1841 mat4 __operator / (const mat4 m, const float b)
1842 {
1843 __retVal[0] = m[0] / b;
1844 __retVal[1] = m[1] / b;
1845 __retVal[2] = m[2] / b;
1846 __retVal[3] = m[3] / b;
1847 }
1848
1849
1850
1851 //// matrix / vector products
1852
1853 vec2 __operator * (const mat2 m, const vec2 v)
1854 {
1855 __retVal = m[0] * v.xx
1856 + m[1] * v.yy;
1857 }
1858
1859 vec2 __operator * (const vec2 v, const mat2 m)
1860 {
1861 __retVal.x = dot(v, m[0]);
1862 __retVal.y = dot(v, m[1]);
1863 }
1864
1865 vec3 __operator * (const mat3 m, const vec3 v)
1866 {
1867 __retVal = m[0] * v.xxx
1868 + m[1] * v.yyy
1869 + m[2] * v.zzz;
1870 }
1871
1872 vec3 __operator * (const vec3 v, const mat3 m)
1873 {
1874 __retVal.x = dot(v, m[0]);
1875 __retVal.y = dot(v, m[1]);
1876 __retVal.z = dot(v, m[2]);
1877 }
1878
1879 vec4 __operator * (const mat4 m, const vec4 v)
1880 {
1881 __retVal = m[0] * v.xxxx
1882 + m[1] * v.yyyy
1883 + m[2] * v.zzzz
1884 + m[3] * v.wwww;
1885 }
1886
1887 vec4 __operator * (const vec4 v, const mat4 m)
1888 {
1889 __retVal.x = dot(v, m[0]);
1890 __retVal.y = dot(v, m[1]);
1891 __retVal.z = dot(v, m[2]);
1892 __retVal.w = dot(v, m[3]);
1893 }
1894
1895
1896
1897 //// mat2 assignment operators
1898
1899 void __operator += (inout mat2 m, const mat2 n)
1900 {
1901 m[0] += n[0];
1902 m[1] += n[1];
1903 }
1904
1905 void __operator -= (inout mat2 m, const mat2 n)
1906 {
1907 m[0] -= n[0];
1908 m[1] -= n[1];
1909 }
1910
1911 void __operator *= (inout mat2 m, const mat2 n)
1912 {
1913 m = m * n;
1914 }
1915
1916 void __operator /= (inout mat2 m, const mat2 n)
1917 {
1918 m[0] /= n[0];
1919 m[1] /= n[1];
1920 }
1921
1922
1923 //// mat3 assignment operators
1924
1925 void __operator += (inout mat3 m, const mat3 n)
1926 {
1927 m[0] += n[0];
1928 m[1] += n[1];
1929 m[2] += n[2];
1930 }
1931
1932 void __operator -= (inout mat3 m, const mat3 n)
1933 {
1934 m[0] -= n[0];
1935 m[1] -= n[1];
1936 m[2] -= n[2];
1937 }
1938
1939 void __operator *= (inout mat3 m, const mat3 n)
1940 {
1941 m = m * n;
1942 }
1943
1944 void __operator /= (inout mat3 m, const mat3 n)
1945 {
1946 m[0] /= n[0];
1947 m[1] /= n[1];
1948 m[2] /= n[2];
1949 }
1950
1951
1952 // mat4 assignment operators
1953
1954 void __operator += (inout mat4 m, const mat4 n)
1955 {
1956 m[0] += n[0];
1957 m[1] += n[1];
1958 m[2] += n[2];
1959 m[3] += n[3];
1960 }
1961
1962 void __operator -= (inout mat4 m, const mat4 n) {
1963 m[0] -= n[0];
1964 m[1] -= n[1];
1965 m[2] -= n[2];
1966 m[3] -= n[3];
1967 }
1968
1969 void __operator *= (inout mat4 m, const mat4 n)
1970 {
1971 m = m * n;
1972 }
1973
1974 void __operator /= (inout mat4 m, const mat4 n)
1975 {
1976 m[0] /= n[0];
1977 m[1] /= n[1];
1978 m[2] /= n[2];
1979 m[3] /= n[3];
1980 }
1981
1982
1983 //// mat2/float assignment operators
1984
1985 void __operator += (inout mat2 m, const float a) {
1986 m[0] += a;
1987 m[1] += a;
1988 }
1989
1990 void __operator -= (inout mat2 m, const float a) {
1991 m[0] -= a;
1992 m[1] -= a;
1993 }
1994
1995 void __operator *= (inout mat2 m, const float a) {
1996 m[0] *= a;
1997 m[1] *= a;
1998 }
1999
2000 void __operator /= (inout mat2 m, const float a) {
2001 m[0] /= a;
2002 m[1] /= a;
2003 }
2004
2005
2006 //// mat3/float assignment operators
2007
2008 void __operator += (inout mat3 m, const float a) {
2009 m[0] += a;
2010 m[1] += a;
2011 m[2] += a;
2012 }
2013
2014 void __operator -= (inout mat3 m, const float a) {
2015 m[0] -= a;
2016 m[1] -= a;
2017 m[2] -= a;
2018 }
2019
2020 void __operator *= (inout mat3 m, const float a) {
2021 m[0] *= a;
2022 m[1] *= a;
2023 m[2] *= a;
2024 }
2025
2026 void __operator /= (inout mat3 m, const float a) {
2027 m[0] /= a;
2028 m[1] /= a;
2029 m[2] /= a;
2030 }
2031
2032
2033 //// mat4/float assignment operators
2034
2035 void __operator += (inout mat4 m, const float a) {
2036 m[0] += a;
2037 m[1] += a;
2038 m[2] += a;
2039 m[3] += a;
2040 }
2041
2042 void __operator -= (inout mat4 m, const float a) {
2043 m[0] -= a;
2044 m[1] -= a;
2045 m[2] -= a;
2046 m[3] -= a;
2047 }
2048
2049 void __operator *= (inout mat4 m, const float a) {
2050 m[0] *= a;
2051 m[1] *= a;
2052 m[2] *= a;
2053 m[3] *= a;
2054 }
2055
2056 void __operator /= (inout mat4 m, const float a) {
2057 m[0] /= a;
2058 m[1] /= a;
2059 m[2] /= a;
2060 m[3] /= a;
2061 }
2062
2063
2064
2065 //// vec/mat assignment operators
2066
2067 void __operator *= (inout vec2 v, const mat2 m)
2068 {
2069 v = v * m;
2070 }
2071
2072 void __operator *= (inout vec3 v, const mat3 m)
2073 {
2074 v = v * m;
2075 }
2076
2077 void __operator *= (inout vec4 v, const mat4 m)
2078 {
2079 v = v * m;
2080 }
2081
2082
2083
2084 //// pre-decrement operators
2085
2086 int __operator --(inout int a)
2087 {
2088 a = a - 1;
2089 __retVal = a;
2090 }
2091
2092 ivec2 __operator --(inout ivec2 v)
2093 {
2094 v = v - ivec2(1);
2095 __retVal = v;
2096 }
2097
2098 ivec3 __operator --(inout ivec3 v)
2099 {
2100 v = v - ivec3(1);
2101 __retVal = v;
2102 }
2103
2104 ivec4 __operator --(inout ivec4 v)
2105 {
2106 v = v - ivec4(1);
2107 __retVal = v;
2108 }
2109
2110
2111 float __operator --(inout float a)
2112 {
2113 a = a - 1.0;
2114 __retVal = a;
2115 }
2116
2117 vec2 __operator --(inout vec2 v)
2118 {
2119 v = v - vec2(1.0);
2120 __retVal = v;
2121 }
2122
2123 vec3 __operator --(inout vec3 v)
2124 {
2125 v = v - vec3(1.0);
2126 __retVal = v;
2127 }
2128
2129 vec4 __operator --(inout vec4 v)
2130 {
2131 v = v - vec4(1.0);
2132 __retVal = v;
2133 }
2134
2135
2136 mat2 __operator --(inout mat2 m)
2137 {
2138 m[0] = m[0] - vec2(1.0);
2139 m[1] = m[1] - vec2(1.0);
2140 __retVal = m;
2141 }
2142
2143 mat3 __operator --(inout mat3 m)
2144 {
2145 m[0] = m[0] - vec3(1.0);
2146 m[1] = m[1] - vec3(1.0);
2147 m[2] = m[2] - vec3(1.0);
2148 __retVal = m;
2149 }
2150
2151 mat4 __operator --(inout mat4 m)
2152 {
2153 m[0] = m[0] - vec4(1.0);
2154 m[1] = m[1] - vec4(1.0);
2155 m[2] = m[2] - vec4(1.0);
2156 m[3] = m[3] - vec4(1.0);
2157 __retVal = m;
2158 }
2159
2160
2161 //// pre-increment operators
2162
2163 int __operator ++(inout int a)
2164 {
2165 a = a + 1;
2166 __retVal = a;
2167 }
2168
2169 ivec2 __operator ++(inout ivec2 v)
2170 {
2171 v = v + ivec2(1);
2172 __retVal = v;
2173 }
2174
2175 ivec3 __operator ++(inout ivec3 v)
2176 {
2177 v = v + ivec3(1);
2178 __retVal = v;
2179 }
2180
2181 ivec4 __operator ++(inout ivec4 v)
2182 {
2183 v = v + ivec4(1);
2184 __retVal = v;
2185 }
2186
2187
2188 float __operator ++(inout float a)
2189 {
2190 a = a + 1.0;
2191 __retVal = a;
2192 }
2193
2194 vec2 __operator ++(inout vec2 v)
2195 {
2196 v = v + vec2(1.0);
2197 __retVal = v;
2198 }
2199
2200 vec3 __operator ++(inout vec3 v)
2201 {
2202 v = v + vec3(1.0);
2203 __retVal = v;
2204 }
2205
2206 vec4 __operator ++(inout vec4 v)
2207 {
2208 v = v + vec4(1.0);
2209 __retVal = v;
2210 }
2211
2212
2213 mat2 __operator ++(inout mat2 m)
2214 {
2215 m[0] = m[0] + vec2(1.0);
2216 m[1] = m[1] + vec2(1.0);
2217 __retVal = m;
2218 }
2219
2220 mat3 __operator ++(inout mat3 m)
2221 {
2222 m[0] = m[0] + vec3(1.0);
2223 m[1] = m[1] + vec3(1.0);
2224 m[2] = m[2] + vec3(1.0);
2225 __retVal = m;
2226 }
2227
2228 mat4 __operator ++(inout mat4 m)
2229 {
2230 m[0] = m[0] + vec4(1.0);
2231 m[1] = m[1] + vec4(1.0);
2232 m[2] = m[2] + vec4(1.0);
2233 m[3] = m[3] + vec4(1.0);
2234 __retVal = m;
2235 }
2236
2237
2238
2239 //// post-decrement
2240
2241 int __postDecr(inout int a)
2242 {
2243 __retVal = a;
2244 a = a - 1;
2245 }
2246
2247 ivec2 __postDecr(inout ivec2 v)
2248 {
2249 __retVal = v;
2250 v = v - ivec2(1);
2251 }
2252
2253 ivec3 __postDecr(inout ivec3 v)
2254 {
2255 __retVal = v;
2256 v = v - ivec3(1);
2257 }
2258
2259 ivec4 __postDecr(inout ivec4 v)
2260 {
2261 __retVal = v;
2262 v = v - ivec4(1);
2263 }
2264
2265
2266 float __postDecr(inout float a)
2267 {
2268 __retVal = a;
2269 a = a - 1.0;
2270 }
2271
2272 vec2 __postDecr(inout vec2 v)
2273 {
2274 __retVal = v;
2275 v = v - vec2(1.0);
2276 }
2277
2278 vec3 __postDecr(inout vec3 v)
2279 {
2280 __retVal = v;
2281 v = v - vec3(1.0);
2282 }
2283
2284 vec4 __postDecr(inout vec4 v)
2285 {
2286 __retVal = v;
2287 v = v - vec4(1.0);
2288 }
2289
2290
2291 mat2 __postDecr(inout mat2 m)
2292 {
2293 __retVal = m;
2294 m[0] = m[0] - vec2(1.0);
2295 m[1] = m[1] - vec2(1.0);
2296 }
2297
2298 mat3 __postDecr(inout mat3 m)
2299 {
2300 __retVal = m;
2301 m[0] = m[0] - vec3(1.0);
2302 m[1] = m[1] - vec3(1.0);
2303 m[2] = m[2] - vec3(1.0);
2304 }
2305
2306 mat4 __postDecr(inout mat4 m)
2307 {
2308 __retVal = m;
2309 m[0] = m[0] - vec4(1.0);
2310 m[1] = m[1] - vec4(1.0);
2311 m[2] = m[2] - vec4(1.0);
2312 m[3] = m[3] - vec4(1.0);
2313 }
2314
2315
2316 //// post-increment
2317
2318 float __postIncr(inout float a)
2319 {
2320 __retVal = a;
2321 a = a + 1;
2322 }
2323
2324 vec2 __postIncr(inout vec2 v)
2325 {
2326 __retVal = v;
2327 v = v + vec2(1.0);
2328 }
2329
2330 vec3 __postIncr(inout vec3 v)
2331 {
2332 __retVal = v;
2333 v = v + vec3(1.0);
2334 }
2335
2336 vec4 __postIncr(inout vec4 v)
2337 {
2338 __retVal = v;
2339 v = v + vec4(1.0);
2340 }
2341
2342
2343 int __postIncr(inout int a)
2344 {
2345 __retVal = a;
2346 a = a + 1;
2347 }
2348
2349 ivec2 __postIncr(inout ivec2 v)
2350 {
2351 __retVal = v;
2352 v = v + ivec2(1);
2353 }
2354
2355 ivec3 __postIncr(inout ivec3 v)
2356 {
2357 __retVal = v;
2358 v = v + ivec3(1);
2359 }
2360
2361 ivec4 __postIncr(inout ivec4 v)
2362 {
2363 __retVal = v;
2364 v = v + ivec3(1);
2365 }
2366
2367
2368 mat2 __postIncr(inout mat2 m)
2369 {
2370 mat2 n = m;
2371 m[0] = m[0] + vec2(1.0);
2372 m[1] = m[1] + vec2(1.0);
2373 return n;
2374 }
2375
2376 mat3 __postIncr(inout mat3 m)
2377 {
2378 mat3 n = m;
2379 m[0] = m[0] + vec3(1.0);
2380 m[1] = m[1] + vec3(1.0);
2381 m[2] = m[2] + vec3(1.0);
2382 return n;
2383 }
2384
2385 mat4 __postIncr(inout mat4 m)
2386 {
2387 mat4 n = m;
2388 m[0] = m[0] + vec4(1.0);
2389 m[1] = m[1] + vec4(1.0);
2390 m[2] = m[2] + vec4(1.0);
2391 m[3] = m[3] + vec4(1.0);
2392 return n;
2393 }
2394
2395
2396
2397 //// inequality operators
2398
2399
2400 // XXX are the inequality operators for floats/ints really needed????
2401 bool __operator < (const float a, const float b)
2402 {
2403 __asm vec4_sgt __retVal.x, b, a;
2404 }
2405
2406
2407 bool __operator < (const int a, const int b) {
2408 return float (a) < float (b);
2409 }
2410
2411 bool __operator > (const float a, const float b) {
2412 bool c;
2413 __asm float_less c, b, a;
2414 return c;
2415 }
2416
2417 bool __operator > (const int a, const int b) {
2418 return float (a) > float (b);
2419 }
2420
2421 bool __operator >= (const float a, const float b) {
2422 bool g, e;
2423 __asm float_less g, b, a;
2424 __asm float_equal e, a, b;
2425 return g || e;
2426 }
2427
2428 bool __operator >= (const int a, const int b) {
2429 return float (a) >= float (b);
2430 }
2431
2432 bool __operator <= (const float a, const float b) {
2433 bool g, e;
2434 __asm float_less g, a, b;
2435 __asm float_equal e, a, b;
2436 return g || e;
2437 }
2438
2439 bool __operator <= (const int a, const int b) {
2440 return float (a) <= float (b);
2441 }
2442
2443
2444
2445 //
2446 // MESA-specific extension functions.
2447 //
2448
2449 void printMESA (const float f) {
2450 __asm float_print f;
2451 }
2452
2453 void printMESA (const int i) {
2454 __asm int_print i;
2455 }
2456
2457 void printMESA (const bool b) {
2458 __asm bool_print b;
2459 }
2460
2461 void printMESA (const vec2 v) {
2462 printMESA (v.x);
2463 printMESA (v.y);
2464 }
2465
2466 void printMESA (const vec3 v) {
2467 printMESA (v.x);
2468 printMESA (v.y);
2469 printMESA (v.z);
2470 }
2471
2472 void printMESA (const vec4 v) {
2473 printMESA (v.x);
2474 printMESA (v.y);
2475 printMESA (v.z);
2476 printMESA (v.w);
2477 }
2478
2479 void printMESA (const ivec2 v) {
2480 printMESA (v.x);
2481 printMESA (v.y);
2482 }
2483
2484 void printMESA (const ivec3 v) {
2485 printMESA (v.x);
2486 printMESA (v.y);
2487 printMESA (v.z);
2488 }
2489
2490 void printMESA (const ivec4 v) {
2491 printMESA (v.x);
2492 printMESA (v.y);
2493 printMESA (v.z);
2494 printMESA (v.w);
2495 }
2496
2497 void printMESA (const bvec2 v) {
2498 printMESA (v.x);
2499 printMESA (v.y);
2500 }
2501
2502 void printMESA (const bvec3 v) {
2503 printMESA (v.x);
2504 printMESA (v.y);
2505 printMESA (v.z);
2506 }
2507
2508 void printMESA (const bvec4 v) {
2509 printMESA (v.x);
2510 printMESA (v.y);
2511 printMESA (v.z);
2512 printMESA (v.w);
2513 }
2514
2515 void printMESA (const mat2 m) {
2516 printMESA (m[0]);
2517 printMESA (m[1]);
2518 }
2519
2520 void printMESA (const mat3 m) {
2521 printMESA (m[0]);
2522 printMESA (m[1]);
2523 printMESA (m[2]);
2524 }
2525
2526 void printMESA (const mat4 m) {
2527 printMESA (m[0]);
2528 printMESA (m[1]);
2529 printMESA (m[2]);
2530 printMESA (m[3]);
2531 }
2532
2533 void printMESA (const sampler1D e) {
2534 __asm int_print e;
2535 }
2536
2537 void printMESA (const sampler2D e) {
2538 __asm int_print e;
2539 }
2540
2541 void printMESA (const sampler3D e) {
2542 __asm int_print e;
2543 }
2544
2545 void printMESA (const samplerCube e) {
2546 __asm int_print e;
2547 }
2548
2549 void printMESA (const sampler1DShadow e) {
2550 __asm int_print e;
2551 }
2552
2553 void printMESA (const sampler2DShadow e) {
2554 __asm int_print e;
2555 }
2556