8000 ENH: reduce the alignment requirement for complex arrays on x86 · juliantaylor/numpy@2998ce8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2998ce8

Browse files
committed
ENH: reduce the alignment requirement for complex arrays on x86
x86 can deal with unaligned memory access so it does not need to align complex types to 2 * sizeof(T) for the dtype transfers which work on the full complex number. closes numpy#3768 Does not fix that new complex arrays are reported as aligned when the allocator does not provide the required alignment.
1 parent 6fbbd7f commit 2998ce8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "npy_pycompat.h"
1111
#include "numpy/npy_math.h"
1212
#include "numpy/halffloat.h"
13+
#include "numpy/npy_cpu.h"
1314

1415
#include "npy_config.h"
1516
#include "npy_sort.h"
@@ -21,6 +22,9 @@
2122

2223
#include "numpyos.h"
2324

25+
#if (defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64))
26+
#define NPY_USE_UNALIGNED_ACCESS
27+
#endif
2428

2529
/*
2630
*****************************************************************************
@@ -3821,8 +3825,15 @@ NPY_NO_EXPORT PyArray_Descr @from@_Descr = {
38213825
NPY_@from@,
38223826
/* elsize */
38233827
@num@ * sizeof(@fromtype@),
3824-
/* alignment */
3828+
/*
3829+
* alignment, platforms without unaligned access need double alignment
3830+
* for dtype dtransfers
3831+
*/
3832+
#ifdef NPY_USE_UNALIGNED_ACCESS
3833+
_ALIGN(@fromtype@),
3834+
#else
38253835
@num@ * _ALIGN(@fromtype@),
3836+
#endif
38263837
/* subarray */
38273838
NULL,
38283839
/* fields */
@@ -4164,7 +4175,15 @@ set_typeinfo(PyObject *dict)
41644175
#endif
41654176
NPY_@name@,
41664177
NPY_BITSOF_@name@,
4178+
/*
4179+
* alignment, platforms without unaligned access need double
4180+
* alignment for dtype dtransfers
4181+
*/
4182+
#ifdef NPY_USE_UNALIGNED_ACCESS
4183+
_ALIGN(@type@),
4184+
#else
41674185
@num@ * _ALIGN(@type@),
4186+
#endif
41684187
(PyObject *) &Py@Name@ArrType_Type));
41694188
Py_DECREF(s);
41704189

0 commit comments

Comments
 (0)
0