SIMD-ize the matrix multiplication in AnimateVertices
[xonotic/darkplaces.git] / mod_skeletal_animatevertices_sse.c
1 #include "mod_skeletal_animatevertices_sse.h"
2
3 #ifdef SSE_POSSIBLE
4
5 #ifdef MATRIX4x4_OPENGLORIENTATION
6 #error "SSE skeletal requires D3D matrix layout"
7 #endif
8
9 #include <xmmintrin.h>
10
11 void Mod_Skeletal_AnimateVertices_SSE(const dp_model_t * RESTRICT model, const frameblend_t * RESTRICT frameblend, const skeleton_t *skeleton, float * RESTRICT vertex3f, float * RESTRICT normal3f, float * RESTRICT svector3f, float * RESTRICT tvector3f)
12 {
13         // vertex weighted skeletal
14         int i, k;
15         int blends;
16         matrix4x4_t *bonepose;
17         matrix4x4_t *boneposerelative;
18         float m[12];
19         const blendweights_t * RESTRICT weights;
20         int num_vertices_minus_one;
21
22         num_vertices_minus_one = model->surfmesh.num_vertices - 1;
23
24         //unsigned long long ts = rdtsc();
25         bonepose = (matrix4x4_t *) Mod_Skeletal_AnimateVertices_AllocBuffers(sizeof(matrix4x4_t) * (model->num_bones*2 + model->surfmesh.num_blends));
26         boneposerelative = bonepose + model->num_bones;
27
28         if (skeleton && !skeleton->relativetransforms)
29                 skeleton = NULL;
30
31         // interpolate matrices
32         if (skeleton)
33         {
34                 for (i = 0;i < model->num_bones;i++)
35                 {
36                         const float * RESTRICT n = model->data_baseboneposeinverse + i * 12;
37                         matrix4x4_t * RESTRICT s = &skeleton->relativetransforms[i];
38                         matrix4x4_t * RESTRICT b = &bonepose[i];
39                         matrix4x4_t * RESTRICT r = &boneposerelative[i];
40                         __m128 b0, b1, b2, b3, r0, r1, r2, r3, nr;
41                         if (model->data_bones[i].parent >= 0)
42                         {
43                                 const matrix4x4_t * RESTRICT p = &bonepose[model->data_bones[i].parent];
44                                 __m128 s0 = _mm_loadu_ps(s->m[0]), s1 = _mm_loadu_ps(s->m[1]), s2 = _mm_loadu_ps(s->m[2]);
45 #ifdef OPENGLORIENTATION
46 #define SKELETON_MATRIX(r, c) _mm_shuffle_ps(s##c, s##c, _MM_SHUFFLE(r, r, r, r))
47 #else
48 #define SKELETON_MATRIX(r, c) _mm_shuffle_ps(s##r, s##r, _MM_SHUFFLE(c, c, c, c))
49 #endif
50                                 __m128 pr = _mm_load_ps(p->m[0]);
51                                 b0 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 0));
52                                 b1 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 1));
53                                 b2 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 2));
54                                 b3 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 3));
55                                 pr = _mm_load_ps(p->m[1]);
56                                 b0 = _mm_add_ps(b0, _mm_mul_ps(pr, SKELETON_MATRIX(1, 0)));
57                                 b1 = _mm_add_ps(b1, _mm_mul_ps(pr, SKELETON_MATRIX(1, 1)));
58                                 b2 = _mm_add_ps(b2, _mm_mul_ps(pr, SKELETON_MATRIX(1, 2)));
59                                 b3 = _mm_add_ps(b3, _mm_mul_ps(pr, SKELETON_MATRIX(1, 3)));
60                                 pr = _mm_load_ps(p->m[2]);
61                                 b0 = _mm_add_ps(b0, _mm_mul_ps(pr, SKELETON_MATRIX(2, 0)));
62                                 b1 = _mm_add_ps(b1, _mm_mul_ps(pr, SKELETON_MATRIX(2, 1)));
63                                 b2 = _mm_add_ps(b2, _mm_mul_ps(pr, SKELETON_MATRIX(2, 2)));
64                                 b3 = _mm_add_ps(b3, _mm_mul_ps(pr, SKELETON_MATRIX(2, 3)));
65                                 b3 = _mm_add_ps(b3, _mm_load_ps(p->m[3]));
66                         }
67                         else
68                         {
69                                 b0 = _mm_loadu_ps(s->m[0]);
70                                 b1 = _mm_loadu_ps(s->m[1]);
71                                 b2 = _mm_loadu_ps(s->m[2]);
72                                 b3 = _mm_loadu_ps(s->m[3]);
73 #ifndef OPENGLORIENTATION
74                                 _MM_TRANSPOSE4_PS(b0, b1, b2, b3);
75 #endif
76                         }
77                         _mm_store_ps(b->m[0], b0);
78                         _mm_store_ps(b->m[1], b1);
79                         _mm_store_ps(b->m[2], b2);
80                         _mm_store_ps(b->m[3], b3);
81                         nr = _mm_loadu_ps(n);
82                         r0 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0)));
83                         r1 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1)));
84                         r2 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2)));
85                         r3 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3)));
86                         nr = _mm_loadu_ps(n+4);
87                         r0 = _mm_add_ps(r0, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
88                         r1 = _mm_add_ps(r1, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
89                         r2 = _mm_add_ps(r2, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
90                         r3 = _mm_add_ps(r3, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
91                         nr = _mm_loadu_ps(n+8);
92                         r0 = _mm_add_ps(r0, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
93                         r1 = _mm_add_ps(r1, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
94                         r2 = _mm_add_ps(r2, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
95                         r3 = _mm_add_ps(r3, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
96                         _mm_store_ps(r->m[0], r0);
97                         _mm_store_ps(r->m[1], r1);
98                         _mm_store_ps(r->m[2], r2);
99                         _mm_store_ps(r->m[3], r3);
100                 }
101         }
102         else
103         {
104                 for (i = 0;i < model->num_bones;i++)
105                 {
106                         const short * RESTRICT pose7s = model->data_poses7s + 7 * (frameblend[0].subframe * model->num_bones + i);
107                         float lerp = frameblend[0].lerp,
108                                 tx = pose7s[0], ty = pose7s[1], tz = pose7s[2],
109                                 rx = pose7s[3] * lerp,
110                                 ry = pose7s[4] * lerp,
111                                 rz = pose7s[5] * lerp,
112                                 rw = pose7s[6] * lerp,
113                                 dx = tx*rw + ty*rz - tz*ry,
114                                 dy = -tx*rz + ty*rw + tz*rx,
115                                 dz = tx*ry - ty*rx + tz*rw,
116                                 dw = -tx*rx - ty*ry - tz*rz,
117                                 scale, originscale;
118                         for (blends = 1;blends < MAX_FRAMEBLENDS && frameblend[blends].lerp > 0;blends++)
119                         {
120                                 const short * RESTRICT pose7s = model->data_poses7s + 7 * (frameblend[blends].subframe * model->num_bones + i);
121                                 float lerp = frameblend[blends].lerp,
122                                         tx = pose7s[0], ty = pose7s[1], tz = pose7s[2],
123                                         qx = pose7s[3], qy = pose7s[4], qz = pose7s[5], qw = pose7s[6];
124                                 if(rx*qx + ry*qy + rz*qz + rw*qw < 0) lerp = -lerp;
125                                 qx *= lerp;
126                                 qy *= lerp;
127                                 qz *= lerp;
128                                 qw *= lerp;
129                                 rx += qx;
130                                 ry += qy;
131                                 rz += qz;
132                                 rw += qw;
133                                 dx += tx*qw + ty*qz - tz*qy;
134                                 dy += -tx*qz + ty*qw + tz*qx;
135                                 dz += tx*qy - ty*qx + tz*qw;
136                                 dw += -tx*qx - ty*qy - tz*qz;
137                         }
138                         scale = 1.0f / (rx*rx + ry*ry + rz*rz + rw*rw);
139                         originscale = -model->num_posescale * scale;
140                         m[0] = scale*(rw*rw + rx*rx - ry*ry - rz*rz);
141                         m[1] = 2*scale*(rx*ry - rw*rz);
142                         m[2] = 2*scale*(rx*rz + rw*ry);
143                         m[3] = originscale*(dw*rx - dx*rw + dy*rz - dz*ry);
144                         m[4] = 2*scale*(rx*ry + rw*rz);
145                         m[5] = scale*(rw*rw + ry*ry - rx*rx - rz*rz);
146                         m[6] = 2*scale*(ry*rz - rw*rx);
147                         m[7] = originscale*(dw*ry - dx*rz - dy*rw + dz*rx);
148                         m[8] = 2*scale*(rx*rz - rw*ry);
149                         m[9] = 2*scale*(ry*rz + rw*rx);
150                         m[10] = scale*(rw*rw + rz*rz - rx*rx - ry*ry);
151                         m[11] = originscale*(dw*rz + dx*ry - dy*rx - dz*rw);
152                         if (i == r_skeletal_debugbone.integer)
153                                 m[r_skeletal_debugbonecomponent.integer % 12] += r_skeletal_debugbonevalue.value;
154                         m[3] *= r_skeletal_debugtranslatex.value;
155                         m[7] *= r_skeletal_debugtranslatey.value;
156                         m[11] *= r_skeletal_debugtranslatez.value;
157                         {
158                                 const float * RESTRICT n = model->data_baseboneposeinverse + i * 12;
159                                 matrix4x4_t * RESTRICT b = &bonepose[i];
160                                 matrix4x4_t * RESTRICT r = &boneposerelative[i];
161                                 __m128 b0, b1, b2, b3, r0, r1, r2, r3, nr;
162                                 if (model->data_bones[i].parent >= 0)
163                                 {
164                                         const matrix4x4_t * RESTRICT p = &bonepose[model->data_bones[i].parent];
165                                         __m128 pr = _mm_load_ps(p->m[0]);
166                                         b0 = _mm_mul_ps(pr, _mm_set1_ps(m[0]));
167                                         b1 = _mm_mul_ps(pr, _mm_set1_ps(m[1]));
168                                         b2 = _mm_mul_ps(pr, _mm_set1_ps(m[2]));
169                                         b3 = _mm_mul_ps(pr, _mm_set1_ps(m[3]));
170                                         pr = _mm_load_ps(p->m[1]);
171                                         b0 = _mm_add_ps(b0, _mm_mul_ps(pr, _mm_set1_ps(m[4])));
172                                         b1 = _mm_add_ps(b1, _mm_mul_ps(pr, _mm_set1_ps(m[5])));
173                                         b2 = _mm_add_ps(b2, _mm_mul_ps(pr, _mm_set1_ps(m[6])));
174                                         b3 = _mm_add_ps(b3, _mm_mul_ps(pr, _mm_set1_ps(m[7])));
175                                         pr = _mm_load_ps(p->m[2]);
176                                         b0 = _mm_add_ps(b0, _mm_mul_ps(pr, _mm_set1_ps(m[8])));
177                                         b1 = _mm_add_ps(b1, _mm_mul_ps(pr, _mm_set1_ps(m[9])));
178                                         b2 = _mm_add_ps(b2, _mm_mul_ps(pr, _mm_set1_ps(m[10])));
179                                         b3 = _mm_add_ps(b3, _mm_mul_ps(pr, _mm_set1_ps(m[11])));
180                                         b3 = _mm_add_ps(b3, _mm_load_ps(p->m[3]));
181                                 }
182                                 else
183                                 {
184                                         b0 = _mm_setr_ps(m[0], m[4], m[8], 0.0f);
185                                         b1 = _mm_setr_ps(m[1], m[5], m[9], 0.0f);
186                                         b2 = _mm_setr_ps(m[2], m[6], m[10], 0.0f);
187                                         b3 = _mm_setr_ps(m[3], m[7], m[11], 1.0f);
188                                 }
189                                 _mm_store_ps(b->m[0], b0);
190                                 _mm_store_ps(b->m[1], b1);
191                                 _mm_store_ps(b->m[2], b2);
192                                 _mm_store_ps(b->m[3], b3);
193                                 nr = _mm_loadu_ps(n);
194                                 r0 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0)));
195                                 r1 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1)));
196                                 r2 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2)));
197                                 r3 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3)));
198                                 nr = _mm_loadu_ps(n+4);
199                                 r0 = _mm_add_ps(r0, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
200                                 r1 = _mm_add_ps(r1, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
201                                 r2 = _mm_add_ps(r2, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
202                                 r3 = _mm_add_ps(r3, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
203                                 nr = _mm_loadu_ps(n+8);
204                                 r0 = _mm_add_ps(r0, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
205                                 r1 = _mm_add_ps(r1, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
206                                 r2 = _mm_add_ps(r2, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
207                                 r3 = _mm_add_ps(r3, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
208                                 r3 = _mm_add_ps(r3, b3);
209                                 _mm_store_ps(r->m[0], r0);
210                                 _mm_store_ps(r->m[1], r1);
211                                 _mm_store_ps(r->m[2], r2);
212                                 _mm_store_ps(r->m[3], r3);
213                         }       
214                 }
215         }
216
217         // generate matrices for all blend combinations
218         weights = model->surfmesh.data_blendweights;
219         for (i = 0;i < model->surfmesh.num_blends;i++, weights++)
220         {
221                 float * RESTRICT b = &boneposerelative[model->num_bones + i].m[0][0];
222                 const float * RESTRICT m = &boneposerelative[weights->index[0]].m[0][0];
223                 float f = weights->influence[0] * (1.0f / 255.0f);
224                 __m128 fv = _mm_set_ps1(f);
225                 __m128 b0 = _mm_load_ps(m);
226                 __m128 b1 = _mm_load_ps(m+4);
227                 __m128 b2 = _mm_load_ps(m+8);
228                 __m128 b3 = _mm_load_ps(m+12);
229                 __m128 m0, m1, m2, m3;
230                 b0 = _mm_mul_ps(b0, fv);
231                 b1 = _mm_mul_ps(b1, fv);
232                 b2 = _mm_mul_ps(b2, fv);
233                 b3 = _mm_mul_ps(b3, fv);
234                 for (k = 1;k < 4 && weights->influence[k];k++)
235                 {
236                         m = &boneposerelative[weights->index[k]].m[0][0];
237                         f = weights->influence[k] * (1.0f / 255.0f);
238                         fv = _mm_set_ps1(f);
239                         m0 = _mm_load_ps(m);
240                         m1 = _mm_load_ps(m+4);
241                         m2 = _mm_load_ps(m+8);
242                         m3 = _mm_load_ps(m+12);
243                         m0 = _mm_mul_ps(m0, fv);
244                         m1 = _mm_mul_ps(m1, fv);
245                         m2 = _mm_mul_ps(m2, fv);
246                         m3 = _mm_mul_ps(m3, fv);
247                         b0 = _mm_add_ps(m0, b0);
248                         b1 = _mm_add_ps(m1, b1);
249                         b2 = _mm_add_ps(m2, b2);
250                         b3 = _mm_add_ps(m3, b3);
251                 }
252                 _mm_store_ps(b, b0);
253                 _mm_store_ps(b+4, b1);
254                 _mm_store_ps(b+8, b2);
255                 _mm_store_ps(b+12, b3);
256         }
257
258 #define LOAD_MATRIX_SCALAR() const float * RESTRICT m = &boneposerelative[*b].m[0][0]
259
260 #define LOAD_MATRIX3() \
261         const float * RESTRICT m = &boneposerelative[*b].m[0][0]; \
262         /* bonepose array is 16 byte aligned */ \
263         __m128 m1 = _mm_load_ps((m)); \
264         __m128 m2 = _mm_load_ps((m)+4); \
265         __m128 m3 = _mm_load_ps((m)+8);
266 #define LOAD_MATRIX4() \
267         const float * RESTRICT m = &boneposerelative[*b].m[0][0]; \
268         /* bonepose array is 16 byte aligned */ \
269         __m128 m1 = _mm_load_ps((m)); \
270         __m128 m2 = _mm_load_ps((m)+4); \
271         __m128 m3 = _mm_load_ps((m)+8); \
272         __m128 m4 = _mm_load_ps((m)+12)
273
274         /* Note that matrix is 4x4 and transposed compared to non-USE_SSE codepath */
275 #define TRANSFORM_POSITION_SCALAR(in, out) \
276         (out)[0] = ((in)[0] * m[0] + (in)[1] * m[4] + (in)[2] * m[ 8] + m[12]); \
277         (out)[1] = ((in)[0] * m[1] + (in)[1] * m[5] + (in)[2] * m[ 9] + m[13]); \
278         (out)[2] = ((in)[0] * m[2] + (in)[1] * m[6] + (in)[2] * m[10] + m[14]);
279 #define TRANSFORM_VECTOR_SCALAR(in, out) \
280         (out)[0] = ((in)[0] * m[0] + (in)[1] * m[4] + (in)[2] * m[ 8]); \
281         (out)[1] = ((in)[0] * m[1] + (in)[1] * m[5] + (in)[2] * m[ 9]); \
282         (out)[2] = ((in)[0] * m[2] + (in)[1] * m[6] + (in)[2] * m[10]);
283
284 #define TRANSFORM_POSITION(in, out) { \
285                 __m128 pin = _mm_loadu_ps(in); /* we ignore the value in the last element (x from the next vertex) */ \
286                 __m128 x = _mm_shuffle_ps(pin, pin, 0x0); \
287                 __m128 t1 = _mm_mul_ps(x, m1); \
288                 \
289                 /* y, + x */ \
290                 __m128 y = _mm_shuffle_ps(pin, pin, 0x55); \
291                 __m128 t2 = _mm_mul_ps(y, m2); \
292                 __m128 t3 = _mm_add_ps(t1, t2); \
293                 \
294                 /* z, + (y+x) */ \
295                 __m128 z = _mm_shuffle_ps(pin, pin, 0xaa); \
296                 __m128 t4 = _mm_mul_ps(z, m3); \
297                 __m128 t5 = _mm_add_ps(t3, t4); \
298                 \
299                 /* + m3 */ \
300                 __m128 pout = _mm_add_ps(t5, m4); \
301                 _mm_storeu_ps((out), pout); \
302         }
303
304 #define TRANSFORM_VECTOR(in, out) { \
305                 __m128 vin = _mm_loadu_ps(in); \
306                 \
307                 /* x */ \
308                 __m128 x = _mm_shuffle_ps(vin, vin, 0x0); \
309                 __m128 t1 = _mm_mul_ps(x, m1); \
310                 \
311                 /* y, + x */ \
312                 __m128 y = _mm_shuffle_ps(vin, vin, 0x55); \
313                 __m128 t2 = _mm_mul_ps(y, m2); \
314                 __m128 t3 = _mm_add_ps(t1, t2); \
315                 \
316                 /* nz, + (ny + nx) */ \
317                 __m128 z = _mm_shuffle_ps(vin, vin, 0xaa); \
318                 __m128 t4 = _mm_mul_ps(z, m3); \
319                 __m128 vout = _mm_add_ps(t3, t4); \
320                 _mm_storeu_ps((out), vout); \
321         }
322
323         // transform vertex attributes by blended matrices
324         if (vertex3f)
325         {
326                 const float * RESTRICT v = model->surfmesh.data_vertex3f;
327                 const unsigned short * RESTRICT b = model->surfmesh.blends;
328                 // special case common combinations of attributes to avoid repeated loading of matrices
329                 if (normal3f)
330                 {
331                         const float * RESTRICT n = model->surfmesh.data_normal3f;
332                         if (svector3f && tvector3f)
333                         {
334                                 const float * RESTRICT sv = model->surfmesh.data_svector3f;
335                                 const float * RESTRICT tv = model->surfmesh.data_tvector3f;
336
337                                 // Note that for SSE each iteration stores one element past end, so we break one vertex short
338                                 // and handle that with scalars in that case
339                                 for (i = 0; i < num_vertices_minus_one; i++, v += 3, n += 3, sv += 3, tv += 3, b++,
340                                                 vertex3f += 3, normal3f += 3, svector3f += 3, tvector3f += 3)
341                                 {
342                                         LOAD_MATRIX4();
343                                         TRANSFORM_POSITION(v, vertex3f);
344                                         TRANSFORM_VECTOR(n, normal3f);
345                                         TRANSFORM_VECTOR(sv, svector3f);
346                                         TRANSFORM_VECTOR(tv, tvector3f);
347                                 }
348
349                                 // Last vertex needs to be done with scalars to avoid reading/writing 1 word past end of arrays
350                                 {
351                                         LOAD_MATRIX_SCALAR();
352                                         TRANSFORM_POSITION_SCALAR(v, vertex3f);
353                                         TRANSFORM_VECTOR_SCALAR(n, normal3f);
354                                         TRANSFORM_VECTOR_SCALAR(sv, svector3f);
355                                         TRANSFORM_VECTOR_SCALAR(tv, tvector3f);
356                                 }
357                                 //printf("elapsed ticks: %llu\n", rdtsc() - ts); // XXX
358                                 return;
359                         }
360
361                         for (i = 0;i < num_vertices_minus_one; i++, v += 3, n += 3, b++, vertex3f += 3, normal3f += 3)
362                         {
363                                 LOAD_MATRIX4();
364                                 TRANSFORM_POSITION(v, vertex3f);
365                                 TRANSFORM_VECTOR(n, normal3f);
366                         }
367                         {
368                                 LOAD_MATRIX_SCALAR();
369                                 TRANSFORM_POSITION_SCALAR(v, vertex3f);
370                                 TRANSFORM_VECTOR_SCALAR(n, normal3f);
371                         }
372                 }
373                 else
374                 {
375                         for (i = 0;i < num_vertices_minus_one; i++, v += 3, b++, vertex3f += 3)
376                         {
377                                 LOAD_MATRIX4();
378                                 TRANSFORM_POSITION(v, vertex3f);
379                         }
380                         {
381                                 LOAD_MATRIX_SCALAR();
382                                 TRANSFORM_POSITION_SCALAR(v, vertex3f);
383                         }
384                 }
385         }
386
387         else if (normal3f)
388         {
389                 const float * RESTRICT n = model->surfmesh.data_normal3f;
390                 const unsigned short * RESTRICT b = model->surfmesh.blends;
391                 for (i = 0; i < num_vertices_minus_one; i++, n += 3, b++, normal3f += 3)
392                 {
393                         LOAD_MATRIX3();
394                         TRANSFORM_VECTOR(n, normal3f);
395                 }
396                 {
397                         LOAD_MATRIX_SCALAR();
398                         TRANSFORM_VECTOR_SCALAR(n, normal3f);
399                 }
400         }
401
402         if (svector3f)
403         {
404                 const float * RESTRICT sv = model->surfmesh.data_svector3f;
405                 const unsigned short * RESTRICT b = model->surfmesh.blends;
406                 for (i = 0; i < num_vertices_minus_one; i++, sv += 3, b++, svector3f += 3)
407                 {
408                         LOAD_MATRIX3();
409                         TRANSFORM_VECTOR(sv, svector3f);
410                 }
411                 {
412                         LOAD_MATRIX_SCALAR();
413                         TRANSFORM_VECTOR_SCALAR(sv, svector3f);
414                 }
415         }
416
417         if (tvector3f)
418         {
419                 const float * RESTRICT tv = model->surfmesh.data_tvector3f;
420                 const unsigned short * RESTRICT b = model->surfmesh.blends;
421                 for (i = 0; i < num_vertices_minus_one; i++, tv += 3, b++, tvector3f += 3)
422                 {
423                         LOAD_MATRIX3();
424                         TRANSFORM_VECTOR(tv, tvector3f);
425                 }
426                 {
427                         LOAD_MATRIX_SCALAR();
428                         TRANSFORM_VECTOR_SCALAR(tv, tvector3f);
429                 }
430         }
431
432 #undef LOAD_MATRIX3
433 #undef LOAD_MATRIX4
434 #undef TRANSFORM_POSITION
435 #undef TRANSFORM_VECTOR
436 #undef LOAD_MATRIX_SCALAR
437 #undef TRANSFORM_POSITION_SCALAR
438 #undef TRANSFORM_VECTOR_SCALAR
439 }
440
441 #endif