This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


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

[RFC] improve tls access for tolower table and errno


Hi, as I mentioned before that inline strcasecmp would be problematic as
it needs to get call to tolower which is suboptimal.

On architectures with tls register you don't need to do call call for tls 
access but start small. 

For x64 and other architectures as these variables are statically
allocated would could just save offset at register. Linker would at
initialization fill it with correct value and applications would just
need to access a normal variable.

A sample implementation would be following, where should I add
initializer and is there other way to get %fs than assembly?

#include <errno.h>
#include <stdio.h>

static long __errno_offset;
__attribute__((constructor))
void  get_offset ()
{
  char *offset;
  char *location = &errno;
 __asm__ ("mov %%fs:0, %0" : "=r" (offset));

  __errno_offset = location - offset;
}

static __always_inline 
int *
__ep()
{
  char *__offset;
  __asm__ ("mov %%fs:0, %0" : "=r" (__offset));

  return (int *)(__offset + __errno_offset);
}

#define errno2 (*__ep())


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