This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Save a few bytes in assembly for TLS accesses in assembly


Hi!

movl %edx, %gs:0(%ecx)
is one byte longer than
movl %edx, %gs(%ecx)
while it does the same thing.  This is the first hunk (should save 151 bytes
in libc.so and 19 bytes in libpthread.so).
The other change is that sem_*.S seems to be really old and using the
GOTTPOFF reloc rather than GOTNTPOFF and of course no direct segment access.
This patch uses direct %gs access unless NO_TLS_DIRECT_SEG_REFS.

2005-01-26  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/i386/sysdep.h
	(SYSCALL_ERROR_HANDLER_TLS_STORE): Remove unnecessary 0 imm.
nptl/
	* sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S (__new_sem_trywait):
	Use direct %gs segment access or, if NO_TLS_DIRECT_SEG_REFS,
	at least gotntpoff relocation and addition.
	* sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S (sem_timedwait):
	Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/sem_post.S (__new_sem_post):
	Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/sem_wait.S (__new_sem_wait):
	Likewise.

--- libc/sysdeps/unix/sysv/linux/i386/sysdep.h.jj	2005-01-26 11:53:41.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/sysdep.h	2005-01-26 19:04:55.326699068 +0100
@@ -159,7 +159,7 @@ __i686.get_pc_thunk.reg:						      \
   jmp L(pseudo_end);
 #   ifndef NO_TLS_DIRECT_SEG_REFS
 #    define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff)		      \
-  movl src, %gs:0(destoff)
+  movl src, %gs:(destoff)
 #   else
 #    define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff)		      \
   addl %gs:0, destoff;							      \
--- libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S.jj	2003-05-10 22:38:06.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S	2005-01-26 19:21:57.837106985 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -55,9 +55,14 @@ __new_sem_trywait:
 #endif
 	addl	$_GLOBAL_OFFSET_TABLE_, %ecx
 #if USE___THREAD
-	movl	%gs:0, %edx
-	subl	errno@gottpoff(%ecx), %edx
+# ifdef NO_TLS_DIRECT_SEG_REFS
+	movl	errno@gotntpoff(%ecx), %edx
+	addl	%gs:0, %edx
 	movl	$EAGAIN, (%edx)
+# else
+	movl	errno@gotntpoff(%ecx), %edx
+	movl	$EAGAIN, %gs:(%edx)
+# endif
 #else
 	call	__errno_location@plt
 	movl	$EAGAIN, (%eax)
--- libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S.jj	2004-05-18 10:52:25.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S	2005-01-26 19:21:21.495604255 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -158,9 +158,14 @@ sem_timedwait:
 #endif
 	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
 #if USE___THREAD
-	movl	%gs:0, %edx
-	subl	errno@gottpoff(%ebx), %edx
+# ifdef NO_TLS_DIRECT_SEG_REFS
+	movl	errno@gotntpoff(%ebx), %edx
+	addl	%gs:0, %edx
 	movl	%esi, (%edx)
+# else
+	movl	errno@gotntpoff(%ebx), %edx
+	movl	%esi, %gs:(%edx)
+# endif
 #else
 	call	__errno_location@plt
 	movl	%esi, (%eax)
--- libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_post.S.jj	2003-03-13 02:06:30.000000000 +0100
+++ libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_post.S	2005-01-26 19:15:07.198438482 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -65,9 +65,14 @@ __new_sem_post:
 #endif
 	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
 #if USE___THREAD
-	movl	%gs:0, %edx
-	subl	errno@gottpoff(%ebx), %edx
+# ifdef NO_TLS_DIRECT_SEG_REFS
+	movl	errno@gotntpoff(%ebx), %edx
+	addl	%gs:0, %edx
 	movl	$EINVAL, (%edx)
+# else
+	movl	errno@gotntpoff(%ebx), %edx
+	movl	$EINVAL, %gs:(%edx)
+# endif
 #else
 	call	__errno_location@plt
 	movl	$EINVAL, (%eax)
--- libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_wait.S.jj	2003-07-08 23:06:32.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_wait.S	2005-01-26 19:20:31.927468385 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -102,9 +102,14 @@ __new_sem_wait:
 #endif
 	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
 #if USE___THREAD
-	movl	%gs:0, %edx
-	subl	errno@gottpoff(%ebx), %edx
+# ifdef NO_TLS_DIRECT_SEG_REFS
+	movl	errno@gotntpoff(%ebx), %edx
+	addl	%gs:0, %edx
 	movl	%esi, (%edx)
+# else
+	movl	errno@gotntpoff(%ebx), %edx
+	movl	%esi, %gs:(%edx)
+# endif
 #else
 	call	__errno_location@plt
 	movl	%esi, (%eax)

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]