Skip to content

Commit 541cba8

Browse files
authored
GH-47784: [C++] Patch vendored pcg library to enable msvc arm64 intrinsics (#47779)
### Rationale for this change This change enables building Arrow C++ for Windows ARM64 with MSVC when setting `ARROW_SIMD_LEVEL` to `NONE`. This is useful to be able to build Arrow with `vcpkg` and use it as a dependency. Setting `ARROW_SIMD_LEVEL` to `NONE` is done to disable the use of `xsimd`, which does not yet support msvc arm64 intrinsics, and is non-trivial to fix. ### What changes are included in this PR? A patch to the vendored `pcg` library, based on imneme/pcg-cpp#99. The upstream pcg library has not been updated in the past 3 years, so this may never get merged. ### Are these changes tested? Yes, the changes have been tested in microsoft/vcpkg#47750 (the same patch for `vcpkg`, which this change would alleviate) and in https://github.com/jgiannuzzi/ParquetSharp/actions/runs/18354286294 (a full run of the ParquetSharp CI, using this patch to build Arrow with `vcpkg`). ### Are there any user-facing changes? Not really, unless you consider adding the ability to build Arrow on Windows ARM64 user-facing? * GitHub Issue: #47784 Authored-by: Jonathan Giannuzzi <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent a53ebde commit 541cba8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cpp/src/arrow/vendored/pcg/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ Sources are taken from git changeset ffd522e7188bef30a00c74dc7eb9de5faff90092
2525
Changes:
2626
- enclosed in `arrow_vendored` namespace
2727
- remove `struct arbitrary_seed` definition because of https://github.com/apache/arrow/issues/35596
28+
- enable MSVC ARM64 intrinsics to allow building on Windows ARM64 with Visual Studio - see https://github.com/apache/arrow/pull/47779
2829

cpp/src/arrow/vendored/pcg/pcg_uint128.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#define PCG_LITTLE_ENDIAN 1
6868
#elif __BIG_ENDIAN__ || _BIG_ENDIAN
6969
#define PCG_LITTLE_ENDIAN 0
70-
#elif __x86_64 || __x86_64__ || _M_X64 || __i386 || __i386__ || _M_IX86
70+
#elif __x86_64 || __x86_64__ || _M_X64 || __i386 || __i386__ || _M_IX86 || _M_ARM64
7171
#define PCG_LITTLE_ENDIAN 1
7272
#elif __powerpc__ || __POWERPC__ || __ppc__ || __PPC__ \
7373
|| __m68k__ || __mc68000__
@@ -734,7 +734,13 @@ uint_x4<UInt,UIntX2> operator*(const uint_x4<UInt,UIntX2>& a,
734734

735735
#if PCG_64BIT_SPECIALIZATIONS
736736
#if defined(_MSC_VER)
737+
#if defined(_M_X64) || defined(_M_IX86)
737738
#pragma intrinsic(_umul128)
739+
#elif defined(_M_ARM64)
740+
#pragma intrinsic(__umulh)
741+
#else
742+
#error Unsupported architecture
743+
#endif
738744
#endif
739745

740746
#if defined(_MSC_VER) || __SIZEOF_INT128__
@@ -743,8 +749,15 @@ uint_x4<UInt32,uint64_t> operator*(const uint_x4<UInt32,uint64_t>& a,
743749
const uint_x4<UInt32,uint64_t>& b)
744750
{
745751
#if defined(_MSC_VER)
752+
#if defined(_M_X64) || defined(_M_IX86)
746753
uint64_t hi;
747754
uint64_t lo = _umul128(a.d.v01, b.d.v01, &hi);
755+
#elif defined(_M_ARM64)
756+
uint64_t lo = a.d.v01 * b.d.v01;
757+
uint64_t hi = __umulh(a.d.v01, b.d.v01);
758+
#else
759+
#error Unsupported architecture
760+
#endif
748761
#else
749762
__uint128_t r = __uint128_t(a.d.v01) * __uint128_t(b.d.v01);
750763
uint64_t lo = uint64_t(r);

0 commit comments

Comments
 (0)