Skip to content

Commit a006772

Browse files
authored
Merge pull request #34 from ConstexprCore/sse2-intrinsic-load
sse2_compare.h: load with _mm_loadu_si128 instead of inline asm
2 parents 4fdf1b7 + 2dca949 commit a006772

2 files changed

Lines changed: 11 additions & 35 deletions

File tree

‎include/ConstexprCore/detail/sse2_compare.h‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,13 @@ inline constexpr std::uint8_t and_masks[17][16] = {
5353
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
5454
};
5555

56-
// Read an address range that the caller has established is mapped. The
57-
// explicit machine load keeps the page-safe overread out of C++ vector-load
58-
// folding, including when LTO later discovers a short input object. The
59-
// memory operand describes exactly the bytes read, without a memory clobber.
56+
// Read an address range that the caller has established is mapped. Known
57+
// short objects never reach this load (the __builtin_object_size guards in
58+
// page_safe_load_16 and compare_chunks copy them first), and windows past the
59+
// first chunk are formed by integer arithmetic (sse2_mapped_offset), so the
60+
// optimizer cannot fold the overread, even under LTO.
6061
constexprcore_really_inline __m128i sse2_load_mapped_16(const char* p) noexcept {
61-
#if defined(__GNUC__) || defined(__clang__)
62-
using bytes16 = char[16];
63-
__m128i raw;
64-
#if defined(__AVX__)
65-
__asm__("vmovdqu {%1, %0|%0, %1}" : "=x"(raw)
66-
: "m"(*reinterpret_cast<const bytes16*>(p)));
67-
#else
68-
__asm__("movdqu {%1, %0|%0, %1}" : "=x"(raw)
69-
: "m"(*reinterpret_cast<const bytes16*>(p)));
70-
#endif
71-
return raw;
72-
#else
7362
return _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
74-
#endif
7563
}
7664

7765
// Page-safe 16-byte load helper for x86-64.

‎singleheader/perfect_hash.h‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on 2026-10-26 18:33:42 +0000. Do not edit! */
1+
/* auto-generated on 2026-10-28 18:10:33 -0400. Do not edit! */
22
/*
33
* ConstexprCore perfect_hash 0.3.0 — single-header amalgamation.
44
*
@@ -1762,25 +1762,13 @@ inline constexpr std::uint8_t and_masks[17][16] = {
17621762
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
17631763
};
17641764

1765-
// Read an address range that the caller has established is mapped. The
1766-
// explicit machine load keeps the page-safe overread out of C++ vector-load
1767-
// folding, including when LTO later discovers a short input object. The
1768-
// memory operand describes exactly the bytes read, without a memory clobber.
1765+
// Read an address range that the caller has established is mapped. Known
1766+
// short objects never reach this load (the __builtin_object_size guards in
1767+
// page_safe_load_16 and compare_chunks copy them first), and windows past the
1768+
// first chunk are formed by integer arithmetic (sse2_mapped_offset), so the
1769+
// optimizer cannot fold the overread, even under LTO.
17691770
constexprcore_really_inline __m128i sse2_load_mapped_16(const char* p) noexcept {
1770-
#if defined(__GNUC__) || defined(__clang__)
1771-
using bytes16 = char[16];
1772-
__m128i raw;
1773-
#if defined(__AVX__)
1774-
__asm__("vmovdqu {%1, %0|%0, %1}" : "=x"(raw)
1775-
: "m"(*reinterpret_cast<const bytes16*>(p)));
1776-
#else
1777-
__asm__("movdqu {%1, %0|%0, %1}" : "=x"(raw)
1778-
: "m"(*reinterpret_cast<const bytes16*>(p)));
1779-
#endif
1780-
return raw;
1781-
#else
17821771
return _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
1783-
#endif
17841772
}
17851773

17861774
// Page-safe 16-byte load helper for x86-64.

0 commit comments

Comments
 (0)