Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .clangd
Empty file.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

142 changes: 97 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.30)
cmake_minimum_required(VERSION 3.24)
project(pernix VERSION 0.1.0 LANGUAGES CXX C)

option(PERNIX_ENABLE_TESTS "Enable tests for pernix" on)
Expand All @@ -8,19 +8,49 @@ option(PERNIX_ENABLE_INSTALL "Enable installation of pernix" on)
option(PERNIX_ENABLE_DOXYGEN "Build documentation with Doxygen." off)
option(PERNIX_INSTALL_DOCS "Install documentation with pernix" off)

option(PERNIX_DISABLE_BMI2 "Disable BMI2 optimizations" off)
option(PERNIX_DISABLE_AVX2 "Disable AVX2 optimizations" off)
option(PERNIX_DISABLE_AVX512 "Disable AVX512 optimizations" off)
option(PERNIX_ENABLE_X86_BMI2 "Build x86 BMI2 backend" ON)
option(PERNIX_ENABLE_X86_AVX2 "Build x86 AVX2 backend" ON)
option(PERNIX_ENABLE_X86_AVX512VBMI "Build x86 AVX512-VBMI backend" ON)
option(PERNIX_ENABLE_ARM64_NEON "Build arm64 NEON backend" ON)
option(PERNIX_ENABLE_ARM64_SVE2 "Build arm64 SVE2 backend" ON)

option(PERNIX_USE_SIMDE "Use SIMDe library for portable SIMD support" off)

option(PERNIX_ENABLE_FORTRAN_BINDINGS "Build Fortran bindings for pernix" off)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")

#[===[
set(PERNIX_BUNDLE_SIMDE_FOR_INSTALL OFF)
if (PERNIX_USE_SIMDE)
add_subdirectory(external/simde EXCLUDE_FROM_ALL)
if (PERNIX_SIMDE_PROVIDER STREQUAL "AUTO" OR PERNIX_SIMDE_PROVIDER STREQUAL "PACKAGE")
find_package(simde CONFIG QUIET)
endif ()

if (NOT TARGET simde::simde AND (PERNIX_SIMDE_PROVIDER STREQUAL "AUTO" OR PERNIX_SIMDE_PROVIDER STREQUAL "FETCH"))
include(FetchContent)
set(SIMDE_TEST_CMAKE_PACKAGING OFF CACHE BOOL "Test SIMDe CMake packaging" FORCE)
FetchContent_Declare(
simde
GIT_REPOSITORY https://github.com/simd-everywhere/simde.git
GIT_TAG f3e8262173b7089db9a9d57a9ecef8dd07ad9c97
GIT_PROGRESS TRUE
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(simde)
set(PERNIX_BUNDLE_SIMDE_FOR_INSTALL ON)
endif ()

if (NOT TARGET simde::simde AND DEFINED simde_SOURCE_DIR AND EXISTS "${simde_SOURCE_DIR}/simde")
add_library(simde::simde INTERFACE IMPORTED GLOBAL)
target_include_directories(simde::simde INTERFACE "${simde_SOURCE_DIR}")
endif ()

if (NOT TARGET simde::simde)
message(FATAL_ERROR "PERNIX_USE_SIMDE is enabled, but simde::simde was not found. Set PERNIX_SIMDE_PROVIDER=FETCH or install SIMDe's CMake package.")
endif ()
endif ()
]===]

include(CTest)
include(GitVersion)
Expand All @@ -40,51 +70,73 @@ else ()
endif ()
message(STATUS "Pernix version: ${VERSION}, normalized to ${NORMALIZED_VERSION}")

set(BENCHMARK_CXX_STANDARD 20)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Intel")
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}")
endif ()

set(CMAKE_CXX_STANDARD ${BENCHMARK_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
include(CheckCXXCompilerFlag)
set(PERNIX_PRIVATE_COMPILE_OPTIONS)
foreach (PERNIX_CXX_FLAG
-Wall
-Wextra
-Wshadow
-Wfloat-equal
-Wold-style-cast
-Wconversion
-fstrict-aliasing
-Wno-ignored-attributes
)
string(MAKE_C_IDENTIFIER "PERNIX_HAS_CXX_FLAG_${PERNIX_CXX_FLAG}" PERNIX_CXX_FLAG_VARIABLE)
check_cxx_compiler_flag("${PERNIX_CXX_FLAG}" "${PERNIX_CXX_FLAG_VARIABLE}")
if (${PERNIX_CXX_FLAG_VARIABLE})
list(APPEND PERNIX_PRIVATE_COMPILE_OPTIONS "${PERNIX_CXX_FLAG}")
else ()
message(STATUS "Compiler flag not supported: ${PERNIX_CXX_FLAG}")
endif ()
endforeach ()

include(AddCXXCompilerFlag)
if (MSVC)
message(FATAL_ERROR "MSVC compiler is not supported")
else ()
add_cxx_compiler_flag(-Wall)
add_cxx_compiler_flag(-Wextra)
add_cxx_compiler_flag(-Wshadow)
add_cxx_compiler_flag(-Wfloat-equal)
add_cxx_compiler_flag(-Wold-style-cast)
add_cxx_compiler_flag(-Wconversion)
add_cxx_compiler_flag(-fstrict-aliasing)
add_cxx_compiler_flag(-Wno-ignored-attributes)

if (PERNIX_ENABLE_LTO)
add_cxx_compiler_flag(-flto=auto)
add_cxx_compiler_flag(-Wno-lto-type-mismatch)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
find_program(GCC_AR gcc-ar)
if (GCC_AR)
set(CMAKE_AR ${GCC_AR})
endif ()
find_program(GCC_RANLIB gcc-ranlib)
if (GCC_RANLIB)
set(CMAKE_RANLIB ${GCC_RANLIB})
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
find_program(LLVM_AR llvm-ar)
if (LLVM_AR)
set(CMAKE_AR ${LLVM_AR})
endif ()
find_program(LLVM_RANLIB llvm-ranlib)
if (LLVM_RANLIB)
set(CMAKE_RANLIB ${LLVM_RANLIB})
endif ()
if (PERNIX_ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT PERNIX_IPO_SUPPORTED OUTPUT PERNIX_IPO_ERROR)
if (NOT PERNIX_IPO_SUPPORTED)
message(FATAL_ERROR "PERNIX_ENABLE_LTO is enabled, but IPO/LTO is not supported: ${PERNIX_IPO_ERROR}")
endif ()

check_cxx_compiler_flag("-Wno-lto-type-mismatch" PERNIX_HAS_CXX_FLAG_WNO_LTO_TYPE_MISMATCH)
if (PERNIX_HAS_CXX_FLAG_WNO_LTO_TYPE_MISMATCH)
list(APPEND PERNIX_PRIVATE_COMPILE_OPTIONS "-Wno-lto-type-mismatch")
endif ()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
find_program(GCC_AR gcc-ar)
if (GCC_AR)
set(CMAKE_AR ${GCC_AR})
endif ()
find_program(GCC_RANLIB gcc-ranlib)
if (GCC_RANLIB)
set(CMAKE_RANLIB ${GCC_RANLIB})
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
find_program(LLVM_AR llvm-ar)
if (LLVM_AR)
set(CMAKE_AR ${LLVM_AR})
endif ()
find_program(LLVM_RANLIB llvm-ranlib)
if (LLVM_RANLIB)
set(CMAKE_RANLIB ${LLVM_RANLIB})
endif ()
endif ()
endif ()

include_directories(${PROJECT_SOURCE_DIR}/include)
set(PERNIX_TARGET_IS_X86 OFF)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|i[3-6]86|i686)$")
set(PERNIX_TARGET_IS_X86 ON)
endif ()

set(PERNIX_TARGET_IS_ARM64 OFF)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|ARM64)$")
set(PERNIX_TARGET_IS_ARM64 ON)
endif ()

add_subdirectory(src)

Expand All @@ -97,4 +149,4 @@ endif ()
if (PERNIX_ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif ()
endif ()
18 changes: 18 additions & 0 deletions cmake/pernixConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@PACKAGE_INIT@

if (@PERNIX_USE_SIMDE@)
find_package(simde CONFIG QUIET)
if (NOT TARGET simde::simde AND @PERNIX_BUNDLE_SIMDE_FOR_INSTALL@)
add_library(simde::simde INTERFACE IMPORTED)
target_include_directories(simde::simde INTERFACE "${PACKAGE_PREFIX_DIR}/include")
endif ()
if (NOT TARGET simde::simde)
set(pernix_FOUND FALSE)
set(pernix_NOT_FOUND_MESSAGE "pernix was built with SIMDe support, but simde::simde was not found. Install SIMDe's CMake package or use a Pernix package built with bundled SIMDe headers.")
return()
endif ()
endif ()

include("${CMAKE_CURRENT_LIST_DIR}/pernixTargets.cmake")

check_required_components(pernix)
1 change: 0 additions & 1 deletion external/simde
Submodule simde deleted from 1747b2
45 changes: 45 additions & 0 deletions include/pernix/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef PERNIX_COMPAT_H
#define PERNIX_COMPAT_H

#include <cstdint>
#include <cmath>
#include <cstddef>

#ifndef __always_inline
#if defined(__GNUC__) || defined(__clang__)
#define __always_inline inline __attribute__((always_inline))
#elif defined(_MSC_VER)
#define __always_inline __forceinline
#else
#define __always_inline inline
#endif
#endif

#if defined(_WIN32) && defined(PERNIX_SHARED)
#if defined(PERNIX_BUILD_LIB)
#define PERNIX_API __declspec(dllexport)
#else
#define PERNIX_API __declspec(dllimport)
#endif
#else
#define PERNIX_API
#endif

// Convenient type declarations
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef uintptr_t uptr;

typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;

typedef float_t f32;
typedef double_t f64;

typedef size_t usize;

#endif //PERNIX_COMPAT_H
70 changes: 0 additions & 70 deletions include/pernix/detection.h

This file was deleted.

Loading