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