diff --git a/tests/_feature_detect.cpp b/tests/_feature_detect.cpp index 875abac..60de46f 100644 --- a/tests/_feature_detect.cpp +++ b/tests/_feature_detect.cpp @@ -5,8 +5,12 @@ #include -#include "oaknut/feature_detection/feature_detection.hpp" -#include "oaknut/feature_detection/feature_detection_idregs.hpp" +#include "architecture.hpp" + +#ifdef ON_ARM64 + +# include "oaknut/feature_detection/feature_detection.hpp" +# include "oaknut/feature_detection/feature_detection_idregs.hpp" using namespace oaknut; @@ -16,26 +20,6 @@ TEST_CASE("Print CPU features (Default)") std::fputs("CPU Features: ", stdout); -#define OAKNUT_CPU_FEATURE(name) \ - if (features.has(CpuFeature::name)) \ - std::fputs(#name " ", stdout); -#include "oaknut/impl/cpu_feature.inc.hpp" -#undef OAKNUT_CPU_FEATURE - - std::fputs("\n", stdout); -} - -#if OAKNUT_SUPPORTS_READING_ID_REGISTERS == 1 - -TEST_CASE("Print CPU features (Using CPUID)") -{ - std::optional id_regs = read_id_registers(); - REQUIRE(!!id_regs); - - CpuFeatures features = detect_features_via_id_registers(*id_regs); - - std::fputs("CPU Features (CPUID method): ", stdout); - # define OAKNUT_CPU_FEATURE(name) \ if (features.has(CpuFeature::name)) \ std::fputs(#name " ", stdout); @@ -45,7 +29,27 @@ TEST_CASE("Print CPU features (Using CPUID)") std::fputs("\n", stdout); } -#elif OAKNUT_SUPPORTS_READING_ID_REGISTERS == 2 +# if OAKNUT_SUPPORTS_READING_ID_REGISTERS == 1 + +TEST_CASE("Print CPU features (Using CPUID)") +{ + std::optional id_regs = read_id_registers(); + REQUIRE(!!id_regs); + + CpuFeatures features = detect_features_via_id_registers(*id_regs); + + std::fputs("CPU Features (CPUID method): ", stdout); + +# define OAKNUT_CPU_FEATURE(name) \ + if (features.has(CpuFeature::name)) \ + std::fputs(#name " ", stdout); +# include "oaknut/impl/cpu_feature.inc.hpp" +# undef OAKNUT_CPU_FEATURE + + std::fputs("\n", stdout); +} + +# elif OAKNUT_SUPPORTS_READING_ID_REGISTERS == 2 TEST_CASE("Print CPU features (Using CPUID)") { @@ -58,14 +62,16 @@ TEST_CASE("Print CPU features (Using CPUID)") std::printf("CPU Features (CPUID method - Core %zu): ", core_index); -# define OAKNUT_CPU_FEATURE(name) \ - if (features.has(CpuFeature::name)) \ - std::fputs(#name " ", stdout); -# include "oaknut/impl/cpu_feature.inc.hpp" -# undef OAKNUT_CPU_FEATURE +# define OAKNUT_CPU_FEATURE(name) \ + if (features.has(CpuFeature::name)) \ + std::fputs(#name " ", stdout); +# include "oaknut/impl/cpu_feature.inc.hpp" +# undef OAKNUT_CPU_FEATURE std::fputs("\n", stdout); } } +# endif + #endif diff --git a/tests/architecture.hpp b/tests/architecture.hpp new file mode 100644 index 0000000..90471a7 --- /dev/null +++ b/tests/architecture.hpp @@ -0,0 +1,6 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 merryhime +// SPDX-License-Identifier: MIT + +#if defined(__ARM64__) || defined(__aarch64__) || defined(_M_ARM64) +# define ON_ARM64 +#endif diff --git a/tests/basic.cpp b/tests/basic.cpp index e621fae..344d9d7 100644 --- a/tests/basic.cpp +++ b/tests/basic.cpp @@ -7,14 +7,18 @@ #include -#include "oaknut/code_block.hpp" -#include "oaknut/dual_code_block.hpp" +#include "architecture.hpp" #include "oaknut/oaknut.hpp" #include "rand_int.hpp" using namespace oaknut; using namespace oaknut::util; +#ifdef ON_ARM64 + +# include "oaknut/code_block.hpp" +# include "oaknut/dual_code_block.hpp" + TEST_CASE("Basic Test") { CodeBlock mem{4096}; @@ -196,19 +200,6 @@ TEST_CASE("ADR", "[slow]") } } -TEST_CASE("PageOffset (rollover)") -{ - REQUIRE(PageOffset<21, 12>::encode(0x0000000088e74000, 0xffffffffd167dece) == 0xd2202); -} - -TEST_CASE("PageOffset (page boundary)") -{ - REQUIRE(PageOffset<21, 12>::encode(0x0001000000000002, 0x0001000000000001) == 0); - REQUIRE(PageOffset<21, 12>::encode(0x0001000000000001, 0x0001000000000002) == 0); - REQUIRE(PageOffset<21, 12>::encode(0x0001000000001000, 0x0001000000000fff) == 0x1fffff); - REQUIRE(PageOffset<21, 12>::encode(0x0001000000000fff, 0x0001000000001000) == 0x080000); -} - TEST_CASE("ADRP", "[slow]") { CodeBlock mem{4096}; @@ -325,3 +316,18 @@ TEST_CASE("MOVP2R (4GiB boundary)") test(-i); } } + +#endif + +TEST_CASE("PageOffset (rollover)") +{ + REQUIRE(PageOffset<21, 12>::encode(0x0000000088e74000, 0xffffffffd167dece) == 0xd2202); +} + +TEST_CASE("PageOffset (page boundary)") +{ + REQUIRE(PageOffset<21, 12>::encode(0x0001000000000002, 0x0001000000000001) == 0); + REQUIRE(PageOffset<21, 12>::encode(0x0001000000000001, 0x0001000000000002) == 0); + REQUIRE(PageOffset<21, 12>::encode(0x0001000000001000, 0x0001000000000fff) == 0x1fffff); + REQUIRE(PageOffset<21, 12>::encode(0x0001000000000fff, 0x0001000000001000) == 0x080000); +} diff --git a/tests/vector_code_gen.cpp b/tests/vector_code_gen.cpp index baceeef..5ede9e5 100644 --- a/tests/vector_code_gen.cpp +++ b/tests/vector_code_gen.cpp @@ -9,9 +9,13 @@ #include -#include "oaknut/code_block.hpp" -#include "oaknut/oaknut.hpp" -#include "rand_int.hpp" +#include "architecture.hpp" + +#ifdef ON_ARM64 + +# include "oaknut/code_block.hpp" +# include "oaknut/oaknut.hpp" +# include "rand_int.hpp" using namespace oaknut; using namespace oaknut::util; @@ -83,3 +87,5 @@ TEST_CASE("Fibonacci (VectorCodeGenerator)") REQUIRE(fib(5) == 5); REQUIRE(fib(9) == 34); } + +#endif