Skip to content

Commit 128bed9

Browse files
committed
Rewrite Solaris compiler tas() assembly routines, merge i386 and x86_64
assembler files, renamed as solaris_x86.s. Theo Schlossnagle
1 parent 4ade4fe commit 128bed9

File tree

6 files changed

+71
-157
lines changed

6 files changed

+71
-157
lines changed

src/backend/port/tas/solaris_i386.s

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/backend/port/tas/solaris_sparc.s

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,20 @@
1-
!!
2-
!! $PostgreSQL: pgsql/src/backend/port/tas/solaris_sparc.s,v 1.2 2003/11/29 19:51:54 pgsql Exp $
3-
!!
4-
!! this would be a piece of inlined assembler but it appears
5-
!! to be easier to just write the assembler than to try to
6-
!! figure out how to make sure that in/out registers are kept
7-
!! straight in the asm's.
8-
!!
9-
.file "tas.c"
10-
.section ".text"
11-
.align 4
12-
.global tas
13-
.type tas,#function
14-
.proc 04
15-
tas:
16-
!!
17-
!! this is a leaf procedure - no need to save windows and
18-
!! diddle the CWP.
19-
!!
20-
!#PROLOGUE# 0
21-
!#PROLOGUE# 1
22-
23-
!!
24-
!! write 0xFF into the lock address, saving the old value in %o0.
25-
!! this is an atomic action, even on multiprocessors.
26-
!!
27-
ldstub [%o0],%o0
28-
29-
!!
30-
!! if it was already set when we set it, somebody else already
31-
!! owned the lock -- return 1.
32-
!!
33-
cmp %o0,0
34-
bne .LL2
35-
mov 1,%o0
36-
37-
!!
38-
!! otherwise, it was clear and we now own the lock -- return 0.
39-
!!
40-
mov 0,%o0
41-
.LL2:
42-
!!
43-
!! this is a leaf procedure - no need to restore windows and
44-
!! diddle the CWP.
45-
!!
46-
retl
47-
nop
48-
.LLfe1:
49-
.size tas,.LLfe1-tas
50-
.ident "GCC: (GNU) 2.5.8"
1+
/=======================================================================
2+
/ solaris_sparc.s -- compare and swap for solaris_sparc
3+
/=======================================================================
4+
5+
#if defined(__sparcv9) || defined(__sparc)
6+
7+
.section ".text"
8+
.align 8
9+
.skip 24
10+
.align 4
11+
12+
.global pg_atomic_cas
13+
pg_atomic_cas:
14+
cas [%o0],%o2,%o1
15+
mov %o1,%o0
16+
retl
17+
nop
18+
.type pg_atomic_cas,2
19+
.size pg_atomic_cas,(.-pg_atomic_cas)
20+
#endif

src/backend/port/tas/solaris_x86.s

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/=======================================================================
2+
/ solaris_i386.s -- compare and swap for solaris_i386
3+
/=======================================================================
4+
5+
/ Fortunately the Sun compiler understands cpp conditionals
6+
7+
.file "tas.s"
8+
9+
#if defined(__amd64)
10+
.code64
11+
#endif
12+
13+
.globl pg_atomic_cas
14+
.type pg_atomic_cas, @function
15+
16+
.section .text, "ax"
17+
.align 16
18+
19+
pg_atomic_cas:
20+
#if defined(__amd64)
21+
movl %edx,%eax
22+
lock
23+
cmpxchgl %esi,(%rdi)
24+
#else
25+
movl 4(%esp), %edx
26+
movl 8(%esp), %ecx
27+
movl 12(%esp), %eax
28+
lock
29+
cmpxchgl %ecx, (%edx)
30+
#endif
31+
ret
32+
.size pg_atomic_cas, . - pg_atomic_cas

src/backend/port/tas/solaris_x86_64.s

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/include/storage/s_lock.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
6767
* Portions Copyright (c) 1994, Regents of the University of California
6868
*
69-
* $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.149 2006/04/19 23:11:15 tgl Exp $
69+
* $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.150 2006/04/27 22:28:42 momjian Exp $
7070
*
7171
*-------------------------------------------------------------------------
7272
*/
@@ -763,23 +763,14 @@ typedef unsigned char slock_t;
763763
#endif
764764

765765

766-
#if defined(__sparc__) || defined(__sparc)
766+
#if defined(__sun) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc))
767767
#define HAS_TEST_AND_SET
768-
769768
typedef unsigned char slock_t;
770-
#endif
771-
772-
773-
/* out-of-line assembler from src/backend/port/tas/foo.s */
774769

775-
/* i386/X86_64 using Sun compiler */
776-
#if defined(__sun) && (defined(__i386) || defined(__x86_64__))
777-
/*
778-
* Solaris/386 (we only get here for non-gcc case)
779-
*/
780-
#define HAS_TEST_AND_SET
770+
extern volatile slock_t pg_atomic_cas(volatile slock_t *lock, slock_t with,
771+
slock_t cmp);
781772

782-
typedef unsigned char slock_t;
773+
#define TAS(a) (pg_atomic_cas((a), 1, 0) != 0)
783774
#endif
784775

785776

src/template/solaris

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,21 @@ if test "$GCC" != yes ; then
44
if test "$enable_debug" != yes; then
55
CFLAGS="$CFLAGS -O" # any optimization breaks debug
66
fi
7-
fi
8-
9-
# Pick right test-and-set (TAS) code. We need out-of-line assembler
10-
# when not using gcc.
11-
case $host in
12-
sparc-*-solaris*)
13-
if test "$GCC" != yes ; then
14-
need_tas=yes
15-
tas_file=solaris_sparc.s
16-
fi
7+
else
8+
# Pick the right test-and-set (TAS) code for the Sun compiler.
9+
# We would like to use in-line assembler, but the compiler
10+
# requires *.il files to be on every compile line, making
11+
# the build system too fragile.
12+
case $host in
13+
sparc-*-solaris*)
14+
need_tas=yes
15+
tas_file=solaris_sparc.s
1716
;;
18-
i?86-*-solaris*)
19-
if test "$GCC" != yes ; then
20-
if isainfo | grep amd64
21-
then
22-
need_tas=yes
23-
tas_file=solaris_x86_64.s
24-
else
25-
need_tas=yes
26-
tas_file=solaris_i386.s
27-
fi
28-
fi
17+
i?86-*-solaris*)
18+
need_tas=yes
19+
tas_file=solaris_x86.s
2920
;;
30-
esac
21+
esac
22+
fi
3123

3224
# -D_POSIX_PTHREAD_SEMANTICS enables 5-arg getpwuid_r, among other things

0 commit comments

Comments
 (0)