Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
afd1f91d
Commit
afd1f91d
authored
6 years ago
by
Aidan Chalk
Committed by
Peter W. Draper
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Modern C approach to memswap after we found issues on ARM architectures with…
parent
726d3264
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/memswap.h
+16
-15
16 additions, 15 deletions
src/memswap.h
with
16 additions
and
15 deletions
src/memswap.h
+
16
−
15
View file @
afd1f91d
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
*
*
2018 STFC (author email aidan.chalk@stfc.ac.uk)
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
...
...
@@ -21,6 +21,7 @@
/* Config parameters. */
#include
"../config.h"
#include
<stdint.h>
#ifdef HAVE_IMMINTRIN_H
/* Include the header file with the intrinsics for Intel architecture. */
...
...
@@ -33,7 +34,7 @@
#endif
/* Macro for in-place swap of two values a and b of type t. a and b are
assumed to be of type
char
* so that the pointer arithmetic works. */
assumed to be of type
uint8_t
* so that the pointer arithmetic works. */
#define swap_loop(type, a, b, count) \
while (count >= sizeof(type)) { \
register type temp = *(type *)a; \
...
...
@@ -60,9 +61,9 @@
* @param void_b Pointer to the second element.
* @param bytes Size, in bytes, of the data pointed to by @c a and @c b.
*/
__attribute__
((
always_inline
))
inline
void
memswap
(
void
*
void_a
,
void
*
void_b
,
__attribute__
((
always_inline
))
inline
void
memswap
(
void
*
restrict
void_a
,
void
*
restrict
void_b
,
size_t
bytes
)
{
char
*
a
=
(
char
*
)
void_a
,
*
b
=
(
char
*
)
void_b
;
int8_t
*
restrict
a
=
(
int8_t
*
)
void_a
,
*
restrict
b
=
(
int8_t
*
)
void_b
;
#if defined(__AVX512F__) && defined(__INTEL_COMPILER)
swap_loop
(
__m512i
,
a
,
b
,
bytes
);
#endif
...
...
@@ -75,10 +76,10 @@ __attribute__((always_inline)) inline void memswap(void *void_a, void *void_b,
#ifdef __ALTIVEC__
swap_loop
(
vector
int
,
a
,
b
,
bytes
);
#endif
swap_loop
(
size
_t
,
a
,
b
,
bytes
);
swap_loop
(
int
,
a
,
b
,
bytes
);
swap_loop
(
shor
t
,
a
,
b
,
bytes
);
swap_loop
(
char
,
a
,
b
,
bytes
);
swap_loop
(
int_least64
_t
,
a
,
b
,
bytes
);
swap_loop
(
int
_least32_t
,
a
,
b
,
bytes
);
swap_loop
(
int_least16_
t
,
a
,
b
,
bytes
);
swap_loop
(
int_least8_t
,
a
,
b
,
bytes
);
}
/**
...
...
@@ -93,10 +94,10 @@ __attribute__((always_inline)) inline void memswap(void *void_a, void *void_b,
* @param void_b Pointer to the second element.
* @param bytes Size, in bytes, of the data pointed to by @c a and @c b.
*/
__attribute__
((
always_inline
))
inline
void
memswap_unaligned
(
void
*
void_a
,
void
*
void_b
,
__attribute__
((
always_inline
))
inline
void
memswap_unaligned
(
void
*
restrict
void_a
,
void
*
restrict
void_b
,
size_t
bytes
)
{
char
*
a
=
(
char
*
)
void_a
,
*
b
=
(
char
*
)
void_b
;
int8_t
*
restrict
a
=
(
int8_t
*
)
void_a
,
*
restrict
b
=
(
int8_t
*
)
void_b
;
#ifdef __AVX512F__
while
(
bytes
>=
sizeof
(
__m512i
))
{
register
__m512i
temp
;
...
...
@@ -134,10 +135,10 @@ __attribute__((always_inline)) inline void memswap_unaligned(void *void_a,
// Power8 supports unaligned load/stores, but not sure what it will do here.
swap_loop
(
vector
int
,
a
,
b
,
bytes
);
#endif
swap_loop
(
size
_t
,
a
,
b
,
bytes
);
swap_loop
(
int
,
a
,
b
,
bytes
);
swap_loop
(
shor
t
,
a
,
b
,
bytes
);
swap_loop
(
char
,
a
,
b
,
bytes
);
swap_loop
(
int_least64
_t
,
a
,
b
,
bytes
);
swap_loop
(
int
_least32_t
,
a
,
b
,
bytes
);
swap_loop
(
int_least16_
t
,
a
,
b
,
bytes
);
swap_loop
(
int_least8_t
,
a
,
b
,
bytes
);
}
#endif
/* SWIFT_MEMSWAP_H */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment