| 1 |
/* Copyright 2016 Google Inc. |
| 2 |
|
| 3 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
you may not use this file except in compliance with the License. |
| 5 |
You may obtain a copy of the License at |
| 6 |
|
| 7 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
| 9 |
Unless required by applicable law or agreed to in writing, software |
| 10 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
See the License for the specific language governing permissions and |
| 13 |
limitations under the License. */ |
| 14 |
|
| 15 |
/* Helper routines for vax implementation of atomic operations. */ |
| 16 |
|
| 17 |
/* The vax has no compare-and-swap operation. Instead, we implement |
| 18 |
interlocked updates to words by protecting such updates with a spin lock. |
| 19 |
This works because on words where nsync uses atomic operations, no |
| 20 |
non-atomic operations are used. The spin lock is implemented by mapping |
| 21 |
from the word location to a bit in the following array, and using |
| 22 |
test-and-set (bbssi) on that bit. bbcci is used to clear the bit to |
| 23 |
guarantee isolation between the bits. */ |
| 24 |
.data |
| 25 |
.lcomm locks,128 |
| 26 |
|
| 27 |
.text |
| 28 |
|
| 29 |
/* Atomically, with acquire and release barrier semantics, |
| 30 |
int nsync_atm_cas_ (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { |
| 31 |
if (*p == old_value) { |
| 32 |
*p = new_value; |
| 33 |
return (some-non-zero-value); |
| 34 |
} else { |
| 35 |
return (0); |
| 36 |
} |
| 37 |
} |
| 38 |
*/ |
| 39 |
.align 1 |
| 40 |
.globl nsync_atm_cas_ |
| 41 |
.globl nsync_atm_cas_acq_ |
| 42 |
.globl nsync_atm_cas_rel_ |
| 43 |
.globl nsync_atm_cas_relacq_ |
| 44 |
nsync_atm_cas_: |
| 45 |
nsync_atm_cas_acq_: |
| 46 |
nsync_atm_cas_rel_: |
| 47 |
nsync_atm_cas_relacq_: |
| 48 |
.word 0x0 |
| 49 |
1: |
| 50 |
movl 4(%ap),%r0 |
| 51 |
ashl $-2,%r0,%r1 |
| 52 |
bicl2 $-1024,%r1 |
| 53 |
bbssi %r1, locks, 4f |
| 54 |
movl (%r0),%r2 |
| 55 |
clrl %r3 |
| 56 |
cmpl 8(%ap),%r2 |
| 57 |
bneq 2f |
| 58 |
movl 12(%ap),(%r0) |
| 59 |
movl $1, %r3 |
| 60 |
2: |
| 61 |
bbcci %r1, locks, 3f |
| 62 |
3: |
| 63 |
movl %r3,%r0 |
| 64 |
ret |
| 65 |
4: |
| 66 |
calls $0, nsync_yield_ |
| 67 |
jmp 1b |
| 68 |
|
| 69 |
/* Atomically, with acquire barrier semantics, |
| 70 |
uint32_t nsync_atm_load_ (nsync_atomic_uint32_ *p) { return (*p); } */ |
| 71 |
.align 1 |
| 72 |
.globl nsync_atm_load_ |
| 73 |
.globl nsync_atm_load_acq_ |
| 74 |
nsync_atm_load_: |
| 75 |
nsync_atm_load_acq_: |
| 76 |
.word 0x0 |
| 77 |
movl *4(%ap),%r0 |
| 78 |
ret |
| 79 |
|
| 80 |
/* Atomically, with release barrier semantics, |
| 81 |
void nsync_atm_store_ (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } */ |
| 82 |
.align 1 |
| 83 |
.globl nsync_atm_store_ |
| 84 |
.globl nsync_atm_store_rel_ |
| 85 |
nsync_atm_store_: |
| 86 |
nsync_atm_store_rel_: |
| 87 |
.word 0x0 |
| 88 |
1: |
| 89 |
movl 4(%ap),%r0 |
| 90 |
ashl $-2,%r0,%r1 |
| 91 |
bicl2 $-1024,%r1 |
| 92 |
bbssi %r1, locks, 3f |
| 93 |
movl 8(%ap),(%r0) |
| 94 |
bbcci %r1, locks, 2f |
| 95 |
2: |
| 96 |
ret |
| 97 |
3: |
| 98 |
calls $0, nsync_yield_ |
| 99 |
jmp 1b |