cpu_loong64.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2022 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build loong64
  5. package cpu
  6. const cacheLineSize = 64
  7. // Bit fields for CPUCFG registers, Related reference documents:
  8. // https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_cpucfg
  9. const (
  10. // CPUCFG1 bits
  11. cpucfg1_CRC32 = 1 << 25
  12. // CPUCFG2 bits
  13. cpucfg2_LAM_BH = 1 << 27
  14. cpucfg2_LAMCAS = 1 << 28
  15. )
  16. func initOptions() {
  17. options = []option{
  18. {Name: "lsx", Feature: &Loong64.HasLSX},
  19. {Name: "lasx", Feature: &Loong64.HasLASX},
  20. {Name: "crc32", Feature: &Loong64.HasCRC32},
  21. {Name: "lam_bh", Feature: &Loong64.HasLAM_BH},
  22. {Name: "lamcas", Feature: &Loong64.HasLAMCAS},
  23. }
  24. // The CPUCFG data on Loong64 only reflects the hardware capabilities,
  25. // not the kernel support status, so features such as LSX and LASX that
  26. // require kernel support cannot be obtained from the CPUCFG data.
  27. //
  28. // These features only require hardware capability support and do not
  29. // require kernel specific support, so they can be obtained directly
  30. // through CPUCFG
  31. cfg1 := get_cpucfg(1)
  32. cfg2 := get_cpucfg(2)
  33. Loong64.HasCRC32 = cfgIsSet(cfg1, cpucfg1_CRC32)
  34. Loong64.HasLAMCAS = cfgIsSet(cfg2, cpucfg2_LAMCAS)
  35. Loong64.HasLAM_BH = cfgIsSet(cfg2, cpucfg2_LAM_BH)
  36. }
  37. func get_cpucfg(reg uint32) uint32
  38. func cfgIsSet(cfg uint32, val uint32) bool {
  39. return cfg&val != 0
  40. }