2
* Mesa 3-D graphics library
5
* Copyright (C) 2006 Brian Paul All Rights Reserved.
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:
14
* The above copyright notice and this permission notice shall be included
15
* in all copies or substantial portions of the Software.
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.
26
// This file overrides most of the standard built-in functions that operate on vec4 data type.
27
// This file also overrides most commonly used functions that do not neccessarily operate
28
// on vec4 data type, like dot(vec3,vec3). Those are adapted to vec4 instructions and are believed
30
// This file replaces parts of the core.gc and common.gc, so it must be included somewhere after
31
// the common.gc file.
33
// Assembly instructions required:
44
vec4 __constructor (const float f) {
46
__asm float_to_vec4 v, f;
51
void __operator += (inout vec4 v, const vec4 u) {
55
void __operator -= (inout vec4 v, const vec4 u) {
56
__asm vec4_subtract v, u;
59
void __operator *= (inout vec4 v, const vec4 u) {
60
__asm vec4_multiply v, u;
63
void __operator /= (inout vec4 v, const vec4 u) {
64
__asm vec4_divide v, u;
68
void __operator += (inout vec4 v, const float a) {
70
__asm float_to_vec4 u, a;
74
void __operator -= (inout vec4 v, const float a) {
76
__asm float_to_vec4 u, a;
77
__asm vec4_subtract v, u;
80
void __operator *= (inout vec4 v, const float a) {
82
__asm float_to_vec4 u, a;
83
__asm vec4_multiply v, u;
86
void __operator /= (inout vec4 v, const float a) {
88
__asm float_to_vec4 u, a;
89
__asm vec4_divide v, u;
93
vec4 __operator + (vec4 v, const vec4 u) {
98
vec4 __operator - (vec4 v, const vec4 u) {
99
__asm vec4_subtract v, u;
103
vec4 __operator * (vec4 v, const vec4 u) {
104
__asm vec4_multiply v, u;
108
vec4 __operator / (vec4 v, const vec4 u) {
109
__asm vec4_divide v, u;
114
vec4 __operator + (const float a, const vec4 u) {
116
__asm float_to_vec4 v, a;
121
vec4 __operator + (const vec4 v, const float b) {
123
__asm float_to_vec4 u, b;
128
vec4 __operator - (const float a, const vec4 u) {
130
__asm float_to_vec4 v, a;
131
__asm vec4_subtract v, u;
135
vec4 __operator - (vec4 v, const float b) {
137
__asm float_to_vec4 u, b;
138
__asm vec4_subtract v, u;
142
vec4 __operator * (const float a, const vec4 u) {
144
__asm float_to_vec4 v, a;
145
__asm vec4_multiply v, u;
149
vec4 __operator * (const vec4 v, const float b) {
151
__asm float_to_vec4 u, b;
152
__asm vec4_multiply u, v;
156
vec4 __operator / (const float a, const vec4 u) {
158
__asm float_to_vec4 v, a;
159
__asm vec4_divide v, u;
163
vec4 __operator / (vec4 v, const float b) {
165
__asm float_to_vec4 u, b;
166
__asm vec4_divide v, u;
171
vec4 __operator - (vec4 v) {
177
float dot (vec3 v, vec3 u) {
178
vec4 v4 = vec4 (v, 0.0);
179
vec4 u4 = vec4 (u, 0.0);
180
__asm vec4_dot v4, u4;
184
float dot (vec4 v, vec4 u) {
190
float length (vec3 v) {
191
vec4 u = vec4 (v, 0.0);
196
float length (vec4 v) {
202
vec3 normalize (vec3 v) {
203
vec4 u = vec4 (v, 0.0);
206
float l = sqrt (u.x);
207
__asm float_to_vec4 u, l;
208
__asm vec4_divide w, u;
212
vec4 normalize (vec4 v) {
215
float l = sqrt (v.x);
216
__asm float_to_vec4 v, l;
217
__asm vec4_divide w, v;