Skip to content

Commit 1b4c800

Browse files
authored
Merge pull request #170 from SwayamInSync/backport-sleef-runtime
2 parents 151b4d1 + 5f4b294 commit 1b4c800

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

quaddtype/meson.build

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,59 @@ endif
1515

1616
qblas_dep = dependency('qblas', fallback: ['qblas', 'qblas_dep'])
1717

18-
sleef_subproj = subproject('sleef', required: true)
19-
sleef_dep = sleef_subproj.get_variable('sleef_dep')
20-
sleefquad_dep = sleef_subproj.get_variable('sleefquad_dep')
18+
# Try to find SLEEF system-wide first, fall back to subproject if not found
19+
sleef_dep = dependency('sleef', fallback: ['sleef', 'sleef_dep'], required: false)
20+
21+
use_system_sleef = false
22+
fallback_reason = ''
23+
24+
if sleef_dep.found() and sleef_dep.type_name() != 'internal'
25+
# SLEEF found system-wide - verify quad-precision support
26+
cpp = meson.get_compiler('cpp')
27+
sleefquad_lib = cpp.find_library('sleefquad', required: false)
28+
29+
if sleefquad_lib.found()
30+
sleefquad_test_code = '''
31+
#include <sleefquad.h>
32+
33+
int main(void) {
34+
Sleef_quad q1 = Sleef_cast_from_doubleq1(1.0);
35+
Sleef_quad q2 = Sleef_cast_from_doubleq1(2.0);
36+
Sleef_quad result = Sleef_addq1_u05(q1, q2);
37+
return 0;
38+
}
39+
'''
40+
# this should compile and link
41+
quad_works = cpp.links(
42+
sleefquad_test_code,
43+
dependencies: [sleef_dep, sleefquad_lib],
44+
name: 'SLEEF quad-precision support'
45+
)
46+
47+
if quad_works
48+
sleefquad_dep = declare_dependency(
49+
dependencies: [sleef_dep, sleefquad_lib]
50+
)
51+
use_system_sleef = true
52+
else
53+
fallback_reason = 'quad-precision support is not working'
54+
endif
55+
else
56+
fallback_reason = 'sleefquad library is missing'
57+
endif
58+
else
59+
fallback_reason = 'SLEEF not found system-wide'
60+
endif
61+
62+
if use_system_sleef
63+
message('Using system-wide SLEEF installation with quad-precision support')
64+
else
65+
warning('Falling back to SLEEF subproject: ' + fallback_reason)
66+
sleef_subproj = subproject('sleef')
67+
sleef_dep = sleef_subproj.get_variable('sleef_dep')
68+
sleefquad_dep = sleef_subproj.get_variable('sleefquad_dep')
69+
message('Using SLEEF subproject')
70+
endif
2171

2272
incdir_numpy = run_command(py,
2373
['-c', 'import numpy; print(numpy.get_include())'],

quaddtype/reinstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ fi
1111
# export CFLAGS="-g -O0"
1212
# export CXXFLAGS="-g -O0"
1313
python -m pip uninstall -y numpy_quaddtype
14-
python -m pip install . -v --no-build-isolation 2>&1 | tee build_log.txt
14+
python -m pip install . -vv --no-build-isolation 2>&1 | tee build_log.txt

0 commit comments

Comments
 (0)