Skip to content

Commit

Permalink
Emit always, even when exceeding.
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Dec 7, 2020
1 parent 966a9d2 commit 1f39cf5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
16 changes: 10 additions & 6 deletions s2/_generate/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ func (o options) genEncodeBlockAsm(name string, tableBits, skipLog, hashBytes, m
// Bail if we exceed the maximum size.
// if d+len(src)-nextEmitL > dstLimitPtrQ { return 0
{
// If we didn't output anything, we always have space to emit as is.
CMPL(nextEmitL, U8(0))
JEQ(LabelRef("emit_remainder_ok_" + name))

// remain = len(src) - nextEmit
remain := GP64()
MOVQ(lenSrcQ, remain)
Expand All @@ -678,12 +682,10 @@ func (o options) genEncodeBlockAsm(name string, tableBits, skipLog, hashBytes, m
LEAQ(Mem{Base: dst, Index: remain, Scale: 1, Disp: literalMaxOverhead}, dstExpect)
CMPQ(dstExpect, dstLimitPtrQ)
JL(LabelRef("emit_remainder_ok_" + name))
ri, err := ReturnIndex(0).Resolve()
if err != nil {
panic(err)
}
MOVQ(U32(0), ri.Addr)
RET()
// Emit as single literal block, overwriting what we have.
MOVL(U32(0), nextEmitL)
Load(Param("dst").Base(), dst)
Load(Param("src").Base(), src)
Label("emit_remainder_ok_" + name)
}
// emitLiteral(dst[d:], src[nextEmitL:])
Expand Down Expand Up @@ -785,6 +787,8 @@ type hashGen struct {
bytes int
tablebits int
mulreg reg.GPVirtual
vbmireg reg.GPVirtual
vbmi bool
}

// hashN uses multiply to get a 'output' hash on the hash of the lowest 'bytes' bytes in value.
Expand Down
56 changes: 40 additions & 16 deletions s2/encodeblock_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -1047,13 +1047,16 @@ match_nolit_dst_ok_encodeBlockAsm:
JMP search_loop_encodeBlockAsm

emit_remainder_encodeBlockAsm:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeBlockAsm
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeBlockAsm
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeBlockAsm:
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -1982,13 +1985,16 @@ match_nolit_dst_ok_encodeBlockAsm12B:
JMP search_loop_encodeBlockAsm12B

emit_remainder_encodeBlockAsm12B:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeBlockAsm12B
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeBlockAsm12B
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeBlockAsm12B:
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -2898,13 +2904,16 @@ match_nolit_dst_ok_encodeBlockAsm10B:
JMP search_loop_encodeBlockAsm10B

emit_remainder_encodeBlockAsm10B:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeBlockAsm10B
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeBlockAsm10B
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeBlockAsm10B:
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -3798,13 +3807,16 @@ match_nolit_dst_ok_encodeBlockAsm8B:
JMP search_loop_encodeBlockAsm8B

emit_remainder_encodeBlockAsm8B:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeBlockAsm8B
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeBlockAsm8B
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeBlockAsm8B:
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -4669,13 +4681,16 @@ match_nolit_dst_ok_encodeSnappyBlockAsm:
JMP search_loop_encodeSnappyBlockAsm

emit_remainder_encodeSnappyBlockAsm:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeSnappyBlockAsm
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeSnappyBlockAsm
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeSnappyBlockAsm:
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -5475,13 +5490,16 @@ match_nolit_dst_ok_encodeSnappyBlockAsm12B:
JMP search_loop_encodeSnappyBlockAsm12B

emit_remainder_encodeSnappyBlockAsm12B:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeSnappyBlockAsm12B
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeSnappyBlockAsm12B
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeSnappyBlockAsm12B:
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -6262,13 +6280,16 @@ match_nolit_dst_ok_encodeSnappyBlockAsm10B:
JMP search_loop_encodeSnappyBlockAsm10B

emit_remainder_encodeSnappyBlockAsm10B:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeSnappyBlockAsm10B
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeSnappyBlockAsm10B
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeSnappyBlockAsm10B:
MOVQ src_len+32(FP), CX
Expand Down Expand Up @@ -7045,13 +7066,16 @@ match_nolit_dst_ok_encodeSnappyBlockAsm8B:
JMP search_loop_encodeSnappyBlockAsm8B

emit_remainder_encodeSnappyBlockAsm8B:
CMPL 12(SP), $0x00
JEQ emit_remainder_ok_encodeSnappyBlockAsm8B
MOVQ src_len+32(FP), CX
SUBL 12(SP), CX
LEAQ 4(AX)(CX*1), CX
CMPQ CX, (SP)
JL emit_remainder_ok_encodeSnappyBlockAsm8B
MOVQ $0x00000000, ret+48(FP)
RET
MOVL $0x00000000, 12(SP)
MOVQ dst_base+0(FP), AX
MOVQ src_base+24(FP), DX

emit_remainder_ok_encodeSnappyBlockAsm8B:
MOVQ src_len+32(FP), CX
Expand Down

0 comments on commit 1f39cf5

Please sign in to comment.