From 128bed948fb17b3c0bf47ecc0274c7701a5cf18a Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 27 Apr 2006 22:28:42 +0000 Subject: [PATCH] Rewrite Solaris compiler tas() assembly routines, merge i386 and x86_64 assembler files, renamed as solaris_x86.s. Theo Schlossnagle --- src/backend/port/tas/solaris_i386.s | 33 ----------------- src/backend/port/tas/solaris_sparc.s | 70 ++++++++++------------------------- src/backend/port/tas/solaris_x86.s | 32 ++++++++++++++++ src/backend/port/tas/solaris_x86_64.s | 38 ------------------- src/include/storage/s_lock.h | 19 +++------- src/template/solaris | 36 +++++++----------- 6 files changed, 71 insertions(+), 157 deletions(-) delete mode 100644 src/backend/port/tas/solaris_i386.s create mode 100644 src/backend/port/tas/solaris_x86.s delete mode 100644 src/backend/port/tas/solaris_x86_64.s diff --git a/src/backend/port/tas/solaris_i386.s b/src/backend/port/tas/solaris_i386.s deleted file mode 100644 index c63aebef32..0000000000 --- a/src/backend/port/tas/solaris_i386.s +++ /dev/null @@ -1,33 +0,0 @@ -/============================================================================= -/ 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 - diff --git a/src/backend/port/tas/solaris_sparc.s b/src/backend/port/tas/solaris_sparc.s index c327848d8e..f2ef5de78d 100644 --- a/src/backend/port/tas/solaris_sparc.s +++ b/src/backend/port/tas/solaris_sparc.s @@ -1,50 +1,20 @@ - !! - !! $PostgreSQL: pgsql/src/backend/port/tas/solaris_sparc.s,v 1.2 2003/11/29 19:51:54 pgsql Exp $ - !! - !! 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 - - !! - !! write 0xFF into the lock address, saving the old value in %o0. - !! this is an atomic action, even on multiprocessors. - !! - ldstub [%o0],%o0 - - !! - !! if it was already set when we set it, somebody else already - !! owned the lock -- return 1. - !! - cmp %o0,0 - bne .LL2 - mov 1,%o0 - - !! - !! otherwise, it was clear and we now own the lock -- return 0. - !! - mov 0,%o0 -.LL2: - !! - !! this is a leaf procedure - no need to restore windows and - !! diddle the CWP. - !! - retl - nop -.LLfe1: - .size tas,.LLfe1-tas - .ident "GCC: (GNU) 2.5.8" +/======================================================================= +/ solaris_sparc.s -- compare and swap for solaris_sparc +/======================================================================= + +#if defined(__sparcv9) || defined(__sparc) + + .section ".text" + .align 8 + .skip 24 + .align 4 + + .global pg_atomic_cas +pg_atomic_cas: + cas [%o0],%o2,%o1 + mov %o1,%o0 + retl + nop + .type pg_atomic_cas,2 + .size pg_atomic_cas,(.-pg_atomic_cas) +#endif diff --git a/src/backend/port/tas/solaris_x86.s b/src/backend/port/tas/solaris_x86.s new file mode 100644 index 0000000000..32abb2e6ad --- /dev/null +++ b/src/backend/port/tas/solaris_x86.s @@ -0,0 +1,32 @@ +/======================================================================= +/ 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 diff --git a/src/backend/port/tas/solaris_x86_64.s b/src/backend/port/tas/solaris_x86_64.s deleted file mode 100644 index ee74fe61fc..0000000000 --- a/src/backend/port/tas/solaris_x86_64.s +++ /dev/null @@ -1,38 +0,0 @@ -/============================================================================= -/ 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 - diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index 6305016f25..1ce8886c74 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -66,7 +66,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * 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; #endif -#if defined(__sparc__) || defined(__sparc) +#if defined(__sun) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc)) #define HAS_TEST_AND_SET - typedef unsigned char slock_t; -#endif - - -/* out-of-line assembler from src/backend/port/tas/foo.s */ -/* i386/X86_64 using Sun compiler */ -#if defined(__sun) && (defined(__i386) || defined(__x86_64__)) -/* - * Solaris/386 (we only get here for non-gcc case) - */ -#define HAS_TEST_AND_SET +extern volatile slock_t pg_atomic_cas(volatile slock_t *lock, slock_t with, + slock_t cmp); -typedef unsigned char slock_t; +#define TAS(a) (pg_atomic_cas((a), 1, 0) != 0) #endif diff --git a/src/template/solaris b/src/template/solaris index 2efe24949b..c8b522cc4a 100644 --- a/src/template/solaris +++ b/src/template/solaris @@ -4,29 +4,21 @@ if test "$GCC" != yes ; then if test "$enable_debug" != yes; then CFLAGS="$CFLAGS -O" # any optimization breaks debug fi -fi - -# Pick right test-and-set (TAS) code. We need out-of-line assembler -# when not using gcc. -case $host in - sparc-*-solaris*) - if test "$GCC" != yes ; then - need_tas=yes - tas_file=solaris_sparc.s - fi +else + # Pick the right test-and-set (TAS) code for the Sun compiler. + # We would like to use in-line assembler, but the compiler + # requires *.il files to be on every compile line, making + # the build system too fragile. + case $host in + sparc-*-solaris*) + need_tas=yes + tas_file=solaris_sparc.s ;; - 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 - tas_file=solaris_i386.s - fi - fi + i?86-*-solaris*) + need_tas=yes + tas_file=solaris_x86.s ;; -esac + esac +fi # -D_POSIX_PTHREAD_SEMANTICS enables 5-arg getpwuid_r, among other things -- 2.11.0