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
449346aa
Commit
449346aa
authored
5 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Added an atomic max for int
parent
85af978e
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1048
Atomic gravity and time-step limiter
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/atomic.h
+46
-23
46 additions, 23 deletions
src/atomic.h
with
46 additions
and
23 deletions
src/atomic.h
+
46
−
23
View file @
449346aa
...
@@ -38,6 +38,29 @@
...
@@ -38,6 +38,29 @@
#define atomic_cas(v, o, n) __sync_val_compare_and_swap(v, o, n)
#define atomic_cas(v, o, n) __sync_val_compare_and_swap(v, o, n)
#define atomic_swap(v, n) __sync_lock_test_and_set(v, n)
#define atomic_swap(v, n) __sync_lock_test_and_set(v, n)
/**
* @brief Atomic min operation on ints.
*
* 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
(
volatile
int
*
const
address
,
const
int
y
)
{
int
*
int_ptr
=
(
int
*
)
address
;
int
test_val
,
old_val
,
new_val
;
old_val
=
*
address
;
do
{
test_val
=
old_val
;
new_val
=
min
(
old_val
,
y
);
old_val
=
atomic_cas
(
int_ptr
,
test_val
,
new_val
);
}
while
(
test_val
!=
old_val
);
}
/**
/**
* @brief Atomic min operation on floats.
* @brief Atomic min operation on floats.
*
*
...
@@ -69,29 +92,6 @@ __attribute__((always_inline)) INLINE static void atomic_min_f(
...
@@ -69,29 +92,6 @@ __attribute__((always_inline)) INLINE static void atomic_min_f(
}
while
(
test_val
.
as_int
!=
old_val
.
as_int
);
}
while
(
test_val
.
as_int
!=
old_val
.
as_int
);
}
}
/**
* @brief Atomic min operation on ints.
*
* 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
(
volatile
int
*
address
,
int
y
)
{
int
*
int_ptr
=
(
int
*
)
address
;
int
test_val
,
old_val
,
new_val
;
old_val
=
*
address
;
do
{
test_val
=
old_val
;
new_val
=
min
(
old_val
,
y
);
old_val
=
atomic_cas
(
int_ptr
,
test_val
,
new_val
);
}
while
(
test_val
!=
old_val
);
}
/**
/**
* @brief Atomic min operation on doubles.
* @brief Atomic min operation on doubles.
*
*
...
@@ -145,6 +145,29 @@ __attribute__((always_inline)) INLINE static void atomic_max_c(
...
@@ -145,6 +145,29 @@ __attribute__((always_inline)) INLINE static void atomic_max_c(
}
while
(
test_val
!=
old_val
);
}
while
(
test_val
!=
old_val
);
}
}
/**
* @brief Atomic max operation on ints.
*
* 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
(
volatile
int
*
const
address
,
const
int
y
)
{
int
*
int_ptr
=
(
int
*
)
address
;
int
test_val
,
old_val
,
new_val
;
old_val
=
*
address
;
do
{
test_val
=
old_val
;
new_val
=
max
(
old_val
,
y
);
old_val
=
atomic_cas
(
int_ptr
,
test_val
,
new_val
);
}
while
(
test_val
!=
old_val
);
}
/**
/**
* @brief Atomic max operation on floats.
* @brief Atomic max operation on floats.
*
*
...
...
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