Skip to content

Commit dae85c4

Browse files
skirpichevvstinner
andauthored
gh-145633: Remove support for ancient ARM platforms with mixed-endian doubles (#145634)
* Drop DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 macro. * Use DOUBLE_IS_BIG/LITTLE_ENDIAN_IEEE754 to detect endianness of float/doubles. * Drop "unknown_format" code path in PyFloat_Pack/Unpack*(). Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent bdf6de8 commit dae85c4

File tree

14 files changed

+129
-585
lines changed

14 files changed

+129
-585
lines changed

Doc/c-api/float.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,6 @@ endian processor, or ``0`` on little endian processor.
224224
Return value: ``0`` if all is OK, ``-1`` if error (and an exception is set,
225225
most likely :exc:`OverflowError`).
226226
227-
There are two problems on non-IEEE platforms:
228-
229-
* What this does is undefined if *x* is a NaN or infinity.
230-
* ``-0.0`` and ``+0.0`` produce the same bytes string.
231-
232227
.. c:function:: int PyFloat_Pack2(double x, char *p, int le)
233228
234229
Pack a C double as the IEEE 754 binary16 half-precision format.
@@ -256,9 +251,6 @@ Return value: The unpacked double. On error, this is ``-1.0`` and
256251
:c:func:`PyErr_Occurred` is true (and an exception is set, most likely
257252
:exc:`OverflowError`).
258253
259-
Note that on a non-IEEE platform this will refuse to unpack a bytes string that
260-
represents a NaN or infinity.
261-
262254
.. c:function:: double PyFloat_Unpack2(const char *p, int le)
263255
264256
Unpack the IEEE 754 binary16 half-precision format as a C double.

Include/internal/pycore_floatobject.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212

1313
/* runtime lifecycle */
1414

15-
extern void _PyFloat_InitState(PyInterpreterState *);
1615
extern PyStatus _PyFloat_InitTypes(PyInterpreterState *);
1716
extern void _PyFloat_FiniType(PyInterpreterState *);
1817

@@ -42,6 +41,15 @@ extern double _Py_parse_inf_or_nan(const char *p, char **endptr);
4241

4342
extern int _Py_convert_int_to_double(PyObject **v, double *dbl);
4443

44+
/* Should match endianness of the platform in most (all?) cases. */
45+
46+
#ifdef DOUBLE_IS_BIG_ENDIAN_IEEE754
47+
# define _PY_FLOAT_BIG_ENDIAN 1
48+
# define _PY_FLOAT_LITTLE_ENDIAN 0
49+
#else
50+
# define _PY_FLOAT_BIG_ENDIAN 0
51+
# define _PY_FLOAT_LITTLE_ENDIAN 1
52+
#endif
4553

4654
#ifdef __cplusplus
4755
}

Include/internal/pycore_pymath.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ extern void _Py_set_387controlword(unsigned short);
182182
// (extended precision), and we don't know how to change
183183
// the rounding precision.
184184
#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
185-
!defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
186-
!defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
185+
!defined(DOUBLE_IS_BIG_ENDIAN_IEEE754)
187186
# define _PY_SHORT_FLOAT_REPR 0
188187
#endif
189188

Include/internal/pycore_runtime_init.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313
#include "pycore_debug_offsets.h" // _Py_DebugOffsets_INIT()
1414
#include "pycore_dtoa.h" // _dtoa_state_INIT()
1515
#include "pycore_faulthandler.h" // _faulthandler_runtime_state_INIT
16-
#include "pycore_floatobject.h" // _py_float_format_unknown
16+
#include "pycore_floatobject.h" // _py_float_format_*
1717
#include "pycore_function.h"
1818
#include "pycore_hamt.h" // _PyHamt_BitmapNode_Type
1919
#include "pycore_import.h" // IMPORTS_INIT
@@ -84,10 +84,6 @@ extern PyTypeObject _PyExc_MemoryError;
8484
.stoptheworld = { \
8585
.is_global = 1, \
8686
}, \
87-
.float_state = { \
88-
.float_format = _py_float_format_unknown, \
89-
.double_format = _py_float_format_unknown, \
90-
}, \
9187
.types = { \
9288
.next_version_tag = _Py_TYPE_VERSION_NEXT, \
9389
}, \
@@ -233,4 +229,4 @@ extern PyTypeObject _PyExc_MemoryError;
233229
#ifdef __cplusplus
234230
}
235231
#endif
236-
#endif /* !Py_INTERNAL_RUNTIME_INIT_H */
232+
#endif /* !Py_INTERNAL_RUNTIME_INIT_H */

Include/internal/pycore_runtime_structs.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ struct _pymem_allocators {
3535
PyObjectArenaAllocator obj_arena;
3636
};
3737

38-
enum _py_float_format_type {
39-
_py_float_format_unknown,
40-
_py_float_format_ieee_big_endian,
41-
_py_float_format_ieee_little_endian,
42-
};
43-
44-
struct _Py_float_runtime_state {
45-
enum _py_float_format_type float_format;
46-
enum _py_float_format_type double_format;
47-
};
48-
4938
struct pyhash_runtime_state {
5039
struct {
5140
#ifndef MS_WINDOWS
@@ -270,7 +259,6 @@ struct pyruntimestate {
270259
} audit_hooks;
271260

272261
struct _py_object_runtime_state object_state;
273-
struct _Py_float_runtime_state float_state;
274262
struct _Py_unicode_runtime_state unicode_state;
275263
struct _types_runtime_state types;
276264
struct _Py_time_runtime_state time;

Include/pymacconfig.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#undef SIZEOF_UINTPTR_T
1919
#undef SIZEOF_PTHREAD_T
2020
#undef WORDS_BIGENDIAN
21-
#undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754
2221
#undef DOUBLE_IS_BIG_ENDIAN_IEEE754
2322
#undef DOUBLE_IS_LITTLE_ENDIAN_IEEE754
2423
#undef HAVE_GCC_ASM_FOR_X87
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove support for ancient ARM platforms (ARMv4L and ARMv5L OABI boards),
2+
using mixed-endian representation
3+
for doubles. Patch by Sergey B Kirpichev.

Objects/clinic/floatobject.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)