make sure the new instruction Data pointer is set to NULL
[mesa.git] / src / mesa / shader / slang_core.gc
1
2 //
3 // This file defines nearly all constructors and operators for built-in data types, using
4 // extended language syntax. In general, compiler treats constructors and operators as
5 // ordinary functions with some exceptions. For example, the language does not allow
6 // functions to be called in constant expressions - here the exception is made to allow it.
7 //
8 // Each implementation provides its own version of this file. Each implementation can define
9 // the required set of operators and constructors in its own fashion.
10 //
11 // The extended language syntax is only present when compiling this file. It is implicitly
12 // included at the very beginning of the compiled shader, so no built-in functions can be
13 // used.
14 //
15 // To communicate with the implementation, a special extended "__asm" keyword is used, followed
16 // by an instruction name (any valid identifier), a destination variable identifier and a
17 // a list of zero or more source variable identifiers. A variable identifier is a variable name
18 // declared earlier in the code (as a function parameter, local or global variable).
19 // An instruction name designates an instruction that must be exported by the implementation.
20 // Each instruction receives data from destination and source variable identifiers and returns
21 // data in the destination variable identifier.
22 //
23 // It is up to the implementation how to define a particular operator or constructor. If it is
24 // expected to being used rarely, it can be defined in terms of other operators and constructors,
25 // for example:
26 //
27 // ivec2 __operator + (const ivec2 x, const ivec2 y) {
28 // return ivec2 (x[0] + y[0], x[1] + y[1]);
29 // }
30 //
31 // If a particular operator or constructor is expected to be used very often or is an atomic
32 // operation (that is, an operation that cannot be expressed in terms of other operations or
33 // would create a dependency cycle) it must be defined using one or more __asm constructs.
34 //
35 // Each implementation must define constructors for all scalar types (bool, float, int).
36 // There are 9 scalar-to-scalar constructors (including identity constructors). However,
37 // since the language introduces special constructors (like matrix constructor with a single
38 // scalar value), implementations must also implement these cases.
39 // The compiler provides the following algorithm when resolving a constructor:
40 // - try to find a constructor with a prototype matching ours,
41 // - if no constructor is found and this is a scalar-to-scalar constructor, raise an error,
42 // - if a constructor is found, execute it and return,
43 // - count the size of the constructor parameter list - if it is less than the size of
44 // our constructor's type, raise an error,
45 // - for each parameter in the list do a recursive constructor matching for appropriate
46 // scalar fields in the constructed variable,
47 //
48 // Each implementation must also define a set of operators that deal with built-in data types.
49 // There are four kinds of operators:
50 // 1) Operators that are implemented only by the compiler: "()" (function call), "," (sequence)
51 // and "?:" (selection).
52 // 2) Operators that are implemented by the compiler by expressing it in terms of other operators:
53 // - "." (field selection) - translated to subscript access,
54 // - "&&" (logical and) - translated to "<left_expr> ? <right_expr> : false",
55 // - "||" (logical or) - translated to "<left_expr> ? true : <right_expr>",
56 // 3) Operators that can be defined by the implementation and if the required prototype is not
57 // found, standard behaviour is used:
58 // - "==", "!=", "=" (equality, assignment) - compare or assign matching fields one-by-one;
59 // note that at least operators for scalar data types must be defined by the implementation
60 // to get it work,
61 // 4) All other operators not mentioned above. If no required prototype is found, an error is
62 // raised. An implementation must follow the language specification to provide all valid
63 // operator prototypes.
64 //
65
66 //
67 // From Shader Spec, ver. 1.10, rev. 59
68 //
69
70 //
71 // 5.4.1 Conversion and Scalar Constructors
72 //
73
74 //
75 // When constructors are used to convert a float to an int, the fractional part of the
76 // floating-point value is dropped.
77 //
78
79 int __constructor (const float _f) {
80 int _i;
81 __asm float_to_int _i, _f;
82 return _i;
83 }
84
85 //
86 // When a constructor is used to convert an int or a float to bool, 0 and 0.0 are converted to
87 // false, and nonzero values are converted to true.
88 //
89
90 bool __constructor (const int _i) {
91 return _i != 0;
92 }
93
94 bool __constructor (const float _f) {
95 return _f != 0.0;
96 }
97
98 //
99 // When a constructor is used to convert a bool to an int or float, false is converted to 0 or
100 // 0.0, and true is converted to 1 or 1.0.
101 //
102
103 int __constructor (const bool _b) {
104 return _b ? 1 : 0;
105 }
106
107 float __constructor (const bool _b) {
108 return _b ? 1.0 : 0.0;
109 }
110
111 //
112 // Int to float constructor.
113 //
114
115 float __constructor (const int _i) {
116 float _f;
117 __asm int_to_float _f, _i;
118 return _f;
119 }
120
121 //
122 // Identity constructors, like float(float) are also legal, but of little use.
123 //
124
125 bool __constructor (const bool _b) {
126 return _b;
127 }
128
129 int __constructor (const int _i) {
130 return _i;
131 }
132
133 float __constructor (const float _f) {
134 return _f;
135 }
136
137 //
138 // Scalar constructors with non-scalar parameters can be used to take the first element from
139 // a non-scalar. For example, the constructor float(vec3) will select the first component of the
140 // vec3 parameter.
141 //
142
143 // [These scalar conversions will be handled internally by the compiler.]
144
145 //
146 // 5.4.2 Vector and Matrix Constructors
147 //
148 // Constructors can be used to create vectors or matrices from a set of scalars, vectors,
149 // or matrices. This includes the ability to shorten vectors.
150 //
151
152 //
153 // If there is a single scalar parameter to a vector constructor, it is used to initialize all
154 // components of the constructed vector to that scalar\92s value.
155 //
156 // If the basic type (bool, int, or float) of a parameter to a constructor does not match the basic
157 // type of the object being constructed, the scalar construction rules (above) are used to convert
158 // the parameters.
159 //
160
161 vec2 __constructor (const float _f) {
162 return vec2 (_f, _f);
163 }
164
165 vec2 __constructor (const int _i) {
166 return vec2 (_i, _i);
167 }
168
169 vec2 __constructor (const bool _b) {
170 return vec2 (_b, _b);
171 }
172
173 vec3 __constructor (const float _f) {
174 return vec3 (_f, _f, _f);
175 }
176
177 vec3 __constructor (const int _i) {
178 return vec3 (_i, _i, _i);
179 }
180
181 vec3 __constructor (const bool _b) {
182 return vec3 (_b, _b, _b);
183 }
184
185 vec4 __constructor (const float _f) {
186 return vec4 (_f, _f, _f, _f);
187 }
188
189 vec4 __constructor (const int _i) {
190 return vec4 (_i, _i, _i, _i);
191 }
192
193 vec4 __constructor (const bool _b) {
194 return vec4 (_b, _b, _b, _b);
195 }
196
197 ivec2 __constructor (const int _i) {
198 return ivec2 (_i, _i);
199 }
200
201 ivec2 __constructor (const float _f) {
202 return ivec2 (_f, _f);
203 }
204
205 ivec2 __constructor (const bool _b) {
206 return ivec2 (_b, _b);
207 }
208
209 ivec3 __constructor (const int _i) {
210 return ivec3 (_i, _i, _i);
211 }
212
213 ivec3 __constructor (const float _f) {
214 return ivec3 (_f, _f, _f);
215 }
216
217 ivec3 __constructor (const bool _b) {
218 return ivec3 (_b, _b, _b);
219 }
220
221 ivec4 __constructor (const int _i) {
222 return ivec4 (_i, _i, _i, _i);
223 }
224
225 ivec4 __constructor (const float _f) {
226 return ivec4 (_f, _f, _f, _f);
227 }
228
229 ivec4 __constructor (const bool _b) {
230 return ivec4 (_b, _b, _b, _b);
231 }
232
233 bvec2 __constructor (const bool _b) {
234 return bvec2 (_b, _b);
235 }
236
237 bvec2 __constructor (const float _f) {
238 return bvec2 (_f, _f);
239 }
240
241 bvec2 __constructor (const int _i) {
242 return bvec2 (_i, _i);
243 }
244
245 bvec3 __constructor (const bool _b) {
246 return bvec3 (_b, _b, _b);
247 }
248
249 bvec3 __constructor (const float _f) {
250 return bvec3 (_f, _f, _f);
251 }
252
253 bvec3 __constructor (const int _i) {
254 return bvec3 (_i, _i, _i);
255 }
256
257 bvec4 __constructor (const bool _b) {
258 return bvec4 (_b, _b, _b, _b);
259 }
260
261 bvec4 __constructor (const float _f) {
262 return bvec4 (_f, _f, _f, _f);
263 }
264
265 bvec4 __constructor (const int _i) {
266 return bvec4 (_i, _i, _i, _i);
267 }
268
269 //
270 // If there is a single scalar parameter to a matrix constructor, it is used to initialize all the
271 // components on the matrix\92s diagonal, with the remaining components initialized to 0.0.
272 // (...) Matrices will be constructed in column major order. It is an error to construct matrices
273 // from other matrices. This is reserved for future use.
274 //
275 // If the basic type (bool, int, or float) of a parameter to a constructor does not match the basic
276 // type of the object being constructed, the scalar construction rules (above) are used to convert
277 // the parameters.
278 //
279
280 mat2 __constructor (const float _f) {
281 return mat2 (
282 _f, .0,
283 .0, _f
284 );
285 }
286
287 mat2 __constructor (const int _i) {
288 return mat2 (
289 _i, .0,
290 .0, _i
291 );
292 }
293
294 mat2 __constructor (const bool _b) {
295 return mat2 (
296 _b, .0,
297 .0, _b
298 );
299 }
300
301 mat3 __constructor (const float _f) {
302 return mat3 (
303 _f, .0, .0,
304 .0, _f, .0,
305 .0, .0, _f
306 );
307 }
308
309 mat3 __constructor (const int _i) {
310 return mat3 (
311 _i, .0, .0,
312 .0, _i, .0,
313 .0, .0, _i
314 );
315 }
316
317 mat3 __constructor (const bool _b) {
318 return mat3 (
319 _b, .0, .0,
320 .0, _b, .0,
321 .0, .0, _b
322 );
323 }
324
325 mat4 __constructor (const float _f) {
326 return mat4 (
327 _f, .0, .0, .0,
328 .0, _f, .0, .0,
329 .0, .0, _f, .0,
330 .0, .0, .0, _f
331 );
332 }
333
334 mat4 __constructor (const int _i) {
335 return mat4 (
336 _i, .0, .0, .0,
337 .0, _i, .0, .0,
338 .0, .0, _i, .0,
339 .0, .0, .0, _i
340 );
341 }
342
343 mat4 __constructor (const bool _b) {
344 return mat4 (
345 _b, .0, .0, .0,
346 .0, _b, .0, .0,
347 .0, .0, _b, .0,
348 .0, .0, .0, _b
349 );
350 }
351
352 //
353 // 5.8 Assignments
354 //
355 // Assignments of values to variable names are done with the assignment operator ( = ), like
356 //
357 // lvalue = expression
358 //
359 // The assignment operator stores the value of expression into lvalue. It will compile only if
360 // expression and lvalue have the same type. All desired type-conversions must be specified
361 // explicitly via a constructor. Lvalues must be writable. Variables that are built-in types,
362 // entire structures, structure fields, l-values with the field selector ( . ) applied to select
363 // components or swizzles without repeated fields, and l-values dereferenced with the array
364 // subscript operator ( [ ] ) are all possible l-values. Other binary or unary expressions,
365 // non-dereferenced arrays, function names, swizzles with repeated fields, and constants cannot
366 // be l-values.
367 //
368 // Expressions on the left of an assignment are evaluated before expressions on the right of the
369 // assignment.
370 //
371
372 void __operator = (inout float a, const float b) {
373 __asm float_copy a, b;
374 }
375
376 void __operator = (inout int a, const int b) {
377 __asm int_copy a, b;
378 }
379
380 void __operator = (inout bool a, const bool b) {
381 __asm bool_copy a, b;
382 }
383
384 void __operator = (inout vec2 v, const vec2 u) {
385 v.x = u.x, v.y = u.y;
386 }
387
388 void __operator = (inout vec3 v, const vec3 u) {
389 v.x = u.x, v.y = u.y, v.z = u.z;
390 }
391
392 void __operator = (inout vec4 v, const vec4 u) {
393 v.x = u.x, v.y = u.y, v.z = u.z, v.w = u.w;
394 }
395
396 void __operator = (inout ivec2 v, const ivec2 u) {
397 v.x = u.x, v.y = u.y;
398 }
399
400 void __operator = (inout ivec3 v, const ivec3 u) {
401 v.x = u.x, v.y = u.y, v.z = u.z;
402 }
403
404 void __operator = (inout ivec4 v, const ivec4 u) {
405 v.x = u.x, v.y = u.y, v.z = u.z, v.w = u.w;
406 }
407
408 void __operator = (inout bvec2 v, const bvec2 u) {
409 v.x = u.x, v.y = u.y;
410 }
411
412 void __operator = (inout bvec3 v, const bvec3 u) {
413 v.x = u.x, v.y = u.y, v.z = u.z;
414 }
415
416 void __operator = (inout bvec4 v, const bvec4 u) {
417 v.x = u.x, v.y = u.y, v.z = u.z, v.w = u.w;
418 }
419
420 void __operator = (inout mat2 m, const mat2 n) {
421 m[0] = n[0], m[1] = n[1];
422 }
423
424 void __operator = (inout mat3 m, const mat3 n) {
425 m[0] = n[0], m[1] = n[1], m[2] = n[2];
426 }
427
428 void __operator = (inout mat4 m, const mat4 n) {
429 m[0] = n[0], m[1] = n[1], m[2] = n[2], m[3] = n[3];
430 }
431
432 //
433 // \95 The arithmetic assignments add into (+=), subtract from (-=), multiply into (*=), and divide
434 // into (/=). The variable and expression must be the same floating-point or integer type, ...
435 //
436
437 void __operator += (inout float a, const float b) {
438 __asm float_add a, b;
439 }
440
441 void __operator -= (inout float a, const float b) {
442 a += -b;
443 }
444
445 void __operator *= (inout float a, const float b) {
446 __asm float_multiply a, b;
447 }
448
449 void __operator /= (inout float a, const float b) {
450 __asm float_divide a, b;
451 }
452
453 void __operator += (inout int x, const int y) {
454 __asm int_add x, y;
455 }
456
457 void __operator -= (inout int x, const int y) {
458 x += -y;
459 }
460
461 void __operator *= (inout int x, const int y) {
462 __asm int_multiply x, y;
463 }
464
465 void __operator /= (inout int x, const int y) {
466 __asm int_divide x, y;
467 }
468
469 void __operator += (inout vec2 v, const vec2 u) {
470 v.x += u.x, v.y += u.y;
471 }
472
473 void __operator -= (inout vec2 v, const vec2 u) {
474 v.x -= u.x, v.y -= u.y;
475 }
476
477 void __operator *= (inout vec2 v, const vec2 u) {
478 v.x *= u.x, v.y *= u.y;
479 }
480
481 void __operator /= (inout vec2 v, const vec2 u) {
482 v.x /= u.x, v.y /= u.y;
483 }
484
485 void __operator += (inout vec3 v, const vec3 u) {
486 v.x += u.x, v.y += u.y, v.z += u.z;
487 }
488
489 void __operator -= (inout vec3 v, const vec3 u) {
490 v.x -= u.x, v.y -= u.y, v.z -= u.z;
491 }
492
493 void __operator *= (inout vec3 v, const vec3 u) {
494 v.x *= u.x, v.y *= u.y, v.z *= u.z;
495 }
496
497 void __operator /= (inout vec3 v, const vec3 u) {
498 v.x /= u.x, v.y /= u.y, v.z /= u.z;
499 }
500
501 void __operator += (inout vec4 v, const vec4 u) {
502 v.x += u.x, v.y += u.y, v.z += u.z, v.w += u.w;
503 }
504
505 void __operator -= (inout vec4 v, const vec4 u) {
506 v.x -= u.x, v.y -= u.y, v.z -= u.z, v.w -= u.w;
507 }
508
509 void __operator *= (inout vec4 v, const vec4 u) {
510 v.x *= u.x, v.y *= u.y, v.z *= u.z, v.w *= u.w;
511 }
512
513 void __operator /= (inout vec4 v, const vec4 u) {
514 v.x /= u.x, v.y /= u.y, v.z /= u.z, v.w /= u.w;
515 }
516
517 void __operator += (inout ivec2 v, const ivec2 u) {
518 v.x += u.x, v.y += u.y;
519 }
520
521 void __operator -= (inout ivec2 v, const ivec2 u) {
522 v.x -= u.x, v.y -= u.y;
523 }
524
525 void __operator *= (inout ivec2 v, const ivec2 u) {
526 v.x *= u.x, v.y *= u.y;
527 }
528
529 void __operator /= (inout ivec2 v, const ivec2 u) {
530 v.x /= u.x, v.y /= u.y;
531 }
532
533 void __operator += (inout ivec3 v, const ivec3 u) {
534 v.x += u.x, v.y += u.y, v.z += u.z;
535 }
536
537 void __operator -= (inout ivec3 v, const ivec3 u) {
538 v.x -= u.x, v.y -= u.y, v.z -= u.z;
539 }
540
541 void __operator *= (inout ivec3 v, const ivec3 u) {
542 v.x *= u.x, v.y *= u.y, v.z *= u.z;
543 }
544
545 void __operator /= (inout ivec3 v, const ivec3 u) {
546 v.x /= u.x, v.y /= u.y, v.z /= u.z;
547 }
548
549 void __operator += (inout ivec4 v, const ivec4 u) {
550 v.x += u.x, v.y += u.y, v.z += u.z, v.w += u.w;
551 }
552
553 void __operator -= (inout ivec4 v, const ivec4 u) {
554 v.x -= u.x, v.y -= u.y, v.z -= u.z, v.w -= u.w;
555 }
556
557 void __operator *= (inout ivec4 v, const ivec4 u) {
558 v.x *= u.x, v.y *= u.y, v.z *= u.z, v.w *= u.w;
559 }
560
561 void __operator /= (inout ivec4 v, const ivec4 u) {
562 v.x /= u.x, v.y /= u.y, v.z /= u.z, v.w /= u.w;
563 }
564
565 void __operator += (inout mat2 m, const mat2 n) {
566 m[0] += n[0], m[1] += n[1];
567 }
568
569 void __operator -= (inout mat2 v, const mat2 n) {
570 m[0] -= n[0], m[1] -= n[1];
571 }
572
573 void __operator *= (inout mat2 m, const mat2 n) {
574 m = m * n;
575 }
576
577 void __operator /= (inout mat2 m, const mat2 n) {
578 m[0] /= n[0], m[1] /= n[1];
579 }
580
581 void __operator += (inout mat3 m, const mat3 n) {
582 m[0] += n[0], m[1] += n[1], m[2] += n[2];
583 }
584
585 void __operator -= (inout mat3 m, const mat3 n) {
586 m[0] -= n[0], m[1] -= n[1], m[2] -= n[2];
587 }
588
589 void __operator *= (inout mat3 m, const mat3 n) {
590 m = m * n;
591 }
592
593 void __operator /= (inout mat3 m, const mat3 n) {
594 m[0] /= n[0], m[1] /= n[1], m[2] /= n[2];
595 }
596
597 void __operator += (inout mat4 m, const mat4 n) {
598 m[0] += n[0], m[1] += n[1], m[2] += n[2], m[3] += n[3];
599 }
600
601 void __operator -= (inout mat4 m, const mat4 n) {
602 m[0] -= n[0], m[1] -= n[1], m[2] -= n[2], m[3] -= n[3];
603 }
604
605 void __operator *= (inout mat4 m, const mat4 n) {
606 m = m * n;
607 }
608
609 void __operator /= (inout mat4 m, const mat4 n) {
610 m[0] /= n[0], m[1] /= n[1], m[2] /= n[2], m[3] /= n[3];
611 }
612
613 //
614 // ... or if the expression is a float, then the variable can be floating-point, a vector, or
615 // a matrix, ...
616 //
617
618 void __operator += (inout vec2 v, const float a) {
619 v.x += a, v.y += a;
620 }
621
622 void __operator -= (inout vec2 v, const float a) {
623 v.x -= a, v.y -= a;
624 }
625
626 void __operator *= (inout vec2 v, const float a) {
627 v.x *= a, v.y *= a;
628 }
629
630 void __operator /= (inout vec2 v, const float a) {
631 v.x /= a, v.y /= a;
632 }
633
634 void __operator += (inout vec3 v, const float a) {
635 v.x += a, v.y += a, v.z += a;
636 }
637
638 void __operator -= (inout vec3 v, const float a) {
639 v.x -= a, v.y -= a, v.z -= a;
640 }
641
642 void __operator *= (inout vec3 v, const float a) {
643 v.x *= a, v.y *= a, v.z *= a;
644 }
645
646 void __operator /= (inout vec3 v, const float a) {
647 v.x /= a, v.y /= a, v.z /= a;
648 }
649
650 void __operator += (inout vec4 v, const float a) {
651 v.x += a, v.y += a, v.z += a, v.w += a;
652 }
653
654 void __operator -= (inout vec4 v, const float a) {
655 v.x -= a, v.y -= a, v.z -= a, v.w -= a;
656 }
657
658 void __operator *= (inout vec4 v, const float a) {
659 v.x *= a, v.y *= a, v.z *= a, v.w *= a;
660 }
661
662 void __operator /= (inout vec4 v, const float a) {
663 v.x /= a, v.y /= a, v.z /= a, v.w /= a;
664 }
665
666 void __operator += (inout mat2 m, const float a) {
667 m[0] += a, m[1] += a;
668 }
669
670 void __operator -= (inout mat2 m, const float a) {
671 m[0] -= a, m[1] -= a;
672 }
673
674 void __operator *= (inout mat2 m, const float a) {
675 m[0] *= a, m[1] *= a;
676 }
677
678 void __operator /= (inout mat2 m, const float a) {
679 m[0] /= a, m[1] /= a;
680 }
681
682 void __operator += (inout mat3 m, const float a) {
683 m[0] += a, m[1] += a, m[2] += a;
684 }
685
686 void __operator -= (inout mat3 m, const float a) {
687 m[0] -= a, m[1] -= a, m[2] -= a;
688 }
689
690 void __operator *= (inout mat3 m, const float a) {
691 m[0] *= a, m[1] *= a, m[2] *= a;
692 }
693
694 void __operator /= (inout mat3 m, const float a) {
695 m[0] /= a, m[1] /= a, m[2] /= a;
696 }
697
698 void __operator += (inout mat4 m, const float a) {
699 m[0] += a, m[1] += a, m[2] += a, m[3] += a;
700 }
701
702 void __operator -= (inout mat4 m, const float a) {
703 m[0] -= a, m[1] -= a, m[2] -= a, m[3] -= a;
704 }
705
706 void __operator *= (inout mat4 m, const float a) {
707 m[0] *= a, m[1] *= a, m[2] *= a, m[3] *= a;
708 }
709
710 void __operator /= (inout mat4 m, const float a) {
711 m[0] /= a, m[1] /= a, m[2] /= a, m[3] /= a;
712 }
713
714 //
715 // ... or if the operation is multiply into (*=), then the variable can be a vector and the
716 // expression can be a matrix of matching size.
717 //
718
719 void __operator *= (inout vec2 v, const mat2 m) {
720 v = v * m;
721 }
722
723 void __operator *= (inout vec3 v, const mat3 m) {
724 v = v * m;
725 }
726
727 void __operator *= (inout vec4 v, const mat4 m) {
728 v = v * m;
729 }
730
731 //
732 // 5.9 Expressions
733 //
734 // Expressions in the shading language include the following:
735 //
736
737 //
738 // \95 The arithmetic binary operators add (+), subtract (-), multiply (*), and divide (/), that
739 // operate on integer and floating-point typed expressions (including vectors and matrices).
740 // The two operands must be the same type, (...) Additionally, for multiply (*) (...) If one
741 // operand is scalar and the other is a vector or matrix, the scalar is applied component-wise
742 // to the vector or matrix, resulting in the same type as the vector or matrix.
743 //
744
745 float __operator + (const float a, const float b) {
746 float c = a;
747 return c += b;
748 }
749
750 float __operator - (const float a, const float b) {
751 return a + -b;
752 }
753
754 float __operator * (const float a, const float b) {
755 float c = a;
756 return c *= b;
757 }
758
759 float __operator / (const float a, const float b) {
760 float c = a;
761 return c /= b;
762 }
763
764 int __operator + (const int a, const int b) {
765 int c = a;
766 return c += b;
767 }
768
769 int __operator - (const int x, const int y) {
770 return x + -y;
771 }
772
773 int __operator * (const int x, const int y) {
774 int z = x;
775 return z *= y;
776 }
777
778 int __operator / (const int x, const int y) {
779 int z = x;
780 return z /= y;
781 }
782
783 vec2 __operator + (const vec2 v, const vec2 u) {
784 return vec2 (v.x + u.x, v.y + u.y);
785 }
786
787 vec2 __operator - (const vec2 v, const vec2 u) {
788 return vec2 (v.x - u.x, v.y - u.y);
789 }
790
791 vec3 __operator + (const vec3 v, const vec3 u) {
792 return vec3 (v.x + u.x, v.y + u.y, v.z + u.z);
793 }
794
795 vec3 __operator - (const vec3 v, const vec3 u) {
796 return vec3 (v.x - u.x, v.y - u.y, v.z - u.z);
797 }
798
799 vec4 __operator + (const vec4 v, const vec4 u) {
800 return vec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
801 }
802
803 vec4 __operator - (const vec4 v, const vec4 u) {
804 return vec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
805 }
806
807 ivec2 __operator + (const ivec2 v, const ivec2 u) {
808 return ivec2 (v.x + u.x, v.y + u.y);
809 }
810
811 ivec2 __operator - (const ivec2 v, const ivec2 u) {
812 return ivec2 (v.x - u.x, v.y - u.y);
813 }
814
815 ivec3 __operator + (const ivec3 v, const ivec3 u) {
816 return ivec3 (v.x + u.x, v.y + u.y, v.z + u.z);
817 }
818
819 ivec3 __operator - (const ivec3 v, const ivec3 u) {
820 return ivec3 (v.x - u.x, v.y - u.y, v.z - u.z);
821 }
822
823 ivec4 __operator + (const ivec4 v, const ivec4 u) {
824 return ivec4 (v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w);
825 }
826
827 ivec4 __operator - (const ivec4 v, const ivec4 u) {
828 return ivec4 (v.x - u.x, v.y - u.y, v.z - u.z, v.w - u.w);
829 }
830
831 mat2 __operator + (const mat2 m, const mat2 n) {
832 return mat2 (m[0] + n[0], m[1] + n[1]);
833 }
834
835 mat2 __operator - (const mat2 m, const mat2 n) {
836 return mat2 (m[0] - n[0], m[1] - n[1]);
837 }
838
839 mat3 __operator + (const mat3 m, const mat3 n) {
840 return mat3 (m[0] + n[0], m[1] + n[1], m[2] + n[2]);
841 }
842
843 mat3 __operator - (const mat3 m, const mat3 n) {
844 return mat3 (m[0] - n[0], m[1] - n[1], m[2] - n[2]);
845 }
846
847 mat4 __operator + (const mat4 m, const mat4 n) {
848 return mat4 (m[0] + n[0], m[1] + n[1], m[2] + n[2], m[3] + n[3]);
849 }
850
851 mat4 __operator - (const mat4 m, const mat4 n) {
852 return mat4 (m[0] - n[0], m[1] - n[1], m[2] - n[2], m[3] - n[3]);
853 }
854
855 //
856 // ... or one can be a scalar float and the other a float vector or matrix, ...
857 //
858
859 vec2 __operator + (const float a, const vec2 u) {
860 return vec2 (a + u.x, a + u.y);
861 }
862
863 vec2 __operator + (const vec2 v, const float b) {
864 return vec2 (v.x + b, v.y + b);
865 }
866
867 vec2 __operator - (const float a, const vec2 u) {
868 return vec2 (a - u.x, a - u.y);
869 }
870
871 vec2 __operator - (const vec2 v, const float b) {
872 return vec2 (v.x - b, v.y - b);
873 }
874
875 vec2 __operator * (const float a, const vec2 u) {
876 return vec2 (a * u.x, a * u.y);
877 }
878
879 vec2 __operator * (const vec2 v, const float b) {
880 return vec2 (v.x * b, v.y * b);
881 }
882
883 vec2 __operator / (const float a, const vec2 u) {
884 return vec2 (a / u.x, a / u.y);
885 }
886
887 vec2 __operator / (const vec2 v, const float b) {
888 return vec2 (v.x / b, v.y / b);
889 }
890
891 vec3 __operator + (const float a, const vec3 u) {
892 return vec3 (a + u.x, a + u.y, a + u.z);
893 }
894
895 vec3 __operator + (const vec3 v, const float b) {
896 return vec3 (v.x + b, v.y + b, v.z + b);
897 }
898
899 vec3 __operator - (const float a, const vec3 u) {
900 return vec3 (a - u.x, a - u.y, a - u.z);
901 }
902
903 vec3 __operator - (const vec3 v, const float b) {
904 return vec3 (v.x - b, v.y - b, v.z - b);
905 }
906
907 vec3 __operator * (const float a, const vec3 u) {
908 return vec3 (a * u.x, a * u.y, a * u.z);
909 }
910
911 vec3 __operator * (const vec3 v, const float b) {
912 return vec3 (v.x * b, v.y * b, v.z * b);
913 }
914
915 vec3 __operator / (const float a, const vec3 u) {
916 return vec3 (a / u.x, a / u.y, a / u.z);
917 }
918
919 vec3 __operator / (const vec3 v, const float b) {
920 return vec3 (v.x / b, v.y / b, v.z / b);
921 }
922
923 vec4 __operator + (const float a, const vec4 u) {
924 return vec4 (a + u.x, a + u.y, a + u.z, a + u.w);
925 }
926
927 vec4 __operator + (const vec4 v, const float b) {
928 return vec4 (v.x + b, v.y + b, v.z + b, v.w + b);
929 }
930
931 vec4 __operator - (const float a, const vec4 u) {
932 return vec4 (a - u.x, a - u.y, a - u.z, a - u.w);
933 }
934
935 vec4 __operator - (const vec4 v, const float b) {
936 return vec4 (v.x - b, v.y - b, v.z - b, v.w - b);
937 }
938
939 vec4 __operator * (const float a, const vec4 u) {
940 return vec4 (a * u.x, a * u.y, a * u.z, a * u.w);
941 }
942
943 vec4 __operator * (const vec4 v, const float b) {
944 return vec4 (v.x * b, v.y * b, v.z * b, v.w * b);
945 }
946
947 vec4 __operator / (const float a, const vec4 u) {
948 return vec4 (a / u.x, a / u.y, a / u.z, a / u.w);
949 }
950
951 vec4 __operator / (const vec4 v, const float b) {
952 return vec4 (v.x / b, v.y / b, v.z / b, v.w / b);
953 }
954
955 mat2 __operator + (const float a, const mat2 n) {
956 return mat2 (a + n[0], a + n[1]);
957 }
958
959 mat2 __operator + (const mat2 m, const float b) {
960 return mat2 (m[0] + b, m[1] + b);
961 }
962
963 mat2 __operator - (const float a, const mat2 n) {
964 return mat2 (a - n[0], a - n[1]);
965 }
966
967 mat2 __operator - (const mat2 m, const float b) {
968 return mat2 (m[0] - b, m[1] - b);
969 }
970
971 mat2 __operator * (const float a, const mat2 n) {
972 return mat2 (a * n[0], a * n[1]);
973 }
974
975 mat2 __operator * (const mat2 m, const float b) {
976 return mat2 (m[0] * b, m[1] * b);
977 }
978
979 mat2 __operator / (const float a, const mat2 n) {
980 return mat2 (a / n[0], a / n[1]);
981 }
982
983 mat2 __operator / (const mat2 m, const float b) {
984 return mat2 (m[0] / b, m[1] / b);
985 }
986
987 mat3 __operator + (const float a, const mat3 n) {
988 return mat3 (a + n[0], a + n[1], a + n[2]);
989 }
990
991 mat3 __operator + (const mat3 m, const float b) {
992 return mat3 (m[0] + b, m[1] + b, m[2] + b);
993 }
994
995 mat3 __operator - (const float a, const mat3 n) {
996 return mat3 (a - n[0], a - n[1], a - n[2]);
997 }
998
999 mat3 __operator - (const mat3 m, const float b) {
1000 return mat3 (m[0] - b, m[1] - b, m[2] - b);
1001 }
1002
1003 mat3 __operator * (const float a, const mat3 n) {
1004 return mat3 (a * n[0], a * n[1], a * n[2]);
1005 }
1006
1007 mat3 __operator * (const mat3 m, const float b) {
1008 return mat3 (m[0] * b, m[1] * b, m[2] * b);
1009 }
1010
1011 mat3 __operator / (const float a, const mat3 n) {
1012 return mat3 (a / n[0], a / n[1], a / n[2]);
1013 }
1014
1015 mat3 __operator / (const mat3 m, const float b) {
1016 return mat3 (m[0] / b, m[1] / b, m[2] / b);
1017 }
1018
1019 mat4 __operator + (const float a, const mat4 n) {
1020 return mat4 (a + n[0], a + n[1], a + n[2], a + n[3]);
1021 }
1022
1023 mat4 __operator + (const mat4 m, const float b) {
1024 return mat4 (m[0] + b, m[1] + b, m[2] + b, m[3] + b);
1025 }
1026
1027 mat4 __operator - (const float a, const mat4 n) {
1028 return mat4 (a - n[0], a - n[1], a - n[2], a - n[3]);
1029 }
1030
1031 mat4 __operator - (const mat4 m, const float b) {
1032 return mat4 (m[0] - b, m[1] - b, m[2] - b, m[3] - b);
1033 }
1034
1035 mat4 __operator * (const float a, const mat4 n) {
1036 return mat4 (a * n[0], a * n[1], a * n[2], a * n[3]);
1037 }
1038
1039 mat4 __operator * (const mat4 m, const float b) {
1040 return mat4 (m[0] * b, m[1] * b, m[2] * b, m[3] * b);
1041 }
1042
1043 mat4 __operator / (const float a, const mat4 n) {
1044 return mat4 (a / n[0], a / n[1], a / n[2], a / n[3]);
1045 }
1046
1047 mat4 __operator / (const mat4 m, const float b) {
1048 return mat4 (m[0] / b, m[1] / b, m[2] / b, m[3] / b);
1049 }
1050
1051 //
1052 // ... or one can be a scalar integer and the other an integer vector.
1053 //
1054
1055 ivec2 __operator + (const int a, const ivec2 u) {
1056 return ivec2 (a + u.x, a + u.y);
1057 }
1058
1059 ivec2 __operator + (const ivec2 v, const int b) {
1060 return ivec2 (v.x + b, v.y + b);
1061 }
1062
1063 ivec2 __operator - (const int a, const ivec2 u) {
1064 return ivec2 (a - u.x, a - u.y);
1065 }
1066
1067 ivec2 __operator - (const ivec2 v, const int b) {
1068 return ivec2 (v.x - b, v.y - b);
1069 }
1070
1071 ivec2 __operator * (const int a, const ivec2 u) {
1072 return ivec2 (a * u.x, a * u.y);
1073 }
1074
1075 ivec2 __operator * (const ivec2 v, const int b) {
1076 return ivec2 (v.x * b, v.y * b);
1077 }
1078
1079 ivec2 __operator / (const int a, const ivec2 u) {
1080 return ivec2 (a / u.x, a / u.y);
1081 }
1082
1083 ivec2 __operator / (const ivec2 v, const int b) {
1084 return ivec2 (v.x / b, v.y / b);
1085 }
1086
1087 ivec3 __operator + (const int a, const ivec3 u) {
1088 return ivec3 (a + u.x, a + u.y, a + u.z);
1089 }
1090
1091 ivec3 __operator + (const ivec3 v, const int b) {
1092 return ivec3 (v.x + b, v.y + b, v.z + b);
1093 }
1094
1095 ivec3 __operator - (const int a, const ivec3 u) {
1096 return ivec3 (a - u.x, a - u.y, a - u.z);
1097 }
1098
1099 ivec3 __operator - (const ivec3 v, const int b) {
1100 return ivec3 (v.x - b, v.y - b, v.z - b);
1101 }
1102
1103 ivec3 __operator * (const int a, const ivec3 u) {
1104 return ivec3 (a * u.x, a * u.y, a * u.z);
1105 }
1106
1107 ivec3 __operator * (const ivec3 v, const int b) {
1108 return ivec3 (v.x * b, v.y * b, v.z * b);
1109 }
1110
1111 ivec3 __operator / (const int a, const ivec3 u) {
1112 return ivec3 (a / u.x, a / u.y, a / u.z);
1113 }
1114
1115 ivec3 __operator / (const ivec3 v, const int b) {
1116 return ivec3 (v.x / b, v.y / b, v.z / b);
1117 }
1118
1119 ivec4 __operator + (const int a, const ivec4 u) {
1120 return ivec4 (a + u.x, a + u.y, a + u.z, a + u.w);
1121 }
1122
1123 ivec4 __operator + (const ivec4 v, const int b) {
1124 return ivec4 (v.x + b, v.y + b, v.z + b, v.w + b);
1125 }
1126
1127 ivec4 __operator - (const int a, const ivec4 u) {
1128 return ivec4 (a - u.x, a - u.y, a - u.z, a - u.w);
1129 }
1130
1131 ivec4 __operator - (const ivec4 v, const int b) {
1132 return ivec4 (v.x - b, v.y - b, v.z - b, v.w - b);
1133 }
1134
1135 ivec4 __operator * (const int a, const ivec4 u) {
1136 return ivec4 (a * u.x, a * u.y, a * u.z, a * u.w);
1137 }
1138
1139 ivec4 __operator * (const ivec4 v, const int b) {
1140 return ivec4 (v.x * b, v.y * b, v.z * b, v.w * b);
1141 }
1142
1143 ivec4 __operator / (const int a, const ivec4 u) {
1144 return ivec4 (a / u.x, a / u.y, a / u.z, a / u.w);
1145 }
1146
1147 ivec4 __operator / (const ivec4 v, const int b) {
1148 return ivec4 (v.x / b, v.y / b, v.z / b, v.w / b);
1149 }
1150
1151 //
1152 // Additionally, for multiply (*) one can be a vector and the other a matrix with the same
1153 // dimensional size of the vector. These result in the same fundamental type (integer or float)
1154 // as the expressions they operate on.
1155 //
1156 // [When:]
1157 // \95 the left argument is a floating-point vector and the right is a matrix with a compatible
1158 // dimension in which case the * operator will do a row vector matrix multiplication.
1159 // \95 the left argument is a matrix and the right is a floating-point vector with a compatible
1160 // dimension in which case the * operator will do a column vector matrix multiplication.
1161 //
1162
1163 vec2 __operator * (const mat2 m, const vec2 v) {
1164 return vec2 (
1165 v.x * m[0].x + v.y * m[1].x,
1166 v.x * m[0].y + v.y * m[1].y
1167 );
1168 }
1169
1170 vec2 __operator * (const vec2 v, const mat2 m) {
1171 return vec2 (
1172 v.x * m[0].x + v.y * m[0].y,
1173 v.x * m[1].x + v.y * m[1].y
1174 );
1175 }
1176
1177 vec3 __operator * (const mat3 m, const vec3 v) {
1178 return vec3 (
1179 v.x * m[0].x + v.y * m[1].x + v.z * m[2].x,
1180 v.x * m[0].y + v.y * m[1].y + v.z * m[2].y,
1181 v.x * m[0].z + v.y * m[1].z + v.z * m[2].z
1182 );
1183 }
1184
1185 vec3 __operator * (const vec3 v, const mat3 m) {
1186 return vec3 (
1187 v.x * m[0].x + v.y * m[0].y + v.z * m[0].z,
1188 v.x * m[1].x + v.y * m[1].y + v.z * m[1].z,
1189 v.x * m[2].x + v.y * m[2].y + v.z * m[2].z
1190 );
1191 }
1192
1193 vec4 __operator * (const mat4 m, const vec4 v) {
1194 return vec4 (
1195 v.x * m[0].x + v.y * m[1].x + v.z * m[2].x + v.w * m[3].x,
1196 v.x * m[0].y + v.y * m[1].y + v.z * m[2].y + v.w * m[3].y,
1197 v.x * m[0].z + v.y * m[1].z + v.z * m[2].z + v.w * m[3].z,
1198 v.x * m[0].w + v.y * m[1].w + v.z * m[2].w + v.w * m[3].w
1199 );
1200 }
1201
1202 vec4 __operator * (const vec4 v, const mat4 m) {
1203 return vec4 (
1204 v.x * m[0].x + v.y * m[0].y + v.z * m[0].z + v.w * m[0].w,
1205 v.x * m[1].x + v.y * m[1].y + v.z * m[1].z + v.w * m[1].w,
1206 v.x * m[2].x + v.y * m[2].y + v.z * m[2].z + v.w * m[2].w,
1207 v.x * m[3].x + v.y * m[3].y + v.z * m[3].z + v.w * m[3].w
1208 );
1209 }
1210
1211 //
1212 // Multiply (*) applied to two vectors yields a component-wise multiply.
1213 //
1214
1215 vec2 __operator * (const vec2 v, const vec2 u) {
1216 return vec2 (v.x * u.x, v.y * u.y);
1217 }
1218
1219 vec3 __operator * (const vec3 v, const vec3 u) {
1220 return vec3 (v.x * u.x, v.y * u.y, v.z * u.z);
1221 }
1222
1223 vec4 __operator * (const vec4 v, const vec4 u) {
1224 return vec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
1225 }
1226
1227 ivec2 __operator * (const ivec2 v, const ivec2 u) {
1228 return ivec2 (v.x * u.x, v.y * u.y);
1229 }
1230
1231 ivec3 __operator * (const ivec3 v, const ivec3 u) {
1232 return ivec3 (v.x * u.x, v.y * u.y, v.z * u.z);
1233 }
1234
1235 ivec4 __operator * (const ivec4 v, const ivec4 u) {
1236 return ivec4 (v.x * u.x, v.y * u.y, v.z * u.z, v.w * u.w);
1237 }
1238
1239 //
1240 // Dividing by zero does not cause an exception but does result in an unspecified value.
1241 //
1242
1243 vec2 __operator / (const vec2 v, const vec2 u) {
1244 return vec2 (v.x / u.x, v.y / u.y);
1245 }
1246
1247 vec3 __operator / (const vec3 v, const vec3 u) {
1248 return vec3 (v.x / u.x, v.y / u.y, v.z / u.z);
1249 }
1250
1251 vec4 __operator / (const vec4 v, const vec4 u) {
1252 return vec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
1253 }
1254
1255 ivec2 __operator / (const ivec2 v, const ivec2 u) {
1256 return ivec2 (v.x / u.x, v.y / u.y);
1257 }
1258
1259 ivec3 __operator / (const ivec3 v, const ivec3 u) {
1260 return ivec3 (v.x / u.x, v.y / u.y, v.z / u.z);
1261 }
1262
1263 ivec4 __operator / (const ivec4 v, const ivec4 u) {
1264 return ivec4 (v.x / u.x, v.y / u.y, v.z / u.z, v.w / u.w);
1265 }
1266
1267 mat2 __operator / (const mat2 m, const mat2 n) {
1268 return mat2 (m[0] / n[0], m[1] / n[1]);
1269 }
1270
1271 mat3 __operator / (const mat3 m, const mat3 n) {
1272 return mat3 (m[0] / n[0], m[1] / n[1], m[2] / n[2]);
1273 }
1274
1275 mat4 __operator / (const mat4 m, const mat4 n) {
1276 return mat4 (m[0] / n[0], m[1] / n[1], m[2] / n[2], m[3] / n[3]);
1277 }
1278
1279 //
1280 // Multiply (*) applied to two matrices yields a linear algebraic matrix multiply, not
1281 // a component-wise multiply.
1282 //
1283
1284 mat2 __operator * (const mat2 m, const mat2 n) {
1285 return mat2 (m * n[0], m * n[1]);
1286 }
1287
1288 mat3 __operator * (const mat3 m, const mat3 n) {
1289 return mat3 (m * n[0], m * n[1], m * n[2]);
1290 }
1291
1292 mat4 __operator * (const mat4 m, const mat4 n) {
1293 return mat4 (m * n[0], m * n[1], m * n[2], m * n[3]);
1294 }
1295
1296 //
1297 // \95 The arithmetic unary operators negate (-), post- and pre-increment and decrement (-- and
1298 // ++) that operate on integer or floating-point values (including vectors and matrices). These
1299 // result with the same type they operated on. For post- and pre-increment and decrement, the
1300 // expression must be one that could be assigned to (an l-value). Pre-increment and predecrement
1301 // add or subtract 1 or 1.0 to the contents of the expression they operate on, and the
1302 // value of the pre-increment or pre-decrement expression is the resulting value of that
1303 // modification. Post-increment and post-decrement expressions add or subtract 1 or 1.0 to
1304 // the contents of the expression they operate on, but the resulting expression has the
1305 // expression\92s value before the post-increment or post-decrement was executed.
1306 //
1307 // [NOTE: postfix increment and decrement operators take additional dummy int parameter to
1308 // distinguish their prototypes from prefix ones.]
1309 //
1310
1311 float __operator - (const float a) {
1312 float c = a;
1313 __asm float_negate c;
1314 return c;
1315 }
1316
1317 int __operator - (const int a) {
1318 int c = a;
1319 __asm int_negate c;
1320 return c;
1321 }
1322
1323 vec2 __operator - (const vec2 v) {
1324 return vec2 (-v.x, -v.y);
1325 }
1326
1327 vec3 __operator - (const vec3 v) {
1328 return vec3 (-v.x, -v.y, -v.z);
1329 }
1330
1331 vec4 __operator - (const vec4 v) {
1332 return vec4 (-v.x, -v.y, -v.z, -v.w);
1333 }
1334
1335 ivec2 __operator - (const ivec2 v) {
1336 return ivec2 (-v.x, -v.y);
1337 }
1338
1339 ivec3 __operator - (const ivec3 v) {
1340 return ivec3 (-v.x, -v.y, -v.z);
1341 }
1342
1343 ivec4 __operator - (const ivec4 v) {
1344 return ivec4 (-v.x, -v.y, -v.z, -v.w);
1345 }
1346
1347 mat2 __operator - (const mat2 m) {
1348 return mat2 (-m[0], -m[1]);
1349 }
1350
1351 mat3 __operator - (const mat3 m) {
1352 return mat3 (-m[0], -m[1], -m[2]);
1353 }
1354
1355 mat4 __operator - (const mat4 m) {
1356 return mat4 (-m[0], -m[1], -m[2], -m[3]);
1357 }
1358
1359 void __operator -- (inout float a) {
1360 a -= 1.0;
1361 }
1362
1363 void __operator -- (inout int a) {
1364 a -= 1;
1365 }
1366
1367 void __operator -- (inout vec2 v) {
1368 --v.x, --v.y;
1369 }
1370
1371 void __operator -- (inout vec3 v) {
1372 --v.x, --v.y, --v.z;
1373 }
1374
1375 void __operator -- (inout vec4 v) {
1376 --v.x, --v.y, --v.z, --v.w;
1377 }
1378
1379 void __operator -- (inout ivec2 v) {
1380 --v.x, --v.y;
1381 }
1382
1383 void __operator -- (inout ivec3 v) {
1384 --v.x, --v.y, --v.z;
1385 }
1386
1387 void __operator -- (inout ivec4 v) {
1388 --v.x, --v.y, --v.z, --v.w;
1389 }
1390
1391 void __operator -- (inout mat2 m) {
1392 --m[0], --m[1];
1393 }
1394
1395 void __operator -- (inout mat3 m) {
1396 --m[0], --m[1], --m[2];
1397 }
1398
1399 void __operator -- (inout mat4 m) {
1400 --m[0], --m[1], --m[2], --m[3];
1401 }
1402
1403 void __operator ++ (inout float a) {
1404 a += 1.0;
1405 }
1406
1407 void __operator ++ (inout int a) {
1408 a += 1;
1409 }
1410
1411 void __operator ++ (inout vec2 v) {
1412 ++v.x, ++v.y;
1413 }
1414
1415 void __operator ++ (inout vec3 v) {
1416 ++v.x, ++v.y, ++v.z;
1417 }
1418
1419 void __operator ++ (inout vec4 v) {
1420 ++v.x, ++v.y, ++v.z, ++v.w;
1421 }
1422
1423 void __operator ++ (inout ivec2 v) {
1424 ++v.x, ++v.y;
1425 }
1426
1427 void __operator ++ (inout ivec3 v) {
1428 ++v.x, ++v.y, ++v.z;
1429 }
1430
1431 void __operator ++ (inout ivec4 v) {
1432 ++v.x, ++v.y, ++v.z, ++v.w;
1433 }
1434
1435 void __operator ++ (inout mat2 m) {
1436 ++m[0], ++m[1];
1437 }
1438
1439 void __operator ++ (inout mat3 m) {
1440 ++m[0], ++m[1], ++m[2];
1441 }
1442
1443 void __operator ++ (inout mat4 m) {
1444 ++m[0], ++m[1], ++m[2], ++m[3];
1445 }
1446
1447 float __operator -- (inout float a, const int) {
1448 const float c = a;
1449 --a;
1450 return c;
1451 }
1452
1453 int __operator -- (inout int a, const int) {
1454 const int c = a;
1455 --a;
1456 return c;
1457 }
1458
1459 vec2 __operator -- (inout vec2 v, const int) {
1460 return vec2 (v.x--, v.y--);
1461 }
1462
1463 vec3 __operator -- (inout vec3 v, const int) {
1464 return vec3 (v.x--, v.y--, v.z--);
1465 }
1466
1467 vec4 __operator -- (inout vec4 v, const int) {
1468 return vec4 (v.x--, v.y--, v.z--, v.w--);
1469 }
1470
1471 ivec2 __operator -- (inout ivec2 v, const int) {
1472 return ivec2 (v.x--, v.y--);
1473 }
1474
1475 ivec3 __operator -- (inout ivec3 v, const int) {
1476 return ivec3 (v.x--, v.y--, v.z--);
1477 }
1478
1479 ivec4 __operator -- (inout ivec4 v, const int) {
1480 return ivec4 (v.x--, v.y--, v.z--, v.w--);
1481 }
1482
1483 mat2 __operator -- (inout mat2 m, const int) {
1484 return mat2 (m[0]--, m[1]--);
1485 }
1486
1487 mat3 __operator -- (inout mat3 m, const int) {
1488 return mat3 (m[0]--, m[1]--, m[2]--);
1489 }
1490
1491 mat4 __operator -- (inout mat4 m, const int) {
1492 return mat4 (m[0]--, m[1]--, m[2]--, m[3]--);
1493 }
1494
1495 float __operator ++ (inout float a, const int) {
1496 const float c = a;
1497 ++a;
1498 return c;
1499 }
1500
1501 int __operator ++ (inout int a, const int) {
1502 const int c = a;
1503 ++a;
1504 return c;
1505 }
1506
1507 vec2 __operator ++ (inout vec2 v, const int) {
1508 return vec2 (v.x++, v.y++);
1509 }
1510
1511 vec3 __operator ++ (inout vec3 v, const int) {
1512 return vec3 (v.x++, v.y++, v.z++);
1513 }
1514
1515 vec4 __operator ++ (inout vec4 v, const int) {
1516 return vec4 (v.x++, v.y++, v.z++, v.w++);
1517 }
1518
1519 ivec2 __operator ++ (inout ivec2 v, const int) {
1520 return ivec2 (v.x++, v.y++);
1521 }
1522
1523 ivec3 __operator ++ (inout ivec3 v, const int) {
1524 return ivec3 (v.x++, v.y++, v.z++);
1525 }
1526
1527 ivec4 __operator ++ (inout ivec4 v, const int) {
1528 return ivec4 (v.x++, v.y++, v.z++, v.w++);
1529 }
1530
1531 mat2 __operator ++ (inout mat2 m, const int) {
1532 return mat2 (m[0]++, m[1]++);
1533 }
1534
1535 mat3 __operator ++ (inout mat3 m, const int) {
1536 return mat3 (m[0]++, m[1]++, m[2]++);
1537 }
1538
1539 mat4 __operator ++ (inout mat4 m, const int) {
1540 return mat4 (m[0]++, m[1]++, m[2]++, m[3]++);
1541 }
1542
1543 //
1544 // \95 The relational operators greater than (>), less than (<), greater than or equal (>=), and less
1545 // than or equal (<=) operate only on scalar integer and scalar floating-point expressions. The
1546 // result is scalar Boolean. The operands\92 types must match. To do component-wise
1547 // comparisons on vectors, use the built-in functions lessThan, lessThanEqual,
1548 // greaterThan, and greaterThanEqual.
1549 //
1550
1551 bool __operator < (const float a, const float b) {
1552 bool c;
1553 __asm float_less c, a, b;
1554 return c;
1555 }
1556
1557 bool __operator < (const int a, const int b) {
1558 bool c;
1559 __asm int_less c, a, b;
1560 return c;
1561 }
1562
1563 bool __operator > (const float a, const float b) {
1564 return b < a;
1565 }
1566
1567 bool __operator > (const int a, const int b) {
1568 return b < a;
1569 }
1570
1571 bool __operator >= (const float a, const float b) {
1572 return a > b || a == b;
1573 }
1574
1575 bool __operator >= (const int a, const int b) {
1576 return a > b || a == b;
1577 }
1578
1579 bool __operator <= (const float a, const float b) {
1580 return a < b || a == b;
1581 }
1582
1583 bool __operator <= (const int a, const int b) {
1584 return a < b || a == b;
1585 }
1586
1587 //
1588 // \95 The equality operators equal (==), and not equal (!=) operate on all types except arrays.
1589 // They result in a scalar Boolean. For vectors, matrices, and structures, all components of the
1590 // operands must be equal for the operands to be considered equal. To get component-wise
1591 // equality results for vectors, use the built-in functions equal and notEqual.
1592 //
1593
1594 bool __operator == (const float a, const float b) {
1595 bool c;
1596 __asm float_equal c, a, b;
1597 return c;
1598 }
1599
1600 bool __operator == (const int a, const int b) {
1601 bool c;
1602 __asm int_equal c, a, b;
1603 return c;
1604 }
1605
1606 bool __operator == (const bool a, const bool b) {
1607 bool c;
1608 __asm bool_equal c, a, b;
1609 return c;
1610 }
1611
1612 bool __operator == (const vec2 v, const vec2 u) {
1613 return v.x == u.x && v.y == u.y;
1614 }
1615
1616 bool __operator == (const vec3 v, const vec3 u) {
1617 return v.x == u.x && v.y == u.y && v.z == u.z;
1618 }
1619
1620 bool __operator == (const vec4 v, const vec4 u) {
1621 return v.x == u.x && v.y == u.y && v.z == u.z && v.w == u.w;
1622 }
1623
1624 bool __operator == (const ivec2 v, const ivec2 u) {
1625 return v.x == u.x && v.y == u.y;
1626 }
1627
1628 bool __operator == (const ivec3 v, const ivec3 u) {
1629 return v.x == u.x && v.y == u.y && v.z == u.z;
1630 }
1631
1632 bool __operator == (const ivec4 v, const ivec4 u) {
1633 return v.x == u.x && v.y == u.y && v.z == u.z && v.w == u.w;
1634 }
1635
1636 bool __operator == (const bvec2 v, const bvec2 u) {
1637 return v.x == u.x && v.y == u.y;
1638 }
1639
1640 bool __operator == (const bvec3 v, const bvec3 u) {
1641 return v.x == u.x && v.y == u.y && v.z == u.z;
1642 }
1643
1644 bool __operator == (const bvec4 v, const bvec4 u) {
1645 return v.x == u.x && v.y == u.y && v.z == u.z && v.w == u.w;
1646 }
1647
1648 bool __operator == (const mat2 m, const mat2 n) {
1649 return m[0] == n[0] && m[1] == n[1];
1650 }
1651
1652 bool __operator == (const mat3 m, const mat3 n) {
1653 return m[0] == n[0] && m[1] == n[1] && m[2] == n[2];
1654 }
1655
1656 bool __operator == (const mat4 m, const mat4 n) {
1657 return m[0] == n[0] && m[1] == n[1] && m[2] == n[2] && m[3] == n[3];
1658 }
1659
1660 bool __operator != (const float a, const float b) {
1661 return !(a == b);
1662 }
1663
1664 bool __operator != (const int a, const int b) {
1665 return !(a == b);
1666 }
1667
1668 bool __operator != (const bool a, const bool b) {
1669 return !(a == b);
1670 }
1671
1672 bool __operator != (const vec2 v, const vec2 u) {
1673 return v.x != u.x || v.y != u.y;
1674 }
1675
1676 bool __operator != (const vec3 v, const vec3 u) {
1677 return v.x != u.x || v.y != u.y || v.z != u.z;
1678 }
1679
1680 bool __operator != (const vec4 v, const vec4 u) {
1681 return v.x != u.x || v.y != u.y || v.z != u.z || v.w != u.w;
1682 }
1683
1684 bool __operator != (const ivec2 v, const ivec2 u) {
1685 return v.x != u.x || v.y != u.y;
1686 }
1687
1688 bool __operator != (const ivec3 v, const ivec3 u) {
1689 return v.x != u.x || v.y != u.y || v.z != u.z;
1690 }
1691
1692 bool __operator != (const ivec4 v, const ivec4 u) {
1693 return v.x != u.x || v.y != u.y || v.z != u.z || v.w != u.w;
1694 }
1695
1696 bool __operator != (const bvec2 v, const bvec2 u) {
1697 return v.x != u.x || v.y != u.y;
1698 }
1699
1700 bool __operator != (const bvec3 v, const bvec3 u) {
1701 return v.x != u.x || v.y != u.y || v.z != u.z;
1702 }
1703
1704 bool __operator != (const bvec4 v, const bvec4 u) {
1705 return v.x != u.x || v.y != u.y || v.z != u.z || v.w != u.w;
1706 }
1707
1708 bool __operator != (const mat2 m, const mat2 n) {
1709 return m[0] != n[0] || m[1] != n[1];
1710 }
1711
1712 bool __operator != (const mat3 m, const mat3 n) {
1713 return m[0] != n[0] || m[1] != n[1] || m[2] != n[2];
1714 }
1715
1716 bool __operator != (const mat4 m, const mat4 n) {
1717 return m[0] != n[0] || m[1] != n[1] || m[2] != n[2] || m[3] != n[3];
1718 }
1719
1720 //
1721 // \95 The logical binary operators and (&&), or ( | | ), and exclusive or (^^). They operate only
1722 // on two Boolean expressions and result in a Boolean expression. And (&&) will only
1723 // evaluate the right hand operand if the left hand operand evaluated to true. Or ( | | ) will
1724 // only evaluate the right hand operand if the left hand operand evaluated to false. Exclusive or
1725 // (^^) will always evaluate both operands.
1726 //
1727
1728 bool __operator ^^ (const bool a, const bool b) {
1729 return a != b;
1730 }
1731
1732 //
1733 // [These operators are handled internally by the compiler:]
1734 //
1735 // bool __operator && (bool a, bool b) {
1736 // return a ? b : false;
1737 // }
1738 // bool __operator || (bool a, bool b) {
1739 // return a ? true : b;
1740 // }
1741 //
1742
1743 //
1744 // \95 The logical unary operator not (!). It operates only on a Boolean expression and results in a
1745 // Boolean expression. To operate on a vector, use the built-in function not.
1746 //
1747
1748 bool __operator ! (const bool a) {
1749 return a == false;
1750 }
1751