flat assembler
Message board for the users of flat assembler.
Index
> Main > How rewrite this code to 32 bits ? |
Author |
|
revolution 29 Oct 2024, 20:32
The FNV hashes also have parameters for 32-bit.
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function?useskin=vector#FNV_hash_parameters |
|||
29 Oct 2024, 20:32 |
|
macomics 29 Oct 2024, 22:52
Check if I got it wrong with multiplying 64-bits by 64-bits. I typed in browser and did not check functionality.
Code: Hash: label .result.low dword at esp + 0 label .result.high dword at esp + 4 label .lpszText dword at esp + 24 label .cchText dword at esp + 28 push ebx push esi push edi push [.hash.high] push [.hash.low] mov ebx, [.mult.low] mov edi, [.mult.high] mov esi, [.lpszText] mov ecx, [.cchText] .loop: mov eax, [.result.high] mul edi xchg eax, [.result.high] mul ebx add edx, [.result.high] xchg eax, [.result.low] push eax mul edi mov edx, eax pop eax add [.result.low], edx mul ebx add [.result.low], eax adc [.result.high], edx xor al, byte [esi] inc esi loop .loop pop eax ; mov eax, [.result.low] pop edx ; mov edx, [.result.high] ; add esp, 8 pop edi pop esi pop ebx retn 8 label .hash.low dword label .hash.high dword at .hash.low + 4 .hash dq 14695981039346656037 label .mult.low dword label .mult.high dword at .mult.low + 4 .mult dq 0100000001B3h |
|||
29 Oct 2024, 22:52 |
|
Roman 31 Oct 2024, 11:26
How about PMULLQ ?
Multiply the packed qword signed integers in xmm2 and xmm3/m128/m64bcst and store the low 64 bits of each product in xmm1 under writemask k1. |
|||
31 Oct 2024, 11:26 |
|
macomics 31 Oct 2024, 11:48
Quote: How about VPMULLQ ? For a 64-bit program, this check may not be performed because most processors capable of operating in 64-bit mode can work with SSE4.1/AVX512DQ Last edited by macomics on 31 Oct 2024, 11:57; edited 2 times in total |
|||
31 Oct 2024, 11:48 |
|
revolution 31 Oct 2024, 11:51
macomics wrote: For a 64-bit program, this check may not be performed because most processors capable of operating in 64-bit mode can work with SSE4.1 |
|||
31 Oct 2024, 11:51 |
|
macomics 31 Oct 2024, 11:56
revolution wrote: My 64-bit CPU doesn't have SSE4. |
|||
31 Oct 2024, 11:56 |
|
Roman 31 Oct 2024, 12:21
Quote:
Buy AMD or Intel 285K(for study of avx 10.2) |
|||
31 Oct 2024, 12:21 |
|
Roman 31 Oct 2024, 12:57
How about this ?
Code: MUL64_MEMORY: mov eax, [val1high] mov esi, [val1low] mov ecx, [val2high] mov ebx, [val2low] mul ebx xchg eax, ebx ; partial product top 32 bits mul esi xchg esi, eax ; partial product lower 32 bits add ebx, edx mul ecx add ebx, eax ; final upper 32 bits ; answer here in EBX:ESI |
|||
31 Oct 2024, 12:57 |
|
macomics 31 Oct 2024, 16:34
If we try to reduce the number of memory accesses, then so. In your version, you forgot to write a record of result to memory so that you can work with it in the next loop. And this, as in my version, is still 6 (7) accesses per loop.
Code: Hash: label .lpszText dword at esp + 20 label .cchText dword at esp + 24 push ebp push ebx push esi push edi mov ebx, [.hash.low] mov ebp, [.hash.high] mov esi, [.lpszText] mov ecx, [.cchText] .loop: mov eax, ebp mul [.mult.high] xchg eax, ebp mul [.mult.low] add ebp, edx xchg eax, ebx mov edi, eax mul [.mult.high] add ebx, eax mov eax, ebp mul [.mult.low] add ebx, eax adc ebp, edx lods byte [esi] xor bl, al loop .loop mov eax, ebx mov edx, ebp pop edi pop esi pop ebx pop ebp retn 8 align 16 label .hash.low dword label .hash.high dword at .hash.low + 4 .hash dq 14695981039346656037 label .mult.low dword label .mult.high dword at .mult.low + 4 .mult dq 0100000001B3h |
|||
31 Oct 2024, 16:34 |
|
Roman 31 Oct 2024, 18:08
macomics
This new 32 bit version get me hash EDX=0x31C61D51 and EAX = 0x9A3F4B1C for db "tasking" In 64 bits program in first post i get hash db "tasking" ;out hash is 0x6431452F21E4F77A |
|||
31 Oct 2024, 18:08 |
|
macomics 31 Oct 2024, 20:57
Code: hash64: push rbx mov rax, [.base_value] mov r8, rdx mov r9, [.mult_value] xor rbx, rbx .loop: mul r9 mov bl, [r8] xor rax, rbx inc r8 loop .loop pop rbx retn align 8 .base_value dq 14695981039346656037 .mult_value dq 0100000001B3h Code: hash32: ; ecx = cchLength, edx = lpszText push ebp push ebx push esi push edi mov ebx, [.base_value.low] mov ebp, [.base_value.high] mov esi, edx .loop: mov eax, [.mult_value.high] mov edi, [.mult_value.low] mul ebx xchg eax, ebx mul edi xchg edi, eax add ebx, edx mul ebp lea ebp, [ebx+eax] mov ebx, edi lods byte [esi] xor bl, al loop .loop mov eax, ebx mov edx, ebp pop edi pop esi pop ebx pop ebp retn align 8 label .base_value.low dword label .base_value.high dword at $ + 4 .base_value dq 14695981039346656037 label .mult_value.low dword label .mult_value.high dword at $ + 4 .mult_value dq 0100000001B3h Code: ; string db 'tasking' ; hash32 = 0xC408FE07C248E99E ; hash64 = 0xC408FE07C248E99E |
|||
31 Oct 2024, 20:57 |
|
Roman 31 Oct 2024, 21:22
Thanks.
Very good. |
|||
31 Oct 2024, 21:22 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.