From ffcb1030f72af757fc03aa395e19b976d6405126 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 3 Dec 2024 15:52:02 -0800 Subject: Add intrinsics for aligned load/store. (#5736) * Add intrinsics for aligned load/store. * Fix. * Update comment. * Implement aligned load/store as intrinsic_op. * Fix. * Add proposal doc. * fix typo. --- source/slang/core.meta.slang | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'source/slang/core.meta.slang') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index a9d53162c..3a7df8e7a 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1038,6 +1038,47 @@ struct Ptr } }; +//@hidden: +__intrinsic_op($(kIROp_AlignedAttr)) +void __align_attr(int alignment); + +__intrinsic_op($(kIROp_Load)) +T __load_aligned(T* ptr, U alignmentAttr); + +__intrinsic_op($(kIROp_Store)) +void __store_aligned(T* ptr, T value, U alignmentAttr); + +//@public: + +/// Load a value from a pointer with a known alignment. +/// Aligned loads are more efficient than unaligned loads on some platforms. +/// @param alignment The alignment of the load operation. +/// @param ptr The pointer to load from. +/// @return The value loaded from the pointer. +/// @remarks When targeting SPIRV, this function maps to an `OpLoad` instruction with the `Aligned` memory operand. +/// The functions maps to normal load operation on other targets. +/// +[__NoSideEffect] +[ForceInline] +T loadAligned(T* ptr) +{ + return __load_aligned(ptr, __align_attr(alignment)); +} + +/// Store a value to a pointer with a known alignment. +/// Aligned stores are more efficient than unaligned stores on some platforms. +/// @param alignment The alignment of the store operation. +/// @param ptr The pointer to store value to. +/// @param value The value to store. +/// @remarks When targeting SPIRV, this function maps to an `OpStore` instruction with the `Aligned` memory operand. +/// The functions maps to normal store operation on other targets. +/// +[ForceInline] +void storeAligned(T* ptr, T value) +{ + __store_aligned(ptr, value, __align_attr(alignment)); +} + //@hidden: __intrinsic_op($(kIROp_Load)) T __load(Ptr ptr); -- cgit v1.2.3