diff options
| author | Ivan Maidanski <ivmai@mail.ru> | 2012-10-03 13:02:13 +0400 |
|---|---|---|
| committer | Ivan Maidanski <ivmai@mail.ru> | 2012-10-03 13:02:13 +0400 |
| commit | 98a3d509fc1c07a95cd62aed03c1968c7b2f87a3 (patch) | |
| tree | 2ccb28d4e2fd2bb1de10e95bb49b7eff7aeb242c | |
| parent | 74357409ce5ee215b48f8ac253c6126abea02e12 (diff) | |
| download | libatomic_ops-98a3d509fc1c07a95cd62aed03c1968c7b2f87a3.tar.gz | |
Optimize AO_spin manually to minimize compiler influence on its duration
* src/atomic_ops.c (dummy, AO_spin): Use AO_t instead of deprecated
AO_T.
* src/atomic_ops_stack.c (AO_spin): Likewise.
* src/atomic_ops.c (AO_spin): Define as static (since not needed
outside).
* src/atomic_ops.c (AO_spin): Optimize code manually to minimize
speed dependency on compiler optimization level; add comment.
* src/atomic_ops_stack.c (AO_spin): Likewise.
| -rw-r--r-- | src/atomic_ops.c | 16 | ||||
| -rw-r--r-- | src/atomic_ops_stack.c | 12 |
2 files changed, 12 insertions, 16 deletions
diff --git a/src/atomic_ops.c b/src/atomic_ops.c index da45eb5..e0f7ae2 100644 --- a/src/atomic_ops.c +++ b/src/atomic_ops.c @@ -101,19 +101,17 @@ AO_TS_t AO_locks[AO_HASH_SIZE] = { AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, }; -static AO_T dummy = 1; +static AO_t dummy = 1; /* Spin for 2**n units. */ -void AO_spin(int n) +static void AO_spin(int n) { - int i; - AO_T j = AO_load(&dummy); + AO_t j = AO_load(&dummy); + int i = 2 << n; - for (i = 0; i < (2 << n); ++i) - { - j *= 5; - j -= 4; - } + while (i-- > 0) + j += (j - 1) << 2; + /* Given 'dummy' is initialized to 1, j is 1 after the loop. */ AO_store(&dummy, j); } diff --git a/src/atomic_ops_stack.c b/src/atomic_ops_stack.c index 13125ea..2f6a640 100644 --- a/src/atomic_ops_stack.c +++ b/src/atomic_ops_stack.c @@ -32,14 +32,12 @@ static AO_t dummy = 1; /* Spin for 2**n units. */ static void AO_spin(int n) { - int i; - AO_T j = AO_load(&dummy); + AO_t j = AO_load(&dummy); + int i = 2 << n; - for (i = 0; i < (2 << n); ++i) - { - j *= 5; - j -= 4; - } + while (i-- > 0) + j += (j - 1) << 2; + /* Given 'dummy' is initialized to 1, j is 1 after the loop. */ AO_store(&dummy, j); } |
