Skip to content

Commit

Permalink
windows: fix build of simd.cc (union init + template conflict because…
Browse files Browse the repository at this point in the history
… of same type)

By default, first member of union only can be initialized. Gcc has
extension to deal with this.

For VS, designated initializer is only available from C++20, so it can't
be used. So, using macro that init with first field of union.

https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.10240.0/km/crt/arm64_neon.h#L103

typedef union __declspec(intrin_type) _ADVSIMD_ALIGN(16) __n128
{
     unsigned __int64   n128_u64[2];
     unsigned __int32   n128_u32[4];
     ...
} __n128;

So we must init as __int64[2] instead.

---

In more, template conflict cause uint64x2_t and uint32x4_t are same
types for VS: https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.10240.0/km/crt/arm64_neon.h#L284

In gcc, those are distinct (builtin) types:
https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.10240.0/km/crt/arm64_neon.h#L284
  • Loading branch information
pbo-linaro committed Sep 20, 2022
1 parent 3f6d2e6 commit 7586c64
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions deps/v8/src/objects/simd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ inline uintptr_t slow_search(T* array, uintptr_t array_len, uintptr_t index,
// max(v & mask) = 4
// index of the first match = 4-max = 4-4 = 0
//
template <typename T>
inline int extract_first_nonzero_index(T v) {
UNREACHABLE();
}

template <>
V8_ALLOW_UNUSED inline int extract_first_nonzero_index(uint32x4_t v) {
uint32x4_t mask = {4, 3, 2, 1};
#if defined(_MSC_VER)
# define PACK32x4(w,x,y,z) { ((w) + (uint64_t(x) << 32)), ((y) + (uint64_t(z) << 32)) }
#else
# define PACK32x4(w,x,y,z) { (w), (x), (y), (z) }
#endif // Microsoft workaround

V8_ALLOW_UNUSED inline int extract_first_nonzero_index_uint32x4_t(uint32x4_t v) {
uint32x4_t mask = PACK32x4(4, 3, 2, 1);
mask = vandq_u32(mask, v);
return 4 - vmaxvq_u32(mask);
}

template <>
inline int extract_first_nonzero_index(uint64x2_t v) {
uint32x4_t mask = {2, 0, 1, 0}; // Could also be {2,2,1,1} or {0,2,0,1}
inline int extract_first_nonzero_index_uint64x2_t(uint64x2_t v) {
uint32x4_t mask = PACK32x4(2, 0, 1, 0); // Could also be {2,2,1,1} or {0,2,0,1}
mask = vandq_u32(mask, vreinterpretq_u32_u64(v));
return 2 - vmaxvq_u32(mask);
}
Expand All @@ -122,7 +122,7 @@ inline int32_t reinterpret_vmaxvq_u64(uint64x2_t v) {
type_load vector = *reinterpret_cast<type_load*>(&array[index]); \
type_eq eq = cmp(vector, search_element_vec); \
if (movemask(eq)) { \
return index + extract_first_nonzero_index(eq); \
return index + extract_first_nonzero_index_##type_eq(eq); \
} \
} \
}
Expand Down

0 comments on commit 7586c64

Please sign in to comment.