Skip to content

Commit 7625a37

Browse files
committed
Use strict memory access for ICC compiler
1 parent c10d0c0 commit 7625a37

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

include/flatcc/portable/pmemaccess.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,22 @@
3232
this to be the same as unaligned access. On x86/64 we can be more relaxed both
3333
with aliasing and alignment, but if at some point a compiler starts to
3434
modify this behaviour, the header can be updated or PORTABLE_MEM_PTR_ACCESS
35-
can be defined to 0 in the build configuration, or this file can be updated. */
35+
can be defined to 0 in the build configuration, or this file can be updated.
36+
37+
The balance is betweem knowing memcpy or __builtin_memcpy is fast,
38+
and knowing that pointer casts do not break.
39+
40+
Known targets that require PORTABLE_MEM_PTR_ACCESS=0 for at least some version:
41+
42+
- ARM cross compiler: arm-none-eabi, -O2, -mcpu=cortext-m7,
43+
breaks on PORTABLE_MEM_PTR_ACCESS=0
44+
slow memcpy, has fast __builtin_memcpy
45+
46+
- Intel ICC -O3 on x86/64 (that compiler is deprecated by Intel).
47+
breaks on PORTABLE_MEM_PTR_ACCESS=0
48+
has __builtin_memcpy, performance unknown, memcpy perforamnce unknown.
49+
50+
*/
3651

3752

3853
/* NOTE: for best performance, `__builtin_memcpy` should be detectable, but
@@ -63,7 +78,11 @@ extern "C" {
6378

6479
#ifndef PORTABLE_MEM_PTR_ACCESS
6580

66-
#if (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
81+
#if defined(__INTEL_COMPILER)
82+
# /* Prevents Intel ICC compiler from breaking on -O3 on x86/64 target,
83+
likely due to strict aliasing rules. */
84+
# define PORTABLE_MEM_PTR_ACCESS 0
85+
#elif (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
6786
# define PORTABLE_MEM_PTR_ACCESS 1
6887
#else
6988
# define PORTABLE_MEM_PTR_ACCESS 0

0 commit comments

Comments
 (0)