summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWasm/AbstractMachine
diff options
context:
space:
mode:
authorNick Johnson <sylvyrfysh@gmail.com>2021-12-19 15:46:55 -0600
committerAndreas Kling <kling@serenityos.org>2021-12-21 22:13:51 +0100
commit08e4a1a4dcbf07853f3c1a63adb64298fc236e3f (patch)
tree96b88d0dd878850c1e9cb7313a28f26964435536 /Userland/Libraries/LibWasm/AbstractMachine
parent26bb3e1acf4aa1814573d628af356f9fbb628786 (diff)
downloadserenity-08e4a1a4dcbf07853f3c1a63adb64298fc236e3f.zip
AK+Everywhere: Replace __builtin bit functions
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount}, this commit removes all calls to these functions and replaces them with the equivalent functions in AK/BuiltinWrappers.h.
Diffstat (limited to 'Userland/Libraries/LibWasm/AbstractMachine')
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/Operators.h19
1 files changed, 7 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h
index de06a3cb79..4d8560abc9 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/Operators.h
+++ b/Userland/Libraries/LibWasm/AbstractMachine/Operators.h
@@ -7,6 +7,7 @@
#pragma once
#include <AK/BitCast.h>
+#include <AK/BuiltinWrappers.h>
#include <AK/Result.h>
#include <AK/StringView.h>
#include <AK/Types.h>
@@ -176,10 +177,8 @@ struct CountLeadingZeros {
if (lhs == 0)
return sizeof(Lhs) * CHAR_BIT;
- if constexpr (sizeof(Lhs) == 4)
- return __builtin_clz(lhs);
- else if constexpr (sizeof(Lhs) == 8)
- return __builtin_clzll(lhs);
+ if constexpr (sizeof(Lhs) == 4 || sizeof(Lhs) == 8)
+ return count_leading_zeroes(MakeUnsigned<Lhs>(lhs));
else
VERIFY_NOT_REACHED();
}
@@ -193,10 +192,8 @@ struct CountTrailingZeros {
if (lhs == 0)
return sizeof(Lhs) * CHAR_BIT;
- if constexpr (sizeof(Lhs) == 4)
- return __builtin_ctz(lhs);
- else if constexpr (sizeof(Lhs) == 8)
- return __builtin_ctzll(lhs);
+ if constexpr (sizeof(Lhs) == 4 || sizeof(Lhs) == 8)
+ return count_trailing_zeroes(MakeUnsigned<Lhs>(lhs));
else
VERIFY_NOT_REACHED();
}
@@ -207,10 +204,8 @@ struct PopCount {
template<typename Lhs>
auto operator()(Lhs lhs) const
{
- if constexpr (sizeof(Lhs) == 4)
- return __builtin_popcount(lhs);
- else if constexpr (sizeof(Lhs) == 8)
- return __builtin_popcountll(lhs);
+ if constexpr (sizeof(Lhs) == 4 || sizeof(Lhs) == 8)
+ return popcount(MakeUnsigned<Lhs>(lhs));
else
VERIFY_NOT_REACHED();
}