github.com/bir3/gocompiler@v0.3.205/src/cmd/asm/internal/arch/loong64.go (about)

     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  // This file encapsulates some of the odd characteristics of the
     6  // Loong64 (LoongArch64) instruction set, to minimize its interaction
     7  // with the core of the assembler.
     8  
     9  package arch
    10  
    11  import (
    12  	"github.com/bir3/gocompiler/src/cmd/internal/obj"
    13  	"github.com/bir3/gocompiler/src/cmd/internal/obj/loong64"
    14  )
    15  
    16  func jumpLoong64(word string) bool {
    17  	switch word {
    18  	case "BEQ", "BFPF", "BFPT", "BLTZ", "BGEZ", "BLEZ", "BGTZ", "BLT", "BLTU", "JIRL", "BNE", "BGE", "BGEU", "JMP", "JAL", "CALL":
    19  		return true
    20  	}
    21  	return false
    22  }
    23  
    24  // IsLoong64CMP reports whether the op (as defined by an loong64.A* constant) is
    25  // one of the CMP instructions that require special handling.
    26  func IsLoong64CMP(op obj.As) bool {
    27  	switch op {
    28  	case loong64.ACMPEQF, loong64.ACMPEQD, loong64.ACMPGEF, loong64.ACMPGED,
    29  		loong64.ACMPGTF, loong64.ACMPGTD:
    30  		return true
    31  	}
    32  	return false
    33  }
    34  
    35  // IsLoong64MUL reports whether the op (as defined by an loong64.A* constant) is
    36  // one of the MUL/DIV/REM instructions that require special handling.
    37  func IsLoong64MUL(op obj.As) bool {
    38  	switch op {
    39  	case loong64.AMUL, loong64.AMULU, loong64.AMULV, loong64.AMULVU,
    40  		loong64.ADIV, loong64.ADIVU, loong64.ADIVV, loong64.ADIVVU,
    41  		loong64.AREM, loong64.AREMU, loong64.AREMV, loong64.AREMVU:
    42  		return true
    43  	}
    44  	return false
    45  }
    46  
    47  func loong64RegisterNumber(name string, n int16) (int16, bool) {
    48  	switch name {
    49  	case "F":
    50  		if 0 <= n && n <= 31 {
    51  			return loong64.REG_F0 + n, true
    52  		}
    53  	case "FCSR":
    54  		if 0 <= n && n <= 31 {
    55  			return loong64.REG_FCSR0 + n, true
    56  		}
    57  	case "FCC":
    58  		if 0 <= n && n <= 31 {
    59  			return loong64.REG_FCC0 + n, true
    60  		}
    61  	case "R":
    62  		if 0 <= n && n <= 31 {
    63  			return loong64.REG_R0 + n, true
    64  		}
    65  	}
    66  	return 0, false
    67  }