matchlen_amd64.s 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. TEXT ·matchLen(SB), NOSPLIT, $0-56
  6. MOVQ a_base+0(FP), AX
  7. MOVQ b_base+24(FP), CX
  8. MOVQ a_len+8(FP), DX
  9. // matchLen
  10. XORL SI, SI
  11. CMPL DX, $0x08
  12. JB matchlen_match4_standalone
  13. matchlen_loopback_standalone:
  14. MOVQ (AX)(SI*1), BX
  15. XORQ (CX)(SI*1), BX
  16. JZ matchlen_loop_standalone
  17. #ifdef GOAMD64_v3
  18. TZCNTQ BX, BX
  19. #else
  20. BSFQ BX, BX
  21. #endif
  22. SHRL $0x03, BX
  23. LEAL (SI)(BX*1), SI
  24. JMP gen_match_len_end
  25. matchlen_loop_standalone:
  26. LEAL -8(DX), DX
  27. LEAL 8(SI), SI
  28. CMPL DX, $0x08
  29. JAE matchlen_loopback_standalone
  30. matchlen_match4_standalone:
  31. CMPL DX, $0x04
  32. JB matchlen_match2_standalone
  33. MOVL (AX)(SI*1), BX
  34. CMPL (CX)(SI*1), BX
  35. JNE matchlen_match2_standalone
  36. LEAL -4(DX), DX
  37. LEAL 4(SI), SI
  38. matchlen_match2_standalone:
  39. CMPL DX, $0x02
  40. JB matchlen_match1_standalone
  41. MOVW (AX)(SI*1), BX
  42. CMPW (CX)(SI*1), BX
  43. JNE matchlen_match1_standalone
  44. LEAL -2(DX), DX
  45. LEAL 2(SI), SI
  46. matchlen_match1_standalone:
  47. CMPL DX, $0x01
  48. JB gen_match_len_end
  49. MOVB (AX)(SI*1), BL
  50. CMPB (CX)(SI*1), BL
  51. JNE gen_match_len_end
  52. INCL SI
  53. gen_match_len_end:
  54. MOVQ SI, ret+48(FP)
  55. RET