File: mod_skeletal_animatevertices_sse.c

package info (click to toggle)
darkplaces 0~20180412~beta1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,200 kB
  • sloc: ansic: 176,886; makefile: 485; pascal: 455; perl: 372; objc: 245; sh: 102
file content (446 lines) | stat: -rw-r--r-- 16,215 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#include "mod_skeletal_animatevertices_sse.h"

#ifdef SSE_POSSIBLE

#ifdef MATRIX4x4_OPENGLORIENTATION
#error "SSE skeletal requires D3D matrix layout"
#endif

#include <xmmintrin.h>

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)
{
	// vertex weighted skeletal
	int i, k;
	int blends;
	matrix4x4_t *bonepose;
	matrix4x4_t *boneposerelative;
	const blendweights_t * RESTRICT weights;
	int num_vertices_minus_one;

	num_vertices_minus_one = model->surfmesh.num_vertices - 1;

	//unsigned long long ts = rdtsc();
	bonepose = (matrix4x4_t *) Mod_Skeletal_AnimateVertices_AllocBuffers(sizeof(matrix4x4_t) * (model->num_bones*2 + model->surfmesh.num_blends));
	boneposerelative = bonepose + model->num_bones;

	if (skeleton && !skeleton->relativetransforms)
		skeleton = NULL;

	// interpolate matrices
	if (skeleton)
	{
		for (i = 0;i < model->num_bones;i++)
		{
			const float * RESTRICT n = model->data_baseboneposeinverse + i * 12;
			matrix4x4_t * RESTRICT s = &skeleton->relativetransforms[i];
			matrix4x4_t * RESTRICT b = &bonepose[i];
			matrix4x4_t * RESTRICT r = &boneposerelative[i];
			__m128 b0, b1, b2, b3, r0, r1, r2, r3, nr;
			if (model->data_bones[i].parent >= 0)
			{
				const matrix4x4_t * RESTRICT p = &bonepose[model->data_bones[i].parent];
				__m128 s0 = _mm_loadu_ps(s->m[0]), s1 = _mm_loadu_ps(s->m[1]), s2 = _mm_loadu_ps(s->m[2]);
#ifdef OPENGLORIENTATION
				__m128 s3 = _mm_loadu_ps(s->m[3]);
#define SKELETON_MATRIX(r, c) _mm_shuffle_ps(s##c, s##c, _MM_SHUFFLE(r, r, r, r))
#else
#define SKELETON_MATRIX(r, c) _mm_shuffle_ps(s##r, s##r, _MM_SHUFFLE(c, c, c, c))
#endif
				__m128 pr = _mm_load_ps(p->m[0]);
				b0 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 0));
				b1 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 1));
				b2 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 2));
				b3 = _mm_mul_ps(pr, SKELETON_MATRIX(0, 3));
				pr = _mm_load_ps(p->m[1]);
				b0 = _mm_add_ps(b0, _mm_mul_ps(pr, SKELETON_MATRIX(1, 0)));
				b1 = _mm_add_ps(b1, _mm_mul_ps(pr, SKELETON_MATRIX(1, 1)));
				b2 = _mm_add_ps(b2, _mm_mul_ps(pr, SKELETON_MATRIX(1, 2)));
				b3 = _mm_add_ps(b3, _mm_mul_ps(pr, SKELETON_MATRIX(1, 3)));
				pr = _mm_load_ps(p->m[2]);
				b0 = _mm_add_ps(b0, _mm_mul_ps(pr, SKELETON_MATRIX(2, 0)));
				b1 = _mm_add_ps(b1, _mm_mul_ps(pr, SKELETON_MATRIX(2, 1)));
				b2 = _mm_add_ps(b2, _mm_mul_ps(pr, SKELETON_MATRIX(2, 2)));
				b3 = _mm_add_ps(b3, _mm_mul_ps(pr, SKELETON_MATRIX(2, 3)));
				b3 = _mm_add_ps(b3, _mm_load_ps(p->m[3]));
			}
			else
			{
				b0 = _mm_loadu_ps(s->m[0]);
				b1 = _mm_loadu_ps(s->m[1]);
				b2 = _mm_loadu_ps(s->m[2]);
				b3 = _mm_loadu_ps(s->m[3]);
#ifndef OPENGLORIENTATION
				_MM_TRANSPOSE4_PS(b0, b1, b2, b3);
#endif
			}
			_mm_store_ps(b->m[0], b0);
			_mm_store_ps(b->m[1], b1);
			_mm_store_ps(b->m[2], b2);
			_mm_store_ps(b->m[3], b3);
			nr = _mm_loadu_ps(n);
			r0 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0)));
			r1 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1)));
			r2 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2)));
			r3 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3)));
			nr = _mm_loadu_ps(n+4);
			r0 = _mm_add_ps(r0, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
			r1 = _mm_add_ps(r1, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
			r2 = _mm_add_ps(r2, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
			r3 = _mm_add_ps(r3, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
			nr = _mm_loadu_ps(n+8);
			r0 = _mm_add_ps(r0, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
			r1 = _mm_add_ps(r1, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
			r2 = _mm_add_ps(r2, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
			r3 = _mm_add_ps(r3, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
			r3 = _mm_add_ps(r3, b3);
			_mm_store_ps(r->m[0], r0);
			_mm_store_ps(r->m[1], r1);
			_mm_store_ps(r->m[2], r2);
			_mm_store_ps(r->m[3], r3);
		}
	}
	else
	{
		for (i = 0;i < model->num_bones;i++)
		{
			float m[12];
			const short * RESTRICT firstpose7s = model->data_poses7s + 7 * (frameblend[0].subframe * model->num_bones + i);
			float firstlerp = frameblend[0].lerp,
				firsttx = firstpose7s[0], firstty = firstpose7s[1], firsttz = firstpose7s[2],
				rx = firstpose7s[3] * firstlerp,
				ry = firstpose7s[4] * firstlerp,
				rz = firstpose7s[5] * firstlerp,
				rw = firstpose7s[6] * firstlerp,
				dx = firsttx*rw + firstty*rz - firsttz*ry,
				dy = -firsttx*rz + firstty*rw + firsttz*rx,
				dz = firsttx*ry - firstty*rx + firsttz*rw,
				dw = -firsttx*rx - firstty*ry - firsttz*rz,
				scale, sx, sy, sz, sw;
			for (blends = 1;blends < MAX_FRAMEBLENDS && frameblend[blends].lerp > 0;blends++)
			{
				const short * RESTRICT blendpose7s = model->data_poses7s + 7 * (frameblend[blends].subframe * model->num_bones + i);
				float blendlerp = frameblend[blends].lerp,
					blendtx = blendpose7s[0], blendty = blendpose7s[1], blendtz = blendpose7s[2],
					qx = blendpose7s[3], qy = blendpose7s[4], qz = blendpose7s[5], qw = blendpose7s[6];
				if(rx*qx + ry*qy + rz*qz + rw*qw < 0) blendlerp = -blendlerp;
				qx *= blendlerp;
				qy *= blendlerp;
				qz *= blendlerp;
				qw *= blendlerp;
				rx += qx;
				ry += qy;
				rz += qz;
				rw += qw;
				dx += blendtx*qw + blendty*qz - blendtz*qy;
				dy += -blendtx*qz + blendty*qw + blendtz*qx;
				dz += blendtx*qy - blendty*qx + blendtz*qw;
				dw += -blendtx*qx - blendty*qy - blendtz*qz;
			}
			scale = 1.0f / (rx*rx + ry*ry + rz*rz + rw*rw);
			sx = rx * scale;
			sy = ry * scale;
			sz = rz * scale;
			sw = rw * scale;
			m[0] = sw*rw + sx*rx - sy*ry - sz*rz;
			m[1] = 2*(sx*ry - sw*rz);
			m[2] = 2*(sx*rz + sw*ry);
			m[3] = model->num_posescale*(dx*sw - dy*sz + dz*sy - dw*sx);
			m[4] = 2*(sx*ry + sw*rz);
			m[5] = sw*rw + sy*ry - sx*rx - sz*rz;
			m[6] = 2*(sy*rz - sw*rx);
			m[7] = model->num_posescale*(dx*sz + dy*sw - dz*sx - dw*sy);
			m[8] = 2*(sx*rz - sw*ry);
			m[9] = 2*(sy*rz + sw*rx);
			m[10] = sw*rw + sz*rz - sx*rx - sy*ry;
			m[11] = model->num_posescale*(dy*sx + dz*sw - dx*sy - dw*sz);
			if (i == r_skeletal_debugbone.integer)
				m[r_skeletal_debugbonecomponent.integer % 12] += r_skeletal_debugbonevalue.value;
			m[3] *= r_skeletal_debugtranslatex.value;
			m[7] *= r_skeletal_debugtranslatey.value;
			m[11] *= r_skeletal_debugtranslatez.value;
			{
				const float * RESTRICT n = model->data_baseboneposeinverse + i * 12;
				matrix4x4_t * RESTRICT b = &bonepose[i];
				matrix4x4_t * RESTRICT r = &boneposerelative[i];
				__m128 b0, b1, b2, b3, r0, r1, r2, r3, nr;
				if (model->data_bones[i].parent >= 0)
				{
					const matrix4x4_t * RESTRICT p = &bonepose[model->data_bones[i].parent];
					__m128 pr = _mm_load_ps(p->m[0]);
					b0 = _mm_mul_ps(pr, _mm_set1_ps(m[0]));
					b1 = _mm_mul_ps(pr, _mm_set1_ps(m[1]));
					b2 = _mm_mul_ps(pr, _mm_set1_ps(m[2]));
					b3 = _mm_mul_ps(pr, _mm_set1_ps(m[3]));
					pr = _mm_load_ps(p->m[1]);
					b0 = _mm_add_ps(b0, _mm_mul_ps(pr, _mm_set1_ps(m[4])));
					b1 = _mm_add_ps(b1, _mm_mul_ps(pr, _mm_set1_ps(m[5])));
					b2 = _mm_add_ps(b2, _mm_mul_ps(pr, _mm_set1_ps(m[6])));
					b3 = _mm_add_ps(b3, _mm_mul_ps(pr, _mm_set1_ps(m[7])));
					pr = _mm_load_ps(p->m[2]);
					b0 = _mm_add_ps(b0, _mm_mul_ps(pr, _mm_set1_ps(m[8])));
					b1 = _mm_add_ps(b1, _mm_mul_ps(pr, _mm_set1_ps(m[9])));
					b2 = _mm_add_ps(b2, _mm_mul_ps(pr, _mm_set1_ps(m[10])));
					b3 = _mm_add_ps(b3, _mm_mul_ps(pr, _mm_set1_ps(m[11])));
					b3 = _mm_add_ps(b3, _mm_load_ps(p->m[3]));
				}
				else
				{
					b0 = _mm_setr_ps(m[0], m[4], m[8], 0.0f);
					b1 = _mm_setr_ps(m[1], m[5], m[9], 0.0f);
					b2 = _mm_setr_ps(m[2], m[6], m[10], 0.0f);
					b3 = _mm_setr_ps(m[3], m[7], m[11], 1.0f);
				}
				_mm_store_ps(b->m[0], b0);
				_mm_store_ps(b->m[1], b1);
				_mm_store_ps(b->m[2], b2);
				_mm_store_ps(b->m[3], b3);
				nr = _mm_loadu_ps(n);
				r0 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0)));
				r1 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1)));
				r2 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2)));
				r3 = _mm_mul_ps(b0, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3)));
				nr = _mm_loadu_ps(n+4);
				r0 = _mm_add_ps(r0, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
				r1 = _mm_add_ps(r1, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
				r2 = _mm_add_ps(r2, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
				r3 = _mm_add_ps(r3, _mm_mul_ps(b1, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
				nr = _mm_loadu_ps(n+8);
				r0 = _mm_add_ps(r0, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(0, 0, 0, 0))));
				r1 = _mm_add_ps(r1, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(1, 1, 1, 1))));
				r2 = _mm_add_ps(r2, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(2, 2, 2, 2))));
				r3 = _mm_add_ps(r3, _mm_mul_ps(b2, _mm_shuffle_ps(nr, nr, _MM_SHUFFLE(3, 3, 3, 3))));
				r3 = _mm_add_ps(r3, b3);
				_mm_store_ps(r->m[0], r0);
				_mm_store_ps(r->m[1], r1);
				_mm_store_ps(r->m[2], r2);
				_mm_store_ps(r->m[3], r3);
			}	
		}
	}

	// generate matrices for all blend combinations
	weights = model->surfmesh.data_blendweights;
	for (i = 0;i < model->surfmesh.num_blends;i++, weights++)
	{
		float * RESTRICT b = &boneposerelative[model->num_bones + i].m[0][0];
		const float * RESTRICT m = &boneposerelative[weights->index[0]].m[0][0];
		float f = weights->influence[0] * (1.0f / 255.0f);
		__m128 fv = _mm_set_ps1(f);
		__m128 b0 = _mm_load_ps(m);
		__m128 b1 = _mm_load_ps(m+4);
		__m128 b2 = _mm_load_ps(m+8);
		__m128 b3 = _mm_load_ps(m+12);
		__m128 m0, m1, m2, m3;
		b0 = _mm_mul_ps(b0, fv);
		b1 = _mm_mul_ps(b1, fv);
		b2 = _mm_mul_ps(b2, fv);
		b3 = _mm_mul_ps(b3, fv);
		for (k = 1;k < 4 && weights->influence[k];k++)
		{
			m = &boneposerelative[weights->index[k]].m[0][0];
			f = weights->influence[k] * (1.0f / 255.0f);
			fv = _mm_set_ps1(f);
			m0 = _mm_load_ps(m);
			m1 = _mm_load_ps(m+4);
			m2 = _mm_load_ps(m+8);
			m3 = _mm_load_ps(m+12);
			m0 = _mm_mul_ps(m0, fv);
			m1 = _mm_mul_ps(m1, fv);
			m2 = _mm_mul_ps(m2, fv);
			m3 = _mm_mul_ps(m3, fv);
			b0 = _mm_add_ps(m0, b0);
			b1 = _mm_add_ps(m1, b1);
			b2 = _mm_add_ps(m2, b2);
			b3 = _mm_add_ps(m3, b3);
		}
		_mm_store_ps(b, b0);
		_mm_store_ps(b+4, b1);
		_mm_store_ps(b+8, b2);
		_mm_store_ps(b+12, b3);
	}

#define LOAD_MATRIX_SCALAR() const float * RESTRICT m = &boneposerelative[*b].m[0][0]

#define LOAD_MATRIX3() \
	const float * RESTRICT m = &boneposerelative[*b].m[0][0]; \
	/* bonepose array is 16 byte aligned */ \
	__m128 m1 = _mm_load_ps((m)); \
	__m128 m2 = _mm_load_ps((m)+4); \
	__m128 m3 = _mm_load_ps((m)+8);
#define LOAD_MATRIX4() \
	const float * RESTRICT m = &boneposerelative[*b].m[0][0]; \
	/* bonepose array is 16 byte aligned */ \
	__m128 m1 = _mm_load_ps((m)); \
	__m128 m2 = _mm_load_ps((m)+4); \
	__m128 m3 = _mm_load_ps((m)+8); \
	__m128 m4 = _mm_load_ps((m)+12)

	/* Note that matrix is 4x4 and transposed compared to non-USE_SSE codepath */
#define TRANSFORM_POSITION_SCALAR(in, out) \
	(out)[0] = ((in)[0] * m[0] + (in)[1] * m[4] + (in)[2] * m[ 8] + m[12]); \
	(out)[1] = ((in)[0] * m[1] + (in)[1] * m[5] + (in)[2] * m[ 9] + m[13]); \
	(out)[2] = ((in)[0] * m[2] + (in)[1] * m[6] + (in)[2] * m[10] + m[14]);
#define TRANSFORM_VECTOR_SCALAR(in, out) \
	(out)[0] = ((in)[0] * m[0] + (in)[1] * m[4] + (in)[2] * m[ 8]); \
	(out)[1] = ((in)[0] * m[1] + (in)[1] * m[5] + (in)[2] * m[ 9]); \
	(out)[2] = ((in)[0] * m[2] + (in)[1] * m[6] + (in)[2] * m[10]);

#define TRANSFORM_POSITION(in, out) { \
		__m128 pin = _mm_loadu_ps(in); /* we ignore the value in the last element (x from the next vertex) */ \
		__m128 x = _mm_shuffle_ps(pin, pin, 0x0); \
		__m128 t1 = _mm_mul_ps(x, m1); \
		\
		/* y, + x */ \
		__m128 y = _mm_shuffle_ps(pin, pin, 0x55); \
		__m128 t2 = _mm_mul_ps(y, m2); \
		__m128 t3 = _mm_add_ps(t1, t2); \
		\
		/* z, + (y+x) */ \
		__m128 z = _mm_shuffle_ps(pin, pin, 0xaa); \
		__m128 t4 = _mm_mul_ps(z, m3); \
		__m128 t5 = _mm_add_ps(t3, t4); \
		\
		/* + m3 */ \
		__m128 pout = _mm_add_ps(t5, m4); \
		_mm_storeu_ps((out), pout); \
	}

#define TRANSFORM_VECTOR(in, out) { \
		__m128 vin = _mm_loadu_ps(in); \
		\
		/* x */ \
		__m128 x = _mm_shuffle_ps(vin, vin, 0x0); \
		__m128 t1 = _mm_mul_ps(x, m1); \
		\
		/* y, + x */ \
		__m128 y = _mm_shuffle_ps(vin, vin, 0x55); \
		__m128 t2 = _mm_mul_ps(y, m2); \
		__m128 t3 = _mm_add_ps(t1, t2); \
		\
		/* nz, + (ny + nx) */ \
		__m128 z = _mm_shuffle_ps(vin, vin, 0xaa); \
		__m128 t4 = _mm_mul_ps(z, m3); \
		__m128 vout = _mm_add_ps(t3, t4); \
		_mm_storeu_ps((out), vout); \
	}

	// transform vertex attributes by blended matrices
	if (vertex3f)
	{
		const float * RESTRICT v = model->surfmesh.data_vertex3f;
		const unsigned short * RESTRICT b = model->surfmesh.blends;
		// special case common combinations of attributes to avoid repeated loading of matrices
		if (normal3f)
		{
			const float * RESTRICT n = model->surfmesh.data_normal3f;
			if (svector3f && tvector3f)
			{
				const float * RESTRICT svec = model->surfmesh.data_svector3f;
				const float * RESTRICT tvec = model->surfmesh.data_tvector3f;

				// Note that for SSE each iteration stores one element past end, so we break one vertex short
				// and handle that with scalars in that case
				for (i = 0; i < num_vertices_minus_one; i++, v += 3, n += 3, svec += 3, tvec += 3, b++,
						vertex3f += 3, normal3f += 3, svector3f += 3, tvector3f += 3)
				{
					LOAD_MATRIX4();
					TRANSFORM_POSITION(v, vertex3f);
					TRANSFORM_VECTOR(n, normal3f);
					TRANSFORM_VECTOR(svec, svector3f);
					TRANSFORM_VECTOR(tvec, tvector3f);
				}

				// Last vertex needs to be done with scalars to avoid reading/writing 1 word past end of arrays
				{
					LOAD_MATRIX_SCALAR();
					TRANSFORM_POSITION_SCALAR(v, vertex3f);
					TRANSFORM_VECTOR_SCALAR(n, normal3f);
					TRANSFORM_VECTOR_SCALAR(svec, svector3f);
					TRANSFORM_VECTOR_SCALAR(tvec, tvector3f);
				}
				//printf("elapsed ticks: %llu\n", rdtsc() - ts); // XXX
				return;
			}

			for (i = 0;i < num_vertices_minus_one; i++, v += 3, n += 3, b++, vertex3f += 3, normal3f += 3)
			{
				LOAD_MATRIX4();
				TRANSFORM_POSITION(v, vertex3f);
				TRANSFORM_VECTOR(n, normal3f);
			}
			{
				LOAD_MATRIX_SCALAR();
				TRANSFORM_POSITION_SCALAR(v, vertex3f);
				TRANSFORM_VECTOR_SCALAR(n, normal3f);
			}
		}
		else
		{
			for (i = 0;i < num_vertices_minus_one; i++, v += 3, b++, vertex3f += 3)
			{
				LOAD_MATRIX4();
				TRANSFORM_POSITION(v, vertex3f);
			}
			{
				LOAD_MATRIX_SCALAR();
				TRANSFORM_POSITION_SCALAR(v, vertex3f);
			}
		}
	}

	else if (normal3f)
	{
		const float * RESTRICT n = model->surfmesh.data_normal3f;
		const unsigned short * RESTRICT b = model->surfmesh.blends;
		for (i = 0; i < num_vertices_minus_one; i++, n += 3, b++, normal3f += 3)
		{
			LOAD_MATRIX3();
			TRANSFORM_VECTOR(n, normal3f);
		}
		{
			LOAD_MATRIX_SCALAR();
			TRANSFORM_VECTOR_SCALAR(n, normal3f);
		}
	}

	if (svector3f)
	{
		const float * RESTRICT svec = model->surfmesh.data_svector3f;
		const unsigned short * RESTRICT b = model->surfmesh.blends;
		for (i = 0; i < num_vertices_minus_one; i++, svec += 3, b++, svector3f += 3)
		{
			LOAD_MATRIX3();
			TRANSFORM_VECTOR(svec, svector3f);
		}
		{
			LOAD_MATRIX_SCALAR();
			TRANSFORM_VECTOR_SCALAR(svec, svector3f);
		}
	}

	if (tvector3f)
	{
		const float * RESTRICT tvec = model->surfmesh.data_tvector3f;
		const unsigned short * RESTRICT b = model->surfmesh.blends;
		for (i = 0; i < num_vertices_minus_one; i++, tvec += 3, b++, tvector3f += 3)
		{
			LOAD_MATRIX3();
			TRANSFORM_VECTOR(tvec, tvector3f);
		}
		{
			LOAD_MATRIX_SCALAR();
			TRANSFORM_VECTOR_SCALAR(tvec, tvector3f);
		}
	}

#undef LOAD_MATRIX3
#undef LOAD_MATRIX4
#undef TRANSFORM_POSITION
#undef TRANSFORM_VECTOR
#undef LOAD_MATRIX_SCALAR
#undef TRANSFORM_POSITION_SCALAR
#undef TRANSFORM_VECTOR_SCALAR
}

#endif