annotate dmvecmat.h @ 269:159264c27929

Add some new vector and matrix operations, and introduce some SSE inline assembler optimized versions.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 10 Oct 2012 16:35:43 +0300
parents 00785510b743
children 4d42b8910d7e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Vector and matrix functions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2011 Tecnic Software productions (TNSP)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #ifndef DMVECMAT_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define DMVECMAT_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
239
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
11 #include <math.h>
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
12
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 extern "C" {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
239
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
17 #define DM_MATRIX_SIZE (4)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
239
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
21 DMFloat x, y, z, W;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 } DMVector;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 DMFloat m[DM_MATRIX_SIZE][DM_MATRIX_SIZE];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 } DMMatrix;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
269
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
29
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
30 void dm_vector_add_n(DMVector *dst, const DMVector *src, const int nlist);
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
31 void dm_vector_add_r_n(DMVector *dst, const DMVector *src1, const DMVector *src2, const int nlist);
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
32 void dm_vector_sub_n(DMVector *dst, const DMVector *src, const int nlist);
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
33 void dm_vector_sub_r_n(DMVector *dst, const DMVector *src1, const DMVector *src2, const int nlist);
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
34
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
35 void dm_vector_mul_by_mat(DMVector *vd, const DMVector *vs, const DMMatrix *mat);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 void dm_vector_mul_by_mat_n(DMVector *list, const int nlist, const DMMatrix *mat);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 void dm_matrix_unit(DMMatrix *mat);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 void dm_matrix_transpose(DMMatrix *mat1, const DMMatrix *mat2);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 void dm_matrix_mul(DMMatrix *mat1, const DMMatrix *mat2);
269
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
42 void dm_matrix_mul_r(DMMatrix *dst, const DMMatrix *mat1, const DMMatrix *mat2);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 void dm_matrix_mul_n(DMMatrix *list, const int nlist, const DMMatrix *mat);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 void dm_matrix_rot(DMMatrix *mat,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 const DMFloat sx, const DMFloat sy, const DMFloat sz,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 const DMFloat cx, const DMFloat cy, const DMFloat cz);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
239
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
49
269
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
50 /* Basic vector operations
159264c27929 Add some new vector and matrix operations, and introduce some SSE inline
Matti Hamalainen <ccr@tnsp.org>
parents: 244
diff changeset
51 */
244
00785510b743 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 239
diff changeset
52 static inline void dm_vector_copy(DMVector *vd, const DMVector *vs)
239
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
53 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
54 memcpy(vd, vs, sizeof(DMVector));
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
55 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
57
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
58 static inline void dm_vector_add(DMVector *vr, const DMVector *v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
59 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
60 #ifdef DM_USE_SIMD
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
61 asm("movups %2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
62 "movups %1, %%xmm2\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
63 "addps %%xmm2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
64 "movups %%xmm1, %0\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
65 : "=m" (*vr)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
66 : "m" (*vr), "m" (*v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
67 : "memory", "%xmm1", "%xmm2");
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
68 #else
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
69 vr->x += v2->x;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
70 vr->y += v2->y;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
71 vr->z += v2->z;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
72 #endif
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
73 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
74
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
75
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
76 static inline void dm_vector_add_r(DMVector *vr, const DMVector *v1, const DMVector *v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
77 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
78 #ifdef DM_USE_SIMD
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
79 asm("movups %2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
80 "movups %1, %%xmm2\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
81 "addps %%xmm2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
82 "movups %%xmm1, %0\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
83 : "=m" (*vr)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
84 : "m" (*v1), "m" (*v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
85 : "memory", "%xmm1", "%xmm2");
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
86 #else
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
87 vr->x = v1->x + v2->x;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
88 vr->y = v1->y + v2->y;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
89 vr->z = v1->z + v2->z;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
90 #endif
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
91 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
92
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
93
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
94 static inline void dm_vector_sub(DMVector *vr, const DMVector *v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
95 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
96 #ifdef DM_USE_SIMD
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
97 asm("movups %2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
98 "movups %1, %%xmm2\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
99 "subps %%xmm2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
100 "movups %%xmm1, %0\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
101 : "=m" (*vr)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
102 : "m" (*vr), "m" (*v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
103 : "memory", "%xmm1", "%xmm2");
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
104 #else
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
105 vr->x -= v2->x;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
106 vr->y -= v2->y;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
107 vr->z -= v2->z;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
108 #endif
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
109 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
110
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
111
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
112 static inline void dm_vector_sub_r(DMVector *vr, const DMVector *v1, const DMVector *v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
113 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
114 #ifdef DM_USE_SIMD
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
115 asm("movups %2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
116 "movups %1, %%xmm2\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
117 "subps %%xmm2, %%xmm1\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
118 "movups %%xmm1, %0\n"
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
119 : "=m" (*vr)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
120 : "m" (*v1), "m" (*v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
121 : "memory", "%xmm1", "%xmm2");
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
122 #else
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
123 vr->x = v1->x - v2->x;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
124 vr->y = v1->y - v2->y;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
125 vr->z = v1->z - v2->z;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
126 #endif
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
127 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
128
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
129
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
130 /* Returns dot-product of two given vectors
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
131 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
132 static inline DMFloat dm_vector_dot(const DMVector *v1, const DMVector *v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
133 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
134 return (v1->x * v2->x) + (v1->y * v2->y) + (v1->z * v2->z);
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
135 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
136
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
137
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
138 /* Return vector length
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
139 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
140 static inline DMFloat dm_vector_length(const DMVector *vs)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
141 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
142 return sqrt((vs->x * vs->x) + (vs->y * vs->y) + (vs->z * vs->z));
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
143 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
144
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
145
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
146 /* Normalize vector
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
147 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
148 static inline void dm_vector_normalize(DMVector *vec)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
149 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
150 DMFloat l = dm_vector_length(vec);
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
151
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
152 if (l > 0.0f)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
153 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
154 l = 1.0f / l;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
155 vec->x *= l;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
156 vec->y *= l;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
157 vec->z *= l;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
158 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
159 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
160
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
161
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
162 /* Scale given vector
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
163 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
164 static inline void dm_vector_scale(DMVector * vec, const DMFloat k)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
165 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
166 vec->x *= k;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 vec->y *= k;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
168 vec->z *= k;
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
169 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
170
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
171
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
172 /* Returns cross-product of two given vectors
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
173 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
174 static inline void dm_vector_cross(DMVector *vr, const DMVector *v1, const DMVector *v2)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
175 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
176 vr->x = (v1->y * v2->z) - (v1->z * v2->y);
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
177 vr->y = (v1->z * v2->x) - (v1->x * v2->z);
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
178 vr->z = (v1->x * v2->y) - (v1->y * v2->x);
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
179 }
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
180
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
181
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
182 /* Make rotation matrix from given angles (radians)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
183 */
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
184 static inline void dm_matrix_rot_a(DMMatrix *mat, const DMFloat ax, const DMFloat ay, const DMFloat az)
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
185 {
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
186 dm_matrix_rot(mat, sin(ax), sin(ay), sin(az), cos(ax), cos(ay), cos(az));
07c4f1a7ddc6 Make DMVector 16 bytes in size (4 floats), add SSE optimizations, move some
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
187 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 #endif // DMVECMAT_H