Source file src/cmd/asm/internal/arch/riscv64.go

     1  // Copyright 2020 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  // This file encapsulates some of the odd characteristics of the RISCV64
     6  // instruction set, to minimize its interaction with the core of the
     7  // assembler.
     8  
     9  package arch
    10  
    11  import (
    12  	"cmd/internal/obj"
    13  	"cmd/internal/obj/riscv"
    14  )
    15  
    16  // IsRISCV64AMO reports whether op is an AMO instruction that requires
    17  // special handling.
    18  func IsRISCV64AMO(op obj.As) bool {
    19  	switch op {
    20  	case riscv.ASCW, riscv.ASCD, riscv.AAMOSWAPW, riscv.AAMOSWAPD, riscv.AAMOADDW, riscv.AAMOADDD,
    21  		riscv.AAMOANDW, riscv.AAMOANDD, riscv.AAMOORW, riscv.AAMOORD, riscv.AAMOXORW, riscv.AAMOXORD,
    22  		riscv.AAMOMINW, riscv.AAMOMIND, riscv.AAMOMINUW, riscv.AAMOMINUD,
    23  		riscv.AAMOMAXW, riscv.AAMOMAXD, riscv.AAMOMAXUW, riscv.AAMOMAXUD:
    24  		return true
    25  	}
    26  	return false
    27  }
    28  
    29  // IsRISCV64VTypeI reports whether op is a vtype immediate instruction that
    30  // requires special handling.
    31  func IsRISCV64VTypeI(op obj.As) bool {
    32  	return op == riscv.AVSETVLI || op == riscv.AVSETIVLI
    33  }
    34  
    35  var riscv64SpecialOperand map[string]riscv.SpecialOperand
    36  
    37  // RISCV64SpecialOperand returns the internal representation of a special operand.
    38  func RISCV64SpecialOperand(name string) riscv.SpecialOperand {
    39  	if riscv64SpecialOperand == nil {
    40  		// Generate mapping when function is first called.
    41  		riscv64SpecialOperand = map[string]riscv.SpecialOperand{}
    42  		for opd := riscv.SPOP_BEGIN; opd < riscv.SPOP_END; opd++ {
    43  			riscv64SpecialOperand[opd.String()] = opd
    44  		}
    45  	}
    46  	if opd, ok := riscv64SpecialOperand[name]; ok {
    47  		return opd
    48  	}
    49  	return riscv.SPOP_END
    50  }
    51  
    52  // RISCV64ValidateVectorType reports whether the given configuration is a
    53  // valid vector type.
    54  func RISCV64ValidateVectorType(vsew, vlmul, vtail, vmask int64) error {
    55  	_, err := riscv.EncodeVectorType(vsew, vlmul, vtail, vmask)
    56  	return err
    57  }
    58  

View as plain text