%global debug_package %{nil}
%global gitdate 20230131
%global commit 097a5ecacd527d5b5c3006e360fb9cb1c1c48a1f
%global shortcommit %(c=%{commit}; echo ${c:0:8})

Name:		neon2sse
Version:	0.0%{?with_snapshot:^%{gitdate}git%{shortcommit}}
Release:	%autorelease
Summary:	Library intended to simplify ARM->IA32 porting

License:	BSD-2-Clause
URL:		https://github.com/intel/ARM_NEON_2_x86_SSE
Source0:	%{url}/archive/%{commit}/%{name}-%{shortcommit}.tar.gz

BuildArch:	noarch
ExclusiveArch:	x86_64

BuildRequires:	cmake >= 3.1
BuildRequires:	gcc-c++

%description
The platform independent header allowing to compile any C/C++ code containing
ARM NEON intrinsic functions for x86 target systems using SIMD up to SSE4
intrinsic functions.

The NEON_2_SSE.h file is intended to simplify ARM->IA32 porting

%package devel
Summary:	Development files for %{name}
Provides:	%{name}-static = %{version}-%{release}

%description devel
The platform independent header allowing to compile any C/C++ code containing
ARM NEON intrinsic functions for x86 target systems using SIMD up to SSE4
intrinsic functions.

The NEON_2_SSE.h file is intended to simplify ARM->IA32 porting

%prep
%autosetup -n ARM_NEON_2_x86_SSE-%{commit}

# fix path
sed -i 's/lib\/cmake/%{_lib}\/cmake/g' CMakeLists.txt

%build
%cmake
%cmake_build

%install
%cmake_install

%check
# test vector addition
cat << EOF > test.c
#include <NEON_2_SSE.h>
#include <stdio.h>

int main() {
    // Initialize two 8-element vectors
    uint64_t a = 0x0102030405060708;
    uint64_t b = 0x0807060504030201;

    // Create NEON vectors
    uint8x8_t va = vcreate_u8(a);
    uint8x8_t vb = vcreate_u8(b);

    // Perform the addition
    uint8x8_t vc = vadd_u8(va, vb);

    // Store the resulting vector for comparison
    union {
        char c[8];
        uint64_t i;
    } result;
    vst1_u8(result.c, vc);

    // Expected result after adding byte by byte
    uint64_t expected = 0x0909090909090909;

    if (result.i == expected) {
        printf("NEON_2_SSE test passed successfully\n");
    } else {
        fprintf(stderr, "NEON_2_SSE test failed\n");
        return 1;
    }

    return 0;
}
EOF

$CC -o test test.c -I%{buildroot}%{_includedir}
./test

%files devel
%license LICENSE
%doc ReadMe.md
%{_includedir}/NEON_2_SSE.h
%{_libdir}/cmake/NEON_2_SSE/

%changelog
%autochangelog