summaryrefslogtreecommitdiff
path: root/src/backend/port/tas/sunstudio_sparc.s
blob: 56d85f4514ff0af02968cc1e7717e95a7c9ca48c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
!-------------------------------------------------------------------------
!
! sunstudio_sparc.s
!	  compare and swap for Sun Studio on Sparc
!
! Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
! Portions Copyright (c) 1994, Regents of the University of California
!
! IDENTIFICATION
!	  $PostgreSQL: pgsql/src/backend/port/tas/sunstudio_sparc.s,v 1.1 2008/10/29 16:06:47 petere Exp $
!
!-------------------------------------------------------------------------

! Fortunately the Sun compiler can process cpp conditionals with -P

! '/' is the comment for x86, while '!' is the comment for Sparc

#if defined(__sparcv9) || defined(__sparc)

	.section        ".text"
	.align  8
	.skip   24
	.align  4

	.global pg_atomic_cas
pg_atomic_cas:
	
	! "cas" only works on sparcv9 and sparcv8plus chips, and
	! requies a compiler targeting these CPUs.  It will fail
	! on a compiler targeting sparcv8, and of course will not
	! be understood by a sparcv8 CPU.  gcc continues to use
	! "ldstub" because it targets sparcv7.
	!
	! There is actually a trick for embedding "cas" in a 
	! sparcv8-targeted compiler, but it can only be run
	! on a sparcv8plus/v9 cpus:
	!
	!   http://cvs.opensolaris.org/source/xref/on/usr/src/lib/libc/sparc/threads/sparc.il
	!

#if defined(__sparcv9) || defined(__sparcv8plus)
	cas     [%o0],%o2,%o1
#else
	ldstub [%o0],%o1
#endif
	mov     %o1,%o0
	retl
	nop
	.type   pg_atomic_cas,2
	.size   pg_atomic_cas,(.-pg_atomic_cas)
#endif