summaryrefslogtreecommitdiff
path: root/asl/base
diff options
context:
space:
mode:
Diffstat (limited to 'asl/base')
-rw-r--r--asl/base/BUILD.bazel7
-rw-r--r--asl/base/assert.hpp20
-rw-r--r--asl/base/bit.hpp4
-rw-r--r--asl/base/config.hpp10
4 files changed, 30 insertions, 11 deletions
diff --git a/asl/base/BUILD.bazel b/asl/base/BUILD.bazel
index 7870ad9..6c90f06 100644
--- a/asl/base/BUILD.bazel
+++ b/asl/base/BUILD.bazel
@@ -24,6 +24,13 @@ cc_library(
srcs = [
"assert.cpp",
],
+ defines = select({
+ "//asl:debug": ["ASL_DEBUG=1"],
+ "//conditions:default": ["ASL_DEBUG=0"],
+ }) + select({
+ "//asl:optimized": ["ASL_OPTIMIZED=1"],
+ "//conditions:default": ["ASL_OPTIMIZED=0"],
+ }),
visibility = ["//visibility:public"],
)
diff --git a/asl/base/assert.hpp b/asl/base/assert.hpp
index 5aeb161..a899564 100644
--- a/asl/base/assert.hpp
+++ b/asl/base/assert.hpp
@@ -24,15 +24,17 @@ void report_assert_failure(const char* msg, const source_location& sl = source_l
#define ASL_DEBUG_BREAK() __builtin_debugtrap()
#endif
-// @Todo Configure asserts at build time
-
-#define ASL_ASSERT(...) \
- if (__VA_ARGS__) {} \
- else \
- { \
- ::asl::report_assert_failure(#__VA_ARGS__); \
- ASL_DEBUG_BREAK(); \
- }
+#if !ASL_OPTIMIZED
+ #define ASL_ASSERT(...) \
+ if (__VA_ARGS__) {} \
+ else \
+ { \
+ ::asl::report_assert_failure(#__VA_ARGS__); \
+ ASL_DEBUG_BREAK(); \
+ }
+#else
+ #define ASL_ASSERT(...)
+#endif
#define ASL_ASSERT_RELEASE(...) \
if (__VA_ARGS__) {} \
diff --git a/asl/base/bit.hpp b/asl/base/bit.hpp
index 5056383..824005c 100644
--- a/asl/base/bit.hpp
+++ b/asl/base/bit.hpp
@@ -114,7 +114,7 @@ constexpr T rotl(T v, int s) // NOLINT(*-no-recursion)
{
static constexpr int N = sizeof(decltype(v)) * 8;
s = s % N;
- return (s >= 0) ? (v << s) | (v >> (N - s)) : rotr(v, -s);
+ return (s >= 0) ? (v << s) | (v >> ((N - s) % N)) : rotr(v, -s);
}
template<is_unsigned_integer T>
@@ -122,7 +122,7 @@ constexpr T rotr(T v, int s) // NOLINT(*-no-recursion)
{
static constexpr int N = sizeof(decltype(v)) * 8;
s = s % N;
- return (s >= 0) ? (v >> s) | (v << (N - s)) : rotl(v, -s);
+ return (s >= 0) ? (v >> s) | (v << ((N - s) % N)) : rotl(v, -s);
}
constexpr uint16_t byteswap(uint16_t v)
diff --git a/asl/base/config.hpp b/asl/base/config.hpp
index f5756c3..e4e6e5d 100644
--- a/asl/base/config.hpp
+++ b/asl/base/config.hpp
@@ -22,5 +22,15 @@
#error Unknown compiler
#endif
+// ASL_DEBUG=1 for slow builds, with extra validation logic and such.
+#if !defined(ASL_DEBUG)
+ #error ASL_DEBUG should be defined to 0 or 1
+#endif
+
+// ASL_OPTIMIZED=1 for fast builds, with minimal validation logic.
+#if !defined(ASL_OPTIMIZED)
+ #error ASL_OPTIMIZED should be defined to 0 or 1
+#endif
+
// NOLINTEND(*-macro-to-enum)