Skip to content

Commit 9dd59f2

Browse files
committed
BUG: Fix LUT compile failures on MSVC and Highway debug builds
Two portability issues in the transposed-load LUT path: - kTransposeLength evaluated to 0 when kInitTranspose is false (kRows < kTransposeBy), producing a zero-size array that MSVC rejects. Clamp it to 1 as an unused placeholder. - Lanes(du) is not constexpr in Highway debug builds, so it cannot initialize a constexpr size_t. Use the HWY_LANES(T) macro, which is a compile-time constant in all build modes.
1 parent 5f1646d commit 9dd59f2

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

npsr/lut-inl.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ class Lut {
4444
// Implementation details for transposition optimization
4545
static constexpr size_t kTransposeBy = HWY_LANES(T);
4646
static constexpr size_t kTransposeTail = kRows % kTransposeBy;
47-
static constexpr size_t kTransposeLength = (kRows - kTransposeTail) * kCols;
48-
4947
// Determine at compile-time if transposition optimization is viable
5048
static constexpr bool kInitTranspose = !HWY_HAVE_SCALABLE && (
5149
kRows / kTransposeBy > 0 && kCols % kTransposeBy == 0 &&
5250
(kTransposeBy == 2 || kTransposeBy == 4) // Currently supports 2x or 4x unrolling
5351
);
52+
// When kInitTranspose is false kTransposeLength would be 0 (kRows < kTransposeBy),
53+
// which would produce a zero-size array (MSVC forbid it) — use 1 as a placeholder instead.
54+
static constexpr size_t kTransposeLength = kInitTranspose
55+
? (kRows - kTransposeTail) * kCols
56+
: 1;
5457

5558
/**
5659
* @brief Constructs the table from row arrays.
@@ -145,7 +148,7 @@ class Lut {
145148
using TU = TFromD<DU>;
146149
const DU du;
147150

148-
constexpr size_t kLanes = Lanes(du);
151+
constexpr size_t kLanes = HWY_LANES(T);
149152

150153
// Only use transposed load if vector lanes match the transpose blocking factor
151154
if constexpr (kLanes == kTransposeBy) {
@@ -237,7 +240,7 @@ class Lut {
237240
const D d;
238241

239242
#if !HWY_HAVE_SCALABLE
240-
constexpr size_t kLanes = Lanes(du);
243+
constexpr size_t kLanes = HWY_LANES(T);
241244
// Strategy 1: Vector size equals table width (Single Table Lookup)
242245
if constexpr (kLanes == kCols) {
243246
const auto ind = IndicesFromVec(d, idx);

0 commit comments

Comments
 (0)