arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/spqlios/CMakeLists.txt
poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/spqlios/CMakeLists.txtRaw
  1enable_language(ASM)
  2
  3# C source files that are compiled for all targets (i.e. reference code)
  4set(SRCS_GENERIC
  5        commons.c 
  6        commons_private.c
  7        coeffs/coeffs_arithmetic.c
  8        arithmetic/vec_znx.c
  9        arithmetic/vec_znx_dft.c
 10        arithmetic/vector_matrix_product.c
 11        cplx/cplx_common.c
 12        cplx/cplx_conversions.c
 13        cplx/cplx_fft_asserts.c
 14        cplx/cplx_fft_ref.c
 15        cplx/cplx_fftvec_ref.c
 16        cplx/cplx_ifft_ref.c
 17        cplx/spqlios_cplx_fft.c
 18        reim4/reim4_arithmetic_ref.c
 19        reim4/reim4_fftvec_addmul_ref.c
 20        reim4/reim4_fftvec_conv_ref.c
 21        reim/reim_conversions.c
 22        reim/reim_fft_ifft.c
 23        reim/reim_fft_ref.c
 24        reim/reim_fftvec_ref.c
 25        reim/reim_ifft_ref.c
 26        reim/reim_ifft_ref.c
 27        reim/reim_to_tnx_ref.c
 28        q120/q120_ntt.c
 29        q120/q120_arithmetic_ref.c
 30        q120/q120_arithmetic_simple.c
 31        arithmetic/scalar_vector_product.c
 32        arithmetic/vec_znx_big.c
 33        arithmetic/znx_small.c
 34        arithmetic/module_api.c
 35        arithmetic/zn_vmp_int8_ref.c
 36        arithmetic/zn_vmp_int16_ref.c
 37        arithmetic/zn_vmp_int32_ref.c
 38        arithmetic/zn_vmp_ref.c
 39        arithmetic/zn_api.c
 40        arithmetic/zn_conversions_ref.c
 41        arithmetic/zn_approxdecomp_ref.c
 42        arithmetic/vec_rnx_api.c
 43        arithmetic/vec_rnx_conversions_ref.c
 44        arithmetic/vec_rnx_svp_ref.c
 45        reim/reim_execute.c
 46        cplx/cplx_execute.c
 47        reim4/reim4_execute.c
 48        arithmetic/vec_rnx_arithmetic.c
 49        arithmetic/vec_rnx_approxdecomp_ref.c
 50        arithmetic/vec_rnx_vmp_ref.c
 51)
 52# C or assembly source files compiled only on x86 targets
 53set(SRCS_X86
 54        )
 55# C or assembly source files compiled only on aarch64 targets
 56set(SRCS_AARCH64
 57        cplx/cplx_fallbacks_aarch64.c
 58        reim/reim_fallbacks_aarch64.c
 59        reim4/reim4_fallbacks_aarch64.c
 60        q120/q120_fallbacks_aarch64.c
 61        reim/reim_fft_neon.c
 62)
 63
 64# C or assembly source files compiled only on x86: avx, avx2, fma targets
 65set(SRCS_FMA_C
 66        arithmetic/vector_matrix_product_avx.c
 67        cplx/cplx_conversions_avx2_fma.c
 68        cplx/cplx_fft_avx2_fma.c
 69        cplx/cplx_fft_sse.c
 70        cplx/cplx_fftvec_avx2_fma.c
 71        cplx/cplx_ifft_avx2_fma.c
 72        reim4/reim4_arithmetic_avx2.c
 73        reim4/reim4_fftvec_conv_fma.c
 74        reim4/reim4_fftvec_addmul_fma.c
 75        reim/reim_conversions_avx.c
 76        reim/reim_fft4_avx_fma.c
 77        reim/reim_fft8_avx_fma.c
 78        reim/reim_ifft4_avx_fma.c
 79        reim/reim_ifft8_avx_fma.c
 80        reim/reim_fft_avx2.c
 81        reim/reim_ifft_avx2.c
 82        reim/reim_to_tnx_avx.c
 83        reim/reim_fftvec_fma.c
 84)
 85set(SRCS_FMA_ASM
 86        cplx/cplx_fft16_avx_fma.s
 87        cplx/cplx_ifft16_avx_fma.s
 88        reim/reim_fft16_avx_fma.s
 89        reim/reim_ifft16_avx_fma.s
 90)
 91set(SRCS_FMA_WIN32_ASM
 92        cplx/cplx_fft16_avx_fma_win32.s
 93        cplx/cplx_ifft16_avx_fma_win32.s
 94        reim/reim_fft16_avx_fma_win32.s
 95        reim/reim_ifft16_avx_fma_win32.s
 96)
 97set_source_files_properties(${SRCS_FMA_C} PROPERTIES COMPILE_OPTIONS "-mfma;-mavx;-mavx2")
 98set_source_files_properties(${SRCS_FMA_ASM} PROPERTIES COMPILE_OPTIONS "-mfma;-mavx;-mavx2")
 99
100# C or assembly source files compiled only on x86: avx512f/vl/dq + fma targets
101set(SRCS_AVX512
102        cplx/cplx_fft_avx512.c
103        )
104set_source_files_properties(${SRCS_AVX512} PROPERTIES COMPILE_OPTIONS "-mfma;-mavx512f;-mavx512vl;-mavx512dq")
105
106# C or assembly source files compiled only on x86: avx2 + bmi targets
107set(SRCS_AVX2
108        arithmetic/vec_znx_avx.c
109        coeffs/coeffs_arithmetic_avx.c
110        arithmetic/vec_znx_dft_avx2.c
111        arithmetic/zn_vmp_int8_avx.c
112        arithmetic/zn_vmp_int16_avx.c
113        arithmetic/zn_vmp_int32_avx.c
114        q120/q120_arithmetic_avx2.c
115        q120/q120_ntt_avx2.c
116        arithmetic/vec_rnx_arithmetic_avx.c
117        arithmetic/vec_rnx_approxdecomp_avx.c
118        arithmetic/vec_rnx_vmp_avx.c
119        
120)
121set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_OPTIONS "-mbmi2;-mavx2")
122
123# C source files on float128 via libquadmath on x86 targets targets
124set(SRCS_F128
125        cplx_f128/cplx_fft_f128.c
126        cplx_f128/cplx_fft_f128.h
127        )
128
129# H header files containing the public API (these headers are installed)
130set(HEADERSPUBLIC
131        commons.h
132        arithmetic/vec_znx_arithmetic.h
133        arithmetic/vec_rnx_arithmetic.h
134        arithmetic/zn_arithmetic.h
135        cplx/cplx_fft.h
136        reim/reim_fft.h
137        q120/q120_common.h
138        q120/q120_arithmetic.h
139        q120/q120_ntt.h
140        )
141
142# H header files containing the private API (these headers are used internally)
143set(HEADERSPRIVATE
144        commons_private.h
145        cplx/cplx_fft_internal.h
146        cplx/cplx_fft_private.h
147        reim4/reim4_arithmetic.h
148        reim4/reim4_fftvec_internal.h
149        reim4/reim4_fftvec_private.h
150        reim4/reim4_fftvec_public.h
151        reim/reim_fft_internal.h
152        reim/reim_fft_private.h
153        q120/q120_arithmetic_private.h
154        q120/q120_ntt_private.h
155        arithmetic/vec_znx_arithmetic.h
156        arithmetic/vec_rnx_arithmetic_private.h
157        arithmetic/vec_rnx_arithmetic_plugin.h
158        arithmetic/zn_arithmetic_private.h
159        arithmetic/zn_arithmetic_plugin.h
160        coeffs/coeffs_arithmetic.h
161        reim/reim_fft_core_template.h
162)
163
164set(SPQLIOSSOURCES
165        ${SRCS_GENERIC}
166        ${HEADERSPUBLIC}
167        ${HEADERSPRIVATE}
168        )
169if (${X86})
170    set(SPQLIOSSOURCES ${SPQLIOSSOURCES}
171            ${SRCS_X86}
172            ${SRCS_FMA_C}
173            ${SRCS_FMA_ASM}
174            ${SRCS_AVX2}
175            ${SRCS_AVX512}
176            )
177elseif (${X86_WIN32})
178    set(SPQLIOSSOURCES ${SPQLIOSSOURCES}
179            #${SRCS_X86}
180            ${SRCS_FMA_C}
181            ${SRCS_FMA_WIN32_ASM}
182            ${SRCS_AVX2}
183            ${SRCS_AVX512}
184    )
185elseif (${AARCH64})
186    set(SPQLIOSSOURCES ${SPQLIOSSOURCES}
187            ${SRCS_AARCH64}
188            )
189endif ()
190
191
192set(SPQLIOSLIBDEP
193        m         # libmath depencency for cosinus/sinus functions
194        )
195
196if (ENABLE_SPQLIOS_F128)
197    find_library(quadmath REQUIRED NAMES quadmath)
198    set(SPQLIOSSOURCES ${SPQLIOSSOURCES} ${SRCS_F128})
199    set(SPQLIOSLIBDEP ${SPQLIOSLIBDEP} quadmath)
200endif (ENABLE_SPQLIOS_F128)
201
202add_library(libspqlios-static STATIC ${SPQLIOSSOURCES})
203add_library(libspqlios SHARED ${SPQLIOSSOURCES})
204set_property(TARGET libspqlios-static PROPERTY POSITION_INDEPENDENT_CODE ON)
205set_property(TARGET libspqlios PROPERTY OUTPUT_NAME spqlios)
206set_property(TARGET libspqlios-static PROPERTY OUTPUT_NAME spqlios)
207set_property(TARGET libspqlios PROPERTY POSITION_INDEPENDENT_CODE ON)
208set_property(TARGET libspqlios PROPERTY SOVERSION ${SPQLIOS_VERSION_MAJOR})
209set_property(TARGET libspqlios PROPERTY VERSION ${SPQLIOS_VERSION})
210if (NOT APPLE)
211target_link_options(libspqlios-static PUBLIC -Wl,--no-undefined)
212target_link_options(libspqlios PUBLIC -Wl,--no-undefined)
213endif()
214target_link_libraries(libspqlios ${SPQLIOSLIBDEP})
215target_link_libraries(libspqlios-static ${SPQLIOSLIBDEP})
216install(TARGETS libspqlios-static)
217install(TARGETS libspqlios)
218
219# install the public headers only
220foreach (file ${HEADERSPUBLIC})
221    get_filename_component(dir ${file} DIRECTORY)
222    install(FILES ${file} DESTINATION include/spqlios/${dir})
223endforeach ()