Skip to content

Commit 2c4ccc4

Browse files
kecnryhorvatm
andauthored
M1 bugfix (2.3.61 release) (#590)
* TST: add macos11 to test matrix * Removing some optimizations that are not portable to ARM. * Adding check if sincos is enabled on a platform. Co-authored-by: Martin Horvat <horvat77@gmail.com>
1 parent ff962d1 commit 2c4ccc4

File tree

5 files changed

+73
-37
lines changed

5 files changed

+73
-37
lines changed

.github/workflows/ci-nosetests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
astropy-version: ["==1.*", ""]
1919
numpy-version: ["~=1.10.0", ""]
2020
scipy-version: ["~=1.2.0", ""]
21-
os: [ubuntu-latest] # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
21+
os: [ubuntu-latest, macos-11] # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
2222
exclude:
2323
- astropy-version: ""
2424
numpy-version: "~=1.10.0"

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ To understand how to use PHOEBE, please consult the [tutorials, scripts and manu
8484
CHANGELOG
8585
----------
8686

87+
### 2.3.61 - M1 compiler optimization bugfix
88+
89+
* remove compiler optimizations that are not portable to ARM architectures
90+
8791
### 2.3.60 - passband timestamp bugfix
8892

8993
* compare version strings instead of datetime to avoid some systems throwing an error when looking for passband updates.

phoebe/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
"""
1919

20-
__version__ = '2.3.60'
20+
__version__ = '2.3.61'
2121

2222
import os as _os
2323
import sys as _sys

phoebe/lib/sincos.h

+5-32
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,23 @@
66
double
77
long double
88
9-
Double is enabled by pseudo-asm code and TESTED on AMD64 system!
109
11-
12-
Author: Martin Horvat, July 2016
13-
14-
Refs:
15-
* https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
16-
* http://www.tptp.cc/mirrors/siyobik.info/instruction/FSINCOS.html
17-
* x86 Assembly Language Reference Manual - Oracle
18-
https://docs.oracle.com/cd/E19641-01/802-1948/802-1948.pdf
19-
* http://stackoverflow.com/questions/11165379/loading-double-to-fpu-with-gcc-inline-assembler
20-
* http://www.willus.com/mingw/x87inline.h
10+
Author: Martin Horvat, July 2016, April 2022
2111
*/
2212

2313
#include <cmath>
2414

25-
// TODO: How to test is architecture has sincos as part of assembly language
26-
// Tested using g++ 5.4 and Intel icpc (ICC) 16.0.2 20160204 on
27-
// Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz
28-
29-
#if defined(__GNUC__) || defined(__clang__)
30-
#define TARGET_HAS_SINCOS 1
31-
#else
32-
#define TARGET_HAS_SINCOS 0
33-
#endif
34-
3515
namespace utils {
3616

37-
#if TARGET_HAS_SINCOS
38-
template <class T>
39-
inline void sincos(const T &angle, T *s, T *c){
40-
// works with gcc
41-
//asm volatile("fsincos" : "=t" (*c), "=u" (*s) : "0" (angle) : "st(7)");
42-
43-
// works with gcc and clang
44-
asm volatile("fsincos" : "=t" (*c), "=u" (*s) : "0" (angle));
45-
}
46-
#else
4717
template<class T>
4818
inline void sincos(const T &angle, T *s, T *c){
19+
#if defined(TARGET_HAS_SINCOS)
20+
asm volatile("fsincos" : "=t" (*c), "=u" (*s) : "0" (angle));
21+
#else
4922
*s = std::sin(angle);
5023
*c = std::cos(angle);
24+
#endif
5125
}
52-
#endif
5326

5427
/*
5528
Calculate array of scaled sinus and cosinus

setup.py

+62-3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,62 @@ def check_unix_compiler(plat, plat_ver, compiler, extensions, compiler_name):
200200

201201
return status
202202

203+
#
204+
# Checking if certain optimizations are available
205+
#
206+
def check_unix_optimization(plat, plat_ver, compiler, extensions, compiler_name):
207+
208+
#
209+
# checking is fsincos is enabled
210+
#
211+
import tempfile
212+
import random
213+
import string
214+
215+
tempdir = tempfile.gettempdir();
216+
217+
pat = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
218+
src = pat+'_sincos_opt.c'
219+
exe = pat+'_sincos_opt.exe'
220+
obj = pat+'_sincos_opt.o'
221+
222+
with open(tempdir + '/' + src, 'w') as tmp:
223+
tmp.writelines([
224+
'#include <math.h>\n',
225+
'void our_sincos(double angle, double *s, double *c){\n',
226+
' asm volatile("fsincos" : "=t" (*c), "=u" (*s) : "0" (angle));\n',
227+
'}\n',
228+
229+
'int main() {\n',
230+
' double t = 1, x[2];\n',
231+
' our_sincos(t, x, x+1);\n',
232+
' return 0;\n',
233+
'}\n'
234+
])
235+
236+
status = True
237+
try:
238+
objects = compiler.compile([tempdir+'/'+ src], output_dir = tempdir)
239+
compiler.link_executable(objects, exe, output_dir = tempdir)
240+
241+
if re.search(r'gcc', compiler_name) or re.search(r'g\+\+', compiler_name) or \
242+
re.search(r'clang', compiler_name) or re.search(r'icc', compiler_name) or \
243+
re.search(r'icpc', compiler_name):
244+
for e in extensions: e.extra_compile_args.append('-DTARGET_HAS_SINCOS')
245+
else:
246+
print("Did not recognize the compiler %s." % (compiler_name))
247+
status = False
248+
except:
249+
print("Failed to compile sincos test case on compiler %s." % (compiler_name))
250+
status = False
251+
252+
# Cleanup
253+
removefile(tempdir+'/'+ src)
254+
removefile(tempdir+'/'+ exe)
255+
removefile(tempdir+'/'+ obj)
256+
257+
return status
258+
203259
#
204260
# Hooking the building of extentions
205261
#
@@ -219,6 +275,9 @@ def build_extensions(self):
219275
build_ext.build_extensions(self)
220276

221277
elif plat in ['Linux', 'Darwin']:
278+
279+
check_unix_optimization(plat, plat_ver, self.compiler, self.extensions, self.compiler.compiler_cxx[0])
280+
222281
if (
223282
check_unix_compiler(plat, plat_ver, self.compiler, self.extensions, self.compiler.compiler_cxx[0]) and
224283
check_unix_compiler(plat, plat_ver, self.compiler, self.extensions, self.compiler.compiler_so[0])
@@ -346,8 +405,8 @@ def _env_variable_bool(key, default):
346405
long_description = "\n".join(long_description_s[long_description_s.index("INTRODUCTION"):])
347406

348407
setup (name = 'phoebe',
349-
version = '2.3.60',
350-
description = 'PHOEBE 2.3.60',
408+
version = '2.3.61',
409+
description = 'PHOEBE 2.3.61',
351410
long_description=long_description,
352411
author = 'PHOEBE development team',
353412
author_email = 'phoebe-devel@lists.sourceforge.net',
@@ -367,7 +426,7 @@ def _env_variable_bool(key, default):
367426
'Programming Language :: Python :: 3 :: Only',
368427
],
369428
python_requires='>=3.6, <4',
370-
download_url = 'https://github.com/phoebe-project/phoebe2/tarball/2.3.60',
429+
download_url = 'https://github.com/phoebe-project/phoebe2/tarball/2.3.61',
371430
packages = ['phoebe', 'phoebe.parameters', 'phoebe.parameters.solver', 'phoebe.parameters.figure', 'phoebe.frontend', 'phoebe.constraints', 'phoebe.dynamics', 'phoebe.distortions', 'phoebe.algorithms', 'phoebe.atmospheres', 'phoebe.backend', 'phoebe.solverbackends', 'phoebe.solverbackends.ebai', 'phoebe.utils', 'phoebe.helpers', 'phoebe.pool', 'phoebe.dependencies', 'phoebe.dependencies.autofig', 'phoebe.dependencies.nparray', 'phoebe.dependencies.distl', 'phoebe.dependencies.unitsiau2015'],
372431
install_requires=['numpy>=1.12','scipy>=1.2','astropy>=1.0', 'corner', 'pytest', 'requests', 'python-socketio[client]']+['flask', 'flask-cors', 'flask-socketio==4.3.*', 'gevent-websocket'],
373432
package_data={'phoebe.atmospheres':['tables/wd/*', 'tables/passbands/*'],

0 commit comments

Comments
 (0)