Mercurial > vec
diff 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 |
line wrap: on
line diff
--- a/gen/genlib.c Wed Apr 30 18:36:38 2025 -0400 +++ b/gen/genlib.c Sat Aug 09 15:55:59 2025 -0400 @@ -111,7 +111,7 @@ (void)op; } -struct op_info ops[] = { +struct op_info ops[OP_FINAL_] = { [OP_SPLAT] = {"SPLAT", "splat", vret, vsplatparam}, [OP_LOAD_ALIGNED] = {"LOAD_ALIGNED", "load_aligned", vret, vloadparam}, [OP_LOAD] = {"LOAD", "load", vret, vloadparam}, @@ -137,6 +137,12 @@ [OP_RSHIFT] = {"RSHIFT", "rshift", vret, vshiftparam}, [OP_LRSHIFT] = {"LRSHIFT", "lrshift", vret, vshiftparam}, [OP_LSHIFT] = {"LSHIFT", "lshift", vret, vshiftparam}, + + /* floating-point specific operations */ + [OP_FLOOR] = {"FLOOR", "floor", vret, voneparam}, + [OP_CEIL] = {"CEIL", "ceil", vret, voneparam}, + [OP_ROUND] = {"ROUND", "round", vret, voneparam}, + [OP_TRUNC] = {"TRUNC", "trunc", vret, voneparam}, }; struct op_info *gen_op_info(int op) @@ -168,13 +174,18 @@ if (type == TYPE_FLOAT) return 0; break; + case OP_FLOOR: + case OP_CEIL: + case OP_ROUND: + /* likewise, these operations make no sense for integer types */ + if (type != TYPE_FLOAT) + return 0; + break; } return 1; } -/* XXX: would it be faster to unroll literally everything instead of defining everything, - * and then unpacking it all? */ static const char *header_tmpl = "/**\n" " * vec - a tiny SIMD vector library in C99\n"