Changeset 20827
- Timestamp:
- Nov 24, 2008, 5:09:38 PM (17 years ago)
- Files:
-
- 1 added
- 4 edited
-
branches/eam_branch_20081124/Ohana/src/libautocode/def/common.h (modified) (1 diff)
-
branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h (modified) (2 diffs)
-
branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c (modified) (6 diffs)
-
branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c (modified) (1 diff)
-
trunk/Ohana/src/opihi/doc/opihi-vectors.txt (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20081124/Ohana/src/libautocode/def/common.h
r15007 r20827 38 38 # endif 39 39 40 # define e_time unsignedint40 # define e_time int 41 41 # define e_void long long 42 42 # define rawshort short -
branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h
r15878 r20827 5 5 6 6 # define NCHARS 256 7 # define opihi_float float 8 # define opihi_int unsigned int 7 9 8 10 enum {ANYVECTOR, NEWVECTOR, OLDVECTOR}; 9 11 enum {ANYBUFFER, NEWBUFFER, OLDBUFFER}; 12 enum {OPIHI_FLOAT, OPIHI_INT}; 10 13 11 14 typedef struct { /* representation of a variable (0-D) */ … … 16 19 typedef struct { /* representation of a vector (1-D) */ 17 20 char name[1024]; 21 char type; 18 22 float *elements; 23 unsigned int *elementsInt; 19 24 int Nelements; 20 25 } Vector; -
branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c
r16887 r20827 18 18 19 19 for (i = 0; i < Nvectors; i++) { 20 free (vectors[i][0].elements); 20 if (vectors[i][0].elements) { 21 free (vectors[i][0].elements); 22 } 23 if (vectors[i][0].elementsInt) { 24 free (vectors[i][0].elementsInt); 25 } 21 26 free (vectors[i]); 22 27 } … … 28 33 29 34 ALLOCATE (vec, Vector, 1); 30 ALLOCATE (vec[0].elements, float, 1); 35 36 vec[0].elementsInt = NULL; 37 ALLOCATE (vec[0].elements, opihi_float, 1); 38 vec[0].type = OPIHI_FLOAT; /* is a float unless specified otherwise */ 39 31 40 bzero (vec[0].name, 1024); 32 41 vec[0].Nelements = 0; … … 95 104 if (i == Nvectors) return (FALSE); 96 105 97 free (vectors[i][0].elements); 106 if (vectors[i][0].elements) free (vectors[i][0].elements); 107 if (vectors[i][0].elementsInt) free (vectors[i][0].elementsInt); 98 108 free (vectors[i]); 99 109 … … 115 125 if (i == Nvectors) return (FALSE); 116 126 117 free (vectors[i][0].elements); 127 if (vectors[i][0].elements) free (vectors[i][0].elements); 128 if (vectors[i][0].elementsInt) free (vectors[i][0].elementsInt); 118 129 free (vectors[i]); 119 130 … … 137 148 free (out[0].elements); 138 149 out[0].Nelements = in[0].Nelements; 139 ALLOCATE (out[0].elements, float, out[0].Nelements); 140 memcpy (out[0].elements, in[0].elements, out[0].Nelements*sizeof(float)); 150 if (in[0].elements) { 151 assert (in[0].type == OPIHI_FLOAT); 152 ALLOCATE (out[0].elements, opihi_float, out[0].Nelements); 153 memcpy (out[0].elements, in[0].elements, out[0].Nelements*sizeof(opihi_float)); 154 out[0].type = OPIHI_FLOAT; 155 } else { 156 assert (in[0].type == OPIHI_INT); 157 ALLOCATE (out[0].elementsInt, opihi_int, out[0].Nelements); 158 memcpy (out[0].elementsInt, in[0].elementsInt, out[0].Nelements*sizeof(opihi_int)); 159 out[0].type = OPIHI_INT; 160 } 141 161 return (TRUE); 142 162 } … … 154 174 155 175 free (out[0].elements); 156 out[0].Nelements = in[0].Nelements; 157 out[0].elements = in[0].elements; 176 out[0].Nelements = in[0].Nelements; 177 out[0].elements = in[0].elements; 178 out[0].elementsInt = in[0].elementsInt; 179 out[0].type = in[0].type; 158 180 159 181 /* delete vector entry from vector list, if it exists */ -
branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c
r18078 r20827 35 35 out = OUT[0].ptr = (float *)OUT[0].vector[0].elements; 36 36 37 switch (op[0]) { 37 // XXX this is not quite there: 38 // 1) do I drop the .ptr element of StackVar? 39 // 2) things below are using type from a StackVar to get the vector type -- wrong place 40 // 3) the temp would need lots of work -- is it worth it? 41 // 4) some operators force the output to be float -- we cannot use a single bit of code to 42 // define the output type based on which is a float and which is not. getting ugly. 43 // ??? how much more work to bring the MV, etc functions into shape ??? 44 45 # define VV_FUNC(OP) \ 46 if ((M1->type == OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) { \ 47 // output must be float, can use either as a temp \ 48 opihi_float *M1 = V1[0].vector[0].elements; \ 49 opihi_float *M2 = V2[0].vector[0].elements; \ 50 for (i = 0; i < Nx; i++, out++, M1++, M2++) { \ 51 *out = *M1 OP *M2; \ 52 } \ 53 break; \ 54 } \ 55 if ((M1->type != OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) { \ 56 // output must be float, can use M2 as a temp \ 57 opihi_float *M1 = V1[0].vector[0].elementsInt; \ 58 opihi_float *M2 = V2[0].vector[0].elements; \ 59 for (i = 0; i < Nx; i++, out++, M1++, M2++) { \ 60 *out = *M1 OP *M2; \ 61 } \ 62 break; \ 63 } \ 64 if ((M1->type == OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) { \ 65 // output must be float, can use M1 as a temp \ 66 opihi_float *M1 = V1[0].vector[0].elements; \ 67 opihi_float *M2 = V2[0].vector[0].elementsInt; \ 68 for (i = 0; i < Nx; i++, out++, M1++, M2++) { \ 69 *out = *M1 OP *M2; \ 70 } \ 71 break; \ 72 } \ 73 if ((M1->type != OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) { \ 74 // output may be int, can use either as temp \ 75 opihi_float *M1 = V1[0].vector[0].elementsInt; \ 76 opihi_float *M2 = V2[0].vector[0].elementsInt; \ 77 for (i = 0; i < Nx; i++, out++, M1++, M2++) { \ 78 *out = *M1 OP *M2; \ 79 } \ 80 break; \ 81 } 82 83 switch (op[0]) { 38 84 case '+': 39 for (i = 0; i < Nx; i++, out++, M1++, M2++) 40 *out = *M1 + *M2; 41 break; 85 VV_FUNC 86 87 if ((M1->type == OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) { 88 // output must be float, can use either as a temp 89 M1 = V1[0].vector[0].elements; 90 M2 = V2[0].vector[0].elements; 91 for (i = 0; i < Nx; i++, out++, M1++, M2++) { 92 *out = *M1 + *M2; 93 } 94 break; 95 } 96 if ((M1->type != OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) { 97 // output must be float, can use M2 as a temp 98 M1 = V1[0].vector[0].elementsInt; 99 M2 = V2[0].vector[0].elements; 100 for (i = 0; i < Nx; i++, out++, M1++, M2++) { 101 *out = *M1 + *M2; 102 } 103 break; 104 } 105 if ((M1->type == OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) { 106 // output must be float, can use M1 as a temp 107 M1 = V1[0].vector[0].elements; 108 M2 = V2[0].vector[0].elementsInt; 109 for (i = 0; i < Nx; i++, out++, M1++, M2++) { 110 *out = *M1 + *M2; 111 } 112 break; 113 } 114 if ((M1->type != OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) { 115 // output may be int, can use either as temp 116 M1 = V1[0].vector[0].elementsInt; 117 M2 = V2[0].vector[0].elementsInt; 118 for (i = 0; i < Nx; i++, out++, M1++, M2++) { 119 *out = *M1 + *M2; 120 } 121 break; 122 } 42 123 case '-': 43 124 for (i = 0; i < Nx; i++, out++, M1++, M2++)
Note:
See TracChangeset
for help on using the changeset viewer.
