Source file src/internal/cpu/cpu_loong64.go

     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  
     5  //go:build loong64
     6  
     7  package cpu
     8  
     9  // CacheLinePadSize is used to prevent false sharing of cache lines.
    10  // We choose 64 because Loongson 3A5000 the L1 Dcache is 4-way 256-line 64-byte-per-line.
    11  const CacheLinePadSize = 64
    12  
    13  // Bit fields for CPUCFG registers, Related reference documents:
    14  // https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_cpucfg
    15  const (
    16  	// CPUCFG1 bits
    17  	cpucfg1_CRC32 = 1 << 25
    18  
    19  	// CPUCFG2 bits
    20  	cpucfg2_LAM_BH      = 1 << 27
    21  	cpucfg2_LAMCAS      = 1 << 28
    22  	cpucfg2_LLACQ_SCREL = 1 << 29
    23  	cpucfg2_SCQ         = 1 << 30
    24  
    25  	// CPUCFG3 bits
    26  	cpucfg3_DBAR_HINTS = 1 << 17
    27  )
    28  
    29  // get_cpucfg is implemented in cpu_loong64.s.
    30  func get_cpucfg(reg uint32) uint32
    31  
    32  func doinit() {
    33  	options = []option{
    34  		{Name: "lsx", Feature: &Loong64.HasLSX},
    35  		{Name: "lasx", Feature: &Loong64.HasLASX},
    36  		{Name: "crc32", Feature: &Loong64.HasCRC32},
    37  		{Name: "lamcas", Feature: &Loong64.HasLAMCAS},
    38  		{Name: "lam_bh", Feature: &Loong64.HasLAM_BH},
    39  		{Name: "llacq_screl", Feature: &Loong64.HasLLACQ_SCREL},
    40  		{Name: "scq", Feature: &Loong64.HasSCQ},
    41  		{Name: "dbar_hints", Feature: &Loong64.HasDBAR_HINTS},
    42  	}
    43  
    44  	// The CPUCFG data on Loong64 only reflects the hardware capabilities,
    45  	// not the kernel support status, so features such as LSX and LASX that
    46  	// require kernel support cannot be obtained from the CPUCFG data.
    47  	//
    48  	// These features only require hardware capability support and do not
    49  	// require kernel specific support, so they can be obtained directly
    50  	// through CPUCFG
    51  	cfg1 := get_cpucfg(1)
    52  	cfg2 := get_cpucfg(2)
    53  	cfg3 := get_cpucfg(3)
    54  
    55  	Loong64.HasCRC32 = cfgIsSet(cfg1, cpucfg1_CRC32)
    56  	Loong64.HasLAMCAS = cfgIsSet(cfg2, cpucfg2_LAMCAS)
    57  	Loong64.HasLAM_BH = cfgIsSet(cfg2, cpucfg2_LAM_BH)
    58  	Loong64.HasLLACQ_SCREL = cfgIsSet(cfg2, cpucfg2_LLACQ_SCREL)
    59  	Loong64.HasSCQ = cfgIsSet(cfg2, cpucfg2_SCQ)
    60  	Loong64.HasDBAR_HINTS = cfgIsSet(cfg3, cpucfg3_DBAR_HINTS)
    61  
    62  	osInit()
    63  }
    64  
    65  func cfgIsSet(cfg uint32, val uint32) bool {
    66  	return cfg&val != 0
    67  }
    68  

View as plain text