aboutsummaryrefslogtreecommitdiff
path: root/test/aarch64
diff options
context:
space:
mode:
authorJacob Bramley <jacob.bramley@arm.com>2019-02-19 11:47:31 +0000
committerJacob Bramley <jacob.bramley@arm.com>2019-02-19 16:52:35 +0000
commitaf0ca0a8e5a90c116e09c359323ef428839df372 (patch)
tree6831b6b1ef56ba1c0b33b83d83c9b8136611fe06 /test/aarch64
parentdddf02dba39e6b3f59a8052ee605f31c199d27ff (diff)
downloadvixl-af0ca0a8e5a90c116e09c359323ef428839df372.tar.gz
Fix warnings on Clang 8.
This re-implements (and adds tests for) CountLeadingSignBits. Change-Id: I308254f2ca97251173bcc76ef046dae4a445b9b8
Diffstat (limited to 'test/aarch64')
-rw-r--r--test/aarch64/test-api-aarch64.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/aarch64/test-api-aarch64.cc b/test/aarch64/test-api-aarch64.cc
index cca50374..1cb66cd7 100644
--- a/test/aarch64/test-api-aarch64.cc
+++ b/test/aarch64/test-api-aarch64.cc
@@ -41,6 +41,67 @@
namespace vixl {
namespace aarch64 {
+// Check compiler intrinsics helpers.
+
+TEST(count_leading_sign_bits) {
+ class Helper {
+ public:
+ static void Check(int64_t value, int non_sign_bits) {
+ VIXL_ASSERT((0 <= non_sign_bits) && (non_sign_bits < 64));
+
+ for (int width = 1; width <= 64; width *= 2) {
+ // Note that leading_sign_bits does not include the topmost bit.
+ int leading_sign_bits = width - non_sign_bits - 1;
+ if (leading_sign_bits < 0) continue;
+
+ int64_t result = CountLeadingSignBits(value, width);
+ int64_t fallback_result = CountLeadingSignBitsFallBack(value, width);
+ VIXL_CHECK(result == leading_sign_bits);
+ VIXL_CHECK(fallback_result == leading_sign_bits);
+ }
+ }
+ };
+
+ // Basic positive (and zero) cases. Sign bits are all zeroes.
+ Helper::Check(0, 0); // 0b++++
+ Helper::Check(1, 1); // 0b+++1
+ Helper::Check(2, 2); // 0b++10
+ Helper::Check(3, 2); // 0b++11
+ Helper::Check(4, 3); // 0b+100
+
+ // Basic negative cases. Sign bits are all ones.
+ Helper::Check(-1, 0); // 0b----
+ Helper::Check(-2, 1); // 0b---0
+ Helper::Check(-3, 2); // 0b--01
+ Helper::Check(-4, 2); // 0b--00
+ Helper::Check(-5, 3); // 0b-011
+
+ // Boundary conditions.
+ Helper::Check(INT8_MAX, 7);
+ Helper::Check(INT8_MIN, 7);
+ Helper::Check(static_cast<int64_t>(INT8_MAX) + 1, 8);
+ Helper::Check(static_cast<int64_t>(INT8_MIN) - 1, 8);
+
+ Helper::Check(INT16_MAX, 15);
+ Helper::Check(INT16_MIN, 15);
+ Helper::Check(static_cast<int64_t>(INT16_MAX) + 1, 16);
+ Helper::Check(static_cast<int64_t>(INT16_MIN) - 1, 16);
+
+ Helper::Check(INT32_MAX, 31);
+ Helper::Check(INT32_MIN, 31);
+ Helper::Check(static_cast<int64_t>(INT32_MAX) + 1, 32);
+ Helper::Check(static_cast<int64_t>(INT32_MIN) - 1, 32);
+
+ Helper::Check(INT64_MAX, 63);
+ Helper::Check(INT64_MIN, 63);
+
+ // Check automatic width detection.
+ VIXL_CHECK(CountLeadingSignBits(static_cast<int8_t>(42)) == 1); // 0b00101010
+ VIXL_CHECK(CountLeadingSignBits(static_cast<int16_t>(42)) == 9);
+ VIXL_CHECK(CountLeadingSignBits(static_cast<int32_t>(42)) == 25);
+ VIXL_CHECK(CountLeadingSignBits(static_cast<int64_t>(42)) == 57);
+}
+
// Check SimFloat16 class mechanics.
TEST(float16_operators) {
::vixl::internal::SimFloat16 f1 = kFP16DefaultNaN;