diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2025-07-17 14:59:33 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-17 06:59:33 +0000 |
| commit | 28758e0e427ceca196937dc90efe3ab1cb35bd70 (patch) | |
| tree | 7a609525e686772854d8cd82b7a91f69a97c0e30 /source/core/slang-common.h | |
| parent | 020a16072923a66ae0985be618fd32310aa87242 (diff) | |
Perf improvements to IR serialization (#7751)
* option to use riff as serialization backend
* option to use riff as serialization backend
* perf
* shuffle code
* perf improvements to deserialization
* formatting
* remove bit_cast
* correct IR verification
* neaten serialized format
* fix peek module info
* formatting
* remove temporary profiling code
* cleanup
* fix wasm build
* more explicit sizes
* deserialize via fossil on 32 bit wasm
* Make serialized modules Int size agnostic
* reorder stable names to allow range based check for 64 bit constants
* format
* review comments
* fix build
* fix
* c++17 compat slang-common.h
Diffstat (limited to 'source/core/slang-common.h')
| -rw-r--r-- | source/core/slang-common.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/source/core/slang-common.h b/source/core/slang-common.h index 9248e250f..015c3233c 100644 --- a/source/core/slang-common.h +++ b/source/core/slang-common.h @@ -5,7 +5,9 @@ #include <assert.h> #include <cstddef> +#include <cstring> #include <stdint.h> +#include <type_traits> #define VARIADIC_TEMPLATE @@ -199,6 +201,19 @@ inline bool isBitSet(T value, T bitToTest) static_assert(sizeof(T) <= sizeof(uint32_t), "Only support up to 32 bit enums"); return (T)((uint32_t)value & (uint32_t)bitToTest) == bitToTest; } + +template<typename To, typename From> +typename std::enable_if_t< + sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && + std::is_trivially_copyable_v<To> && std::is_trivially_constructible_v<To>, + To> +bitCast(const From& src) +{ + To dst; + std::memcpy(&dst, &src, sizeof(To)); + return dst; +} + } // namespace Slang // SLANG_DEFER @@ -349,7 +364,7 @@ public: #define SLANG_ASSERT(VALUE) \ do \ { \ - if (!(VALUE)) \ + if (!(VALUE)) [[unlikely]] \ SLANG_ASSERT_FAILURE(#VALUE); \ } while (0) #else @@ -357,7 +372,7 @@ public: #endif #define SLANG_RELEASE_ASSERT(VALUE) \ - if (VALUE) \ + if (VALUE) [[likely]] \ { \ } \ else \ |
