Skip to content

Commit 7463eca

Browse files
committed
Support AVX on ARM via SIMDe
1 parent 671a8cd commit 7463eca

File tree

20 files changed

+545599
-15
lines changed

20 files changed

+545599
-15
lines changed

CMake/Common.cmake

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ if (USE_DOUBLE_PRECISION)
1717
endif (USE_DOUBLE_PRECISION)
1818

1919
cmake_dependent_option(USE_AVX "Use AVX" ON "NOT USE_DOUBLE_PRECISION" OFF)
20-
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
21-
set(USE_AVX OFF)
22-
endif()
2320
if (USE_AVX)
24-
message(STATUS "If your CPU does not support AVX, turn off the USE_AVX flag.")
21+
message(STATUS "If your CPU does not support SIMD, turn off the USE_AVX flag.")
2522
add_definitions(-DUSE_AVX)
2623
endif()
2724

@@ -88,17 +85,21 @@ if (UNIX OR MINGW)
8885
if (CI_BUILD)
8986
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=x86-64")
9087
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=x86-64")
91-
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
92-
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -mcpu=apple-m1")
93-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -mcpu=apple-m1")
88+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
89+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -mcpu=native")
90+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -mcpu=native")
9491
else()
9592
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native")
9693
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=native")
9794
endif ()
9895
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
9996
if (USE_AVX)
100-
add_compile_options("-mavx")
101-
add_compile_options("-mfma")
97+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
98+
add_compile_options("-mcpu=native+fp+simd")
99+
else()
100+
add_compile_options("-mavx")
101+
add_compile_options("-mfma")
102+
endif()
102103
endif()
103104
endif (UNIX OR MINGW)
104105
if(MINGW)

SPlisHSPlasH/Utilities/AVX_math.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <iomanip>
66
#include <vector>
77
#include <memory>
8-
#include <immintrin.h>
8+
#define SIMDE_ENABLE_NATIVE_ALIASES
9+
#include "extern/simde/x86/avx.h"
10+
#include "extern/simde/x86/fma.h"
911

1012
#include "SPlisHSPlasH/Common.h"
1113

@@ -1014,7 +1016,7 @@ class AlignmentAllocator {
10141016
inline pointer allocate(size_type n) {
10151017
#ifdef _WIN32
10161018
return (pointer)_aligned_malloc(n * sizeof(value_type), N);
1017-
#elif __linux__
1019+
#elif defined(__linux__) || defined(__APPLE__)
10181020
// NB! Argument order is opposite from MSVC/Windows
10191021
return (pointer) aligned_alloc(N, n * sizeof(value_type));
10201022
#else
@@ -1025,7 +1027,7 @@ class AlignmentAllocator {
10251027
inline void deallocate(pointer p, size_type) {
10261028
#ifdef _WIN32
10271029
_aligned_free(p);
1028-
#elif __linux__
1030+
#elif defined(__linux__) || defined(__APPLE__)
10291031
free(p);
10301032
#else
10311033
#error "Unknown platform"

extern/simde/COPYING.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2017 Evan Nemerson <evan@nemerson.com>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)