MCPcopy Create free account
hub / github.com/numpy/numpy / check_long_double_representation

Function check_long_double_representation

numpy/core/setup_common.py:223–268  ·  view source on GitHub ↗
(cmd)

Source from the content-addressed store, hash-verified

221
222# Code to detect long double representation taken from MPFR m4 macro
223def check_long_double_representation(cmd):
224 cmd._check_compiler()
225 body = LONG_DOUBLE_REPRESENTATION_SRC % {'type': 'long double'}
226
227 # Disable whole program optimization (the default on vs2015, with python 3.5+)
228 # which generates intermediary object files and prevents checking the
229 # float representation.
230 if sys.platform == "win32" and not mingw32():
231 try:
232 cmd.compiler.compile_options.remove("/GL")
233 except (AttributeError, ValueError):
234 pass
235
236 # Disable multi-file interprocedural optimization in the Intel compiler on Linux
237 # which generates intermediary object files and prevents checking the
238 # float representation.
239 elif (sys.platform != "win32"
240 and cmd.compiler.compiler_type.startswith('intel')
241 and '-ipo' in cmd.compiler.cc_exe):
242 newcompiler = cmd.compiler.cc_exe.replace(' -ipo', '')
243 cmd.compiler.set_executables(
244 compiler=newcompiler,
245 compiler_so=newcompiler,
246 compiler_cxx=newcompiler,
247 linker_exe=newcompiler,
248 linker_so=newcompiler + ' -shared'
249 )
250
251 # We need to use _compile because we need the object filename
252 src, obj = cmd._compile(body, None, None, 'c')
253 try:
254 ltype = long_double_representation(pyod(obj))
255 return ltype
256 except ValueError:
257 # try linking to support CC="gcc -flto" or icc -ipo
258 # struct needs to be volatile so it isn't optimized away
259 # additionally "clang -flto" requires the foo struct to be used
260 body = body.replace('struct', 'volatile struct')
261 body += "int main(void) { return foo.before[0]; }\n"
262 src, obj = cmd._compile(body, None, None, 'c')
263 cmd.temp_files.append("_configtest")
264 cmd.compiler.link_executable([obj], "_configtest")
265 ltype = long_double_representation(pyod("_configtest"))
266 return ltype
267 finally:
268 cmd._clean()
269
270LONG_DOUBLE_REPRESENTATION_SRC = r"""
271/* "before" is 16 bytes to ensure there's no padding between it and "x".

Callers 1

generate_config_hFunction · 0.85

Calls 7

mingw32Function · 0.90
pyodFunction · 0.85
_check_compilerMethod · 0.80
startswithMethod · 0.80
replaceMethod · 0.80
_compileMethod · 0.45

Tested by

no test coverage detected