Created
March 20, 2020 16:31
-
-
Save vizee/5679e08d9a027e1222dc5d7fc2efd978 to your computer and use it in GitHub Desktop.
search indirect tag by binary search
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
#include "textflag.h" | |
// func searchTag(m *Message, tag int) int | |
TEXT ·searchTag(SB), NOSPLIT, $0-24 | |
MOVQ m+0(FP), BX | |
MOVQ tag+8(FP), R9 | |
MOVQ 16(BX), DI | |
MOVQ 24(BX), CX | |
MOVQ 40(BX), SI | |
XORQ DX, DX | |
LEAQ -1(CX), CX | |
loop: | |
CMPQ DX, CX | |
JG notfound | |
LEAQ (DX)(CX*1), BX | |
SHRQ $1, AX | |
MOVQ (SI)(BX*8), AX | |
MOVQ (DI)(AX*8), R8 | |
CMPQ R9, (R8) | |
JZ return | |
JL right | |
LEAQ 1(BX), DX | |
JMP loop | |
right: | |
LEAQ -1(BX), CX | |
JMP loop | |
notfound: | |
XORQ AX, AX | |
NOTQ AX | |
JMP return | |
return: | |
MOVQ AX, ret+16(FP) | |
RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment