auto import from //depot/cupcake/@135843
[android/platform/external/neven.git] / Embedded / common / src / b_TensorEm / Flt16Alt3D.c
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /* ---- includes ----------------------------------------------------------- */
18
19 #include "b_TensorEm/Flt16Alt3D.h"
20 #include "b_BasicEm/Math.h"
21 #include "b_BasicEm/Memory.h"
22 #include "b_BasicEm/Functions.h"
23
24 /* ------------------------------------------------------------------------- */
25
26 /* ========================================================================= */
27 /*                                                                           */
28 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
29 /*                                                                           */
30 /* ========================================================================= */
31
32 /* ------------------------------------------------------------------------- */
33
34 /* ========================================================================= */
35 /*                                                                           */
36 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
37 /*                                                                           */
38 /* ========================================================================= */
39
40 /* ------------------------------------------------------------------------- */
41
42 void bts_Flt16Alt3D_init( struct bts_Flt16Alt3D* ptrA )
43 {
44         bts_Flt16Mat3D_init( &ptrA->matE );
45         bts_Flt16Vec3D_init( &ptrA->vecE );
46 }
47
48 /* ------------------------------------------------------------------------- */
49
50 void bts_Flt16Alt3D_exit( struct bts_Flt16Alt3D* ptrA )
51 {
52         bts_Flt16Mat3D_exit( &ptrA->matE );
53         bts_Flt16Vec3D_exit( &ptrA->vecE );
54 }
55
56 /* ------------------------------------------------------------------------- */
57
58 /* ========================================================================= */
59 /*                                                                           */
60 /* ---- \ghd{ operators } -------------------------------------------------- */
61 /*                                                                           */
62 /* ========================================================================= */
63
64 /* ------------------------------------------------------------------------- */
65
66 /* ========================================================================= */
67 /*                                                                           */
68 /* ---- \ghd{ query functions } -------------------------------------------- */
69 /*                                                                           */
70 /* ========================================================================= */
71
72 /* ------------------------------------------------------------------------- */
73
74 /* ========================================================================= */
75 /*                                                                           */
76 /* ---- \ghd{ modify functions } ------------------------------------------- */
77 /*                                                                           */
78 /* ========================================================================= */
79
80 /* ------------------------------------------------------------------------- */
81         
82 /* ========================================================================= */
83 /*                                                                           */
84 /* ---- \ghd{ I/O } -------------------------------------------------------- */
85 /*                                                                           */
86 /* ========================================================================= */
87
88 /* ------------------------------------------------------------------------- */
89         
90 uint32 bts_Flt16Alt3D_memSize( struct bbs_Context* cpA,
91                                                            const struct bts_Flt16Alt3D *ptrA )
92 {
93         bbs_ERROR0( "unimplemented function" );
94         return 0;
95 }
96
97 /* ------------------------------------------------------------------------- */
98         
99 uint32 bts_Flt16Alt3D_memWrite( struct bbs_Context* cpA,
100                                                             const struct bts_Flt16Alt3D* ptrA, 
101                                                                 uint16* memPtrA )
102 {
103         bbs_ERROR0( "unimplemented function" );
104         return 0;
105 }
106
107 /* ------------------------------------------------------------------------- */
108         
109 uint32 bts_Flt16Alt3D_memRead( struct bbs_Context* cpA,
110                                                            struct bts_Flt16Alt3D* ptrA, 
111                                                            const uint16* memPtrA )
112 {
113         if( bbs_Context_error( cpA ) ) return 0;
114         bbs_ERROR0( "unimplemented function" );
115         return 0;
116 }
117
118 /* ------------------------------------------------------------------------- */
119         
120 /* ========================================================================= */
121 /*                                                                           */
122 /* ---- \ghd{ exec functions } --------------------------------------------- */
123 /*                                                                           */
124 /* ========================================================================= */
125         
126 /* ------------------------------------------------------------------------- */
127
128 struct bts_Flt16Alt3D bts_Flt16Alt3D_createIdentity()
129 {
130         struct bts_Flt16Alt3D altL = { { 1, 0, 0,
131                                                                          0, 1, 0,
132                                                                          0, 0, 1, 0 }, { 0, 0, 0, 0 } };
133         return altL;
134 }
135
136 /* ------------------------------------------------------------------------- */
137
138 struct bts_Flt16Alt3D bts_Flt16Alt3D_createScale( int32 scaleA, 
139                                                                                                   int32 scaleBbpA, 
140                                                                                                   const struct bts_Flt16Vec3D* centerPtrA )
141 {
142         struct bts_Flt16Alt3D altL;
143         altL.matE = bts_Flt16Mat3D_createScale( scaleA, scaleBbpA );
144         altL.vecE = bts_Flt16Vec3D_sub( *centerPtrA, bts_Flt16Mat3D_mapFlt( &altL.matE, centerPtrA ) );
145         return altL;
146 }
147
148 /* ------------------------------------------------------------------------- */
149
150 struct bts_Flt16Alt3D bts_Flt16Alt3D_createLinear( const struct bts_Flt16Mat3D* matPtrA,
151                                                                                                    const struct bts_Flt16Vec3D* centerPtrA )
152 {
153         struct bts_Flt16Alt3D altL;
154         altL.matE = *matPtrA;
155         altL.vecE = bts_Flt16Vec3D_sub( *centerPtrA, bts_Flt16Mat3D_mapFlt( &altL.matE, centerPtrA ) );
156         return altL;
157 }
158
159 /* ------------------------------------------------------------------------- */
160
161 struct bts_Flt16Alt3D bts_Flt16Alt3D_create16( int16 xxA, int16 xyA, int16 xzA,
162                                                                                            int16 yxA, int16 yyA, int16 yzA,
163                                                                                            int16 zxA, int16 zyA, int16 zzA,
164                                                                                            int16 matBbpA,
165                                                                                            int16 xA, int16 yA, int16 zA,
166                                                                                            int16 vecBbpA )
167 {
168         struct bts_Flt16Alt3D altL;
169         altL.matE = bts_Flt16Mat3D_create16( xxA, xyA, xzA,
170                                                                                  yxA, yyA, yzA,
171                                                                                  zxA, zyA, zzA,
172                                                                                  matBbpA );
173
174         altL.vecE = bts_Flt16Vec3D_create16( xA, yA, zA, vecBbpA );
175         return altL;
176 }
177
178 /* ------------------------------------------------------------------------- */
179
180 struct bts_Flt16Alt3D bts_Flt16Alt3D_create32( int32 xxA, int32 xyA, int32 xzA,
181                                                                                            int32 yxA, int32 yyA, int32 yzA,
182                                                                                            int32 zxA, int32 zyA, int32 zzA,
183                                                                                            int16 matBbpA,
184                                                                                            int32 xA, int32 yA, int32 zA,
185                                                                                            int16 vecBbpA )
186 {
187         struct bts_Flt16Alt3D altL;
188         altL.matE = bts_Flt16Mat3D_create32( xxA, xyA, xzA,
189                                                                                  yxA, yyA, yzA,
190                                                                                  zxA, zyA, zzA,
191                                                                                  matBbpA );
192
193         altL.vecE = bts_Flt16Vec3D_create32( xA, yA, zA, vecBbpA );
194         return altL;
195 }
196
197 /* ------------------------------------------------------------------------- */
198
199 struct bts_Flt16Vec3D bts_Flt16Alt3D_mapFlt( const struct bts_Flt16Alt3D* altPtrA, 
200                                                                              const struct bts_Flt16Vec3D* vecPtrA )
201 {
202         struct bts_Flt16Vec3D vecL = bts_Flt16Mat3D_mapFlt( &altPtrA->matE, vecPtrA );
203         int32 shiftL = altPtrA->vecE.bbpE - vecL.bbpE;
204         if( shiftL > 0 )
205         {
206                 int32 sh1L = shiftL - 1;
207                 vecL.xE += ( ( altPtrA->vecE.xE >> sh1L ) + 1 ) >> 1;
208                 vecL.yE += ( ( altPtrA->vecE.yE >> sh1L ) + 1 ) >> 1;
209                 vecL.zE += ( ( altPtrA->vecE.zE >> sh1L ) + 1 ) >> 1;
210         }
211         else
212         {
213                 vecL.xE += altPtrA->vecE.xE << -shiftL;
214                 vecL.yE += altPtrA->vecE.yE << -shiftL;
215                 vecL.zE += altPtrA->vecE.zE << -shiftL;
216         }
217         return vecL;
218 }
219
220 /* ------------------------------------------------------------------------- */
221
222 struct bts_Flt16Alt3D bts_Flt16Alt3D_mul( const struct bts_Flt16Alt3D* alt1PtrA, 
223                                                                           const struct bts_Flt16Alt3D* alt2PtrA )
224 {
225         struct bts_Flt16Alt3D altL;
226         altL.vecE = bts_Flt16Alt3D_mapFlt( alt1PtrA, &alt2PtrA->vecE );
227         altL.matE = bts_Flt16Mat3D_mul( &alt1PtrA->matE, &alt2PtrA->matE );
228         return altL;
229 }
230
231 /* ------------------------------------------------------------------------- */
232
233 /** multiplies matrix with matA; returns pointer to resulting matrix */
234 struct bts_Flt16Alt3D* bts_Flt16Alt3D_mulTo( struct bts_Flt16Alt3D* alt1PtrA, 
235                                                              const struct bts_Flt16Alt3D* alt2PtrA )
236 {
237         *alt1PtrA = bts_Flt16Alt3D_mul( alt1PtrA, alt2PtrA );
238         return alt1PtrA;
239 }
240
241 /* ------------------------------------------------------------------------- */
242
243 /* ========================================================================= */
244