github.com/c0deoo1/golang1.5@v0.0.0-20220525150107-c87c805d4593/src/cmd/compile/internal/arm64/reg.go (about)

     1  // Derived from Inferno utils/6c/reg.c
     2  // http://code.google.com/p/inferno-os/source/browse/utils/6c/reg.c
     3  //
     4  //	Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
     5  //	Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
     6  //	Portions Copyright © 1997-1999 Vita Nuova Limited
     7  //	Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
     8  //	Portions Copyright © 2004,2006 Bruce Ellis
     9  //	Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
    10  //	Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
    11  //	Portions Copyright © 2009 The Go Authors.  All rights reserved.
    12  //
    13  // Permission is hereby granted, free of charge, to any person obtaining a copy
    14  // of this software and associated documentation files (the "Software"), to deal
    15  // in the Software without restriction, including without limitation the rights
    16  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    17  // copies of the Software, and to permit persons to whom the Software is
    18  // furnished to do so, subject to the following conditions:
    19  //
    20  // The above copyright notice and this permission notice shall be included in
    21  // all copies or substantial portions of the Software.
    22  //
    23  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    24  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    25  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    26  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    27  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    28  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    29  // THE SOFTWARE.
    30  
    31  package arm64
    32  
    33  import (
    34  	"cmd/compile/internal/gc"
    35  	"cmd/internal/obj/arm64"
    36  )
    37  
    38  const (
    39  	NREGVAR = 64 /* 32 general + 32 floating */
    40  )
    41  
    42  var reg [arm64.NREG + arm64.NFREG]uint8
    43  
    44  var regname = []string{
    45  	".R0",
    46  	".R1",
    47  	".R2",
    48  	".R3",
    49  	".R4",
    50  	".R5",
    51  	".R6",
    52  	".R7",
    53  	".R8",
    54  	".R9",
    55  	".R10",
    56  	".R11",
    57  	".R12",
    58  	".R13",
    59  	".R14",
    60  	".R15",
    61  	".R16",
    62  	".R17",
    63  	".R18",
    64  	".R19",
    65  	".R20",
    66  	".R21",
    67  	".R22",
    68  	".R23",
    69  	".R24",
    70  	".R25",
    71  	".R26",
    72  	".R27",
    73  	".R28",
    74  	".R29",
    75  	".R30",
    76  	".R31",
    77  	".F0",
    78  	".F1",
    79  	".F2",
    80  	".F3",
    81  	".F4",
    82  	".F5",
    83  	".F6",
    84  	".F7",
    85  	".F8",
    86  	".F9",
    87  	".F10",
    88  	".F11",
    89  	".F12",
    90  	".F13",
    91  	".F14",
    92  	".F15",
    93  	".F16",
    94  	".F17",
    95  	".F18",
    96  	".F19",
    97  	".F20",
    98  	".F21",
    99  	".F22",
   100  	".F23",
   101  	".F24",
   102  	".F25",
   103  	".F26",
   104  	".F27",
   105  	".F28",
   106  	".F29",
   107  	".F30",
   108  	".F31",
   109  }
   110  
   111  func regnames(n *int) []string {
   112  	*n = NREGVAR
   113  	return regname
   114  }
   115  
   116  func excludedregs() uint64 {
   117  	// Exclude registers with fixed functions
   118  	regbits := uint64(RtoB(arm64.REGRT1) | RtoB(arm64.REGRT2) | RtoB(arm64.REGPR))
   119  
   120  	// Exclude R26 - R31.
   121  	for r := arm64.REGMAX + 1; r <= arm64.REGZERO; r++ {
   122  		regbits |= RtoB(r)
   123  	}
   124  
   125  	// Also exclude floating point registers with fixed constants
   126  	regbits |= RtoB(arm64.REG_F27) | RtoB(arm64.REG_F28) | RtoB(arm64.REG_F29) | RtoB(arm64.REG_F30) | RtoB(arm64.REG_F31)
   127  
   128  	return regbits
   129  }
   130  
   131  func doregbits(r int) uint64 {
   132  	return 0
   133  }
   134  
   135  /*
   136   * track register variables including external registers:
   137   *	bit	reg
   138   *	0	R0
   139   *	1	R1
   140   *	...	...
   141   *	31	R31
   142   *	32+0	F0
   143   *	32+1	F1
   144   *	...	...
   145   *	32+31	F31
   146   */
   147  func RtoB(r int) uint64 {
   148  	if r >= arm64.REG_R0 && r <= arm64.REG_R31 {
   149  		return 1 << uint(r-arm64.REG_R0)
   150  	}
   151  	if r >= arm64.REG_F0 && r <= arm64.REG_F31 {
   152  		return 1 << uint(32+r-arm64.REG_F0)
   153  	}
   154  	return 0
   155  }
   156  
   157  func BtoR(b uint64) int {
   158  	b &= 0xffffffff
   159  	if b == 0 {
   160  		return 0
   161  	}
   162  	return gc.Bitno(b) + arm64.REG_R0
   163  }
   164  
   165  func BtoF(b uint64) int {
   166  	b >>= 32
   167  	if b == 0 {
   168  		return 0
   169  	}
   170  	return gc.Bitno(b) + arm64.REG_F0
   171  }