• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BasicEm/Functions.h"
20 #include "b_TensorEm/VectorMap.h"
21 
22 #include "b_TensorEm/MapSequence.h"
23 #include "b_TensorEm/Normalizer.h"
24 #include "b_TensorEm/Alt.h"
25 #include "b_TensorEm/Mat.h"
26 #include "b_TensorEm/SubVecMap.h"
27 
28 /* ------------------------------------------------------------------------- */
29 
30 /* ========================================================================= */
31 /*                                                                           */
32 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
33 /*                                                                           */
34 /* ========================================================================= */
35 
36 /* ------------------------------------------------------------------------- */
37 
38 /* ========================================================================= */
39 /*                                                                           */
40 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
41 /*                                                                           */
42 /* ========================================================================= */
43 
44 /* ------------------------------------------------------------------------- */
45 
bts_VectorMap_init(struct bbs_Context * cpA,struct bts_VectorMap * ptrA)46 void bts_VectorMap_init( struct bbs_Context* cpA,
47 					     struct bts_VectorMap* ptrA )
48 {
49 	ptrA->typeE = 0;
50 	ptrA->vpMapE = NULL;
51 }
52 
53 /* ------------------------------------------------------------------------- */
54 
bts_VectorMap_exit(struct bbs_Context * cpA,struct bts_VectorMap * ptrA)55 void bts_VectorMap_exit( struct bbs_Context* cpA,
56 					   struct bts_VectorMap* ptrA )
57 {
58 	ptrA->typeE = 0;
59 	ptrA->vpMapE = NULL;
60 }
61 
62 /* ------------------------------------------------------------------------- */
63 
64 /* ========================================================================= */
65 /*                                                                           */
66 /* ---- \ghd{ operators } -------------------------------------------------- */
67 /*                                                                           */
68 /* ========================================================================= */
69 
70 /* ------------------------------------------------------------------------- */
71 
bts_VectorMap_copy(struct bbs_Context * cpA,struct bts_VectorMap * ptrA,const struct bts_VectorMap * srcPtrA)72 void bts_VectorMap_copy( struct bbs_Context* cpA,
73 					     struct bts_VectorMap* ptrA,
74 					     const struct bts_VectorMap* srcPtrA )
75 {
76 	ptrA->typeE  = srcPtrA->typeE;
77 	ptrA->vpMapE = srcPtrA->vpMapE;
78 }
79 
80 /* ------------------------------------------------------------------------- */
81 
bts_VectorMap_equal(struct bbs_Context * cpA,const struct bts_VectorMap * ptrA,const struct bts_VectorMap * srcPtrA)82 flag bts_VectorMap_equal( struct bbs_Context* cpA,
83 					    const struct bts_VectorMap* ptrA,
84 						const struct bts_VectorMap* srcPtrA )
85 {
86 
87 	if( ptrA->typeE	 != srcPtrA->typeE ) return FALSE;
88 	if( ptrA->vpMapE != srcPtrA->vpMapE ) return FALSE;
89 	return TRUE;
90 }
91 
92 /* ------------------------------------------------------------------------- */
93 
94 /* ========================================================================= */
95 /*                                                                           */
96 /* ---- \ghd{ query functions } -------------------------------------------- */
97 /*                                                                           */
98 /* ========================================================================= */
99 
100 /* ------------------------------------------------------------------------- */
101 
102 /* ========================================================================= */
103 /*                                                                           */
104 /* ---- \ghd{ modify functions } ------------------------------------------- */
105 /*                                                                           */
106 /* ========================================================================= */
107 
108 /* ------------------------------------------------------------------------- */
109 
110 /* ========================================================================= */
111 /*                                                                           */
112 /* ---- \ghd{ I/O } -------------------------------------------------------- */
113 /*                                                                           */
114 /* ========================================================================= */
115 
116 /* ------------------------------------------------------------------------- */
117 
bts_VectorMap_memSize(struct bbs_Context * cpA,const struct bts_VectorMap * ptrA)118 uint32 bts_VectorMap_memSize( struct bbs_Context* cpA,
119 						    const struct bts_VectorMap* ptrA )
120 {
121 	uint32 memSizeL = 0;
122 	memSizeL += bbs_SIZEOF16( ptrA->typeE );
123 	return memSizeL;
124 }
125 
126 /* ------------------------------------------------------------------------- */
127 
bts_VectorMap_memWrite(struct bbs_Context * cpA,const struct bts_VectorMap * ptrA,uint16 * memPtrA)128 uint32 bts_VectorMap_memWrite( struct bbs_Context* cpA,
129 							 const struct bts_VectorMap* ptrA,
130 							 uint16* memPtrA )
131 {
132 	uint32 memSizeL = bts_VectorMap_memSize( cpA, ptrA );
133 	memPtrA += bbs_memWrite32( &ptrA->typeE, memPtrA );
134 	return memSizeL;
135 }
136 
137 /* ------------------------------------------------------------------------- */
138 
bts_VectorMap_memRead(struct bbs_Context * cpA,struct bts_VectorMap * ptrA,const uint16 * memPtrA)139 uint32 bts_VectorMap_memRead( struct bbs_Context* cpA,
140 						    struct bts_VectorMap* ptrA,
141 							const uint16* memPtrA )
142 {
143 	if( bbs_Context_error( cpA ) ) return 0;
144 	memPtrA += bbs_memRead32( &ptrA->typeE, memPtrA );
145 	return bts_VectorMap_memSize( cpA, ptrA );
146 }
147 
148 /* ------------------------------------------------------------------------- */
149 
150 /* ========================================================================= */
151 /*                                                                           */
152 /* ---- \ghd{ exec functions } --------------------------------------------- */
153 /*                                                                           */
154 /* ========================================================================= */
155 
156 /* ------------------------------------------------------------------------- */
157 
bts_vectorMapInit(struct bbs_Context * cpA,struct bts_VectorMap * ptrA,enum bts_VectorMapType typeA)158 void bts_vectorMapInit( struct bbs_Context* cpA,
159 					    struct bts_VectorMap* ptrA,
160 					    enum bts_VectorMapType typeA )
161 {
162 	switch( typeA )
163 	{
164 		case bts_VM_MAP_SEQUENCE:	bts_MapSequence_init( cpA,	( struct bts_MapSequence* )ptrA ); return;
165 		case bts_VM_NORMALIZER:		bts_Normalizer_init( cpA,	( struct bts_Normalizer* )ptrA ); return;
166 		case bts_VM_MAT:			bts_Mat_init( cpA,			( struct bts_Mat* )ptrA ); return;
167 		case bts_VM_ALT:			bts_Alt_init( cpA,			( struct bts_Alt* )ptrA ); return;
168 		case bts_VM_SUB_VEC_MAP:	bts_SubVecMap_init( cpA,	( struct bts_SubVecMap* )ptrA ); return;
169 
170 		default: bbs_ERROR0( "bts_vectorMapInit: invalid type" );
171 	}
172 }
173 
174 /* ------------------------------------------------------------------------- */
175 
bts_vectorMapExit(struct bbs_Context * cpA,struct bts_VectorMap * ptrA)176 void bts_vectorMapExit( struct bbs_Context* cpA,
177 					    struct bts_VectorMap* ptrA )
178 {
179 	switch( ptrA->typeE )
180 	{
181 		case bts_VM_MAP_SEQUENCE:	bts_MapSequence_exit( cpA,	( struct bts_MapSequence* )ptrA ); return;
182 		case bts_VM_NORMALIZER:		bts_Normalizer_exit( cpA,	( struct bts_Normalizer* )ptrA ); return;
183 		case bts_VM_MAT:			bts_Mat_exit( cpA,			( struct bts_Mat* )ptrA ); return;
184 		case bts_VM_ALT:			bts_Alt_exit( cpA,			( struct bts_Alt* )ptrA ); return;
185 		case bts_VM_SUB_VEC_MAP:	bts_SubVecMap_exit( cpA,	( struct bts_SubVecMap* )ptrA ); return;
186 
187 		default: bbs_ERROR0( "bts_vectorMapExit: invalid type" );
188 	}
189 }
190 
191 /* ------------------------------------------------------------------------- */
192 
bts_vectorMapMemSize(struct bbs_Context * cpA,const struct bts_VectorMap * ptrA)193 uint32 bts_vectorMapMemSize( struct bbs_Context* cpA,
194 						     const struct bts_VectorMap* ptrA )
195 {
196 	switch( ptrA->typeE )
197 	{
198 		case bts_VM_MAP_SEQUENCE:	return bts_MapSequence_memSize( cpA,	( struct bts_MapSequence* )ptrA );
199 		case bts_VM_NORMALIZER:		return bts_Normalizer_memSize( cpA,		( struct bts_Normalizer* )ptrA );
200 		case bts_VM_MAT:			return bts_Mat_memSize( cpA,			( struct bts_Mat* )ptrA );
201 		case bts_VM_ALT:			return bts_Alt_memSize( cpA,			( struct bts_Alt* )ptrA );
202 		case bts_VM_SUB_VEC_MAP:	return bts_SubVecMap_memSize( cpA,		( struct bts_SubVecMap* )ptrA );
203 
204 		default: bbs_ERROR0( "bts_vectorMapExit: invalid type" );
205 	}
206 	return 0;
207 }
208 
209 /* ------------------------------------------------------------------------- */
210 
bts_vectorMapMemWrite(struct bbs_Context * cpA,const struct bts_VectorMap * ptrA,uint16 * memPtrA)211 uint32 bts_vectorMapMemWrite( struct bbs_Context* cpA,
212 						      const struct bts_VectorMap* ptrA, uint16* memPtrA )
213 {
214 	switch( ptrA->typeE )
215 	{
216 		case bts_VM_MAP_SEQUENCE:	return bts_MapSequence_memWrite( cpA,	( struct bts_MapSequence* )ptrA, memPtrA  );
217 		case bts_VM_NORMALIZER:		return bts_Normalizer_memWrite( cpA,	( struct bts_Normalizer* )ptrA, memPtrA  );
218 		case bts_VM_MAT:			return bts_Mat_memWrite( cpA,			( struct bts_Mat* )ptrA, memPtrA  );
219 		case bts_VM_ALT:			return bts_Alt_memWrite( cpA,			( struct bts_Alt* )ptrA, memPtrA  );
220 		case bts_VM_SUB_VEC_MAP:	return bts_SubVecMap_memWrite( cpA,		( struct bts_SubVecMap* )ptrA, memPtrA  );
221 
222 		default: bbs_ERROR0( "bts_vectorMapMemWrite: invalid type" );
223 	}
224 	return 0;
225 }
226 
227 /* ------------------------------------------------------------------------- */
228 
bts_vectorMapMemRead(struct bbs_Context * cpA,struct bts_VectorMap * ptrA,const uint16 * memPtrA,struct bbs_MemTbl * mtpA)229 uint32 bts_vectorMapMemRead( struct bbs_Context* cpA,
230 						     struct bts_VectorMap* ptrA,
231 						     const uint16* memPtrA,
232 						     struct bbs_MemTbl* mtpA )
233 {
234 	switch( ptrA->typeE )
235 	{
236 		case bts_VM_MAP_SEQUENCE:	return bts_MapSequence_memRead( cpA,	( struct bts_MapSequence* )ptrA, memPtrA, mtpA );
237 		case bts_VM_NORMALIZER:		return bts_Normalizer_memRead( cpA,		( struct bts_Normalizer* )ptrA, memPtrA, mtpA );
238 		case bts_VM_MAT:			return bts_Mat_memRead( cpA,			( struct bts_Mat* )ptrA, memPtrA, mtpA );
239 		case bts_VM_ALT:			return bts_Alt_memRead( cpA,			( struct bts_Alt* )ptrA, memPtrA, mtpA );
240 		case bts_VM_SUB_VEC_MAP:	return bts_SubVecMap_memRead( cpA,		( struct bts_SubVecMap* )ptrA, memPtrA, mtpA );
241 
242 		default: bbs_ERROR0( "bts_vectorMapMemRead: invalid type" );
243 	}
244 	return 0;
245 }
246 
247 /* ------------------------------------------------------------------------- */
248 
bts_vectorMapSizeOf16(struct bbs_Context * cpA,enum bts_VectorMapType typeA)249 uint32 bts_vectorMapSizeOf16( struct bbs_Context* cpA, enum bts_VectorMapType typeA )
250 {
251 	switch( typeA )
252 	{
253 		case bts_VM_MAP_SEQUENCE:	return bbs_SIZEOF16( struct bts_MapSequence );
254 		case bts_VM_NORMALIZER:		return bbs_SIZEOF16( struct bts_Normalizer );
255 		case bts_VM_MAT:			return bbs_SIZEOF16( struct bts_Mat );
256 		case bts_VM_ALT:			return bbs_SIZEOF16( struct bts_Alt );
257 		case bts_VM_SUB_VEC_MAP:	return bbs_SIZEOF16( struct bts_SubVecMap );
258 
259 		default: bbs_ERROR0( "bts_vectorMapSizeOf16: invalid type" );
260 	}
261 	return 0;
262 }
263 
264 /* ------------------------------------------------------------------------- */
265 
266 /* ========================================================================= */
267 
268