matchlen_amd64.s raw

   1  // Copied from S2 implementation.
   2  
   3  //go:build !appengine && !noasm && gc && !noasm
   4  
   5  #include "textflag.h"
   6  
   7  // func matchLen(a []byte, b []byte) int
   8  TEXT ·matchLen(SB), NOSPLIT, $0-56
   9  	MOVQ a_base+0(FP), AX
  10  	MOVQ b_base+24(FP), CX
  11  	MOVQ a_len+8(FP), DX
  12  
  13  	// matchLen
  14  	XORL SI, SI
  15  	CMPL DX, $0x08
  16  	JB   matchlen_match4_standalone
  17  
  18  matchlen_loopback_standalone:
  19  	MOVQ (AX)(SI*1), BX
  20  	XORQ (CX)(SI*1), BX
  21  	JZ   matchlen_loop_standalone
  22  
  23  #ifdef GOAMD64_v3
  24  	TZCNTQ BX, BX
  25  #else
  26  	BSFQ BX, BX
  27  #endif
  28  	SHRL $0x03, BX
  29  	LEAL (SI)(BX*1), SI
  30  	JMP  gen_match_len_end
  31  
  32  matchlen_loop_standalone:
  33  	LEAL -8(DX), DX
  34  	LEAL 8(SI), SI
  35  	CMPL DX, $0x08
  36  	JAE  matchlen_loopback_standalone
  37  
  38  matchlen_match4_standalone:
  39  	CMPL DX, $0x04
  40  	JB   matchlen_match2_standalone
  41  	MOVL (AX)(SI*1), BX
  42  	CMPL (CX)(SI*1), BX
  43  	JNE  matchlen_match2_standalone
  44  	LEAL -4(DX), DX
  45  	LEAL 4(SI), SI
  46  
  47  matchlen_match2_standalone:
  48  	CMPL DX, $0x02
  49  	JB   matchlen_match1_standalone
  50  	MOVW (AX)(SI*1), BX
  51  	CMPW (CX)(SI*1), BX
  52  	JNE  matchlen_match1_standalone
  53  	LEAL -2(DX), DX
  54  	LEAL 2(SI), SI
  55  
  56  matchlen_match1_standalone:
  57  	CMPL DX, $0x01
  58  	JB   gen_match_len_end
  59  	MOVB (AX)(SI*1), BL
  60  	CMPB (CX)(SI*1), BL
  61  	JNE  gen_match_len_end
  62  	INCL SI
  63  
  64  gen_match_len_end:
  65  	MOVQ SI, ret+48(FP)
  66  	RET
  67