|
1 | 1 | /* -*- Mode: C; c-basic-offset:4 ; -*- */
|
2 | 2 | /*
|
3 |
| - * Copyright (c) 2004-2009 The University of Tennessee and The University |
| 3 | + * Copyright (c) 2004-2019 The University of Tennessee and The University |
4 | 4 | * of Tennessee Research Foundation. All rights
|
5 | 5 | * reserved.
|
6 | 6 | * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
|
|
11 | 11 | * $HEADER$
|
12 | 12 | */
|
13 | 13 |
|
| 14 | +#include "opal/runtime/opal.h" |
| 15 | + |
14 | 16 | #ifndef OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED
|
15 | 17 | #define OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED
|
16 | 18 |
|
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) |
19 | 54 |
|
20 | 55 | #endif /* OPAL_DATATYPE_MEMCPY_H_HAS_BEEN_INCLUDED */
|
0 commit comments