From f2285400e65dafe730a073b3ca92494d72c7295b Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 2 Mar 2026 17:52:57 +0100 Subject: add bswap16/32/64 - frontend: __builtin_bswapX intrinsics - backend: ObswapX instructions --- ir/builder.c | 2 ++ ir/fold.c | 4 ++++ ir/op.def | 3 +++ 3 files changed, 9 insertions(+) (limited to 'ir') 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) -- cgit v1.2.3