Skip to content

Commit 025e09a

Browse files
committed
Force inlining memcpy for short data
This work is based on @derbeyn patch provided on #6678. I reworked it to be more inclusive (works now with both gcc and icc) and to cover more standard size lengths (4, 8, 16). Signed-off-by: George Bosilca <[email protected]> Signed-off-by: Nadia Derbey <[email protected]>
1 parent 41aab40 commit 025e09a

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

opal/datatype/opal_datatype_memcpy.h

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4 ; -*- */
22
/*
3-
* Copyright (c) 2004-2009 The University of Tennessee and The University
3+
* Copyright (c) 2004-2019 The University of Tennessee and The University
44
* of Tennessee Research Foundation. All rights
55
* reserved.
66
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
@@ -11,10 +11,45 @@
1111
* $HEADER$
1212
*/
1313

14+
#include "opal/runtime/opal.h"
15+
1416
#ifndef OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED
1517
#define OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED
1618

17-
#define MEMCPY( DST, SRC, BLENGTH ) \
18-
memcpy( (DST), (SRC), (BLENGTH) )
19+
#define TYPED_MEMCPY( DST, SRC, BLENGTH, ALIGN, TYPE) \
20+
if( ((BLENGTH) >= sizeof(TYPE)) && (0 == ((ALIGN) & (sizeof(TYPE) - 1))) ) { \
21+
TYPE *__dst = (TYPE*)(DST), *__src = (TYPE*)(SRC); \
22+
if( (BLENGTH) == sizeof(TYPE) ) { \
23+
*__dst = *__src; \
24+
break; \
25+
} \
26+
size_t _cnt = ((BLENGTH) / sizeof(TYPE)); \
27+
for( ; _cnt > 0; _cnt--, __dst++, __src++ ) { \
28+
*__dst = *__src; \
29+
(BLENGTH) -= sizeof(TYPE); \
30+
} \
31+
if( 0 == (BLENGTH) ) break; \
32+
(DST) = __dst; \
33+
(SRC) = __src; \
34+
}
35+
36+
/*
37+
* This macro is called whenever we are packing/unpacking a DDT that
38+
* that is built with basic datatypes.
39+
* Specifying a fixed size for the memcpy() makes the intel compiler
40+
* inline it as an assignment operation.
41+
*/
42+
#define MEMCPY( DST, SRC, BLENGTH ) \
43+
do { \
44+
void *_dst = (void*)(DST), *_src = (void*)(SRC); \
45+
size_t _blength = (size_t)(BLENGTH); \
46+
if( _blength < (size_t)opal_cache_line_size ) { \
47+
uintptr_t align = ((uintptr_t)_dst) | ((uintptr_t)_src); \
48+
TYPED_MEMCPY( _dst, _src, _blength, align, int64_t ); \
49+
TYPED_MEMCPY( _dst, _src, _blength, align, int32_t ); \
50+
TYPED_MEMCPY( _dst, _src, _blength, align, int8_t ); \
51+
} \
52+
memcpy( _dst, _src, _blength ); \
53+
} while (0)
1954

2055
#endif /* OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED */

0 commit comments

Comments
 (0)