Mercurial > vec
comparison CMakeLists.txt @ 28:c6c99ab1088a
*: add min/max functions and a big big refactor (again)
agh, this time I added a few more implementations (and generally
made the code just a little faster...)
author | Paper <paper@tflc.us> |
---|---|
date | Thu, 24 Apr 2025 00:54:02 -0400 |
parents | d00b95f95dd1 |
children | e59c91d050c0 |
comparison
equal
deleted
inserted
replaced
27:d00b95f95dd1 | 28:c6c99ab1088a |
---|---|
1 cmake_minimum_required(VERSION 3.23) | 1 cmake_minimum_required(VERSION 3.23) |
2 | 2 |
3 project(vec VERSION 3.0.0 DESCRIPTION "a tiny C99 SIMD vector library" LANGUAGES C) | 3 project(vec VERSION 3.0.0 DESCRIPTION "a tiny C99 SIMD vector library" LANGUAGES C) |
4 | 4 |
5 add_library(vec SHARED "src/vec.c;src/cpu.c;src/impl/generic.c;src/impl/fallback.c") | 5 add_library(vec "src/vec.c") |
6 | |
7 target_sources(vec PRIVATE | |
8 "src/cpu.c" | |
9 "src/impl/generic.c" | |
10 # "src/impl/fallback.c" -- deadcode | |
11 ) | |
6 | 12 |
7 include(CheckCCompilerFlag) | 13 include(CheckCCompilerFlag) |
8 | 14 |
9 if(MSVC) | 15 if(MSVC) |
10 # Untested! | 16 # Untested! |
47 endif() | 53 endif() |
48 check_c_compiler_flag("-msse2" COMPILER_HAS_SSE2) | 54 check_c_compiler_flag("-msse2" COMPILER_HAS_SSE2) |
49 if(COMPILER_HAS_SSE2) | 55 if(COMPILER_HAS_SSE2) |
50 set(COMPILER_SSE2_FLAGS "-msse2") | 56 set(COMPILER_SSE2_FLAGS "-msse2") |
51 endif() | 57 endif() |
58 check_c_compiler_flag("-msse3" COMPILER_HAS_SSE3) | |
59 if(COMPILER_HAS_SSE3) | |
60 set(COMPILER_SSE3_FLAGS "-msse3") | |
61 endif() | |
52 check_c_compiler_flag("-msse4.1" COMPILER_HAS_SSE41) | 62 check_c_compiler_flag("-msse4.1" COMPILER_HAS_SSE41) |
53 if(COMPILER_HAS_SSE41) | 63 if(COMPILER_HAS_SSE41) |
54 set(COMPILER_SSE41_FLAGS "-msse4.1") | 64 set(COMPILER_SSE41_FLAGS "-msse4.1") |
55 endif() | 65 endif() |
66 check_c_compiler_flag("-msse4.2" COMPILER_HAS_SSE42) | |
67 if(COMPILER_HAS_SSE42) | |
68 set(COMPILER_SSE42_FLAGS "-msse4.2") | |
69 endif() | |
56 check_c_compiler_flag("-mavx2" COMPILER_HAS_AVX2) | 70 check_c_compiler_flag("-mavx2" COMPILER_HAS_AVX2) |
57 if(COMPILER_HAS_AVX2) | 71 if(COMPILER_HAS_AVX2) |
58 set(COMPILER_AVX2_FLAGS "-mavx2") | 72 set(COMPILER_AVX2_FLAGS "-mavx2") |
59 endif() | 73 endif() |
60 check_c_compiler_flag("-mavx512f" COMPILER_HAS_AVX512F) | 74 check_c_compiler_flag("-mavx512f" COMPILER_HAS_AVX512F) |
61 if(COMPILER_HAS_AVX512F) | 75 if(COMPILER_HAS_AVX512F) |
62 set(COMPILER_AVX512F_FLAGS "-mavx512f") | 76 set(COMPILER_AVX512F_FLAGS "-mavx512f") |
77 endif() | |
78 check_c_compiler_flag("-mavx512bw" COMPILER_HAS_AVX512BW) | |
79 if(COMPILER_HAS_AVX512BW) | |
80 set(COMPILER_AVX512BW_FLAGS "-mavx512bw") | |
81 endif() | |
82 check_c_compiler_flag("-mavx512dq" COMPILER_HAS_AVX512DQ) | |
83 if(COMPILER_HAS_AVX512DQ) | |
84 set(COMPILER_AVX512DQ_FLAGS "-mavx512dq") | |
63 endif() | 85 endif() |
64 endif() | 86 endif() |
65 | 87 |
66 if(COMPILER_HAS_ALTIVEC) | 88 if(COMPILER_HAS_ALTIVEC) |
67 target_sources(vec PRIVATE "src/impl/ppc/altivec.c") | 89 target_sources(vec PRIVATE "src/impl/ppc/altivec.c") |
85 target_sources(vec PRIVATE "src/impl/x86/sse2.c") | 107 target_sources(vec PRIVATE "src/impl/x86/sse2.c") |
86 set_source_files_properties("src/impl/x86/sse2.c" PROPERTIES COMPILE_FLAGS "${COMPILER_SSE2_FLAGS}") | 108 set_source_files_properties("src/impl/x86/sse2.c" PROPERTIES COMPILE_FLAGS "${COMPILER_SSE2_FLAGS}") |
87 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_SSE2") | 109 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_SSE2") |
88 endif() | 110 endif() |
89 | 111 |
112 if(COMPILER_HAS_SSE3) | |
113 target_sources(vec PRIVATE "src/impl/x86/sse3.c") | |
114 set_source_files_properties("src/impl/x86/sse3.c" PROPERTIES COMPILE_FLAGS "${COMPILER_SSE3_FLAGS}") | |
115 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_SSE3") | |
116 endif() | |
117 | |
90 if(COMPILER_HAS_SSE41) | 118 if(COMPILER_HAS_SSE41) |
91 target_sources(vec PRIVATE "src/impl/x86/sse41.c") | 119 target_sources(vec PRIVATE "src/impl/x86/sse41.c") |
92 set_source_files_properties("src/impl/x86/sse41.c" PROPERTIES COMPILE_FLAGS "${COMPILER_SSE41_FLAGS}") | 120 set_source_files_properties("src/impl/x86/sse41.c" PROPERTIES COMPILE_FLAGS "${COMPILER_SSE41_FLAGS}") |
93 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_SSE41") | 121 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_SSE41") |
94 endif() | 122 endif() |
95 | 123 |
124 if(COMPILER_HAS_SSE42) | |
125 target_sources(vec PRIVATE "src/impl/x86/sse42.c") | |
126 set_source_files_properties("src/impl/x86/sse42.c" PROPERTIES COMPILE_FLAGS "${COMPILER_SSE42_FLAGS}") | |
127 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_SSE42") | |
128 endif() | |
129 | |
96 if(COMPILER_HAS_AVX2) | 130 if(COMPILER_HAS_AVX2) |
97 target_sources(vec PRIVATE "src/impl/x86/avx2.c") | 131 target_sources(vec PRIVATE "src/impl/x86/avx2.c") |
98 set_source_files_properties("src/impl/x86/avx2.c" PROPERTIES COMPILE_FLAGS "${COMPILER_AVX2_FLAGS}") | 132 set_source_files_properties("src/impl/x86/avx2.c" PROPERTIES COMPILE_FLAGS "${COMPILER_AVX2_FLAGS}") |
99 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_AVX2") | 133 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_AVX2") |
100 endif() | 134 endif() |
103 target_sources(vec PRIVATE "src/impl/x86/avx512f.c") | 137 target_sources(vec PRIVATE "src/impl/x86/avx512f.c") |
104 set_source_files_properties("src/impl/x86/avx512f.c" PROPERTIES COMPILE_FLAGS "${COMPILER_AVX512F_FLAGS}") | 138 set_source_files_properties("src/impl/x86/avx512f.c" PROPERTIES COMPILE_FLAGS "${COMPILER_AVX512F_FLAGS}") |
105 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_AVX512F") | 139 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_AVX512F") |
106 endif() | 140 endif() |
107 | 141 |
142 if(COMPILER_HAS_AVX512BW) | |
143 target_sources(vec PRIVATE "src/impl/x86/avx512bw.c") | |
144 set_source_files_properties("src/impl/x86/avx512bw.c" PROPERTIES COMPILE_FLAGS "${COMPILER_AVX512BW_FLAGS}") | |
145 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_AVX512BW") | |
146 endif() | |
147 | |
148 if(COMPILER_HAS_AVX512DQ) | |
149 target_sources(vec PRIVATE "src/impl/x86/avx512dq.c") | |
150 set_source_files_properties("src/impl/x86/avx512dq.c" PROPERTIES COMPILE_FLAGS "${COMPILER_AVX512DQ_FLAGS}") | |
151 target_compile_definitions(vec PRIVATE "-DVEC_COMPILER_HAS_AVX512DQ") | |
152 endif() | |
108 | 153 |
109 ######################################################################### | 154 ######################################################################### |
110 # integer types; it's nice to accommodate for older broken systems that | 155 # integer types; it's nice to accommodate for older broken systems that |
111 # may not have stdint.h. | 156 # may not have stdint.h. |
112 | 157 |