Mercurial > vec
comparison gen/genlib.c @ 46:31cee67540b5
f32/f64: add floor, ceil, round, and trunc operations
we also need saturated add sub mul etc
| author | Paper <paper@tflc.us> |
|---|---|
| date | Sat, 09 Aug 2025 15:55:59 -0400 |
| parents | 7955bed1d169 |
| children |
comparison
equal
deleted
inserted
replaced
| 45:7955bed1d169 | 46:31cee67540b5 |
|---|---|
| 109 printf(" x[%d]", size); | 109 printf(" x[%d]", size); |
| 110 | 110 |
| 111 (void)op; | 111 (void)op; |
| 112 } | 112 } |
| 113 | 113 |
| 114 struct op_info ops[] = { | 114 struct op_info ops[OP_FINAL_] = { |
| 115 [OP_SPLAT] = {"SPLAT", "splat", vret, vsplatparam}, | 115 [OP_SPLAT] = {"SPLAT", "splat", vret, vsplatparam}, |
| 116 [OP_LOAD_ALIGNED] = {"LOAD_ALIGNED", "load_aligned", vret, vloadparam}, | 116 [OP_LOAD_ALIGNED] = {"LOAD_ALIGNED", "load_aligned", vret, vloadparam}, |
| 117 [OP_LOAD] = {"LOAD", "load", vret, vloadparam}, | 117 [OP_LOAD] = {"LOAD", "load", vret, vloadparam}, |
| 118 [OP_STORE_ALIGNED] = {"STORE_ALIGNED", "store_aligned", nret, vstoreparam}, | 118 [OP_STORE_ALIGNED] = {"STORE_ALIGNED", "store_aligned", nret, vstoreparam}, |
| 119 [OP_STORE] = {"STORE", "store", nret, vstoreparam}, | 119 [OP_STORE] = {"STORE", "store", nret, vstoreparam}, |
| 135 [OP_MIN] = {"MIN", "min", vret, vtwoparam}, | 135 [OP_MIN] = {"MIN", "min", vret, vtwoparam}, |
| 136 [OP_MAX] = {"MAX", "max", vret, vtwoparam}, | 136 [OP_MAX] = {"MAX", "max", vret, vtwoparam}, |
| 137 [OP_RSHIFT] = {"RSHIFT", "rshift", vret, vshiftparam}, | 137 [OP_RSHIFT] = {"RSHIFT", "rshift", vret, vshiftparam}, |
| 138 [OP_LRSHIFT] = {"LRSHIFT", "lrshift", vret, vshiftparam}, | 138 [OP_LRSHIFT] = {"LRSHIFT", "lrshift", vret, vshiftparam}, |
| 139 [OP_LSHIFT] = {"LSHIFT", "lshift", vret, vshiftparam}, | 139 [OP_LSHIFT] = {"LSHIFT", "lshift", vret, vshiftparam}, |
| 140 | |
| 141 /* floating-point specific operations */ | |
| 142 [OP_FLOOR] = {"FLOOR", "floor", vret, voneparam}, | |
| 143 [OP_CEIL] = {"CEIL", "ceil", vret, voneparam}, | |
| 144 [OP_ROUND] = {"ROUND", "round", vret, voneparam}, | |
| 145 [OP_TRUNC] = {"TRUNC", "trunc", vret, voneparam}, | |
| 140 }; | 146 }; |
| 141 | 147 |
| 142 struct op_info *gen_op_info(int op) | 148 struct op_info *gen_op_info(int op) |
| 143 { | 149 { |
| 144 return &ops[op]; | 150 return &ops[op]; |
| 166 case OP_LRSHIFT: | 172 case OP_LRSHIFT: |
| 167 /* these operations make no sense for floating point */ | 173 /* these operations make no sense for floating point */ |
| 168 if (type == TYPE_FLOAT) | 174 if (type == TYPE_FLOAT) |
| 169 return 0; | 175 return 0; |
| 170 break; | 176 break; |
| 177 case OP_FLOOR: | |
| 178 case OP_CEIL: | |
| 179 case OP_ROUND: | |
| 180 /* likewise, these operations make no sense for integer types */ | |
| 181 if (type != TYPE_FLOAT) | |
| 182 return 0; | |
| 183 break; | |
| 171 } | 184 } |
| 172 | 185 |
| 173 return 1; | 186 return 1; |
| 174 } | 187 } |
| 175 | 188 |
| 176 /* XXX: would it be faster to unroll literally everything instead of defining everything, | |
| 177 * and then unpacking it all? */ | |
| 178 static const char *header_tmpl = | 189 static const char *header_tmpl = |
| 179 "/**\n" | 190 "/**\n" |
| 180 " * vec - a tiny SIMD vector library in C99\n" | 191 " * vec - a tiny SIMD vector library in C99\n" |
| 181 " * \n" | 192 " * \n" |
| 182 " * Copyright (c) 2024-2025 Paper\n" | 193 " * Copyright (c) 2024-2025 Paper\n" |
