matchlen_amd64.s 1.2 KB

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