diff options
author | Tom Smeding <tom@tomsmeding.com> | 2025-03-12 23:20:13 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2025-03-13 09:27:51 +0100 |
commit | ed6acbe5f409aba2fb222693da567ce04b7c4e01 (patch) | |
tree | becbef3f3afeed63c248f057dae6fef0cb6c6147 /cbits | |
parent | bcda5b7eb20874f948fbdc23b6daa3ebb792ffe0 (diff) |
Implement quot/rem
Diffstat (limited to 'cbits')
-rw-r--r-- | cbits/arith.c | 42 | ||||
-rw-r--r-- | cbits/arith_lists.h | 3 |
2 files changed, 44 insertions, 1 deletions
diff --git a/cbits/arith.c b/cbits/arith.c index 9aed3b4..4646ca4 100644 --- a/cbits/arith.c +++ b/cbits/arith.c @@ -18,6 +18,7 @@ // These are the wrapper macros used in arith_lists.h. Preset them to empty to // avoid having to touch macros unrelated to the particular operation set below. #define LIST_BINOP(name, id, hsop) +#define LIST_IBINOP(name, id, hsop) #define LIST_FBINOP(name, id, hsop) #define LIST_UNOP(name, id, _) #define LIST_FUNOP(name, id, _) @@ -410,6 +411,37 @@ enum binop_tag_t { } \ } +enum ibinop_tag_t { +#undef LIST_IBINOP +#define LIST_IBINOP(name, id, hsop) name = id, +#include "arith_lists.h" +#undef LIST_IBINOP +#define LIST_IBINOP(name, id, hsop) +}; + +#define ENTRY_IBINARY_STRIDED_OPS(typ) \ + void oxarop_ibinary_ ## typ ## _sv_strided(enum binop_tag_t tag, i64 rank, const i64 *shape, typ *out, typ x, const i64 *strides, const typ *y) { \ + switch (tag) { \ + case IB_QUOT: oxarop_op_quot_ ## typ ## _sv_strided(rank, shape, out, x, strides, y); break; \ + case IB_REM: oxarop_op_rem_ ## typ ## _sv_strided(rank, shape, out, x, strides, y); break; \ + default: wrong_op("ibinary_sv_strided", tag); \ + } \ + } \ + void oxarop_ibinary_ ## typ ## _vs_strided(enum binop_tag_t tag, i64 rank, const i64 *shape, typ *out, const i64 *strides, const typ *x, typ y) { \ + switch (tag) { \ + case IB_QUOT: oxarop_op_quot_ ## typ ## _vs_strided(rank, shape, out, strides, x, y); break; \ + case IB_REM: oxarop_op_rem_ ## typ ## _vs_strided(rank, shape, out, strides, x, y); break; \ + default: wrong_op("ibinary_vs_strided", tag); \ + } \ + } \ + void oxarop_ibinary_ ## typ ## _vv_strided(enum binop_tag_t tag, i64 rank, const i64 *shape, typ *out, const i64 *strides1, const typ *x, const i64 *strides2, const typ *y) { \ + switch (tag) { \ + case IB_QUOT: oxarop_op_quot_ ## typ ## _vv_strided(rank, shape, out, strides1, x, strides2, y); break; \ + case IB_REM: oxarop_op_rem_ ## typ ## _vv_strided(rank, shape, out, strides1, x, strides2, y); break; \ + default: wrong_op("ibinary_vv_strided", tag); \ + } \ + } + enum fbinop_tag_t { #undef LIST_FBINOP #define LIST_FBINOP(name, id, hsop) name = id, @@ -528,8 +560,9 @@ enum redop_tag_t { * Generate all the functions * *****************************************************************************/ +#define INT_TYPES_XLIST X(i32) X(i64) #define FLOAT_TYPES_XLIST X(double) X(float) -#define NUM_TYPES_XLIST X(i32) X(i64) FLOAT_TYPES_XLIST +#define NUM_TYPES_XLIST INT_TYPES_XLIST FLOAT_TYPES_XLIST #define X(typ) \ COMM_OP_STRIDED(add, +, typ) \ @@ -554,6 +587,13 @@ NUM_TYPES_XLIST #undef X #define X(typ) \ + NONCOMM_OP_STRIDED(quot, /, typ) \ + NONCOMM_OP_STRIDED(rem, %, typ) \ + ENTRY_IBINARY_STRIDED_OPS(typ) +INT_TYPES_XLIST +#undef X + +#define X(typ) \ NONCOMM_OP_STRIDED(fdiv, /, typ) \ PREFIX_BINOP_STRIDED(pow, GEN_POW, typ) \ PREFIX_BINOP_STRIDED(logbase, GEN_LOGBASE, typ) \ diff --git a/cbits/arith_lists.h b/cbits/arith_lists.h index 58de65a..b651b62 100644 --- a/cbits/arith_lists.h +++ b/cbits/arith_lists.h @@ -2,6 +2,9 @@ LIST_BINOP(BO_ADD, 1, +) LIST_BINOP(BO_SUB, 2, -) LIST_BINOP(BO_MUL, 3, *) +LIST_IBINOP(IB_QUOT, 1, quot) +LIST_IBINOP(IB_REM, 2, rem) + LIST_FBINOP(FB_DIV, 1, /) LIST_FBINOP(FB_POW, 2, **) LIST_FBINOP(FB_LOGBASE, 3, logBase) |