summaryrefslogtreecommitdiff
path: root/libpthread/linuxthreads/sysdeps/i386/pt-machine.h
diff options
context:
space:
mode:
Diffstat (limited to 'libpthread/linuxthreads/sysdeps/i386/pt-machine.h')
-rw-r--r--libpthread/linuxthreads/sysdeps/i386/pt-machine.h93
1 files changed, 61 insertions, 32 deletions
diff --git a/libpthread/linuxthreads/sysdeps/i386/pt-machine.h b/libpthread/linuxthreads/sysdeps/i386/pt-machine.h
index 82a5cf077..24c5e6c7c 100644
--- a/libpthread/linuxthreads/sysdeps/i386/pt-machine.h
+++ b/libpthread/linuxthreads/sysdeps/i386/pt-machine.h
@@ -18,17 +18,14 @@
License along with the GNU C Library; see the file COPYING.LIB. If
not, see <http://www.gnu.org/licenses/>. */
-#if defined __pentiumpro__ || defined __pentium4__ || defined __athlon__ || \
- defined __k8__
-# include "i686/pt-machine.h"
-#else
-
#ifndef _PT_MACHINE_H
#define _PT_MACHINE_H 1
+#include <features.h>
+
#ifndef __ASSEMBLER__
#ifndef PT_EI
-# define PT_EI __extern_always_inline
+# define PT_EI __extern_always_inline __attribute__((visibility("hidden")))
#endif
extern long int testandset (int *spinlock);
@@ -39,6 +36,54 @@ extern int __compare_and_swap (long int *p, long int oldval, long int newval);
#define CURRENT_STACK_FRAME __builtin_frame_address (0)
+/* See if we can optimize for newer cpus... */
+#if defined __GNUC__ && __GNUC__ >= 2 && \
+ (defined __i486__ || defined __pentium__ || defined __pentiumpro__ || defined __pentium4__ || \
+ defined __athlon__ || defined __k8__)
+
+/* Spinlock implementation; required. */
+PT_EI long int
+testandset (int *spinlock)
+{
+ long int ret;
+
+ __asm__ __volatile__ (
+ "xchgl %0, %1"
+ : "=r" (ret), "=m" (*spinlock)
+ : "0" (1), "m" (*spinlock)
+ : "memory");
+
+ return ret;
+}
+
+/* Compare-and-swap for semaphores. It's always available on i686. */
+#define HAS_COMPARE_AND_SWAP
+
+PT_EI int
+__compare_and_swap (long int *p, long int oldval, long int newval)
+{
+ char ret;
+ long int readval;
+
+ __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
+ : "=q" (ret), "=m" (*p), "=a" (readval)
+ : "r" (newval), "m" (*p), "a" (oldval)
+ : "memory");
+ return ret;
+}
+
+#if defined(__ASSUME_LDT_WORKS) && __ASSUME_LDT_WORKS > 0
+#include "useldt.h"
+#endif
+
+/* The P4 and above really want some help to prevent overheating. */
+#define BUSY_WAIT_NOP __asm__ ("rep; nop")
+
+
+#else /* Generic i386 implementation */
+
+extern int compare_and_swap_is_available (void);
+
/* Spinlock implementation; required. */
PT_EI long int
testandset (int *spinlock)
@@ -75,43 +120,27 @@ __compare_and_swap (long int *p, long int oldval, long int newval)
return ret;
}
-
-PT_EI int get_eflags (void);
-PT_EI int
-get_eflags (void)
-{
- int res;
- __asm__ __volatile__ ("pushfl; popl %0" : "=r" (res) : );
- return res;
-}
-
-
-PT_EI void set_eflags (int newflags);
-PT_EI void
-set_eflags (int newflags)
-{
- __asm__ __volatile__ ("pushl %0; popfl" : : "r" (newflags) : "cc");
-}
-
-
-PT_EI int compare_and_swap_is_available (void);
PT_EI int
compare_and_swap_is_available (void)
{
- int oldflags = get_eflags ();
int changed;
+ int oldflags;
+ /* get EFLAGS */
+ __asm__ __volatile__ ("pushfl; popl %0" : "=r" (oldflags) : );
/* Flip AC bit in EFLAGS. */
- set_eflags (oldflags ^ 0x40000);
+ __asm__ __volatile__ ("pushl %0; popfl" : : "r" (oldflags ^ 0x40000) : "cc");
+ /* reread EFLAGS */
+ __asm__ __volatile__ ("pushfl; popl %0" : "=r" (changed) : );
/* See if bit changed. */
- changed = (get_eflags () ^ oldflags) & 0x40000;
+ changed = (changed ^ oldflags) & 0x40000;
/* Restore EFLAGS. */
- set_eflags (oldflags);
+ __asm__ __volatile__ ("pushl %0; popfl" : : "r" (oldflags) : "cc");
/* If the AC flag did not change, it's a 386 and it lacks cmpxchg.
Otherwise, it's a 486 or above and it has cmpxchg. */
return changed != 0;
}
+#endif /* Generic i386 implementation */
+
#endif /* __ASSEMBLER__ */
#endif /* pt-machine.h */
-
-#endif