The Android Open Source Project | 30957f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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_FLT_16_VEC_EM_H |
| 18 | #define bts_FLT_16_VEC_EM_H |
| 19 | |
| 20 | /* ---- includes ----------------------------------------------------------- */ |
| 21 | |
| 22 | #include "b_BasicEm/Context.h" |
| 23 | #include "b_BasicEm/MemSeg.h" |
| 24 | #include "b_BasicEm/Int16Arr.h" |
| 25 | #include "b_TensorEm/Functions.h" |
| 26 | |
| 27 | /* ---- related objects --------------------------------------------------- */ |
| 28 | |
| 29 | /* ---- typedefs ----------------------------------------------------------- */ |
| 30 | |
| 31 | /* ---- constants ---------------------------------------------------------- */ |
| 32 | |
| 33 | /* ---- object definition -------------------------------------------------- */ |
| 34 | |
| 35 | /** |
| 36 | * Vector with 16 bit components |
| 37 | * The vector operations are implemented with respect to maintain high accuracy and |
| 38 | * overflow safety for all possible vector configurations. |
| 39 | */ |
| 40 | struct bts_Flt16Vec |
| 41 | { |
| 42 | |
| 43 | /* ---- private data --------------------------------------------------- */ |
| 44 | |
| 45 | /* ---- public data ---------------------------------------------------- */ |
| 46 | |
| 47 | /** array of vector elements */ |
| 48 | struct bbs_Int16Arr arrE; |
| 49 | |
| 50 | /** exponent to elements */ |
| 51 | int16 expE; |
| 52 | }; |
| 53 | |
| 54 | /* ---- associated objects ------------------------------------------------- */ |
| 55 | |
| 56 | /* ---- external functions ------------------------------------------------- */ |
| 57 | |
| 58 | /* ---- \ghd{ constructor/destructor } ------------------------------------- */ |
| 59 | |
| 60 | /** initializes vector */ |
| 61 | void bts_Flt16Vec_init( struct bbs_Context* cpA, |
| 62 | struct bts_Flt16Vec* ptrA ); |
| 63 | |
| 64 | /** destroys vector */ |
| 65 | void bts_Flt16Vec_exit( struct bbs_Context* cpA, |
| 66 | struct bts_Flt16Vec* ptrA ); |
| 67 | |
| 68 | /* ---- \ghd{ operators } -------------------------------------------------- */ |
| 69 | |
| 70 | /** copies vector */ |
| 71 | void bts_Flt16Vec_copy( struct bbs_Context* cpA, |
| 72 | struct bts_Flt16Vec* ptrA, |
| 73 | const struct bts_Flt16Vec* srcPtrA ); |
| 74 | |
| 75 | /** compares vector */ |
| 76 | flag bts_Flt16Vec_equal( struct bbs_Context* cpA, |
| 77 | const struct bts_Flt16Vec* ptrA, |
| 78 | const struct bts_Flt16Vec* srcPtrA ); |
| 79 | |
| 80 | /* ---- \ghd{ query functions } -------------------------------------------- */ |
| 81 | |
| 82 | /** returns average of vector without exponent */ |
| 83 | int16 bts_Flt16Vec_avg( struct bbs_Context* cpA, const struct bts_Flt16Vec* ptrA ); |
| 84 | |
| 85 | /** returns norm of vector without exponent */ |
| 86 | uint32 bts_Flt16Vec_norm( struct bbs_Context* cpA, const struct bts_Flt16Vec* ptrA ); |
| 87 | |
| 88 | /** returns maximum absulute value without exponent */ |
| 89 | uint16 bts_Flt16Vec_maxAbs( struct bbs_Context* cpA, const struct bts_Flt16Vec* ptrA ); |
| 90 | |
| 91 | /* ---- \ghd{ modify functions } ------------------------------------------- */ |
| 92 | |
| 93 | /** allocates vector */ |
| 94 | void bts_Flt16Vec_create( struct bbs_Context* cpA, |
| 95 | struct bts_Flt16Vec* ptrA, |
| 96 | uint32 sizeA, |
| 97 | struct bbs_MemSeg* mspA ); |
| 98 | |
| 99 | /** resize vector (sizeA must be smaller or equal to allocated size)*/ |
| 100 | void bts_Flt16Vec_size( struct bbs_Context* cpA, |
| 101 | struct bts_Flt16Vec* ptrA, |
| 102 | uint32 sizeA ); |
| 103 | |
| 104 | /* ---- \ghd{ memory I/O } ------------------------------------------------- */ |
| 105 | |
| 106 | /** size in words (16-bit) object needs when written to memory */ |
| 107 | uint32 bts_Flt16Vec_memSize( struct bbs_Context* cpA, |
| 108 | const struct bts_Flt16Vec* ptrA ); |
| 109 | |
| 110 | /** writes object to memory; returns number of words (16-bit) written */ |
| 111 | uint32 bts_Flt16Vec_memWrite( struct bbs_Context* cpA, |
| 112 | const struct bts_Flt16Vec* ptrA, |
| 113 | uint16* memPtrA ); |
| 114 | |
| 115 | /** reads object from memory; returns number of words (16-bit) read */ |
| 116 | uint32 bts_Flt16Vec_memRead( struct bbs_Context* cpA, |
| 117 | struct bts_Flt16Vec* ptrA, |
| 118 | const uint16* memPtrA, |
| 119 | struct bbs_MemSeg* mspA ); |
| 120 | |
| 121 | /* ---- \ghd{ exec functions } --------------------------------------------- */ |
| 122 | |
| 123 | /** maximize mantisse values to reduce error propagation through multiple vector operations */ |
| 124 | void bts_Flt16Vec_maximizeMantisse( struct bbs_Context* cpA, struct bts_Flt16Vec* ptrA ); |
| 125 | |
| 126 | /** scales vector such that max abs is as near as possible to 0x7FFF; returns scale factor used in format 16.16; returns 0 when vector is 0 */ |
| 127 | uint32 bts_Flt16Vec_maximizeAbsValue( struct bbs_Context* cpA, struct bts_Flt16Vec* ptrA ); |
| 128 | |
| 129 | /** tranlates vector to zero average */ |
| 130 | void bts_Flt16Vec_zeroAverage( struct bbs_Context* cpA, struct bts_Flt16Vec* ptrA ); |
| 131 | |
| 132 | /** normalizes vector (euclidean norm) */ |
| 133 | void bts_Flt16Vec_normalize( struct bbs_Context* cpA, struct bts_Flt16Vec* ptrA ); |
| 134 | |
| 135 | /** sets vector to zero */ |
| 136 | void bts_Flt16Vec_setZero( struct bbs_Context* cpA, struct bts_Flt16Vec* ptrA ); |
| 137 | |
| 138 | /** multiplies a scalar to vector */ |
| 139 | void bts_Flt16Vec_mul( struct bbs_Context* cpA, struct bts_Flt16Vec* ptrA, int32 valA, int16 expA ); |
| 140 | |
| 141 | /** computes dot product; returns product as mantisse + exponent */ |
| 142 | void bts_Flt16Vec_dotPtrd( struct bbs_Context* cpA, struct bts_Flt16Vec* vp1A, struct bts_Flt16Vec* vp2A, int32* manPtrA, int32* expPtrA ); |
| 143 | |
| 144 | /** appends a vector */ |
| 145 | void bts_Flt16Vec_append( struct bbs_Context* cpA, struct bts_Flt16Vec* ptrA, struct bts_Flt16Vec* srcPtrA ); |
| 146 | |
| 147 | #endif /* bts_FLT_16_VEC_EM_H */ |
| 148 | |