HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VM_Math.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VM_Math.h ( VM Library, C++)
7  *
8  * COMMENTS: Vector Math.
9  */
10 
11 #ifndef __VM_Math__
12 #define __VM_Math__
13 
14 #include "VM_API.h"
15 #include <SYS/SYS_Math.h>
16 #include <SYS/SYS_Floor.h>
17 #include <string.h>
18 #include "VM_SIMD.h"
19 
20 class VM_SPUMath;
21 
22 #define VM_SIV static inline void
23 
24 // On platforms that don't support vector instructions, we define empty
25 // function signatures for SIMD operations. The runtime check on theSIMD
26 // should prevent them from being called.
27 #if defined(CPU_HAS_SIMD_INSTR)
28 #define VM_SIMDFUNC(signature) signature;
29 #define VM_SIMDFUNCR(signature) signature;
30 #else
31 #define VM_SIMDFUNC(signature) signature {}
32 #define VM_SIMDFUNCR(signature) signature { return 0; }
33 #endif
34 
35 #define VM_DECL_vFvFvF(name, expr) \
36  VM_SIV name(fpreal32 *d, const fpreal32 *a, \
37  const fpreal32 *b, exint num) { \
38  if (theSIMD) name##SIMD(d, a, b, num); \
39  else for (exint n=0; n<num; n++) expr; \
40  } \
41  VM_SIV name(fpreal64 *d, const fpreal64 *a, \
42  const fpreal64 *b, exint num) { \
43  for (exint n=0; n<num; n++) expr; \
44  } \
45  VM_SIMDFUNC(static void name##SIMD(fpreal32 *d, const fpreal32 *a, const fpreal32 *b, exint num))
46 
47 #define VM_DECL_vFvFuF(name, expr) \
48  VM_SIV name(fpreal32 *d, const fpreal32 *a, \
49  fpreal32 b, exint num) { \
50  if (theSIMD) name##SIMD(d, a, b, num); \
51  else for (exint n=0; n<num; n++) expr; \
52  } \
53  VM_SIV name(fpreal64 *d, const fpreal64 *a, \
54  fpreal64 b, exint num) { \
55  for (exint n=0; n<num; n++) expr; \
56  } \
57  VM_SIMDFUNC(static void name##SIMD(fpreal32 *d, const fpreal32 *a, fpreal32 b, exint num))
58 
59 #define VM_DECL_vFuFvF(name, expr) \
60  VM_SIV name(fpreal32 *d, fpreal32 a, \
61  const fpreal32 *b, exint num) { \
62  if (theSIMD) name##SIMD(d, a, b, num); \
63  else for (exint n=0; n<num; n++) expr; \
64  } \
65  VM_SIV name(fpreal64 *d, fpreal64 a, const fpreal64 *b, exint num) { \
66  for (exint n=0; n<num; n++) expr; \
67  } \
68  VM_SIMDFUNC(static void name##SIMD(fpreal32 *d, fpreal32 a, const fpreal32 *b, exint num))
69 
70 #define VM_DECL_vFuFuF(name, expr) \
71  VM_SIV name(fpreal32 *d, fpreal32 a, \
72  fpreal32 b, exint num) { \
73  if (theSIMD) name##SIMD(d, a, b, num); \
74  else for (exint n=0; n<num; n++) expr; \
75  } \
76  VM_SIMDFUNC(static void name##SIMD(fpreal32 *d, fpreal32 a, fpreal32 b, exint num))
77 
78 #define VM_DECL_vFvF(name, expr) \
79  VM_SIV name(fpreal32 *d, const fpreal32 *a, exint num) { \
80  if (theSIMD) name##SIMD(d, a, num); \
81  else for (exint n=0; n<num; n++) expr; \
82  } \
83  VM_SIV name(fpreal64 *d, const fpreal64 *a, exint num) { \
84  for (exint n=0; n<num; n++) expr; \
85  } \
86  VM_SIMDFUNC(static void name##SIMD(fpreal32 *d, const fpreal32 *a, exint num))
87 
88 #define VM_DECL_vFuF(name, expr) \
89  VM_SIV name(fpreal32 *d, fpreal32 a, exint num) { \
90  if (theSIMD) name##SIMD(d, a, num); \
91  else for (exint n=0; n<num; n++) expr; \
92  } \
93  VM_SIMDFUNC(static void name##SIMD(fpreal32 *d, fpreal32 a, exint num))
94 
95 #define VM_DECL_vIvF(name, expr) \
96  VM_SIV name(int32 *d, const fpreal32 *a, exint num) { \
97  if (theSIMD) name##SIMD(d, a, num); \
98  else for (exint n=0; n<num; n++) expr; \
99  } \
100  VM_SIMDFUNC(static void name##SIMD(int32 *d, const fpreal32 *a, exint num))
101 
102 #define VM_DECL_vIvF_nonconst(name, expr) \
103  VM_SIV name(int32 *d, fpreal32 *a, exint num) { \
104  if (theSIMD) name##SIMD(d, a, num); \
105  else for (exint n=0; n<num; n++) expr; \
106  } \
107  VM_SIMDFUNC(static void name##SIMD(int32 *d, fpreal32 *a, exint num))
108 
109 #define VM_DECL_vIvFvF(name, expr) \
110  VM_SIV name(int32 *d, const fpreal32 *a, const fpreal32 *b, exint num) { \
111  if (theSIMD) name##SIMD(d, a, b, num); \
112  else for (exint n=0; n<num; n++) expr; \
113  } \
114  VM_SIV name(int32 *d, const fpreal64 *a, const fpreal64 *b, exint num) { \
115  for (exint n=0; n<num; n++) expr; \
116  } \
117  VM_SIMDFUNC(static void name##SIMD(int32 *d, const fpreal32 *a, const fpreal32 *b, exint num))
118 
119 #define VM_DECL_vIvVFvF(name, expr) \
120  VM_SIV name(int32 *d, fpreal32 *a, const fpreal32 *b, exint num) { \
121  if (theSIMD) name##SIMD(d, a, b, num); \
122  else for (exint n=0; n<num; n++) expr; \
123  } \
124  VM_SIMDFUNC(static void name##SIMD(int32 *d, fpreal32 *a, const fpreal32 *b, exint num))
125 
126 #define VM_DECL_vIvFuF(name, expr) \
127  VM_SIV name(int32 *d, const fpreal32 *a, fpreal32 b, exint num) { \
128  if (theSIMD) name##SIMD(d, a, b, num); \
129  else for (exint n=0; n<num; n++) expr; \
130  } \
131  VM_SIV name(int32 *d, const fpreal64 *a, fpreal64 b, exint num) { \
132  for (exint n=0; n<num; n++) expr; \
133  } \
134  VM_SIMDFUNC(static void name##SIMD(int32 *d, const fpreal32 *a, fpreal32 b, exint num))
135 
136 #define VM_DECL_WP(type, name, expr) \
137  VM_SIV name(type *d, const fpreal32 *a, fpreal32 b, \
138  fpreal32 c, fpreal32 e, exint num) { \
139  if (theSIMD) name##SIMD(d, a, b, c, e, num); \
140  else for (exint n=0; n<num; n++) expr; \
141  } \
142  VM_SIMDFUNC(static void name##SIMD(type *d, const fpreal32 *a, fpreal32 b, fpreal32 c, fpreal32 e, exint num))
143 
144 #define VM_DECL_IWP(type, name, expr) \
145  VM_SIV name(fpreal32 *d, const type *a, fpreal32 b, \
146  type e, exint num) { \
147  if (theSIMD) name##SIMD(d, a, b, e, num); \
148  else for (exint n=0; n<num; n++) expr; \
149  } \
150  VM_SIMDFUNC(static void name##SIMD(fpreal32 *d, const type *a, fpreal32 b, type e, exint num))
151 
152 #define VM_DECL_vIvIvI(name, expr) \
153  VM_SIV name(int32 *d, const int32 *a, const int32 *b, exint num) { \
154  if (theSIMD) name##SIMD(d, a, b, num); \
155  else for (exint n=0; n<num; n++) expr; \
156  } \
157  VM_SIMDFUNC(static void name##SIMD(int32 *d, const int32 *a, const int32 *b, exint num))
158 
159 #define VM_DECL_vIvIuI(name, expr) \
160  VM_SIV name(int32 *d, const int32 *a, int32 b, exint num) { \
161  if (theSIMD) name##SIMD(d, a, b, num); \
162  else for (exint n=0; n<num; n++) expr; \
163  } \
164  VM_SIMDFUNC(static void name##SIMD(int32 *d, const int32 *a, int32 b, exint num))
165 
166 #define VM_DECL_uIvI(name, expr) \
167  static inline int32 name##SISD(const int32 *a, exint num) { \
168  int32 d = 0; \
169  for (exint n=0; n < num; n++) expr; \
170  return d; \
171  } \
172  VM_SIMDFUNCR(static int32 name##SIMD(const int32 *a, exint num)) \
173  static inline int32 name(const int32 *a, exint num) { \
174  return theSIMD ? name##SIMD(a, num) : \
175  name##SISD(a, num); \
176  } \
177 
178 // Declare the 8 variations of a single comparison operator
179 // - vector and scalar b
180 // - fast and standard
181 // - int32 and fpreal32
182 #define VM_DECL_CMP(name, op) \
183  VM_DECL_vIvFvF(name, d[n] = a[n] op b[n]) \
184  VM_DECL_vIvFuF(name, d[n] = a[n] op b) \
185  VM_DECL_vIvFvF(fast##name, d[n] = a[n] op b[n]) \
186  VM_DECL_vIvFuF(fast##name, d[n] = a[n] op b) \
187  VM_DECL_vIvIvI(name, d[n] = a[n] op b[n]) \
188  VM_DECL_vIvIuI(name, d[n] = a[n] op b) \
189  VM_DECL_vIvIvI(fast##name, d[n] = a[n] op b[n]) \
190  VM_DECL_vIvIuI(fast##name, d[n] = a[n] op b)
191 
192 template <class T>
193 static inline void
194 wpoint(T &d, fpreal32 v, fpreal32 wpoint, fpreal32 max, fpreal32 offset)
195 {
196  d = (T)SYSclamp(v*wpoint + offset, 0.0F, max);
197 }
198 
199 template <class T>
200 static inline void
201 iwpoint(fpreal32 &d, T v, fpreal32 iwpoint, T offset)
202 {
203  d = (fpreal32)(v - offset) * iwpoint;
204 }
205 
207 public:
208  static bool isSIMD() { return theSIMD; }
209 
210  /// The fast operations assume that any non-zero return value is
211  /// interpreted as true. Standard operations always set the result to
212  /// either 0 or 1.
213  ///
214  /// VM_Math::lt(d, a, b) := d[i] = a[i] < b[i]
215  /// VM_Math::lt(d, a, b) := d[i] = a[i] < b
216  /// VM_Math::fastlt(d, a, b) := d[i] = a[i] < b[i]
217  /// VM_Math::fastlt(d, a, b) := d[i] = a[i] < b
218  VM_DECL_CMP(lt, <)
219  VM_DECL_CMP(le, <=)
220  VM_DECL_CMP(gt, >)
221  VM_DECL_CMP(ge, >=)
222  VM_DECL_CMP(eq, ==)
223  VM_DECL_CMP(ne, !=)
224 
225  /// Bitwise operations
226  VM_DECL_vIvIvI(bor, d[n] = a[n] | b[n])
227  VM_DECL_vIvIuI(bor, d[n] = a[n] | b)
228  VM_DECL_vIvIvI(band, d[n] = a[n] & b[n])
229  VM_DECL_vIvIuI(band, d[n] = a[n] & b)
230  VM_DECL_vIvIvI(bxor, d[n] = a[n] ^ b[n])
231  VM_DECL_vIvIuI(bxor, d[n] = a[n] ^ b)
232 
233  /// VM_Math::add(d, a, b) := d[i] = a[i] + b[i]
234  VM_DECL_vFvFvF(add, d[n] = a[n] + b[n])
235  VM_DECL_vFvFuF(add, d[n] = a[n] + b)
236  VM_DECL_vIvIvI(add, d[n] = a[n] + b[n])
237  VM_DECL_vIvIuI(add, d[n] = a[n] + b)
238 
239  /// VM_Math::sub(d, a, b) := d[i] = a[i] - b[i]
240  VM_DECL_vFvFvF(sub, d[n] = a[n] - b[n])
241  VM_DECL_vFvFuF(sub, d[n] = a[n] - b)
242  VM_DECL_vFuFvF(sub, d[n] = a - b[n])
243 
244  /// VM_Math::mul(d, a, b) := d[i] = a[i] * b[i]
245  VM_DECL_vFvFvF(mul, d[n] = a[n] * b[n])
246  VM_DECL_vFvFuF(mul, d[n] = a[n] * b)
247 
248  /// VM_Math::div(d, a, b) := d[i] = a[i] / b[i]
249  VM_DECL_vFvFvF(div, d[n] = a[n] / b[n])
250  VM_DECL_vFuFvF(div, d[n] = a / b[n])
251 
252  /// VM_Math::safediv(d, a, b) := d[i] = b[i] != 0 ? a[i] / b[i] : a[i]
253  VM_DECL_vFvFvF(safediv, d[n] = SYSsafediv(a[n], b[n]))
254  VM_DECL_vFuFvF(safediv, d[n] = SYSsafediv(a, b[n]))
255 
256  // Multiply by reciprocal rather than dividing by a constant
258  { mul(d, a, 1/b, num); }
259  VM_SIV safediv(fpreal32 *d, const fpreal32 *a, fpreal32 b, exint num)
260  {
261  if (b == 0) set(d, 0.0F, num);
262  else mul(d, a, 1/b, num);
263  }
264 
265  /// VM_Math::fdiv(d, a, b) := d[i] = a[i] * (1.0 / b[i])
266  /// A faster version than div(), but less accurate since it uses the
267  /// reciprocal.
268  VM_DECL_vFvFvF(fdiv, d[n] = a[n] / b[n])
269  VM_DECL_vFuFvF(fdiv, d[n] = a / b[n])
270  VM_SIV fdiv(fpreal32 *d, const fpreal32 *a, fpreal32 b, exint num)
271  { b = 1/b; mul(d, a, b, num); }
272 
273  /// VM_Math::max(d, a, b) := d[i] = SYSmax(a[i] * b[i])
274  VM_DECL_vFvFvF(vmmax, d[n] = SYSmax(a[n], b[n]) )
275  VM_DECL_vFvFuF(vmmax, d[n] = SYSmax(a[n], b) )
276 
277  /// VM_Math::min(d, a, b) := d[i] = SYSmin(a[i] * b[i])
278  VM_DECL_vFvFvF(vmmin, d[n] = SYSmin(a[n], b[n]) )
279  VM_DECL_vFvFuF(vmmin, d[n] = SYSmin(a[n], b) )
280 
281  /// VM_Math::clamp(d, a, b) := d[i] = SYSclamp(a[i], min, max)
283  fpreal32 min, fpreal32 max, exint num)
284  {
285  if (theSIMD) clampSIMD(d, a, min, max, num);
286  else for (exint n=0; n<num; n++) d[n] = SYSclamp(a[n], min, max);
287  }
288  VM_SIMDFUNC(static void clampSIMD(fpreal32 *d, const fpreal32 *a, fpreal32 min, fpreal32 max, exint num))
289 
290  /// VM_Math::dot(a,b,n) := return sum(a[i]*b[i], i=0,n)
291  static inline fpreal64 dot(const fpreal32 *a, const fpreal32 *b, exint n)
292  { return (theSIMD) ? dotSIMD(a, b, n) : dotSISD(a, b, n); }
293  static inline double dotSISD(const fpreal32 *a, const fpreal32 *b, exint n)
294  {
295  exint i;
296  double sum = 0;
297  for (i = 0; i < n; i++)
298  sum += a[i]*b[i];
299  return sum;
300  }
301  VM_SIMDFUNCR(static double dotSIMD(const fpreal32 *a, const fpreal32 *b, exint n))
302 
303  static inline double maddAndNorm(fpreal32 *d, const fpreal32 *a, fpreal s, exint n)
304  { return (theSIMD) ? maddAndNormSIMD(d, a, s, n) : maddAndNormSISD(d, a, s, n); }
305  static inline double maddAndNormSISD(fpreal32 *d, const fpreal32 *a, fpreal s, exint n)
306  {
307  exint i;
308  double sum = 0;
309  for (i = 0; i < n; i++)
310  {
311  d[i] += a[i] * s;
312  sum += d[i] * d[i];
313  }
314  return sum;
315  }
316  VM_SIMDFUNCR(static double maddAndNormSIMD(fpreal32 *d, const fpreal32 *a, fpreal32 s, exint n))
317 
318  static inline double mulAndDotDA(fpreal32 *d, const fpreal32 *a, const fpreal32 *b, exint n)
319  { return (theSIMD) ? mulAndDotDASIMD(d, a, b, n) : mulAndDotDASISD(d, a, b, n); }
320  static inline double mulAndDotDASISD(fpreal32 *d, const fpreal32 *a, const fpreal32 *b, exint n)
321  {
322  exint i;
323  double sum = 0;
324  for (i = 0; i < n; i++)
325  {
326  d[i] = a[i] * b[i];
327  sum += d[i] * a[i];
328  }
329  return sum;
330  }
331  VM_SIMDFUNCR(static double mulAndDotDASIMD(fpreal32 *d, const fpreal32 *a, const fpreal32 *s, exint n))
332 
333  /// VM_Math::zerocount(a,n) := return sum(a[i]==0, i=0,n)
334  VM_DECL_uIvI(zerocount, d += a[n] == 0)
335 
336  /// VM_Math::scaleoffset(d, a, b) := d[i] = d[i]*a[i] + b[i]
337  VM_DECL_vFvFvF(scaleoffset, d[n] = d[n]*a[n] + b[n])
338  VM_DECL_vFvFuF(scaleoffset, d[n] = d[n]*a[n] + b)
339  VM_DECL_vFuFvF(scaleoffset, d[n] = d[n]*a + b[n])
340  VM_DECL_vFuFuF(scaleoffset, d[n] = d[n]*a + b)
341 
342  /// VM_Math::madd(d, a, b) := d[i] = d[i] + a[i]*b[i]
343  VM_DECL_vFvFvF(madd, d[n] += a[n]*b[n])
344  VM_DECL_vFvFuF(madd, d[n] += a[n]*b)
345 
346  /// VM_Math::sqrt(d, a) := d[i] = sqrt(a[i]);
347  VM_DECL_vFvF(sqrt, d[n] = SYSsqrt(a[n]) )
348 
349  /// VM_Math::fsqrt(d, a) := d[i] = 1.0 / isqrt(a[i]);
350  /// This is a faster, but far less accurate version of sqrt() since it uses
351  /// the reciprocal sqrt().
352  VM_DECL_vFvF(fsqrt, d[n] = SYSsqrt(a[n]) )
353 
354  /// VM_Math::isqrt(d, a) := d[i] = 1.0 / sqrt(a[i])
355  VM_DECL_vFvF(isqrt, d[n] = 1/SYSsqrt(a[n]) )
356 
357  /// VM_Math::floor(a) := SYSfloorIL(a)
358  VM_DECL_vIvF(floor, d[n] = (int)SYSfloorIL(a[n]) )
359 
360  VM_DECL_vIvF_nonconst(splitFloat, SYSfastSplitFloat(a[n], d[n]) )
361  VM_DECL_vIvVFvF(splitFloat, { a[n] = b[n]; SYSfastSplitFloat(a[n], d[n]); } )
362 
363  /// VM_Math::cast(a) := (int)a
364  VM_DECL_vIvF(cast, d[n] = (int)a[n] )
365 
366  /// VM_Math::negate(d, a) := d[i] = -a[i]
367  VM_DECL_vFvF(negate, d[n] = -a[n] )
368 
369  /// VM_Math::invert(d, a) := d[i] = 1.0 / a[i]
370  VM_DECL_vFvF(invert, d[n] = 1.0 / a[n] )
371 
372  /// VM_Math::abs(d, a) := d[i] = abs(a[i])
373  VM_DECL_vFvF(abs, d[n] = SYSabs(a[n]) )
374 
375  /// VM_Math::wpoint(d,a,b,c,e) := d[i] = SYSclamp(a[i]*b+e+0.5F, 0, c)
376  VM_DECL_WP(fpreal32, wpoint, ::wpoint<fpreal32>(d[n], a[n], b, c, e+0.5F));
377  VM_DECL_WP(uint8, wpoint, ::wpoint<uint8>(d[n], a[n], b, c, e+0.5F));
378  VM_DECL_WP(uint16, wpoint, ::wpoint<uint16>(d[n], a[n], b, c, e+0.5F));
379 
380  /// VM_Math::iwpoint(d,a,b,e) := d[i] = (fpreal32)(a[i]-e)/b;
381  VM_DECL_IWP(fpreal32, iwpoint, ::iwpoint<fpreal32>(d[n], a[n], 1.0F/b, e));
382  VM_DECL_IWP(uint8, iwpoint, ::iwpoint<uint8>(d[n], a[n], 1.0F/b, e));
383  VM_DECL_IWP(uint16, iwpoint, ::iwpoint<uint16>(d[n], a[n], 1.0F/b, e));
384 
385  VM_DECL_vFuF(set, d[n] = a )
386  /// VM_Math::set(d, a) := d[i] = a
387  VM_SIV set(int32 *d, int a, exint num)
388  { for (exint n=0; n<num; n++) d[n] = a; }
389 
390  /// VM_Math::set(d, a, disabled) := d[i] = disabled[i] ? d[i] : a[i]
391  VM_SIV set(fpreal32 *d, const fpreal32 *a, exint num,
392  const uint32 *disabled)
393  { set((int32 *)d, (const int32 *)a, num, disabled); }
394  VM_SIV set(int32 *d, const int32 *a, exint num,
395  const uint32 *disabled)
396  {
397  if (theSIMD)
398  setSIMD(d, a, num, disabled);
399  else
400  {
401  exint i;
402  for (i = 0; i < num; i++)
403  d[i] = disabled[i] ? d[i] : a[i];
404  }
405  }
406  VM_SIMDFUNC(static void setSIMD(int32 *d, const int32 *a, exint num, const uint32 *disabled))
407  VM_SIV set(fpreal32 *d, fpreal32 a, exint num,
408  const uint32 *disabled)
409  {
410  SYS_FPRealUnionF fu;
411  fu.fval = a;
412  set((int32 *)d, fu.ival, num, disabled);
413  }
414  VM_SIV set(int32 *d, int32 a, exint num,
415  const uint32 *disabled)
416  {
417  if (theSIMD)
418  setSIMD(d, a, num, disabled);
419  else
420  {
421  exint i;
422  for (i = 0; i < num; i++)
423  d[i] = disabled[i] ? d[i] : a;
424  }
425  }
426  VM_SIMDFUNC(static void setSIMD(int32 *d, int32 a, exint num,
427  const uint32 *disabled))
428 
429 
431  {
432  if (theSIMD) swapSIMD(a, b, num);
433  else swapSISD<fpreal32>(a, b, num);
434  }
436  {
437  swapSISD<fpreal64>(a, b, num);
438  }
439  template <typename T>
440  VM_SIV swapSISD(T *a, T *b, exint num)
441  {
442  for (exint i = 0; i < num; i++)
443  {
444  T t = a[i];
445  a[i] = b[i];
446  b[i] = t;
447  }
448  }
449  VM_SIMDFUNC(static void swapSIMD(fpreal32 *a, fpreal32 *b, exint num))
450 
451 
452  /// VM_Math::lerp(d, a, b, t) := d[i] = a[i] + (b[i]-a[i])*t[i]
454  const fpreal32 *t, exint num)
455  {
456  if (theSIMD)
457  {
458  subSIMD(d, b, a, num);
459  scaleoffsetSIMD(d, t, a, num);
460  }
461  else
462  {
463  for (exint n=0; n<num; n++)
464  d[n] = a[n] + (b[n]-a[n])*t[n];
465  }
466  }
467  VM_SIV lerp(fpreal32 *d, const fpreal32 *a, const fpreal32 *b,
468  fpreal32 t, exint num)
469  {
470  if (theSIMD)
471  {
472  mulSIMD (d, a, 1-t, num);
473  maddSIMD(d, b, t, num);
474  }
475  else
476  {
477  for (exint n=0; n<num; n++)
478  d[n] = SYSlerp(a[n], b[n], t);
479  }
480  }
481 
482  /// Vector Functions.
483  /// The following methods assume that the values coming in are "vectors".
484  /// The mnemonics are:
485  /// 3 - Vector3 or Matrix3
486  /// 4 - Vector4 or Matrix4
487  /// The enable_flags are an array corresponding 1-1 to the vectors to be
488  /// processed. Unlike typical flags, the vector will be processed
489  /// if the flag is set to 0. This is to match the VEX style calling.
490  /// If the VEX processor mask flag changes, the mask type here should
491  /// change too.
492  static void mulRowVec44(fpreal32 *v4, const fpreal32 m1[4][4], exint nv,
493  const uint32 *enable_flags=0);
494  static void mulRowVec34(fpreal32 *v3, const fpreal32 m1[4][4], exint nv,
495  const uint32 *enable_flags=0);
496  static void mulColVec44(fpreal32 *v4, const fpreal32 m1[4][4], exint nv,
497  const uint32 *enable_flags=0);
498  static void mulColVec34(fpreal32 *v3, const fpreal32 m1[4][4], exint nv,
499  const uint32 *enable_flags=0);
500  /// Multiplication, but treating the matrix as a 3x3 (i.e. no translate)
501  static void mulRowVec44_3(fpreal32 *v4, const fpreal32 m1[4][4], exint nv,
502  const uint32 *enable_flags=0);
503  static void mulRowVec34_3(fpreal32 *v3, const fpreal32 m1[4][4], exint nv,
504  const uint32 *enable_flags=0);
505  static void mulColVec44_3(fpreal32 *v4, const fpreal32 m1[4][4], exint nv,
506  const uint32 *enable_flags=0);
507  static void mulColVec34_3(fpreal32 *v3, const fpreal32 m1[4][4], exint nv,
508  const uint32 *enable_flags=0);
509 
510  // Add a 4-touple to an array of floats assumed to be a 4-tuple
511  static void vadd4u4(fpreal32 *v4, const fpreal32 a[4], exint nv,
512  const uint32 *enable_flags=0);
513  static void vsub4u4(fpreal32 *v4, const fpreal32 a[4], exint nv,
514  const uint32 *enable_flags=0);
515  static void vmul4u4(fpreal32 *v4, const fpreal32 a[4], exint nv,
516  const uint32 *enable_flags=0);
517 
518  static void forceSIMD(bool onoff) { theSIMD = onoff; }
519  static void setSPUMath(VM_SPUMath *math) { theSPUMath = math; }
520  static VM_SPUMath *getSPUMath() { return theSPUMath; }
521 
522 private:
523  static bool theSIMD;
524  static VM_SPUMath *theSPUMath;
525 };
526 
527 #endif
#define SYSmax(a, b)
Definition: SYS_Math.h:1365
GA_API const UT_StringHolder div
#define VM_DECL_IWP(type, name, expr)
Definition: VM_Math.h:144
#define VM_DECL_vFuFuF(name, expr)
Definition: VM_Math.h:70
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
GLboolean invert
Definition: glcorearb.h:548
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition: UT_ArraySet.h:1561
const GLdouble * v
Definition: glcorearb.h:836
#define VM_DECL_uIvI(name, expr)
Definition: VM_Math.h:166
#define VM_SIMDFUNC(signature)
Definition: VM_Math.h:31
virtual bool lerp(GA_AttributeOperand &d, GA_AttributeOperand &a, GA_AttributeOperand &b, GA_AttributeOperand &t) const
d = SYSlerp(a, b, t);
#define VM_API
Definition: VM_API.h:10
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define SYSabs(a)
Definition: SYS_Math.h:1367
UT_Matrix2T< T > SYSlerp(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2, S t)
Definition: UT_Matrix2.h:595
static void setSPUMath(VM_SPUMath *math)
Definition: VM_Math.h:519
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:818
png_uint_32 i
Definition: png.h:2877
VM_SIV swapSISD(T *a, T *b, exint num)
Definition: VM_Math.h:440
VM_SIV set(int32 *d, int32 a, exint num, const uint32 *disabled)
Definition: VM_Math.h:414
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
#define VM_DECL_vIvIuI(name, expr)
Definition: VM_Math.h:159
GLdouble n
Definition: glcorearb.h:2007
#define VM_DECL_vFvFvF(name, expr)
Definition: VM_Math.h:35
#define VM_DECL_vIvVFvF(name, expr)
Definition: VM_Math.h:119
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T abs(T a)
Definition: ImathFun.h:55
#define VM_DECL_CMP(name, op)
Definition: VM_Math.h:182
int64 exint
Definition: SYS_Types.h:115
static VM_SPUMath * getSPUMath()
Definition: VM_Math.h:520
double fpreal64
Definition: SYS_Types.h:191
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:218
VM_SIV lerp(fpreal32 *d, const fpreal32 *a, const fpreal32 *b, fpreal32 t, exint num)
Definition: VM_Math.h:467
GLintptr offset
Definition: glcorearb.h:664
#define VM_DECL_vFvFuF(name, expr)
Definition: VM_Math.h:47
#define VM_DECL_vFvF(name, expr)
Definition: VM_Math.h:78
int int32
Definition: SYS_Types.h:34
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
#define VM_DECL_vIvF_nonconst(name, expr)
Definition: VM_Math.h:102
int floor(T x)
Definition: ImathFun.h:150
#define VM_SIMDFUNCR(signature)
Definition: VM_Math.h:32
unsigned short uint16
Definition: SYS_Types.h:33
double fpreal
Definition: SYS_Types.h:269
unsigned char uint8
Definition: SYS_Types.h:31
VM_SIV set(fpreal32 *d, const fpreal32 *a, exint num, const uint32 *disabled)
VM_Math::set(d, a, disabled) := d[i] = disabled[i] ? d[i] : a[i].
Definition: VM_Math.h:391
static bool isSIMD()
Definition: VM_Math.h:208
static void forceSIMD(bool onoff)
Definition: VM_Math.h:518
#define VM_SIV
Definition: VM_Math.h:22
png_infop png_uint_32 int num
Definition: png.h:2158
#define const
Definition: zconf.h:214
#define VM_DECL_vFuF(name, expr)
Definition: VM_Math.h:88
#define VM_DECL_vIvIvI(name, expr)
Definition: VM_Math.h:152
#define SYSmin(a, b)
Definition: SYS_Math.h:1366
fpreal32 SYSfloorIL(fpreal32 val)
Definition: SYS_Floor.h:59
float fpreal32
Definition: SYS_Types.h:190
#define VM_DECL_vIvF(name, expr)
Definition: VM_Math.h:95
VM_SIV set(int32 *d, const int32 *a, exint num, const uint32 *disabled)
Definition: VM_Math.h:394
VM_SIV swap(fpreal64 *a, fpreal64 *b, exint num)
Definition: VM_Math.h:435
#define VM_DECL_WP(type, name, expr)
Definition: VM_Math.h:136
#define VM_DECL_vFuFvF(name, expr)
Definition: VM_Math.h:59
GLenum clamp
Definition: glcorearb.h:1233
unsigned int uint32
Definition: SYS_Types.h:35