Commit 128bed94 authored by Bruce Momjian's avatar Bruce Momjian

Rewrite Solaris compiler tas() assembly routines, merge i386 and x86_64

assembler files, renamed as solaris_x86.s.

Theo Schlossnagle
parent 4ade4fe4
/=============================================================================
/ tas.s -- test and set lock for solaris_i386
/=============================================================================
.file "tas.s"
.text
.align 16
.L1.text:
.globl tas
tas:
pushl %ebp /save prev base pointer
movl %esp,%ebp /new base pointer
pushl %ebx /save prev bx
movl 8(%ebp),%ebx /load bx with address of lock
movl $255,%eax /put something in ax
xchgb %al,(%ebx) /swap lock value with "0"
cmpb $0,%al /did we get the lock?
jne .Locked
subl %eax,%eax /yes, we got it -- return 0
jmp .Finish
.align 4
.Locked:
movl $1,%eax /no, we didn't get it - return 1
.Finish:
popl %ebx /restore prev bx
movl %ebp,%esp /restore stack state
popl %ebp
ret /return
.align 4
.type tas,@function
.size tas,.-tas
!! /=======================================================================
!! $PostgreSQL: pgsql/src/backend/port/tas/solaris_sparc.s,v 1.2 2003/11/29 19:51:54 pgsql Exp $ / solaris_sparc.s -- compare and swap for solaris_sparc
!! /=======================================================================
!! this would be a piece of inlined assembler but it appears
!! to be easier to just write the assembler than to try to
!! figure out how to make sure that in/out registers are kept
!! straight in the asm's.
!!
.file "tas.c"
.section ".text"
.align 4
.global tas
.type tas,#function
.proc 04
tas:
!!
!! this is a leaf procedure - no need to save windows and
!! diddle the CWP.
!!
!#PROLOGUE# 0
!#PROLOGUE# 1
!! #if defined(__sparcv9) || defined(__sparc)
!! write 0xFF into the lock address, saving the old value in %o0.
!! this is an atomic action, even on multiprocessors.
!!
ldstub [%o0],%o0
!! .section ".text"
!! if it was already set when we set it, somebody else already .align 8
!! owned the lock -- return 1. .skip 24
!! .align 4
cmp %o0,0
bne .LL2
mov 1,%o0
!! .global pg_atomic_cas
!! otherwise, it was clear and we now own the lock -- return 0. pg_atomic_cas:
!! cas [%o0],%o2,%o1
mov 0,%o0 mov %o1,%o0
.LL2:
!!
!! this is a leaf procedure - no need to restore windows and
!! diddle the CWP.
!!
retl retl
nop nop
.LLfe1: .type pg_atomic_cas,2
.size tas,.LLfe1-tas .size pg_atomic_cas,(.-pg_atomic_cas)
.ident "GCC: (GNU) 2.5.8" #endif
/=======================================================================
/ solaris_i386.s -- compare and swap for solaris_i386
/=======================================================================
/ Fortunately the Sun compiler understands cpp conditionals
.file "tas.s"
#if defined(__amd64)
.code64
#endif
.globl pg_atomic_cas
.type pg_atomic_cas, @function
.section .text, "ax"
.align 16
pg_atomic_cas:
#if defined(__amd64)
movl %edx,%eax
lock
cmpxchgl %esi,(%rdi)
#else
movl 4(%esp), %edx
movl 8(%esp), %ecx
movl 12(%esp), %eax
lock
cmpxchgl %ecx, (%edx)
#endif
ret
.size pg_atomic_cas, . - pg_atomic_cas
/=============================================================================
/ tas.s -- test and set lock for solaris_i386
/ based on i386 ASM with modifications outlined in:
/ http://www.x86-64.org/documentation/assembly.
/ This might require flags: -xtarget=opteron -xarch=amd64
/ DB optimization documenation at:
/ http://developers.sun.com/solaris/articles/mysql_perf_tune.html
/=============================================================================
.file "tas.s"
.text
.align 16
.L1.text:
.globl tas
tas:
pushq %rbp /save prev base pointer
movq %rsp,%rbp /new base pointer
pushq %rbx /save prev bx
movq 8(%rbp),%rbx /load bx with address of lock
movq $255,%rax /put something in ax
xchgb %al,(%rbx) /swap lock value with "0"
cmpb $0,%al /did we get the lock?
jne .Locked
subq %rax,%rax /yes, we got it -- return 0
jmp .Finish
.align 8
.Locked:
movq $1,%rax /no, we didn't get it - return 1
.Finish:
popq %rbx /restore prev bx
movq %rbp,%rsp /restore stack state
popq %rbp
ret /return
.align 8
.type tas,@function
.size tas,.-tas
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.149 2006/04/19 23:11:15 tgl Exp $ * $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.150 2006/04/27 22:28:42 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -763,23 +763,14 @@ typedef unsigned char slock_t; ...@@ -763,23 +763,14 @@ typedef unsigned char slock_t;
#endif #endif
#if defined(__sparc__) || defined(__sparc) #if defined(__sun) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc))
#define HAS_TEST_AND_SET #define HAS_TEST_AND_SET
typedef unsigned char slock_t; typedef unsigned char slock_t;
#endif
/* out-of-line assembler from src/backend/port/tas/foo.s */
/* i386/X86_64 using Sun compiler */ extern volatile slock_t pg_atomic_cas(volatile slock_t *lock, slock_t with,
#if defined(__sun) && (defined(__i386) || defined(__x86_64__)) slock_t cmp);
/*
* Solaris/386 (we only get here for non-gcc case)
*/
#define HAS_TEST_AND_SET
typedef unsigned char slock_t; #define TAS(a) (pg_atomic_cas((a), 1, 0) != 0)
#endif #endif
......
...@@ -4,29 +4,21 @@ if test "$GCC" != yes ; then ...@@ -4,29 +4,21 @@ if test "$GCC" != yes ; then
if test "$enable_debug" != yes; then if test "$enable_debug" != yes; then
CFLAGS="$CFLAGS -O" # any optimization breaks debug CFLAGS="$CFLAGS -O" # any optimization breaks debug
fi fi
fi else
# Pick the right test-and-set (TAS) code for the Sun compiler.
# Pick right test-and-set (TAS) code. We need out-of-line assembler # We would like to use in-line assembler, but the compiler
# when not using gcc. # requires *.il files to be on every compile line, making
case $host in # the build system too fragile.
case $host in
sparc-*-solaris*) sparc-*-solaris*)
if test "$GCC" != yes ; then
need_tas=yes need_tas=yes
tas_file=solaris_sparc.s tas_file=solaris_sparc.s
fi
;; ;;
i?86-*-solaris*) i?86-*-solaris*)
if test "$GCC" != yes ; then
if isainfo | grep amd64
then
need_tas=yes
tas_file=solaris_x86_64.s
else
need_tas=yes need_tas=yes
tas_file=solaris_i386.s tas_file=solaris_x86.s
fi
fi
;; ;;
esac esac
fi
# -D_POSIX_PTHREAD_SEMANTICS enables 5-arg getpwuid_r, among other things # -D_POSIX_PTHREAD_SEMANTICS enables 5-arg getpwuid_r, among other things
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment