Back to index

glibc  2.9
dl-hash.h
Go to the documentation of this file.
00001 /* Compute hash alue for given string according to ELF standard.
00002    Copyright (C) 1998, 2003, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _DL_HASH_H
00022 #define _DL_HASH_H   1
00023 
00024 
00025 /* This is the hashing function specified by the ELF ABI.  It is highly
00026    optimized for the PII processors.  Though it will run on i586 it
00027    would be much slower than the generic C implementation.  So don't
00028    use it.  */
00029 static unsigned int
00030 _dl_elf_hash (const char *name)
00031 {
00032   unsigned int result;
00033   unsigned int temp0;
00034   unsigned int temp1;
00035 
00036   __asm__ __volatile__
00037     ("movzbl (%1),%2\n\t"
00038      "testl %2, %2\n\t"
00039      "jz 1f\n\t"
00040      "movl %2, %0\n\t"
00041      "movzbl 1(%1), %2\n\t"
00042      "jecxz 1f\n\t"
00043      "shll $4, %0\n\t"
00044      "addl %2, %0\n\t"
00045      "movzbl 2(%1), %2\n\t"
00046      "jecxz 1f\n\t"
00047      "shll $4, %0\n\t"
00048      "addl %2, %0\n\t"
00049      "movzbl 3(%1), %2\n\t"
00050      "jecxz 1f\n\t"
00051      "shll $4, %0\n\t"
00052      "addl %2, %0\n\t"
00053      "movzbl 4(%1), %2\n\t"
00054      "jecxz 1f\n\t"
00055      "shll $4, %0\n\t"
00056      "addl $5, %1\n\t"
00057      "addl %2, %0\n\t"
00058      "movzbl (%1), %2\n\t"
00059      "jecxz 1f\n"
00060      "2:\t"
00061      "shll $4, %0\n\t"
00062      "movl $0xf0000000, %3\n\t"
00063      "incl %1\n\t"
00064      "addl %2, %0\n\t"
00065      "andl %0, %3\n\t"
00066      "andl $0x0fffffff, %0\n\t"
00067      "shrl $24, %3\n\t"
00068      "movzbl (%1), %2\n\t"
00069      "xorl %3, %0\n\t"
00070      "testl %2, %2\n\t"
00071      "jnz 2b\n"
00072      "1:\t"
00073      : "=&r" (result), "=r" (name), "=&c" (temp0), "=&r" (temp1)
00074      : "0" (0), "1" ((const unsigned char *) name));
00075 
00076   return result;
00077 }
00078 
00079 #endif /* dl-hash.h */