macosarmclangapple-m1neon

Compile ARM Neon intrinsics on macos (M3 chipsets) using clang


I have some source codes using ARM Neon intrinsics (i.e., arm_neon.h) for finite field arithmetics acceleration. On raspberry pi I compile them using gcc with arguments like this

-DARM_NEON64 -mfloat-abi-hard -mfpu=neon -O3

Now I want to test the codes on Macbook Pro (M3 Max). I never used clang before, and somehow surprisingly I find that it's so difficult to google a workable compiling command for the need. Can anybody provide some hints on this topic? Thanks a log. (no Xcode)


Solution

  • // foo.c
    #include "arm_neon.h"
    poly16x8_t foo(poly8x8_t a) { return vmull_p8(a,a);}
    
    clang -c foo.c -O3
    objdump -d foo.o
    
    f.o:    file format mach-o arm64
    
    Disassembly of section __TEXT,__text:
    
    0000000000000000 <ltmp0>:
           0: 0e20e000      pmull.8h    v0, v0, v0
           4: d65f03c0      ret
    

    The -c is for compilation only (to object file .o).

    The only obstacle I can think of is if the clang is being configured (somehow by environment variables) to produce x64 code.