Project Ne10
An open, optimized software library for the ARM architecture.
NE10_invmat.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011-16 ARM Limited and Contributors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ARM Limited nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * NE10 Library : math/NE10_invmat.c
30  */
31 
32 #include "NE10_types.h"
33 #include "macros.h"
34 #include "NE10_detmat.c.h"
35 #include <math.h>
36 
37 #include <assert.h>
38 
39 // This macro is used to determine floating point values that are small enough to be consiedered nearly zero
40 #define IS_FLOAT_NEAR_ZERO(x) ( ((fabs(x))<(1e-12)) ? 1 : 0 )
41 
43 {
44  ne10_float32_t det = 0.0f;
45 
47  for ( unsigned int itr = 0; itr < count; itr++ )
48  {
49  det = DET2x2 (&src[ itr ]);
50 
51  if (1 == IS_FLOAT_NEAR_ZERO (det))
52  {
53  det = 1.0f;
54  }
55 
56  det = 1.0f / det;
57  dst[ itr ].c1.r1 = det * src[ itr ].c2.r2;
58  dst[ itr ].c1.r2 = -1 * det * src[ itr ].c1.r2;
59  dst[ itr ].c2.r1 = -1 * det * src[ itr ].c2.r1;
60  dst[ itr ].c2.r2 = det * src[ itr ].c1.r1;
61  }
62  return NE10_OK;
63 }
64 
66 {
67 #define aa (src[ itr ].c1.r1)
68 #define bb (src[ itr ].c1.r2)
69 #define cc (src[ itr ].c1.r3)
70 #define dd (src[ itr ].c2.r1)
71 #define ee (src[ itr ].c2.r2)
72 #define ff (src[ itr ].c2.r3)
73 #define gg (src[ itr ].c3.r1)
74 #define hh (src[ itr ].c3.r2)
75 #define ii (src[ itr ].c3.r3)
76 
77  ne10_float32_t det = 0.0f;
78  ne10_mat2x2f_t A, B, C, D, E, F, G, H, I;
79 
81  for ( unsigned int itr = 0; itr < count; itr++ )
82  {
83  det = DET3x3 (&src[ itr ]);
84 
85  if (1 == IS_FLOAT_NEAR_ZERO (det))
86  {
87  det = 1.0f;
88  }
89  det = 1.0f / det;
90 
91  // Calculate the coefficients
92  createColumnMajorMatrix2x2 (&A, ee, ff, hh, ii);
93  createColumnMajorMatrix2x2 (&B, dd, ff, gg, ii);
94  createColumnMajorMatrix2x2 (&C, dd, ee, gg, hh);
95  createColumnMajorMatrix2x2 (&D, bb, cc, hh, ii);
96  createColumnMajorMatrix2x2 (&E, aa, cc, gg, ii);
97  createColumnMajorMatrix2x2 (&F, aa, bb, gg, hh);
98  createColumnMajorMatrix2x2 (&G, bb, cc, ee, ff);
99  createColumnMajorMatrix2x2 (&H, aa, cc, dd, ff);
100  createColumnMajorMatrix2x2 (&I, aa, bb, dd, ee);
101 
102  dst[ itr ].c1.r1 = det * DET2x2 (&A);
103  dst[ itr ].c1.r2 = -1.0f * det * DET2x2 (&D);
104  dst[ itr ].c1.r3 = det * DET2x2 (&G);
105 
106  dst[ itr ].c2.r1 = -1.0f * det * DET2x2 (&B);
107  dst[ itr ].c2.r2 = det * DET2x2 (&E);
108  dst[ itr ].c2.r3 = -1.0f * det * DET2x2 (&H);
109 
110  dst[ itr ].c3.r1 = det * DET2x2 (&C);
111  dst[ itr ].c3.r2 = -1.0f * det * DET2x2 (&F);
112  dst[ itr ].c3.r3 = det * DET2x2 (&I);
113  }
114  return NE10_OK;
115 
116 #undef aa
117 #undef bb
118 #undef cc
119 #undef dd
120 #undef ee
121 #undef ff
122 #undef gg
123 #undef hh
124 #undef ii
125 }
126 
128 {
129 #define aa (src[ itr ].c1.r1)
130 #define bb (src[ itr ].c1.r2)
131 #define cc (src[ itr ].c1.r3)
132 #define dd (src[ itr ].c1.r4)
133 
134 #define ee (src[ itr ].c2.r1)
135 #define ff (src[ itr ].c2.r2)
136 #define gg (src[ itr ].c2.r3)
137 #define hh (src[ itr ].c2.r4)
138 
139 #define ii (src[ itr ].c3.r1)
140 #define jj (src[ itr ].c3.r2)
141 #define kk (src[ itr ].c3.r3)
142 #define ll (src[ itr ].c3.r4)
143 
144 #define mm (src[ itr ].c4.r1)
145 #define nn (src[ itr ].c4.r2)
146 #define oo (src[ itr ].c4.r3)
147 #define pp (src[ itr ].c4.r4)
148 
149  ne10_float32_t det = 0.0f;
150  ne10_mat3x3f_t A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P;
151 
153  for ( unsigned int itr = 0; itr < count; itr++ )
154  {
155  det = DET4x4 (&src[ itr ]);
156 
157  if (1 == IS_FLOAT_NEAR_ZERO (det))
158  {
159  det = 1.0f;
160  }
161  det = 1.0f / det;
162 
163  // Calculate the coefficients
164  createColumnMajorMatrix3x3 (&A, ff, gg, hh, jj, kk, ll, nn, oo, pp);
165  createColumnMajorMatrix3x3 (&B, ee, gg, hh, ii, kk, ll, mm, oo, pp);
166  createColumnMajorMatrix3x3 (&C, ee, ff, hh, ii, jj, ll, mm, nn, pp);
167  createColumnMajorMatrix3x3 (&D, ee, ff, gg, ii, jj, kk, mm, nn, oo);
168  createColumnMajorMatrix3x3 (&E, bb, cc, dd, jj, kk, ll, nn, oo, pp);
169  createColumnMajorMatrix3x3 (&F, aa, cc, dd, ii, kk, ll, mm, oo, pp);
170  createColumnMajorMatrix3x3 (&G, aa, bb, dd, ii, jj, ll, mm, nn, pp);
171  createColumnMajorMatrix3x3 (&H, aa, bb, cc, ii, jj, kk, mm, nn, oo);
172  createColumnMajorMatrix3x3 (&I, bb, cc, dd, ff, gg, hh, nn, oo, pp);
173  createColumnMajorMatrix3x3 (&J, aa, cc, dd, ee, gg, hh, mm, oo, pp);
174  createColumnMajorMatrix3x3 (&K, aa, bb, dd, ee, ff, hh, mm, nn, pp);
175  createColumnMajorMatrix3x3 (&L, aa, bb, cc, ee, ff, gg, mm, nn, oo);
176  createColumnMajorMatrix3x3 (&M, bb, cc, dd, ff, gg, hh, jj, kk, ll);
177  createColumnMajorMatrix3x3 (&N, aa, cc, dd, ee, gg, hh, ii, kk, ll);
178  createColumnMajorMatrix3x3 (&O, aa, bb, dd, ee, ff, hh, ii, jj, ll);
179  createColumnMajorMatrix3x3 (&P, aa, bb, cc, ee, ff, gg, ii, jj, kk);
180 
181 
182  dst[ itr ].c1.r1 = det * DET3x3 (&A);
183  dst[ itr ].c1.r2 = -1.0f * det * DET3x3 (&E);
184  dst[ itr ].c1.r3 = det * DET3x3 (&I);
185  dst[ itr ].c1.r4 = -1.0f * det * DET3x3 (&M);
186 
187  dst[ itr ].c2.r1 = -1.0f * det * DET3x3 (&B);
188  dst[ itr ].c2.r2 = det * DET3x3 (&F);
189  dst[ itr ].c2.r3 = -1.0f * det * DET3x3 (&J);
190  dst[ itr ].c2.r4 = det * DET3x3 (&N);
191 
192  dst[ itr ].c3.r1 = det * DET3x3 (&C);
193  dst[ itr ].c3.r2 = -1.0f * det * DET3x3 (&G);
194  dst[ itr ].c3.r3 = det * DET3x3 (&K);
195  dst[ itr ].c3.r4 = -1.0f * det * DET3x3 (&O);
196 
197  dst[ itr ].c4.r1 = -1.0f * det * DET3x3 (&D);
198  dst[ itr ].c4.r2 = det * DET3x3 (&H);
199  dst[ itr ].c4.r3 = -1.0f * det * DET3x3 (&L);
200  dst[ itr ].c4.r4 = det * DET3x3 (&P);
201  }
202  return NE10_OK;
203 
204 #undef aa
205 #undef bb
206 #undef cc
207 #undef dd
208 #undef ee
209 #undef ff
210 #undef gg
211 #undef hh
212 #undef ii
213 #undef jj
214 #undef kk
215 #undef ll
216 #undef mm
217 #undef nn
218 #undef oo
219 #undef pp
220 }
ne10_float32_t r2
Definition: NE10_types.h:145
#define hh
ne10_mat_row4f c1
Definition: NE10_types.h:187
#define mm
#define bb
#define ee
modules NE10_init c I
Definition: CMakeLists.txt:43
float ne10_float32_t
Definition: NE10_types.h:80
#define jj
ne10_mat_row3f c3
Definition: NE10_types.h:153
#define ll
ne10_float32_t r1
Definition: NE10_types.h:144
#define ii
ne10_mat_row4f c4
Definition: NE10_types.h:190
#define ff
uint32_t ne10_uint32_t
Definition: NE10_types.h:77
#define dd
#define nn
#define kk
ne10_float32_t r3
Definition: NE10_types.h:181
ne10_mat_row2f c2
Definition: NE10_types.h:127
ne10_mat_row4f c2
Definition: NE10_types.h:188
#define gg
ne10_float32_t r3
Definition: NE10_types.h:146
ne10_float32_t r2
Definition: NE10_types.h:180
ne10_mat_row4f c3
Definition: NE10_types.h:189
ne10_result_t ne10_invmat_4x4f_c(ne10_mat4x4f_t *dst, ne10_mat4x4f_t *src, ne10_uint32_t count)
Specific implementation of ne10_invmat_4x4f using plain C code.
Definition: NE10_invmat.c:127
#define aa
ne10_float32_t r2
Definition: NE10_types.h:121
#define NE10_OK
Definition: NE10_types.h:65
#define oo
ne10_result_t ne10_invmat_3x3f_c(ne10_mat3x3f_t *dst, ne10_mat3x3f_t *src, ne10_uint32_t count)
Specific implementation of ne10_invmat_3x3f using plain C code.
Definition: NE10_invmat.c:65
#define pp
#define IS_FLOAT_NEAR_ZERO(x)
Definition: NE10_invmat.c:40
ne10_float32_t r1
Definition: NE10_types.h:120
ne10_mat_row3f c1
Definition: NE10_types.h:151
ne10_mat_row2f c1
Definition: NE10_types.h:126
#define NE10_CHECKPOINTER_DstSrc
Definition: factor.h:56
ne10_float32_t r4
Definition: NE10_types.h:182
int ne10_result_t
Definition: NE10_types.h:82
ne10_float32_t r1
Definition: NE10_types.h:179
#define cc
ne10_result_t ne10_invmat_2x2f_c(ne10_mat2x2f_t *dst, ne10_mat2x2f_t *src, ne10_uint32_t count)
Specific implementation of ne10_invmat_2x2f using plain C code.
Definition: NE10_invmat.c:42
ne10_mat_row3f c2
Definition: NE10_types.h:152