| 1 |
!------------------------------------------------------------------------- |
| 2 |
! |
| 3 |
! sunstudio_sparc.s |
| 4 |
! compare and swap for Sun Studio on Sparc |
| 5 |
! |
| 6 |
! Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 7 |
! Portions Copyright (c) 1994, Regents of the University of California |
| 8 |
! |
| 9 |
! IDENTIFICATION |
| 10 |
! src/backend/port/tas/sunstudio_sparc.s |
| 11 |
! |
| 12 |
!------------------------------------------------------------------------- |
| 13 |
|
| 14 |
! Fortunately the Sun compiler can process cpp conditionals with -P |
| 15 |
|
| 16 |
! '/' is the comment for x86, while '!' is the comment for Sparc |
| 17 |
|
| 18 |
#if defined(__sparcv9) || defined(__sparc) |
| 19 |
|
| 20 |
.section ".text" |
| 21 |
.align 8 |
| 22 |
.skip 24 |
| 23 |
.align 4 |
| 24 |
|
| 25 |
.global pg_atomic_cas |
| 26 |
pg_atomic_cas: |
| 27 |
|
| 28 |
! "cas" only works on sparcv9 and sparcv8plus chips, and |
| 29 |
! requires a compiler targeting these CPUs. It will fail |
| 30 |
! on a compiler targeting sparcv8, and of course will not |
| 31 |
! be understood by a sparcv8 CPU. gcc continues to use |
| 32 |
! "ldstub" because it targets sparcv7. |
| 33 |
! |
| 34 |
! There is actually a trick for embedding "cas" in a |
| 35 |
! sparcv8-targeted compiler, but it can only be run |
| 36 |
! on a sparcv8plus/v9 cpus: |
| 37 |
! |
| 38 |
! http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libc/sparc/threads/sparc.il |
| 39 |
! |
| 40 |
! NB: We're assuming we're running on a TSO system here - solaris |
| 41 |
! userland luckily always has done so. |
| 42 |
|
| 43 |
#if defined(__sparcv9) || defined(__sparcv8plus) |
| 44 |
cas [%o0],%o2,%o1 |
| 45 |
#else |
| 46 |
ldstub [%o0],%o1 |
| 47 |
#endif |
| 48 |
mov %o1,%o0 |
| 49 |
retl |
| 50 |
nop |
| 51 |
.type pg_atomic_cas,2 |
| 52 |
.size pg_atomic_cas,(.-pg_atomic_cas) |
| 53 |
#endif |