From 3a08b7ce40a4de1ddc88e68fc99dc91553af0dc6 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 22 Oct 2026 14:53:01 +0100 Subject: [PATCH] test(libc): cover the sized find, count, min and max vector helpers guest_vector_algorithms ran one size of each MSVC-STL vector helper. It now also runs __std_find_trivial 1, 4 and 8 (first match, or last when there is none), __std_count_trivial 1, 2 and 4, __std_min_element 2, 4 and 8 and __std_max_element 1, 2 and 8. The min and max checks cover signed against unsigned ordering, a tie (the first extreme is returned) and an empty range. --- core/libs/tests/GuestVectorAlgorithms.cpp | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/core/libs/tests/GuestVectorAlgorithms.cpp b/core/libs/tests/GuestVectorAlgorithms.cpp index c3b858bac6..c40f008d86 100644 --- a/core/libs/tests/GuestVectorAlgorithms.cpp +++ b/core/libs/tests/GuestVectorAlgorithms.cpp @@ -4,6 +4,21 @@ #include #include +extern "C" { +const void* APS5_VABI __std_find_trivial_1_nid_postfix(const void*, const void*, std::uint8_t); +const void* APS5_VABI __std_find_trivial_4_nid_postfix(const void*, const void*, std::uint32_t); +const void* APS5_VABI __std_find_trivial_8_nid_postfix(const void*, const void*, std::uint64_t); +std::size_t APS5_VABI __std_count_trivial_1_nid_postfix(const void*, const void*, std::uint8_t); +std::size_t APS5_VABI __std_count_trivial_2_nid_postfix(const void*, const void*, std::uint16_t); +std::size_t APS5_VABI __std_count_trivial_4_nid_postfix(const void*, const void*, std::uint32_t); +const void* APS5_VABI __std_min_element_2_nid_postfix(const void*, const void*, bool); +const void* APS5_VABI __std_min_element_4_nid_postfix(const void*, const void*, bool); +const void* APS5_VABI __std_min_element_8_nid_postfix(const void*, const void*, bool); +const void* APS5_VABI __std_max_element_1_nid_postfix(const void*, const void*, bool); +const void* APS5_VABI __std_max_element_2_nid_postfix(const void*, const void*, bool); +const void* APS5_VABI __std_max_element_8_nid_postfix(const void*, const void*, bool); +} + struct MinMaxPointers { const void* minimum; const void* maximum; @@ -25,6 +40,40 @@ void APS5_VABI __std_swap_ranges_trivially_swappable_noalias_nid_postfix(void*, static void Require(bool value) { if (!value) std::abort(); } +static void CheckSizedHelpers() { + const std::uint8_t bytes[] = {3, 0xff, 3, 9, 0xff}; + Require(__std_find_trivial_1_nid_postfix(bytes, bytes + 5, 0xff) == bytes + 1); + Require(__std_find_trivial_1_nid_postfix(bytes, bytes + 5, 4) == bytes + 5); + Require(__std_find_trivial_1_nid_postfix(bytes, bytes, 3) == bytes); + Require(__std_count_trivial_1_nid_postfix(bytes, bytes + 5, 3) == 2 && __std_count_trivial_1_nid_postfix(bytes, bytes + 5, 7) == 0); + Require(__std_max_element_1_nid_postfix(bytes, bytes + 5, false) == bytes + 1); + Require(__std_max_element_1_nid_postfix(bytes, bytes + 5, true) == bytes + 3); + + const std::uint16_t halves[] = {0x8000, 5, 0x7fff, 5, 0x8000}; + Require(__std_count_trivial_2_nid_postfix(halves, halves + 5, 5) == 2 && __std_count_trivial_2_nid_postfix(halves, halves, 5) == 0); + Require(__std_min_element_2_nid_postfix(halves, halves + 5, false) == halves + 1); + Require(__std_min_element_2_nid_postfix(halves, halves + 5, true) == halves); + Require(__std_max_element_2_nid_postfix(halves, halves + 5, false) == halves); + Require(__std_max_element_2_nid_postfix(halves, halves + 5, true) == halves + 2); + + const std::uint32_t words[] = {7, 0xfffffff0u, 1, 1, 0xfffffff0u}; + Require(__std_find_trivial_4_nid_postfix(words, words + 5, 1) == words + 2); + Require(__std_find_trivial_4_nid_postfix(words, words + 5, 2) == words + 5); + Require(__std_count_trivial_4_nid_postfix(words, words + 5, 0xfffffff0u) == 2); + Require(__std_min_element_4_nid_postfix(words, words + 5, false) == words + 2); + Require(__std_min_element_4_nid_postfix(words, words + 5, true) == words + 1); + Require(__std_min_element_4_nid_postfix(words, words, true) == words); + + const std::uint64_t wides[] = {0x8000000000000000ull, 2, 0x7fffffffffffffffull, 0x8000000000000000ull}; + Require(__std_find_trivial_8_nid_postfix(wides, wides + 4, 0x8000000000000000ull) == wides); + Require(__std_find_trivial_8_nid_postfix(wides + 1, wides + 4, 0x8000000000000000ull) == wides + 3); + Require(__std_min_element_8_nid_postfix(wides, wides + 4, true) == wides); + Require(__std_min_element_8_nid_postfix(wides, wides + 4, false) == wides + 1); + Require(__std_max_element_8_nid_postfix(wides, wides + 4, false) == wides); + Require(__std_max_element_8_nid_postfix(wides, wides + 4, true) == wides + 2); + Require(__std_max_element_8_nid_postfix(wides, wides, false) == wides); +} + static void CheckFindAndCount() { const std::uint16_t halves[] = {5, 7, 9, 7}; Require(__std_find_trivial_2_nid_postfix(halves, halves + 4, 7) == halves + 1); @@ -88,6 +137,7 @@ static void CheckReverseAndSwap() { } int main() { + CheckSizedHelpers(); CheckFindAndCount(); CheckUnsizedRescan(); CheckMinMax();