l0, meta, l1: added "+0" and "-0" conditionals; updated prebuilt binary
[urforth.git] / level0 / urforth0_w_cstr_hash.asm
blob38cdb55d3ece7ae60767b94816a0de0d2d356a78
1 ;; Native x86 GNU/Linux Forth System, Direct Threaded Code
2 ;;
3 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
4 ;;
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, version 3 of the License ONLY.
8 ;;
9 ;; This program is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 urword_code "(STR-NAME-HASH-CODEBLOCK)",str_name_hash_codeblock
20 urword_hidden
21 urword_codeblock
22 ;; IN:
23 ;; EDI: address
24 ;; ECX: count
25 ;; OUT:
26 ;; EAX: u32hash
27 ;; EDI,ECX,flags: destroyed
28 str_name_hash_edi_ecx:
29 xor eax,eax
30 jecxz .done
31 .hashloop:
32 ;; hash <<= 4
33 shl eax,4
34 ;; hash += *key
35 movzx edx,byte [edi]
36 ;; upcase it (this also distorts other chars, but who cares)
37 and dl,0xdf
38 add eax,edx
39 ;; high = hash&0xF0000000
40 ld edx,eax
41 and edx,0xf0000000
42 ld ebx,edx
43 ;; hash ^= high>>24
44 rol edx,8
45 xor eax,edx
46 ;; hash &= ~high
47 xor ebx,0xffffffff
48 and eax,ebx
49 inc edi
50 loop .hashloop
51 .done:
52 ret
54 if WLIST_HASH_BITS
55 ;; IN:
56 ;; EAX: u32hash
57 ;; OUT:
58 ;; EAX: u8hash-masked
59 ;; flags: destroyed
60 str_name_hash_fold_mask_eax:
61 push ecx
62 ;; fold u32->u16
63 ld ecx,eax
64 shr eax,16
65 add ax,cx
66 ;; fold u16->u8
67 add al,ah
68 ;; mask
69 if WLIST_HASH_MASK <> 255
70 and al,WLIST_HASH_MASK
71 end if
72 movzx eax,al
73 pop ecx
74 ret
75 end if
76 urword_end
79 ;; this is used to calculate word name hashes
80 urword_code "STR-NAME-HASH",str_name_hash
81 urword_uses str_name_hash_codeblock
82 ;; ( addr count -- u32hash )
83 pop edi
84 call str_name_hash_edi_ecx
85 ld TOS,eax
86 urnext
87 urword_end
89 if WLIST_HASH_BITS
90 ;; this is used to calculate word name hashes
91 urword_code "STR-NAME-HASH-FOLDED-MASKED",str_name_hash_folded_masked
92 urword_uses str_name_hash_codeblock
93 ;; ( addr count -- maskedhash )
94 pop edi
95 call str_name_hash_edi_ecx
96 call str_name_hash_fold_mask_eax
97 ld TOS,eax
98 urnext
99 urword_end
101 ;; this is used to calculate word name hashes
102 urword_code "NAME-HASH-FOLD-MASK",name_hash_fold_mask
103 urword_uses str_name_hash_codeblock
104 ;; ( u32hash -- maskedhash )
105 ld eax,TOS
106 call str_name_hash_fold_mask_eax
107 ld TOS,eax
108 urnext
109 urword_end
110 end if
113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 ;; fold 32-bit hash to 16-bit hash
115 urword_code "UHASH32->16",fold_hash_u32_to_u16
116 ;; ( u32hash -- u16hash )
117 ld eax,TOS
118 shr eax,16
119 add ecx,eax
120 movzx TOS,cx
121 urnext
122 urword_end
124 urword_code "UHASH16->8",fold_hash_u16_to_u8
125 ;; ( u16hash -- u8hash )
126 add cl,ch
127 movzx TOS,cl
128 urnext
129 urword_end
131 urword_code "UHASH32->8",fold_hash_u32_to_u8
132 ;; ( u16hash -- u8hash )
133 ld eax,TOS
134 shr eax,16
135 add ecx,eax
136 add cl,ch
137 movzx TOS,cl
138 urnext
139 urword_end