@@ -335,86 +335,25 @@ extern "C" {
335335 *
336336 * #define HAVE_PY_SET_53BIT_PRECISION 1
337337 *
338- * and also give appropriate definitions for the following three macros:
339- *
340- * _PY_SET_53BIT_PRECISION_START : store original FPU settings, and
341- * set FPU to 53-bit precision/round-half-to-even
342- * _PY_SET_53BIT_PRECISION_END : restore original FPU settings
343- * _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to
344- * use the two macros above.
345- *
346338 * The macros are designed to be used within a single C function: see
347339 * Python/pystrtod.c for an example of their use.
348340 */
349341
350- /* get and set x87 control word for gcc/x86 */
342+ // HAVE_PY_SET_53BIT_PRECISION macro must be kept in sync with pycore_pymath.h
351343#ifdef HAVE_GCC_ASM_FOR_X87
352- #define HAVE_PY_SET_53BIT_PRECISION 1
353- /* _Py_get/set_387controlword functions are defined in Python/pymath.c */
354- #define _Py_SET_53BIT_PRECISION_HEADER \
355- unsigned short old_387controlword, new_387controlword
356- #define _Py_SET_53BIT_PRECISION_START \
357- do { \
358- old_387controlword = _Py_get_387controlword(); \
359- new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
360- if (new_387controlword != old_387controlword) \
361- _Py_set_387controlword(new_387controlword); \
362- } while (0)
363- #define _Py_SET_53BIT_PRECISION_END \
364- if (new_387controlword != old_387controlword) \
365- _Py_set_387controlword(old_387controlword)
366- #endif
367-
368- /* get and set x87 control word for VisualStudio/x86 */
369- #if defined(_MSC_VER ) && !defined(_WIN64 ) && !defined(_M_ARM ) /* x87 not supported in 64-bit or ARM */
370- #define HAVE_PY_SET_53BIT_PRECISION 1
371- #define _Py_SET_53BIT_PRECISION_HEADER \
372- unsigned int old_387controlword, new_387controlword, out_387controlword
373- /* We use the __control87_2 function to set only the x87 control word.
374- The SSE control word is unaffected. */
375- #define _Py_SET_53BIT_PRECISION_START \
376- do { \
377- __control87_2(0, 0, &old_387controlword, NULL); \
378- new_387controlword = \
379- (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
380- if (new_387controlword != old_387controlword) \
381- __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
382- &out_387controlword, NULL); \
383- } while (0)
384- #define _Py_SET_53BIT_PRECISION_END \
385- do { \
386- if (new_387controlword != old_387controlword) \
387- __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
388- &out_387controlword, NULL); \
389- } while (0)
344+ // Get and set x87 control word for gcc/x86
345+ # define HAVE_PY_SET_53BIT_PRECISION 1
346+ #endif
347+ #if defined(_MSC_VER ) && !defined(_WIN64 ) && !defined(_M_ARM )
348+ // Get and set x87 control word for VisualStudio/x86.
349+ // x87 not supported in 64-bit or ARM.
350+ # define HAVE_PY_SET_53BIT_PRECISION 1
390351#endif
391-
392352#ifdef HAVE_GCC_ASM_FOR_MC68881
393- #define HAVE_PY_SET_53BIT_PRECISION 1
394- #define _Py_SET_53BIT_PRECISION_HEADER \
395- unsigned int old_fpcr, new_fpcr
396- #define _Py_SET_53BIT_PRECISION_START \
397- do { \
398- __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
399- /* Set double precision / round to nearest. */ \
400- new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
401- if (new_fpcr != old_fpcr) \
402- __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \
403- } while (0)
404- #define _Py_SET_53BIT_PRECISION_END \
405- do { \
406- if (new_fpcr != old_fpcr) \
407- __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
408- } while (0)
409- #endif
410-
411- /* default definitions are empty */
412- #ifndef HAVE_PY_SET_53BIT_PRECISION
413- #define _Py_SET_53BIT_PRECISION_HEADER
414- #define _Py_SET_53BIT_PRECISION_START
415- #define _Py_SET_53BIT_PRECISION_END
353+ # define HAVE_PY_SET_53BIT_PRECISION 1
416354#endif
417355
356+
418357/* If we can't guarantee 53-bit precision, don't use the code
419358 in Python/dtoa.c, but fall back to standard code. This
420359 means that repr of a float will be long (17 sig digits).
@@ -430,14 +369,14 @@ extern "C" {
430369#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754 ) && \
431370 !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754 ) && \
432371 !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 )
433- #define PY_NO_SHORT_FLOAT_REPR
372+ # define PY_NO_SHORT_FLOAT_REPR
434373#endif
435374
436375/* double rounding is symptomatic of use of extended precision on x86. If
437376 we're seeing double rounding, and we don't have any mechanism available for
438377 changing the FPU rounding precision, then don't use Python/dtoa.c. */
439378#if defined(X87_DOUBLE_ROUNDING ) && !defined(HAVE_PY_SET_53BIT_PRECISION )
440- #define PY_NO_SHORT_FLOAT_REPR
379+ # define PY_NO_SHORT_FLOAT_REPR
441380#endif
442381
443382
0 commit comments