2 * charybdis: a slightly useful ircd.
3 * fnvhash.s: x86-optimised FNV hashing implementation
5 * Copyright (c) 2006 charybdis development team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * $Id: fnvhash.s 26 2006-09-20 18:02:06Z spb $
25 /* Safely moves hashv from %edx to %eax and returns back to the calling parent. */
42 * Capitalizes the contents of %eax and adds it to the hashv in %edx.
43 * Returns hashv in register %eax.
47 .type fnv_hash_upper, @function
52 movl $
-2128831035, -4(%ebp
) /* u_int32_t h = FNV1_32_INIT */
53 .eat_data_upper: /* while loop construct */
54 movl
8(%ebp
), %eax
/* move value of *s to %eax */
55 cmpb $
0, (%eax
) /* is eax == 0? */
56 jne
.hash_capitalized /* if no, then capitalize and hash */
57 jmp fnv_out
/* if yes, then exit out of the loop */
60 movzbl
(%eax
), %eax
/* increment s (%eax) */
61 movzbl ToUpperTab
(%eax
), %edx
/* hashv ^= ToUpperTab(%eax) */
63 xorl
%edx
, (%eax
) /* hashv = 0 */
66 imull $
16777619, %eax
, %eax
/* FNV1_32_PRIME */
67 movl
%eax
, -4(%ebp
) /* add this byte to hashv, and */
68 jmp
.eat_data_upper /* go back for more... */
71 * Hashes (no case change) the contents of %eax and adds it to the hashv in %edx.
72 * Returns hashv in register %eax.
76 .type fnv_hash, @function
81 movl $
-2128831035, -4(%ebp
) /* u_int32_t h = FNV1_32_INIT */
82 .eat_data: /* again, the while loop construct */
83 movl
8(%ebp
), %eax
/* move value of *s to eax */
84 cmpb $
0, (%eax
) /* is eax == 0? */
85 jne
.hash_lowercase /* if not, jump to .hash_lowercase */
86 jmp fnv_out
/* otherwise, jump to fnv_out */
92 incl
8(%ebp
) /* h << 1 */
94 imull $
16777619, %eax
, %eax
/* FNV1_32_PRIME */
95 movl
%eax
, -4(%ebp
) /* add this byte to hashv, then */
96 jmp
.eat_data /* check for more... */
99 * Hashes (no case change) the contents of %eax and adds it to the hashv in %edx.
100 * Returns hashv in register %eax.
102 * Bounds checking is performed.
106 .type fnv_hash_len, @function
111 movl $
-2128831035, -4(%ebp
)
121 jb
.hash_lowercase_len
130 imull $
16777619, %eax
, %eax
/* FNV1_32_PRIME */
135 * Hashes (no case change) the contents of %eax and adds it to the hashv in %edx.
136 * Returns hashv in register %eax.
138 * Bounds checking is performed.
141 .globl fnv_hash_upper_len
142 .type fnv_hash_upper_len, @function
147 movl $
-2128831035, -4(%ebp
)
157 jb
.hash_uppercase_len
162 movzbl ToUpperTab
(%eax
), %edx
167 imull $
16777619, %eax
, %eax
/* FNV1_32_PRIME */