> Am 08.05.2026 um 12:04 schrieb John Naylor <[email protected]>:
> 
> Taking a quick look at the configure output you provided, certain
> optimizations will be lacking on both architectures:

Indeed. The universal builds seem to disable optimisations that are supported 
natively. I did a comparison on the attached configure outputs with different 
CFLAGS on arm64 - the first three ran the compiler in x86_64 emulation. I'd 
expect 
this to be similar to a native x86_64 environment, but need to verify.

1. configure.x86_64.out: -arch x86_64 using rosetta2
2. configure.universal-cross.out: -arch arm64 -arch x86_64 using rosetta2
3. configure.arm64-cross.out: -arch arm64 using rosetta2
4. configure.x86_64-cross.out: -arch x86_64 
5. configure.universal.out: -arch arm64 -arch x86_64 
6. configure.arm64.out: -arch arm64

The difference on active features in detail are:

Only with arm64 native (6):
* svcnt_x
* pmull and pmull2

Both with arm64 native (6) and cross (3):
* __crc32cb, __crc32ch, __crc32cw, and __crc32cd with CFLAGS

Only with x86_64 emulation (1):
* assembler supports x86_64 popcntq
* _mm512_popcnt_epi64
* _mm512_clmulepi64_epi128

Both with x86_64 emulation/native (1) and arm64 cross (3) and universal cross 
(2)
* AVX2 target attribute support

Both with x86_64 cross (4) and emulation (1):
* __get_cpuid
* __get_cpuid_count
* _xgetbv
* _mm_crc32_u8 and _mm_crc32_u32

This results in the following CRC-32 decisions:

CRC-32C implementation: 
1. x86_64 emulation: SSE 4.2 with runtime check
2. universal emulation: slicing-by-8
3. arm64 cross emulation: ARMv8 CRC instructions
4. x86_64 cross: SSE 4.2 with runtime check
5. universal: slicing-by-8
6. arm64: ARMv8 CRC instructions

Vectorized CRC-32C:
1. x86_64 emulation: AVX-512 with runtime check
2. universal emulation: none
3. arm64 cross emulation: none
4. x86_64 cross: none
5. universal: none
6. arm64: CRYPTO PMULL with runtime check


The differences between cross compilation and emulation(native) may be
worth looking into.


Cross-compiling arm64 or universal from x86_64 does not work, however:

checksum.c:57:6: error: call to undeclared function 'x86_feature_available'
        if (x86_feature_available(PG_AVX2))
            ^
checksum.c:57:28: error: use of undeclared identifier 'PG_AVX2'
        if (x86_feature_available(PG_AVX2))

This may have to do with the detection of "AVX2 target attribute support" 

As Sandeep Thakkar just confirmed on the packagers list, this also affects 
bulding on a native x86_64 host not only an emulated one. The AVX2 target 
attribute support when ran on x86_64 cross compiling to arm64 (3) (or universal 
(2)) seems to be wrong.

Best regards
Tobias


Attachment: configure.x86_64.out
Description: Binary data

Attachment: configure.universal-cross.out
Description: Binary data

Attachment: configure.arm64-cross.out
Description: Binary data

Attachment: configure.x86_64-cross.out
Description: Binary data

Attachment: configure.universal.out
Description: Binary data

Attachment: configure.arm64.out
Description: Binary data


Reply via email to