Optimize access to isXYZ and toXYZ tables

The functions to get the pointers can now depend on the TLS variable
be initialized.
This commit is contained in:
Ulrich Drepper 2011-10-15 16:27:08 -04:00
parent 2d1f3a4db6
commit fd5bdc0924
10 changed files with 135 additions and 18 deletions

View File

@ -1,3 +1,13 @@
2011-10-15 Ulrich Drepper <drepper@gmail.com>
* ctype/ctype-info.c (__ctype_init): Define.
* include/ctype.h (__ctype_init): Declare.
(__ctype_b_loc): The variable is always initialized.
(__ctype_toupper_loc): Likewise.
(__ctype_tolower_loc): Likewise.
* ctype/Versions: Export __ctype_init for GLIBC_PRIVATE.
* sysdeps/unix/sysv/linux/init-first.c (_init): Call __ctype_init.
2011-09-27 Liubov Dmitrieva <liubov.dmitrieva@gmail.com> 2011-09-27 Liubov Dmitrieva <liubov.dmitrieva@gmail.com>
* sysdeps/x86_64/multiarch/Makefile: (sysdep_routines): Add * sysdeps/x86_64/multiarch/Makefile: (sysdep_routines): Add

View File

@ -21,4 +21,7 @@ libc {
# functions used by optimized macros in ctype.h # functions used by optimized macros in ctype.h
__ctype_b_loc; __ctype_tolower_loc; __ctype_toupper_loc; __ctype_b_loc; __ctype_tolower_loc; __ctype_toupper_loc;
} }
GLIBC_PRIVATE {
__ctype_init;
}
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991,92,95,96,97,99,2000, 2002, 2008 /* Copyright (C) 1991,92,95,96,97,99,2000, 2002, 2008, 2011
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
@ -26,6 +26,19 @@ __libc_tsd_define (, const int32_t *, CTYPE_TOLOWER)
__libc_tsd_define (, const int32_t *, CTYPE_TOUPPER) __libc_tsd_define (, const int32_t *, CTYPE_TOUPPER)
void
__ctype_init (void)
{
const uint16_t **bp = __libc_tsd_address (const uint16_t *, CTYPE_B);
*bp = (const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128;
const int32_t **up = __libc_tsd_address (const int32_t *, CTYPE_TOUPPER);
*up = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128);
const int32_t **lp = __libc_tsd_address (const int32_t *, CTYPE_TOLOWER);
*lp = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128);
}
libc_hidden_def (__ctype_init)
#include <shlib-compat.h> #include <shlib-compat.h>
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3) #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)

View File

@ -1,5 +1,9 @@
#ifndef _CTYPE_H #ifndef _CTYPE_H
/* Initialize ctype locale data. */
extern void __ctype_init (void);
libc_hidden_proto (__ctype_init)
extern int __isctype (int __c, int __mask); extern int __isctype (int __c, int __mask);
# ifndef NOT_IN_libc # ifndef NOT_IN_libc
@ -22,31 +26,23 @@ __libc_tsd_define (extern, const uint16_t *, CTYPE_B)
__libc_tsd_define (extern, const int32_t *, CTYPE_TOUPPER) __libc_tsd_define (extern, const int32_t *, CTYPE_TOUPPER)
__libc_tsd_define (extern, const int32_t *, CTYPE_TOLOWER) __libc_tsd_define (extern, const int32_t *, CTYPE_TOLOWER)
CTYPE_EXTERN_INLINE const uint16_t ** __attribute__ ((const)) CTYPE_EXTERN_INLINE const uint16_t ** __attribute__ ((const))
__ctype_b_loc (void) __ctype_b_loc (void)
{ {
const uint16_t **tablep = __libc_tsd_address (const uint16_t *, CTYPE_B); return __libc_tsd_address (const uint16_t *, CTYPE_B);
if (__builtin_expect (*tablep == NULL, 0))
*tablep = (const uint16_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_CLASS) + 128;
return tablep;
} }
CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const)) CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
__ctype_toupper_loc (void) __ctype_toupper_loc (void)
{ {
const int32_t **tablep = __libc_tsd_address (const int32_t *, CTYPE_TOUPPER); return __libc_tsd_address (const int32_t *, CTYPE_TOUPPER);
if (__builtin_expect (*tablep == NULL, 0))
*tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOUPPER) + 128);
return tablep;
} }
CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const)) CTYPE_EXTERN_INLINE const int32_t ** __attribute__ ((const))
__ctype_tolower_loc (void) __ctype_tolower_loc (void)
{ {
const int32_t **tablep = __libc_tsd_address (const int32_t *, CTYPE_TOLOWER); return __libc_tsd_address (const int32_t *, CTYPE_TOLOWER);
if (__builtin_expect (*tablep == NULL, 0))
*tablep = ((int32_t *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_TOLOWER) + 128);
return tablep;
} }
# endif /* Not NOT_IN_libc. */ # endif /* Not NOT_IN_libc. */

View File

@ -1,3 +1,10 @@
2011-10-15 Ulrich Drepper <drepper@gmail.com>
* Makefile (tests): Add tst-setlocale2:
(LOCALES): Add tr_TR.ISO-8859-9;
(tst-setlocale2-ENV): Define.
* tst-setlocale2.c: New file.
2011-07-02 Roland McGrath <roland@hack.frob.com> 2011-07-02 Roland McGrath <roland@hack.frob.com>
* tests-mbwc/tst_funcs.h (TST_DECL_VARS, TST_HEAD_LOCALE): * tests-mbwc/tst_funcs.h (TST_DECL_VARS, TST_HEAD_LOCALE):

View File

@ -94,7 +94,7 @@ locale_test_suite := tst_iswalnum tst_iswalpha tst_iswcntrl \
tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \ tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \
tst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \ tst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \
tst-strfmon1 tst-sscanf tst-strptime bug-setlocale1 tst-strfmon1 tst-sscanf tst-strptime bug-setlocale1 tst-setlocale2
ifeq (yes,$(build-shared)) ifeq (yes,$(build-shared))
ifneq (no,$(PERL)) ifneq (no,$(PERL))
tests: $(objpfx)mtrace-tst-leaks tests: $(objpfx)mtrace-tst-leaks
@ -137,7 +137,7 @@ LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ANSI_X3.4-1968 \
hr_HR.ISO-8859-2 sv_SE.ISO-8859-1 ja_JP.SJIS fr_FR.ISO-8859-1 \ hr_HR.ISO-8859-2 sv_SE.ISO-8859-1 ja_JP.SJIS fr_FR.ISO-8859-1 \
vi_VN.TCVN5712-1 nb_NO.ISO-8859-1 nn_NO.ISO-8859-1 \ vi_VN.TCVN5712-1 nb_NO.ISO-8859-1 nn_NO.ISO-8859-1 \
tr_TR.UTF-8 cs_CZ.UTF-8 zh_TW.EUC-TW fa_IR.UTF-8 fr_FR.UTF-8 \ tr_TR.UTF-8 cs_CZ.UTF-8 zh_TW.EUC-TW fa_IR.UTF-8 fr_FR.UTF-8 \
ja_JP.UTF-8 si_LK.UTF-8 ja_JP.UTF-8 si_LK.UTF-8 tr_TR.ISO-8859-9
LOCALE_SRCS := $(shell echo "$(LOCALES)"|sed 's/\([^ .]*\)[^ ]*/\1/g') LOCALE_SRCS := $(shell echo "$(LOCALES)"|sed 's/\([^ .]*\)[^ ]*/\1/g')
CHARMAPS := $(shell echo "$(LOCALES)" | \ CHARMAPS := $(shell echo "$(LOCALES)" | \
sed -e 's/[^ .]*[.]\([^ ]*\)/\1/g' -e s/SJIS/SHIFT_JIS/g) sed -e 's/[^ .]*[.]\([^ ]*\)/\1/g' -e s/SJIS/SHIFT_JIS/g)
@ -303,6 +303,7 @@ $(objpfx)mtrace-tst-leaks: $(objpfx)tst-leaks.out
bug-setlocale1-ENV = LOCPATH=$(common-objpfx)localedata bug-setlocale1-ENV = LOCPATH=$(common-objpfx)localedata
bug-setlocale1-ARGS = $(common-objpfx) bug-setlocale1-ARGS = $(common-objpfx)
tst-setlocale2-ENV = LOCPATH=$(common-objpfx)localedata
$(objdir)/iconvdata/gconv-modules: $(objdir)/iconvdata/gconv-modules:
$(MAKE) -C ../iconvdata subdir=iconvdata $@ $(MAKE) -C ../iconvdata subdir=iconvdata $@

View File

@ -0,0 +1,76 @@
#include <ctype.h>
#include <locale.h>
#include <stdio.h>
#include <wctype.h>
static int
do_test (void)
{
const char *loc = "de_DE.ISO-8859-1";
if (setlocale (LC_ALL, loc) == NULL)
{
printf ("cannot set %s locale\n", loc);
return 1;
}
printf ("selected locale %s\n", loc);
wint_t win = 0xe4;
wint_t wex = 0xc4;
wint_t wch = towupper (win);
if (wch != wex)
{
printf ("towupper(%x) = %x, expected %x\n", win, wch, wex);
return 1;
}
wch = toupper (win);
if (wch != wex)
{
printf ("toupper(%x) = %x, expected %x\n", win, wch, wex);
return 1;
}
win = 0x69;
wex = 0x49;
wch = towupper (win);
if (wch != wex)
{
printf ("towupper(%x) = %x, expected %x\n", win, wch, wex);
return 1;
}
wch = toupper (win);
if (wch != wex)
{
printf ("toupper(%x) = %x, expected %x\n", win, wch, wex);
return 1;
}
loc = "tr_TR.ISO-8859-9";
if (setlocale (LC_ALL, loc) == NULL)
{
printf ("cannot set %s locale\n", loc);
return 1;
}
printf ("selected locale %s\n", loc);
win = 0x69;
wex = 0x130;
wch = towupper (win);
if (wch != wex)
{
printf ("towupper(%x) = %x, expected %x\n", win, wch, wex);
return 1;
}
wch = toupper (win);
wex = 0xdd;
if (wch != wex)
{
printf ("toupper(%x) = %x, expected %x\n", win, wch, wex);
return 1;
}
return 0;
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

View File

@ -1,3 +1,7 @@
2011-10-15 Ulrich Drepper <drepper@gmail.com>
* pthread_create.c (start_thread): Ca;; __ctype_init.
2011-09-15 Andreas Schwab <schwab@redhat.com> 2011-09-15 Andreas Schwab <schwab@redhat.com>
* sysdeps/pthread/list.h: Define only list_t if __need_list_t is * sysdeps/pthread/list.h: Define only list_t if __need_list_t is

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2002-2007,2008,2009,2010 Free Software Foundation, Inc. /* Copyright (C) 2002-2007,2008,2009,2010,2011 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */ 02111-1307 USA. */
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
@ -239,6 +240,9 @@ start_thread (void *arg)
/* Initialize resolver state pointer. */ /* Initialize resolver state pointer. */
__resp = &pd->res; __resp = &pd->res;
/* Initialize pointers to locale data. */
__ctype_init ();
/* Allow setxid from now onwards. */ /* Allow setxid from now onwards. */
if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0) == -2, 0)) if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0) == -2, 0))
lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE); lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE);

View File

@ -1,5 +1,5 @@
/* Initialization code run first thing by the ELF startup code. Linux version. /* Initialization code run first thing by the ELF startup code. Linux version.
Copyright (C) 1995-2004, 2005, 2007 Free Software Foundation, Inc. Copyright (C) 1995-2004, 2005, 2007, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */ 02111-1307 USA. */
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
@ -93,12 +94,14 @@ _init (int argc, char **argv, char **envp)
__getopt_clean_environment (envp); __getopt_clean_environment (envp);
#endif #endif
/* Initialize ctype data. */
__ctype_init ();
#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS #if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
__libc_global_ctors (); __libc_global_ctors ();
#endif #endif
} }
/* This function is defined here so that if this file ever gets into /* This function is defined here so that if this file ever gets into
ld.so we will get a link error. Having this file silently included ld.so we will get a link error. Having this file silently included
in ld.so causes disaster, because the _init definition above will in ld.so causes disaster, because the _init definition above will