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