intel / ARM_NEON_2_x86_SSE

The platform independent header allowing to compile any C/C++ code containing ARM NEON intrinsic functions for x86 target systems using SIMD up to AVX2 intrinsic functions
Other
430 stars 149 forks source link

unable to use vld1q_lane_f32 with gcc and sse4 #58

Closed sherpya closed 2 years ago

sherpya commented 2 years ago

simple program

#include "NEON_2_SSE.h"
int main(void)
{
    float32x4_t out_float32x4_t;
    float32x4_t arg1_float32x4_t;

    out_float32x4_t = vld1q_lane_f32 (0, arg1_float32x4_t, 1);
    return 0;
}

if compiled with -sse4 gcc fails with:

NEON_2_SSE.h:2311:33: error: the last argument must be an 8-bit immediate
 2311 | #       define _MM_INSERT_PS    _mm_insert_ps

the code ends up to be compiled as:

static inline float32x4_t vld1q_lane_f32(float32_t const * ptr, float32x4_t vec, const int lane)
{
    __m128 p;
    p = _mm_set1_ps(*(ptr));
    return __builtin_ia32_insertps128(vec, p, (int)((0 << 6) | (lane << 4)));
}

that gives the same error, even using lane as last argument

gcc complains about the temporary values created by _INSERTPS_NDX

it works with a literal constant

I've tried various way (const variable, casts) but I'm unable to find a solution e.g.

_NEON2SSE_INLINE float32x4_t vld1q_lane_f32(__transfersize(1) float32_t const * ptr, float32x4_t vec, __constrange(0,3) int lane)
{
    //we need to deal with  ptr  16bit NOT aligned case
    __m128 p;
    p = _mm_set1_ps(*(ptr));
    const int _lane = _INSERTPS_NDX(0, lane);
    return _MM_INSERT_PS(vec,  p, _lane);
}
sherpya commented 2 years ago

gcc version:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 11.2.0-13' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-KdLYb3/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-KdLYb3/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Debian 11.2.0-13) 
Zvictoria commented 2 years ago

Pushed in, thanks for reporting