From 78c9bd1c2fbd55889e62a2032e9bc96684ced3b5 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:50:44 -0600 Subject: Bit extract (#5847) * promoting bitfield extraction and insertion to become intrinsics for internal compiler use * removing duplicate intrinsics from glsl.meta.slang * refactor: update function signatures of bitfield extraction and insertion to use uint as the parameter type for offset and bits. --------- Co-authored-by: Nate Morrical Co-authored-by: Yong He --- source/slang/core.meta.slang | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source/slang/core.meta.slang') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 3a7df8e7a..625f8f608 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -2714,6 +2714,23 @@ __generic __intrinsic_op($(kIROp_Reinterpret)) T reinterpret(U value); +/// `bitfieldInsert` inserts the bits least significant bits of `insert` into base at `offset` offset. +/// The returned value will have bits [offset, offset + bits + 1] taken from [0, bits - 1] of `insert` +/// and all other bits taken directly from the corresponding bits of `base`. +__generic +[__readNone] +[__unsafeForceInlineEarly] +__intrinsic_op($(kIROp_BitfieldInsert)) +T bitfieldInsert(T base, T insert, uint offset, uint bits); + +/// `bitfieldExtract` extracts a subset of the bits of `value` and +/// returns it in the least significant bits of the result. The range of bits extracted is [offset, offset + bits - 1]. +__generic +[__readNone] +[__unsafeForceInlineEarly] +__intrinsic_op($(kIROp_BitfieldExtract)) +T bitfieldExtract(T value, uint offset, uint bits); + /// Use an otherwise unused value /// This can be used to silence the warning about returning before initializing an out paramter. __generic -- cgit v1.2.3