From af0ca0a8e5a90c116e09c359323ef428839df372 Mon Sep 17 00:00:00 2001 From: Jacob Bramley Date: Tue, 19 Feb 2019 11:47:31 +0000 Subject: Fix warnings on Clang 8. This re-implements (and adds tests for) CountLeadingSignBits. Change-Id: I308254f2ca97251173bcc76ef046dae4a445b9b8 --- test/aarch64/test-api-aarch64.cc | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'test/aarch64') 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(INT8_MAX) + 1, 8); + Helper::Check(static_cast(INT8_MIN) - 1, 8); + + Helper::Check(INT16_MAX, 15); + Helper::Check(INT16_MIN, 15); + Helper::Check(static_cast(INT16_MAX) + 1, 16); + Helper::Check(static_cast(INT16_MIN) - 1, 16); + + Helper::Check(INT32_MAX, 31); + Helper::Check(INT32_MIN, 31); + Helper::Check(static_cast(INT32_MAX) + 1, 32); + Helper::Check(static_cast(INT32_MIN) - 1, 32); + + Helper::Check(INT64_MAX, 63); + Helper::Check(INT64_MIN, 63); + + // Check automatic width detection. + VIXL_CHECK(CountLeadingSignBits(static_cast(42)) == 1); // 0b00101010 + VIXL_CHECK(CountLeadingSignBits(static_cast(42)) == 9); + VIXL_CHECK(CountLeadingSignBits(static_cast(42)) == 25); + VIXL_CHECK(CountLeadingSignBits(static_cast(42)) == 57); +} + // Check SimFloat16 class mechanics. TEST(float16_operators) { ::vixl::internal::SimFloat16 f1 = kFP16DefaultNaN; -- cgit v1.2.3