intrinsics.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // License: GPLv3 Copyright: 2024, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package simdstring
  3. import (
  4. "runtime"
  5. "golang.org/x/sys/cpu"
  6. )
  7. var Have128bit = false
  8. var Have256bit = false
  9. var VectorSize = 1
  10. // Return the index at which b first occurs in data. If not found -1 is returned.
  11. var IndexByte func(data []byte, b byte) int = index_byte_scalar
  12. // Return the index at which either a or b first occurs in text. If neither is
  13. // found -1 is returned.
  14. var IndexByteString func(text string, b byte) int = index_byte_string_scalar
  15. // Return the index at which either a or b first occurs in data. If neither is
  16. // found -1 is returned.
  17. var IndexByte2 func(data []byte, a, b byte) int = index_byte2_scalar
  18. // Return the index at which either a or b first occurs in text. If neither is
  19. // found -1 is returned.
  20. var IndexByte2String func(text string, a, b byte) int = index_byte2_string_scalar
  21. // Return the index at which the first C0 byte is found or -1 when no such bytes are present.
  22. var IndexC0 func(data []byte) int = index_c0_scalar
  23. // Return the index at which the first C0 byte is found or -1 when no such bytes are present.
  24. var IndexC0String func(data string) int = index_c0_string_scalar
  25. func init() {
  26. switch runtime.GOARCH {
  27. case "amd64":
  28. if cpu.Initialized {
  29. Have128bit = cpu.X86.HasSSE42 && HasSIMD128Code
  30. Have256bit = cpu.X86.HasAVX2 && HasSIMD256Code
  31. }
  32. case "arm64":
  33. Have128bit = HasSIMD128Code
  34. Have256bit = HasSIMD256Code
  35. }
  36. if Have256bit {
  37. IndexByte = index_byte_asm_256
  38. IndexByteString = index_byte_string_asm_256
  39. IndexByte2 = index_byte2_asm_256
  40. IndexByte2String = index_byte2_string_asm_256
  41. IndexC0 = index_c0_asm_256
  42. IndexC0String = index_c0_string_asm_256
  43. VectorSize = 32
  44. } else if Have128bit {
  45. IndexByte = index_byte_asm_128
  46. IndexByteString = index_byte_string_asm_128
  47. IndexByte2 = index_byte2_asm_128
  48. IndexByte2String = index_byte2_string_asm_128
  49. IndexC0 = index_c0_asm_128
  50. IndexC0String = index_c0_string_asm_128
  51. VectorSize = 16
  52. }
  53. }