summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-common.h19
-rw-r--r--source/core/slang-performance-profiler.cpp21
2 files changed, 31 insertions, 9 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 \
diff --git a/source/core/slang-performance-profiler.cpp b/source/core/slang-performance-profiler.cpp
index 9bc532680..bd046f4cc 100644
--- a/source/core/slang-performance-profiler.cpp
+++ b/source/core/slang-performance-profiler.cpp
@@ -35,15 +35,22 @@ public:
char buffer[512];
for (const auto& func : data)
{
- memset(buffer, 0, sizeof(buffer));
- snprintf(buffer, sizeof(buffer), "[*] %30s", func.key);
- out << buffer << " \t";
- auto milliseconds =
- std::chrono::duration_cast<std::chrono::milliseconds>(func.value.duration);
- out << func.value.invocationCount << " \t"
- << static_cast<uint64_t>(milliseconds.count()) << "ms\n";
+ auto microseconds =
+ std::chrono::duration_cast<std::chrono::microseconds>(func.value.duration);
+ double milliseconds = microseconds.count() / 1000.0;
+ snprintf(
+ buffer,
+ sizeof(buffer),
+ "[*] %30s \t%d \t%8.2fms\n",
+ func.key,
+ func.value.invocationCount,
+ milliseconds);
+
+ out << buffer;
}
}
+
+
virtual void clear() override { data.clear(); }
virtual void dispose() override { data = decltype(data)(); }
};