• 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_BasicEm/Math.h"
21 #include "b_TensorEm/Alt.h"
22 
23 /* ------------------------------------------------------------------------- */
24 
25 /* ========================================================================= */
26 /*                                                                           */
27 /* ---- \ghd{ auxiliary functions } ---------------------------------------- */
28 /*                                                                           */
29 /* ========================================================================= */
30 
31 /* ------------------------------------------------------------------------- */
32 
33 /* ========================================================================= */
34 /*                                                                           */
35 /* ---- \ghd{ constructor / destructor } ----------------------------------- */
36 /*                                                                           */
37 /* ========================================================================= */
38 
39 /* ------------------------------------------------------------------------- */
40 
bts_Alt_init(struct bbs_Context * cpA,struct bts_Alt * ptrA)41 void bts_Alt_init( struct bbs_Context* cpA,
42 			       struct bts_Alt* ptrA )
43 {
44 	bts_VectorMap_init( cpA, &ptrA->baseE );
45 	ptrA->baseE.typeE = ( uint32 )bts_VM_ALT;
46 	ptrA->baseE.vpMapE = bts_Alt_map;
47 
48 	bts_CompactAlt_init( cpA, &ptrA->altE );
49 }
50 
51 /* ------------------------------------------------------------------------- */
52 
bts_Alt_exit(struct bbs_Context * cpA,struct bts_Alt * ptrA)53 void bts_Alt_exit( struct bbs_Context* cpA,
54 			       struct bts_Alt* ptrA )
55 {
56 	bts_CompactAlt_exit( cpA, &ptrA->altE );
57 
58 	bts_VectorMap_exit( cpA, &ptrA->baseE );
59 }
60 
61 /* ------------------------------------------------------------------------- */
62 
63 /* ========================================================================= */
64 /*                                                                           */
65 /* ---- \ghd{ operators } -------------------------------------------------- */
66 /*                                                                           */
67 /* ========================================================================= */
68 
69 /* ------------------------------------------------------------------------- */
70 
bts_Alt_copy(struct bbs_Context * cpA,struct bts_Alt * ptrA,const struct bts_Alt * srcPtrA)71 void bts_Alt_copy( struct bbs_Context* cpA,
72 				   struct bts_Alt* ptrA,
73 				   const struct bts_Alt* srcPtrA )
74 {
75 	bts_CompactAlt_copy( cpA, &ptrA->altE, &srcPtrA->altE );
76 }
77 
78 /* ------------------------------------------------------------------------- */
79 
bts_Alt_equal(struct bbs_Context * cpA,const struct bts_Alt * ptrA,const struct bts_Alt * srcPtrA)80 flag bts_Alt_equal( struct bbs_Context* cpA,
81 					const struct bts_Alt* ptrA,
82 					const struct bts_Alt* srcPtrA )
83 {
84 	bbs_ERROR0( "bts_Alt_equal:\n Function is not available" );
85 	return FALSE;
86 }
87 
88 /* ------------------------------------------------------------------------- */
89 
90 /* ========================================================================= */
91 /*                                                                           */
92 /* ---- \ghd{ query functions } -------------------------------------------- */
93 /*                                                                           */
94 /* ========================================================================= */
95 
96 /* ------------------------------------------------------------------------- */
97 
98 /* ========================================================================= */
99 /*                                                                           */
100 /* ---- \ghd{ modify functions } ------------------------------------------- */
101 /*                                                                           */
102 /* ========================================================================= */
103 
104 /* ------------------------------------------------------------------------- */
105 
106 /* ========================================================================= */
107 /*                                                                           */
108 /* ---- \ghd{ I/O } -------------------------------------------------------- */
109 /*                                                                           */
110 /* ========================================================================= */
111 
112 /* ------------------------------------------------------------------------- */
113 
bts_Alt_memSize(struct bbs_Context * cpA,const struct bts_Alt * ptrA)114 uint32 bts_Alt_memSize( struct bbs_Context* cpA,
115 					    const struct bts_Alt* ptrA )
116 {
117 	uint32 memSizeL = bbs_SIZEOF16( uint32 ) +
118 					  bbs_SIZEOF16( uint32 ); /* version */
119 	memSizeL += bts_VectorMap_memSize( cpA, &ptrA->baseE );
120 	memSizeL += bts_CompactAlt_memSize( cpA, &ptrA->altE );
121 	return memSizeL;
122 }
123 
124 /* ------------------------------------------------------------------------- */
125 
bts_Alt_memWrite(struct bbs_Context * cpA,const struct bts_Alt * ptrA,uint16 * memPtrA)126 uint32 bts_Alt_memWrite( struct bbs_Context* cpA,
127 						 const struct bts_Alt* ptrA,
128 						 uint16* memPtrA )
129 {
130 	uint32 memSizeL = bts_Alt_memSize( cpA, ptrA );
131 	memPtrA += bbs_memWrite32( &memSizeL, memPtrA );
132 	memPtrA += bbs_memWriteUInt32( bts_ALT_VERSION, memPtrA );
133 	memPtrA += bts_VectorMap_memWrite( cpA, &ptrA->baseE, memPtrA );
134 	memPtrA += bts_CompactAlt_memWrite( cpA, &ptrA->altE, memPtrA );
135 	return memSizeL;
136 }
137 
138 /* ------------------------------------------------------------------------- */
139 
bts_Alt_memRead(struct bbs_Context * cpA,struct bts_Alt * ptrA,const uint16 * memPtrA,struct bbs_MemTbl * mtpA)140 uint32 bts_Alt_memRead( struct bbs_Context* cpA,
141 						struct bts_Alt* ptrA,
142 						const uint16* memPtrA,
143 						struct bbs_MemTbl* mtpA )
144 {
145 	uint32 memSizeL, versionL;
146 	struct bbs_MemTbl memTblL = *mtpA;
147 	struct bbs_MemSeg* espL = bbs_MemTbl_segPtr( cpA, &memTblL, 0 );
148 
149 	if( bbs_Context_error( cpA ) ) return 0;
150 	memPtrA += bbs_memRead32( &memSizeL, memPtrA );
151 	memPtrA += bbs_memReadVersion32( cpA, &versionL, bts_ALT_VERSION, memPtrA );
152 	memPtrA += bts_VectorMap_memRead( cpA, &ptrA->baseE, memPtrA );
153 	memPtrA += bts_CompactAlt_memRead( cpA, &ptrA->altE, memPtrA, espL );
154 
155 	if( memSizeL != bts_Alt_memSize( cpA, ptrA ) )
156 	{
157 		bbs_ERR0( bbs_ERR_CORRUPT_DATA, "uint32 bts_Alt_memRead( struct bem_ScanGradientMove* ptrA, const uint16* memPtrA ):\n"
158 			        "size mismatch" );
159 		return 0;
160 	}
161 
162 	return memSizeL;
163 }
164 
165 /* ------------------------------------------------------------------------- */
166 
167 /* ========================================================================= */
168 /*                                                                           */
169 /* ---- \ghd{ exec functions } --------------------------------------------- */
170 /*                                                                           */
171 /* ========================================================================= */
172 
173 /* ------------------------------------------------------------------------- */
174 
bts_Alt_map(struct bbs_Context * cpA,const struct bts_VectorMap * ptrA,const struct bts_Flt16Vec * inVecPtrA,struct bts_Flt16Vec * outVecPtrA)175 void bts_Alt_map( struct bbs_Context* cpA,
176 				  const struct bts_VectorMap* ptrA,
177 				  const struct bts_Flt16Vec* inVecPtrA,
178 				  struct bts_Flt16Vec* outVecPtrA )
179 {
180 	bbs_DEF_fNameL( "bts_Alt_map" )
181 	const struct bts_Alt* ptrL = ( const struct bts_Alt* )ptrA;
182 
183 	if( inVecPtrA->arrE.sizeE != ptrL->altE.matE.widthE )
184 	{
185 		bbs_ERROR1( "%s:\ninput vector has incorrect size", fNameL );
186 		return;
187 	}
188 
189 	if( outVecPtrA->arrE.allocatedSizeE < ptrL->altE.matE.heightE )
190 	{
191 		bbs_ERROR1( "%s:\noutput vector is insufficiently allocated", fNameL );
192 		return;
193 	}
194 
195 	bts_Flt16Vec_size( cpA, outVecPtrA, ptrL->altE.matE.heightE );
196 
197 	bts_CompactAlt_map( cpA, &ptrL->altE, inVecPtrA->arrE.arrPtrE, inVecPtrA->expE, outVecPtrA->arrE.arrPtrE, &outVecPtrA->expE );
198 
199 	bts_Flt16Vec_maximizeMantisse( cpA, outVecPtrA );
200 }
201 
202 /* ------------------------------------------------------------------------- */
203 
204 /* ========================================================================= */
205 
206