Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/include/Diderot/cl-inline-matrix.h
ViewVC logotype

Diff of /branches/pure-cfg/src/include/Diderot/cl-inline-matrix.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1317, Sat Jun 11 22:50:21 2011 UTC revision 1318, Sun Jun 12 00:58:35 2011 UTC
# Line 17  Line 17 
17    
18  /********** 2x2 matrix functions **********/  /********** 2x2 matrix functions **********/
19    
20  STATIC_INLINE void zero2x2f (Diderot_Mat2x2_t dst)  inline void zero2x2f (Diderot_Mat2x2_t dst)
21  {  {
22      dst[0] = (float2)(0.0, 0.0);      dst[0] = (float2)(0.0, 0.0);
23      dst[1] = (float2)(0.0, 0.0);      dst[1] = (float2)(0.0, 0.0);
24  }  }
25    
26  STATIC_INLINE void identity2x2f (Diderot_Mat2x2_t dst)  inline void identity2x2f (Diderot_Mat2x2_t dst)
27  {  {
28      dst[0] = (float2)(1.0, 0.0);      dst[0] = (float2)(1.0, 0.0);
29      dst[1] = (float2)(0.0, 1.0);      dst[1] = (float2)(0.0, 1.0);
30  }  }
31    
32  /*STATIC_INLINE float2 column2x2f (Diderot_Mat2x2_t m, int i)  inline void copy2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)
 {  
     return (float2)(m[0].s[i], m[1].r[i]);  
 }*/  
   
 STATIC_INLINE void copy2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)  
33  {  {
34      dst[0] = src[0];      dst[0] = src[0];
35      dst[1] = src[1];      dst[1] = src[1];
36  }  }
37    
38  STATIC_INLINE void scale2x2f (Diderot_Mat2x2_t dst, float s, Diderot_Mat2x2_t src)  inline void scale2x2f (Diderot_Mat2x2_t dst, float s, Diderot_Mat2x2_t src)
39  {  {
40      float2 scale = float2(s, s);      float2 scale = (float2)(s, s);
41      dst[0] = scale * src[0];      dst[0] = scale * src[0];
42      dst[1] = scale * src[1];      dst[1] = scale * src[1];
43  }  }
44    
45  STATIC_INLINE void add2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)  inline void add2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)
46  {  {
47      dst[0] = a[0] + b[0];      dst[0] = a[0] + b[0];
48      dst[1] = a[1] + b[1];      dst[1] = a[1] + b[1];
49  }  }
50    
51  STATIC_INLINE void sub2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)  inline void sub2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t a, Diderot_Mat2x2_t b)
52  {  {
53      dst[0] = a[0] - b[0];      dst[0] = a[0] - b[0];
54      dst[1] = a[1] - b[1];      dst[1] = a[1] - b[1];
55  }  }
56    
57  STATIC_INLINE float2 mulVec3Mat2x2f (float2 v, Diderot_Mat2x2_t m)  inline float2 mulVec3Mat2x2f (float2 v, Diderot_Mat2x2_t m)
58  {  {
59      return (float2)(      return (float2)(
60          dot(v, column2x2f(m, 0)),          dot(v, (float2)(m[0].s0, m[1].s0)),
61          dot(v, column2x2f(m, 1)));          dot(v, (float2)(m[0].s1, m[1].s1)));
62  }  }
63    
64  STATIC_INLINE float2 mulMat2x2Vec2f (Diderot_Mat2x2_t m, float2 v)  inline float2 mulMat2x2Vec2f (Diderot_Mat2x2_t m, float2 v)
65  {  {
66      return (float2)(dot(m[0], v), dot(m[1], v));      return (float2)(dot(m[0], v), dot(m[1], v));
67  }  }
68    
69  STATIC_INLINE void mulMat2x2Mat2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t m1, Diderot_Mat2x2_t m2)  inline void mulMat2x2Mat2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t m1, Diderot_Mat2x2_t m2)
70  {  {
71      dst[0] = vec2f(      dst[0] = vec2f(
72          dot(m1[0].v, column2x2f(m2, 0)),          dot(m1[0], (float2)(m2[0].s0, m2[1].s0)),
73          dot(m1[0].v, column2x2f(m2, 1)));          dot(m1[0], (float2)(m2[0].s1, m2[1].s1)));
74      dst[1] = vec2f(      dst[1] = vec2f(
75          dot(m1[1].v, column2x2f(m2, 0)),          dot(m1[1], (float2)(m2[0].s0, m2[1].s0)),
76          dot(m1[1].v, column2x2f(m2, 1)));          dot(m1[1], (float2)(m2[0].s1, m2[1].s1)));
77  }  }
78    
79  STATIC_INLINE void transpose2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)  inline void transpose2x2f (Diderot_Mat2x2_t dst, Diderot_Mat2x2_t src)
80  {  {
81      dst[0] = column2x2f(src, 0);      dst[0] = (float2)(src[0].s0, src[1].s0);
82      dst[1] = column2x2f(src, 1);      dst[1] = (float2)(src[0].s1, src[1].s1);
83  }  }
84    
85  STATIC_INLINE float trace2x2f (Diderot_Mat2x2_t m)  inline float trace2x2f (Diderot_Mat2x2_t m)
86  {  {
87      return m[0].r[0] + m[1].r[1];      return m[0].s0 + m[1].s1;
88  }  }
89    
90  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
91  STATIC_INLINE float norm2x2f (Diderot_Mat2x2_t m)  inline float norm2x2f (Diderot_Mat2x2_t m)
92  {  {
93      return sqrtf(dot(m[0],m[0]) + dot(m[1],m[1]));      return sqrtf(dot(m[0],m[0]) + dot(m[1],m[1]));
94  }  }
# Line 101  Line 96 
96    
97  /********** 3x3 matrix functions **********/  /********** 3x3 matrix functions **********/
98    
99  STATIC_INLINE void zero3x3f (Diderot_Mat3x3_t dst)  inline void zero3x3f (Diderot_Mat3x3_t dst)
100  {  {
101      dst[0] = (float3)(0.0, 0.0, 0.0);      dst[0] = (float3)(0.0, 0.0, 0.0);
102      dst[1] = (float3)(0.0, 0.0, 0.0);      dst[1] = (float3)(0.0, 0.0, 0.0);
103      dst[2] = (float3)(0.0, 0.0, 0.0);      dst[2] = (float3)(0.0, 0.0, 0.0);
104  }  }
105    
106  STATIC_INLINE void identity3x3f (Diderot_Mat3x3_t dst)  inline void identity3x3f (Diderot_Mat3x3_t dst)
107  {  {
108      dst[0] = (float3)(1.0, 0.0, 0.0);      dst[0] = (float3)(1.0, 0.0, 0.0);
109      dst[1] = (float3)(0.0, 1.0, 0.0);      dst[1] = (float3)(0.0, 1.0, 0.0);
110      dst[2] = (float3)(0.0, 0.0, 1.0);      dst[2] = (float3)(0.0, 0.0, 1.0);
111  }  }
112    
113  STATIC_INLINE float3 column3x3f (Diderot_Mat3x3_t m, int i)  inline float3 column3x3f (Diderot_Mat3x3_t m, int i)
114  {  {
115      return (float3)(m[0].r[i], m[1].r[i], m[2].r[i]);      return (float3)(m[0].r[i], m[1].r[i], m[2].r[i]);
116  }  }
117    
118  STATIC_INLINE void copy3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)  inline void copy3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)
119  {  {
120      dst[0] = src[0];      dst[0] = src[0];
121      dst[1] = src[1];      dst[1] = src[1];
122      dst[2] = src[2];      dst[2] = src[2];
123  }  }
124    
125  STATIC_INLINE void scale3x3f (Diderot_Mat3x3_t dst, float s, Diderot_Mat3x3_t src)  inline void scale3x3f (Diderot_Mat3x3_t dst, float s, Diderot_Mat3x3_t src)
126  {  {
127      float3 scale = vec3f(s, s, s);      float3 scale = vec3f(s, s, s);
128      dst[0] = scale * src[0];      dst[0] = scale * src[0];
# Line 135  Line 130 
130      dst[2] = scale * src[2];      dst[2] = scale * src[2];
131  }  }
132    
133  STATIC_INLINE void add3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)  inline void add3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)
134  {  {
135      dst[0] = a[0].v + b[0].v;      dst[0] = a[0] + b[0];
136      dst[1] = a[1].v + b[1].v;      dst[1] = a[1] + b[1];
137      dst[2] = a[2].v + b[2].v;      dst[2] = a[2] + b[2];
138  }  }
139    
140  STATIC_INLINE void sub3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)  inline void sub3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t a, Diderot_Mat3x3_t b)
141  {  {
142      dst[0] = a[0].v - b[0].v;      dst[0] = a[0] - b[0];
143      dst[1] = a[1].v - b[1].v;      dst[1] = a[1] - b[1];
144      dst[2] = a[2].v - b[2].v;      dst[2] = a[2] - b[2];
145  }  }
146    
147  STATIC_INLINE float3 mulVec3Mat3x3f (float3 v, Diderot_Mat3x3_t m)  inline float3 mulVec3Mat3x3f (float3 v, Diderot_Mat3x3_t m)
148  {  {
149      return (float3)(      return (float3)(
150          dot(v, column3x3f(m, 0)),          dot(v, (float3)(m[0].s0, m[1].s0, m[2].s0)),
151          dot(v, column3x3f(m, 1)),          dot(v, (float3)(m[0].s1, m[1].s1, m[2].s1)),
152          dot(v, column3x3f(m, 2)));          dot(v, (float3)(m[0].s2, m[1].s2, m[2].s2)));
153  }  }
154    
155  STATIC_INLINE float3 mulMat3x3Vec3f (Diderot_Mat3x3_t m, float3 v)  inline float3 mulMat3x3Vec3f (Diderot_Mat3x3_t m, float3 v)
156  {  {
157      return (float3)(dot(m[0], v), dof(m[1], v), dot(m[2], v));      return (float3)(dot(m[0], v), dof(m[1], v), dot(m[2], v));
158  }  }
159    
160  STATIC_INLINE void mulMat3x3Mat3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t m1, Diderot_Mat3x3_t m2)  inline void mulMat3x3Mat3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t m1, Diderot_Mat3x3_t m2)
161  {  {
162      dst[0] = (float3)(      dst[0] = (float3)(
163          dot(m1[0], column3x3f(m2, 0)),          dot(m1[0], (float3)(m2[0].s0, m2[1].s0, m2[2].s0)),
164          dot(m1[0], column3x3f(m2, 1)),          dot(m1[0], (float3)(m2[0].s1, m2[1].s1, m2[2].s1)),
165          dot(m1[0], column3x3f(m2, 2)));          dot(m1[0], (float3)(m2[0].s2, m2[1].s2, m2[2].s2)));
166      dst[1] = (float3)(      dst[1] = (float3)(
167          dot(m1[1], column3x3f(m2, 0)),          dot(m1[1], (float3)(m2[0].s0, m2[1].s0, m2[2].s0)),
168          dot(m1[1], column3x3f(m2, 1)),          dot(m1[1], (float3)(m2[0].s1, m2[1].s1, m2[2].s1)),
169          dot(m1[1], column3x3f(m2, 2)));          dot(m1[1], (float3)(m2[0].s2, m2[1].s2, m2[2].s2)));
170      dst[2] = (float3)(      dst[2] = (float3)(
171          dot(m1[2], column3x3f(m2, 0)),          dot(m1[2], (float3)(m2[0].s0, m2[1].s0, m2[2].s0)),
172          dot(m1[2], column3x3f(m2, 1)),          dot(m1[2], (float3)(m2[0].s1, m2[1].s1, m2[2].s1)),
173          dot(m1[2], column3x3f(m2, 2)));          dot(m1[2], (float3)(m2[0].s2, m2[1].s2, m2[2].s2)));
174  }  }
175    
176  STATIC_INLINE void transpose3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)  inline void transpose3x3f (Diderot_Mat3x3_t dst, Diderot_Mat3x3_t src)
177  {  {
178      dst[0] = column3x3f(src, 0);      dst[0] = (float3)(src[0].s0, src[1].s0, src[2].s0);
179      dst[1] = column3x3f(src, 1);      dst[1] = (float3)(src[0].s1, src[1].s1, src[2].s1);
180      dst[2] = column3x3f(src, 2);      dst[2] = (float3)(src[0].s2, src[1].s2, src[2].s2);
181  }  }
182    
183  STATIC_INLINE float trace3x3f (Diderot_Mat3x3_t m)  inline float trace3x3f (Diderot_Mat3x3_t m)
184  {  {
185      return m[0] + m[1] + m[2];      return m[0].s0 + m[1].s1 + m[2].s2;
186  }  }
187    
188  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
189  STATIC_INLINE float norm3x3f (Diderot_Mat3x3_t m)  inline float norm3x3f (Diderot_Mat3x3_t m)
190  {  {
191      return sqrtf(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]));      return sqrtf(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]));
192  }  }
# Line 199  Line 194 
194    
195  /********** 4x4 matrix functions **********/  /********** 4x4 matrix functions **********/
196    
197  STATIC_INLINE void copy4x4f (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)  inline void copy4x4f (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)
198  {  {
199      dst[0] = src[0];      dst[0] = src[0];
200      dst[1] = src[1];      dst[1] = src[1];
# Line 207  Line 202 
202      dst[3] = src[3];      dst[3] = src[3];
203  }  }
204    
205  STATIC_INLINE float4 column4x4f (Diderot_Mat4x4_t m, int i)  inline float4 column4x4f (Diderot_Mat4x4_t m, int i)
206  {  {
207      return (float4)(((union4f_t)m[0]).r[i], ((union4f_t)m[1]).r[i], ((union4f_t)m[2]).r[i], ((union4f_t)m[3]).r[i]);      return (float4)(((union4f_t)m[0]).r[i], ((union4f_t)m[1]).r[i], ((union4f_t)m[2]).r[i], ((union4f_t)m[3]).r[i]);
208  }  }
209    
210  STATIC_INLINE void transpose4x4f (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)  inline void transpose4x4f (Diderot_Mat4x4_t dst, Diderot_Mat4x4_t src)
211  {  {
212      dst[0] = column4x4f(src, 0);      dst[0] = (float4)(src[0].s0, src[1].s0, src[2].s0, src[3].s0);
213      dst[1] = column4x4f(src, 1);      dst[1] = (float4)(src[0].s1, src[1].s1, src[2].s1, src[3].s1);
214      dst[2] = column4x4f(src, 2);      dst[2] = (float4)(src[0].s2, src[1].s2, src[2].s2, src[3].s2);
215      dst[3] = column4x4f(src, 3);      dst[3] = (float4)(src[0].s3, src[1].s3, src[2].s3, src[3].s3);
216  }  }
217    
218  STATIC_INLINE float trace4x4f (Diderot_Mat4x4_t m)  inline float trace4x4f (Diderot_Mat4x4_t m)
219  {  {
220      return m[0] + m[1] + m[2] + m[3];      return m[0].s0 + m[1].s1 + m[2].s2 + m[3].s3;
221  }  }
222    
223  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements  // The Frobenius norm of a matrix is the sqrt of the sum of the squares of the elements
224  STATIC_INLINE float norm4x4f (Diderot_Mat4x4_t m)  inline float norm4x4f (Diderot_Mat4x4_t m)
225  {  {
226      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]) + dot(m[3],m[3]));      return sqrt(dot(m[0],m[0]) + dot(m[1],m[1]) + dot(m[2],m[2]) + dot(m[3],m[3]));
227  }  }

Legend:
Removed from v.1317  
changed lines
  Added in v.1318

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0