aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-03-02 17:52:57 +0100
committerlemon <lsof@mailbox.org>2026-03-02 17:52:57 +0100
commitf2285400e65dafe730a073b3ca92494d72c7295b (patch)
treed5a96f09fbd0402ada3c39165a9d2d8202ee8e5d /ir
parenta498f851ef2f50c9b8ac47e238137af52b54057d (diff)
add bswap16/32/64
- frontend: __builtin_bswapX intrinsics - backend: ObswapX instructions
Diffstat (limited to 'ir')
-rw-r--r--ir/builder.c2
-rw-r--r--ir/fold.c4
-rw-r--r--ir/op.def3
3 files changed, 9 insertions, 0 deletions
diff --git a/ir/builder.c b/ir/builder.c
index 6758533..206e66d 100644
--- a/ir/builder.c
+++ b/ir/builder.c
@@ -191,6 +191,8 @@ irunop(struct function *fn, enum op op, enum irclass k, union ref a)
case Oexts32: case Oextu32:
case Ocopy:
break;
+ case Obswap16: case Obswap32: case Obswap64:
+ break;
default: assert(!"unop?");
}
return fn ? addinstr(fn, mkinstr(op, k, a)) : NOREF;
diff --git a/ir/fold.c b/ir/fold.c
index c87ca4d..ba50e40 100644
--- a/ir/fold.c
+++ b/ir/fold.c
@@ -1,4 +1,5 @@
#include "ir.h"
+#include "../endian.h"
static union ref
foldint(enum op op, enum irclass k, union ref lr, union ref rr)
@@ -24,6 +25,9 @@ foldint(enum op op, enum irclass k, union ref lr, union ref rr)
case Oextu16: x = (ushort)l.s; break;
case Oexts32: x = (int)l.s; break;
case Oextu32: x = (uint)l.s; break;
+ case Obswap16: x = bswap16(l.u); break;
+ case Obswap32: x = bswap32(l.u); break;
+ case Obswap64: x = bswap64(l.u); break;
case Oadd: x = l.u + r.u; break;
case Osub: x = l.u - r.u; break;
case Omul: x = l.u * r.u; break;
diff --git a/ir/op.def b/ir/op.def
index ac753c0..4a18b4b 100644
--- a/ir/op.def
+++ b/ir/op.def
@@ -20,6 +20,9 @@ _(exts16, 1)
_(extu16, 1)
_(exts32, 1)
_(extu32, 1)
+_(bswap16, 1)
+_(bswap32, 1)
+_(bswap64, 1)
_(add, 2)
_(sub, 2)
_(mul, 2)