Created
October 6, 2017 19:01
-
-
Save ryancdotorg/4a3eb7bcd6edf7a19e3888f8bdc8ee07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CPU X64 | |
%macro check_bit 0 ; check whether bit rax | |
; of the bloom filter is set | |
mov rdx, rax ; copy hash | |
shr rax, byte 3 ; byte to check in rax | |
movzx rax, byte [rdi+rax] ; load byte to check from memory | |
and rdx, byte 7 ; mask off bit to check | |
bt rax, rdx ; bit test against bloom filter | |
jnc bloom_miss ; jump to return a 'miss' if bit isn't set | |
%endmacro ; rax and rdx are clobbered | |
global bloom_chk_hash160:function | |
section .text | |
; unsigned int bloom_chk_hash160(unsigned char *bloom, uint32_t *h); | |
; should compatible with the old fixed parameter bloom filter from brainflayer | |
bloom_chk_hash160: | |
mov eax, [rsi+0x00] | |
check_bit | |
mov eax, [rsi+0x04] | |
check_bit | |
mov eax, [rsi+0x08] | |
check_bit | |
mov eax, [rsi+0x0c] | |
check_bit | |
mov eax, [rsi+0x10] | |
check_bit | |
mov ax, [rsi+0x06] | |
shl eax, 16 | |
mov ax, [rsi+0x00] | |
check_bit | |
mov ax, [rsi+0x0a] | |
shl eax, 16 | |
mov ax, [rsi+0x04] | |
check_bit | |
mov ax, [rsi+0x0e] | |
shl eax, 16 | |
mov ax, [rsi+0x08] | |
check_bit | |
mov ax, [rsi+0x12] | |
shl eax, 16 | |
mov ax, [rsi+0x0c] | |
check_bit | |
mov ax, [rsi+0x02] | |
shl eax, 16 | |
mov ax, [rsi+0x10] | |
check_bit | |
mov al, [rsi+0x07] | |
shl eax, 16 | |
mov ax, [rsi+0x00] | |
shl eax, 8 | |
mov al, [rsi+0x02] | |
check_bit | |
mov al, [rsi+0x0b] | |
shl eax, 16 | |
mov ax, [rsi+0x04] | |
shl eax, 8 | |
mov al, [rsi+0x06] | |
check_bit | |
mov al, [rsi+0x0f] | |
shl eax, 16 | |
mov ax, [rsi+0x08] | |
shl eax, 8 | |
mov al, [rsi+0x0a] | |
check_bit | |
mov al, [rsi+0x13] | |
shl eax, 16 | |
mov ax, [rsi+0x0c] | |
shl eax, 8 | |
mov al, [rsi+0x0e] | |
check_bit | |
mov al, [rsi+0x03] | |
shl eax, 16 | |
mov ax, [rsi+0x10] | |
shl eax, 8 | |
mov al, [rsi+0x12] | |
check_bit | |
mov eax [rsi+0x05] | |
mov al [rsi+0x00] | |
check_bit | |
mov eax [rsi+0x09] | |
mov al [rsi+0x04] | |
check_bit | |
mov eax [rsi+0x0d] | |
mov al [rsi+0x08] | |
check_bit | |
mov ax [rsi+0x11] | |
shl eax, 16 | |
mov ah [rsi+0x13] | |
mov al [rsi+0x0c] | |
check_bit | |
mov eax [rsi+0x01] | |
mov al [rsi+0x10] | |
check_bit | |
bloom_hit: | |
mov eax, 1 | |
ret | |
bloom_miss: | |
xor eax, eax | |
ret | |
; vim:ai:sw=2:ts=2:et:syntax=nasm:filetype=nasm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment