~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/shader/slang/library/slang_builtin_vec4.gc

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 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
29
 
// to execute faster.
30
 
// This file replaces parts of the core.gc and common.gc, so it must be included somewhere after
31
 
// the common.gc file.
32
 
// 
33
 
// Assembly instructions required:
34
 
//   float_to_vec4
35
 
//   vec4_add
36
 
//   vec4_subtract
37
 
//   vec4_multiply
38
 
//   vec4_divide
39
 
//   vec4_negate
40
 
//   vec4_dot
41
 
//
42
 
 
43
 
 
44
 
vec4 __constructor (const float f) {
45
 
    vec4 v;
46
 
    __asm float_to_vec4 v, f;
47
 
    return v;
48
 
}
49
 
 
50
 
 
51
 
void __operator += (inout vec4 v, const vec4 u) {
52
 
    __asm vec4_add v, u;
53
 
}
54
 
 
55
 
void __operator -= (inout vec4 v, const vec4 u) {
56
 
    __asm vec4_subtract v, u;
57
 
}
58
 
 
59
 
void __operator *= (inout vec4 v, const vec4 u) {
60
 
    __asm vec4_multiply v, u;
61
 
}
62
 
 
63
 
void __operator /= (inout vec4 v, const vec4 u) {
64
 
    __asm vec4_divide v, u;
65
 
}
66
 
 
67
 
 
68
 
void __operator += (inout vec4 v, const float a) {
69
 
    vec4 u;
70
 
    __asm float_to_vec4 u, a;
71
 
    __asm vec4_add      v, u;
72
 
}
73
 
 
74
 
void __operator -= (inout vec4 v, const float a) {
75
 
    vec4 u;
76
 
    __asm float_to_vec4 u, a;
77
 
    __asm vec4_subtract v, u;
78
 
}
79
 
 
80
 
void __operator *= (inout vec4 v, const float a) {
81
 
    vec4 u;
82
 
    __asm float_to_vec4 u, a;
83
 
    __asm vec4_multiply v, u;
84
 
}
85
 
 
86
 
void __operator /= (inout vec4 v, const float a) {
87
 
    vec4 u;
88
 
    __asm float_to_vec4 u, a;
89
 
    __asm vec4_divide   v, u;
90
 
}
91
 
 
92
 
 
93
 
vec4 __operator + (vec4 v, const vec4 u) {
94
 
    __asm vec4_add v, u;
95
 
    return v;
96
 
}
97
 
 
98
 
vec4 __operator - (vec4 v, const vec4 u) {
99
 
    __asm vec4_subtract v, u;
100
 
    return v;
101
 
}
102
 
 
103
 
vec4 __operator * (vec4 v, const vec4 u) {
104
 
    __asm vec4_multiply v, u;
105
 
    return v;
106
 
}
107
 
 
108
 
vec4 __operator / (vec4 v, const vec4 u) {
109
 
    __asm vec4_divide v, u;
110
 
    return v;
111
 
}
112
 
 
113
 
 
114
 
vec4 __operator + (const float a, const vec4 u) {
115
 
    vec4 v;
116
 
    __asm float_to_vec4 v, a;
117
 
    __asm vec4_add      v, u;
118
 
    return v;
119
 
}
120
 
 
121
 
vec4 __operator + (const vec4 v, const float b) {
122
 
    vec4 u;
123
 
    __asm float_to_vec4 u, b;
124
 
    __asm vec4_add      u, v;
125
 
    return u;
126
 
}
127
 
 
128
 
vec4 __operator - (const float a, const vec4 u) {
129
 
    vec4 v;
130
 
    __asm float_to_vec4 v, a;
131
 
    __asm vec4_subtract v, u;
132
 
    return v;
133
 
}
134
 
 
135
 
vec4 __operator - (vec4 v, const float b) {
136
 
    vec4 u;
137
 
    __asm float_to_vec4 u, b;
138
 
    __asm vec4_subtract v, u;
139
 
    return v;
140
 
}
141
 
 
142
 
vec4 __operator * (const float a, const vec4 u) {
143
 
    vec4 v;
144
 
    __asm float_to_vec4 v, a;
145
 
    __asm vec4_multiply v, u;
146
 
    return v;
147
 
}
148
 
 
149
 
vec4 __operator * (const vec4 v, const float b) {
150
 
    vec4 u;
151
 
    __asm float_to_vec4 u, b;
152
 
    __asm vec4_multiply u, v;
153
 
    return u;
154
 
}
155
 
 
156
 
vec4 __operator / (const float a, const vec4 u) {
157
 
    vec4 v;
158
 
    __asm float_to_vec4 v, a;
159
 
    __asm vec4_divide   v, u;
160
 
    return v;
161
 
}
162
 
 
163
 
vec4 __operator / (vec4 v, const float b) {
164
 
    vec4 u;
165
 
    __asm float_to_vec4 u, b;
166
 
    __asm vec4_divide   v, u;
167
 
    return v;
168
 
}
169
 
 
170
 
 
171
 
vec4 __operator - (vec4 v) {
172
 
    __asm vec4_negate v;
173
 
    return v;
174
 
}
175
 
 
176
 
 
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;
181
 
    return v4.x;
182
 
}
183
 
 
184
 
float dot (vec4 v, vec4 u) {
185
 
    __asm vec4_dot v, u;
186
 
    return v.x;
187
 
}
188
 
 
189
 
 
190
 
float length (vec3 v) {
191
 
    vec4 u = vec4 (v, 0.0);
192
 
    __asm vec4_dot u, u;
193
 
    return sqrt (u.x);
194
 
}
195
 
 
196
 
float length (vec4 v) {
197
 
    __asm vec4_dot v, v;
198
 
    return sqrt (v.x);
199
 
}
200
 
 
201
 
 
202
 
vec3 normalize (vec3 v) {
203
 
    vec4 u = vec4 (v, 0.0);
204
 
    vec4 w = u;
205
 
    __asm vec4_dot      u, u;
206
 
    float l = sqrt (u.x);
207
 
    __asm float_to_vec4 u, l;
208
 
    __asm vec4_divide   w, u;
209
 
    return w.xyz;
210
 
}
211
 
 
212
 
vec4 normalize (vec4 v) {
213
 
    vec4 w = v;
214
 
    __asm vec4_dot      v, v;
215
 
    float l = sqrt (v.x);
216
 
    __asm float_to_vec4 v, l;
217
 
    __asm vec4_divide   w, v;
218
 
    return w;
219
 
}
220