2 * charybdis: a slightly useful ircd.
3 * fnvhash.s: x86-optimised FNV hashing implementation
5 * Copyright (c) 2006 charybdis development team
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * $Id: fnvhash.s 2725 2006-11-09 23:43:35Z jilles $
36 /* Safely moves hashv from %edx to %eax and returns back to the calling parent. */
53 * Capitalizes the contents of %eax and adds it to the hashv in %edx.
54 * Returns hashv in register %eax.
58 .type fnv_hash_upper, @function
63 movl $-2128831035, -4(%ebp) /* u_int32_t h = FNV1_32_INIT */
64 .eat_data_upper: /* while loop construct */
65 movl 8(%ebp), %eax /* move value of *s to %eax */
66 cmpb $0, (%eax) /* is eax == 0? */
67 jne .hash_capitalized /* if no, then capitalize and hash */
68 jmp fnv_out /* if yes, then exit out of the loop */
71 movzbl (%eax), %eax /* increment s (%eax) */
72 movzbl ToUpperTab(%eax), %edx /* hashv ^= ToUpperTab(%eax) */
74 xorl %edx, (%eax) /* hashv = 0 */
77 imull $16777619, %eax, %eax /* FNV1_32_PRIME */
78 movl %eax, -4(%ebp) /* add this byte to hashv, and */
79 jmp .eat_data_upper /* go back for more... */
82 * Hashes (no case change) the contents of %eax and adds it to the hashv in %edx.
83 * Returns hashv in register %eax.
87 .type fnv_hash, @function
92 movl $-2128831035, -4(%ebp) /* u_int32_t h = FNV1_32_INIT */
93 .eat_data: /* again, the while loop construct */
94 movl 8(%ebp), %eax /* move value of *s to eax */
95 cmpb $0, (%eax) /* is eax == 0? */
96 jne .hash_lowercase /* if not, jump to .hash_lowercase */
97 jmp fnv_out /* otherwise, jump to fnv_out */
103 incl 8(%ebp) /* h << 1 */
105 imull $16777619, %eax, %eax /* FNV1_32_PRIME */
106 movl %eax, -4(%ebp) /* add this byte to hashv, then */
107 jmp .eat_data /* check for more... */
110 * Hashes (no case change) the contents of %eax and adds it to the hashv in %edx.
111 * Returns hashv in register %eax.
113 * Bounds checking is performed.
117 .type fnv_hash_len, @function
122 movl $-2128831035, -4(%ebp)
132 jb .hash_lowercase_len
141 imull $16777619, %eax, %eax /* FNV1_32_PRIME */
146 * Hashes (no case change) the contents of %eax and adds it to the hashv in %edx.
147 * Returns hashv in register %eax.
149 * Bounds checking is performed.
152 .globl fnv_hash_upper_len
153 .type fnv_hash_upper_len, @function
158 movl $-2128831035, -4(%ebp)
168 jb .hash_uppercase_len
173 movzbl ToUpperTab(%eax), %edx
178 imull $16777619, %eax, %eax /* FNV1_32_PRIME */