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
3379d0e8
Commit
3379d0e8
authored
7 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Cleaner implementation of the atomic operations for floats.
parent
68c5af52
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/atomic.h
+63
-21
63 additions, 21 deletions
src/atomic.h
with
63 additions
and
21 deletions
src/atomic.h
+
63
−
21
View file @
3379d0e8
...
@@ -36,44 +36,86 @@
...
@@ -36,44 +36,86 @@
/**
/**
* @brief Atomic min operation on floats.
* @brief Atomic min operation on floats.
*
* This is a text-book implementation based on an atomic CAS.
*
* @param address The address to update.
* @param y The value to update the address with.
*/
*/
__attribute__
((
always_inline
))
INLINE
static
void
atomic_min_f
(
__attribute__
((
always_inline
))
INLINE
static
void
atomic_min_f
(
volatile
float
*
x
,
float
y
)
{
volatile
float
*
address
,
float
y
)
{
float
test
,
new
;
float
old
=
*
x
;
int
*
int_ptr
=
(
int
*
)
address
;
typedef
union
{
float
as_float
;
int
as_int
;
}
cast_type
;
cast_type
assumed
,
old
,
new
;
old
.
as_float
=
*
address
;
do
{
do
{
test
=
old
;
assumed
.
as_int
=
old
.
as_int
;
new
=
min
(
old
,
y
);
new
.
as_float
=
min
(
old
.
as_float
,
y
);
old
=
atomic_cas
(
(
int
*
)
x
,
test
,
new
);
old
.
as_int
=
atomic_cas
(
int
_ptr
,
assumed
.
as_int
,
new
.
as_int
);
}
while
(
tes
t
!=
old
);
}
while
(
assumed
.
as_in
t
!=
old
.
as_int
);
}
}
/**
/**
* @brief Atomic max operation on floats.
* @brief Atomic max operation on floats.
*
* This is a text-book implementation based on an atomic CAS.
*
* @param address The address to update.
* @param y The value to update the address with.
*/
*/
__attribute__
((
always_inline
))
INLINE
static
void
atomic_max_f
(
__attribute__
((
always_inline
))
INLINE
static
void
atomic_max_f
(
volatile
float
*
x
,
float
y
)
{
volatile
float
*
address
,
float
y
)
{
float
test
,
new
;
float
old
=
*
x
;
int
*
int_ptr
=
(
int
*
)
address
;
typedef
union
{
float
as_float
;
int
as_int
;
}
cast_type
;
cast_type
assumed
,
old
,
new
;
old
.
as_float
=
*
address
;
do
{
do
{
test
=
old
;
assumed
.
as_int
=
old
.
as_int
;
new
=
max
(
old
,
y
);
new
.
as_float
=
max
(
old
.
as_float
,
y
);
old
=
atomic_cas
(
(
int
*
)
x
,
test
,
new
);
old
.
as_int
=
atomic_cas
(
int
_ptr
,
assumed
.
as_int
,
new
.
as_int
);
}
while
(
tes
t
!=
old
);
}
while
(
assumed
.
as_in
t
!=
old
.
as_int
);
}
}
/**
/**
* @brief Atomic add operation on floats.
* @brief Atomic add operation on floats.
*
* This is a text-book implementation based on an atomic CAS.
*
* @param address The address to update.
* @param y The value to update the address with.
*/
*/
__attribute__
((
always_inline
))
INLINE
static
void
atomic_add_f
(
__attribute__
((
always_inline
))
INLINE
static
void
atomic_add_f
(
volatile
float
*
x
,
float
y
)
{
volatile
float
*
address
,
float
y
)
{
float
test
,
new
;
float
old
=
*
x
;
int
*
int_ptr
=
(
int
*
)
address
;
typedef
union
{
float
as_float
;
int
as_int
;
}
cast_type
;
cast_type
assumed
,
old
,
new
;
old
.
as_float
=
*
address
;
do
{
do
{
test
=
old
;
assumed
.
as_int
=
old
.
as_int
;
new
=
old
+
y
;
new
.
as_float
=
old
.
as_float
+
y
;
old
=
atomic_cas
(
(
int
*
)
x
,
test
,
new
);
old
.
as_int
=
atomic_cas
(
int
_ptr
,
assumed
.
as_int
,
new
.
as_int
);
}
while
(
tes
t
!=
old
);
}
while
(
assumed
.
as_in
t
!=
old
.
as_int
);
}
}
#endif
/* SWIFT_ATOMIC_H */
#endif
/* SWIFT_ATOMIC_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