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 #ifndef bts_VECTOR_MAP_EM_H
18 #define bts_VECTOR_MAP_EM_H
19 
20 /* ---- includes ----------------------------------------------------------- */
21 
22 #include "b_BasicEm/Context.h"
23 #include "b_BasicEm/Basic.h"
24 #include "b_BasicEm/MemTbl.h"
25 #include "b_TensorEm/Flt16Vec.h"
26 
27 /* ---- related objects  --------------------------------------------------- */
28 
29 /* ---- typedefs ----------------------------------------------------------- */
30 
31 /** Object Type */
32 enum bts_VectorMapType
33 {
34 	bts_VM_UNDEFINED = 0,
35 	bts_VM_MAP_SEQUENCE,   /* sequence of vector maps */
36 	bts_VM_NORMALIZER,     /* normalizes a vector using euclidean norm */
37 	bts_VM_MAT,            /* linear transformation (matrix) */
38 	bts_VM_ALT,		       /* affine linear transformation */
39 	bts_VM_SUB_VEC_MAP     /* sub vector extraction */
40 };
41 
42 /* ---- constants ---------------------------------------------------------- */
43 
44 /* ---- object definition -------------------------------------------------- */
45 
46 /** base object for vector maps (occurs as first element in all vector map objects) */
47 struct bts_VectorMap
48 {
49 	/* ---- private data --------------------------------------------------- */
50 
51 	/* ---- public data ---------------------------------------------------- */
52 
53 	/** vector map type */
54 	uint32 typeE;
55 
56 	/* ---- virtual functions ---------------------------------------------- */
57 
58 	/** vector map operation.
59 	 *  Maps vector inVec to outVec (overflow-safe)
60 	 *  Memory areas of vectors may not overlap
61 	 */
62 	void ( *vpMapE )( struct bbs_Context* cpA,
63 					  const struct bts_VectorMap* ptrA,
64 					  const struct bts_Flt16Vec* inVecPtrA,
65 					  struct bts_Flt16Vec* outVecPtrA );
66 
67 };
68 
69 /* ---- associated objects ------------------------------------------------- */
70 
71 /* ---- external functions ------------------------------------------------- */
72 
73 /* ---- \ghd{ constructor/destructor } ------------------------------------- */
74 
75 /** initializes bts_VectorMap  */
76 void bts_VectorMap_init( struct bbs_Context* cpA,
77 					     struct bts_VectorMap* ptrA );
78 
79 /** resets bts_VectorMap  */
80 void bts_VectorMap_exit( struct bbs_Context* cpA,
81 					     struct bts_VectorMap* ptrA );
82 
83 /* ---- \ghd{ operators } -------------------------------------------------- */
84 
85 /** copy operator */
86 void bts_VectorMap_copy( struct bbs_Context* cpA,
87 					     struct bts_VectorMap* ptrA,
88 					     const struct bts_VectorMap* srcPtrA );
89 
90 /** equal operator */
91 flag bts_VectorMap_equal( struct bbs_Context* cpA,
92 						  const struct bts_VectorMap* ptrA,
93 						  const struct bts_VectorMap* srcPtrA );
94 
95 /* ---- \ghd{ query functions } -------------------------------------------- */
96 
97 /* ---- \ghd{ modify functions } ------------------------------------------- */
98 
99 /* ---- \ghd{ memory I/O } ------------------------------------------------- */
100 
101 /** word size (16-bit) object needs when written to memory */
102 uint32 bts_VectorMap_memSize( struct bbs_Context* cpA,
103 						      const struct bts_VectorMap* ptrA );
104 
105 /** writes object to memory; returns number of words (16-bit) written */
106 uint32 bts_VectorMap_memWrite( struct bbs_Context* cpA,
107 							   const struct bts_VectorMap* ptrA, uint16* memPtrA );
108 
109 /** reads object from memory; returns number of words (16-bit) read */
110 uint32 bts_VectorMap_memRead( struct bbs_Context* cpA,
111 							  struct bts_VectorMap* ptrA, const uint16* memPtrA );
112 
113 /* ---- \ghd{ exec functions } --------------------------------------------- */
114 
115 /** virtual init function  */
116 void bts_vectorMapInit( struct bbs_Context* cpA,
117 					    struct bts_VectorMap* ptrA,
118 					    enum bts_VectorMapType typeA );
119 
120 /** virtual exit function */
121 void bts_vectorMapExit( struct bbs_Context* cpA,
122 					    struct bts_VectorMap* ptrA );
123 
124 /** virtual mem size function */
125 uint32 bts_vectorMapMemSize( struct bbs_Context* cpA,
126 						     const struct bts_VectorMap* ptrA );
127 
128 /** virtual mem write function */
129 uint32 bts_vectorMapMemWrite( struct bbs_Context* cpA,
130 						      const struct bts_VectorMap* ptrA, uint16* memPtrA );
131 
132 /** virtual mem read function */
133 uint32 bts_vectorMapMemRead( struct bbs_Context* cpA,
134 						     struct bts_VectorMap* ptrA,
135 						     const uint16* memPtrA,
136 						     struct bbs_MemTbl* mtpA );
137 
138 /** virtual sizeof operator for 16bit units */
139 uint32 bts_vectorMapSizeOf16( struct bbs_Context* cpA, enum bts_VectorMapType typeA );
140 
141 #endif /* bts_VECTOR_MAP_EM_H */
142 
143