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