Skip to content

Commit

Permalink
varint: simplify AsmLoop
Browse files Browse the repository at this point in the history
This simplifies AsmLoop a bit without changing its performance. This
code would probably be completely reasonable for the compiler to
generate.
  • Loading branch information
aclements committed Aug 25, 2016
1 parent f49f811 commit b009255
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions varint/asm_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ TEXT ·decodeVarintAsmLoop(SB),NOSPLIT,$0-40
XORL DX, DX // Value

loop:
CMPL SI, AX
CMPL SI, AX // (fused with JEQ)
JEQ bad // Reached end of buffer or >10 bytes

MOVBLZX (SI)(BX*1), DI // Load next byte
INCL SI
BTRL $7, DI // Is bit 7 set? Clear bit 7.
JNC last // If not set, this is the final byte
// This could be a BTRL $7, DI, but this is simpler and
// just as fast thanks to macro-op fusion.
TESTL $0x80, DI // Is bit 7 set? (fused with JZ)
JZ last
ANDL $0x7f, DI // Clear bit 7
SHLQ CL, DI // value |= value << shift
ORQ DI, DX
ADDL $7, CX // shift += 7
Expand Down

0 comments on commit b009255

Please sign in to comment.