summaryrefslogtreecommitdiff
path: root/libpthread/linuxthreads/sysdeps/i386/pt-machine.h
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@uclibc-ng.org>2016-05-18 18:41:24 +0200
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2016-05-18 18:41:24 +0200
commit6a8ccc95528f5e86a8770ed15ce89609b5b3dee9 (patch)
treebbd4df35b4d4a6a8b00d7a5e61fb2668b850ad62 /libpthread/linuxthreads/sysdeps/i386/pt-machine.h
parent398a27a5b323956344b4f831d892fed3bd9813c7 (diff)
remove linuxthreads.new, rename linuxthreads.old
Linuxthreads.new isn't really useful with the existence of NPTL/TLS for well supported architectures. There is no reason to use LT.new for ARM/MIPS or other architectures supporting NPTL/TLS. It is not available for noMMU architectures like Blackfin or FR-V. To simplify the live of the few uClibc-ng developers, LT.new is removed and LT.old is renamed to LT. LINUXTHREADS_OLD -> UCLIBC_HAS_LINUXTHREADS
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