github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/src/cmd/compile/internal/sparc64/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 sparc64
    32  
    33  import (
    34  	"cmd/compile/internal/gc"
    35  	"cmd/internal/obj/sparc64"
    36  )
    37  
    38  const (
    39  	NREGVAR = 64 /* 32 general + 32 floating */
    40  )
    41  
    42  var regname = []string{
    43  	".R0",
    44  	".R1",
    45  	".R2",
    46  	".R3",
    47  	".R4",
    48  	".R5",
    49  	".R6",
    50  	".R7",
    51  	".R8",
    52  	".R9",
    53  	".R10",
    54  	".R11",
    55  	".R12",
    56  	".R13",
    57  	".R14",
    58  	".R15",
    59  	".R16",
    60  	".R17",
    61  	".R18",
    62  	".R19",
    63  	".R20",
    64  	".R21",
    65  	".R22",
    66  	".R23",
    67  	".R24",
    68  	".R25",
    69  	".R26",
    70  	".R27",
    71  	".R28",
    72  	".R29",
    73  	".R30",
    74  	".R31",
    75  	".F0",
    76  	".F1",
    77  	".F2",
    78  	".F3",
    79  	".F4",
    80  	".F5",
    81  	".F6",
    82  	".F7",
    83  	".F8",
    84  	".F9",
    85  	".F10",
    86  	".F11",
    87  	".F12",
    88  	".F13",
    89  	".F14",
    90  	".F15",
    91  	".F16",
    92  	".F17",
    93  	".F18",
    94  	".F19",
    95  	".F20",
    96  	".F21",
    97  	".F22",
    98  	".F23",
    99  	".F24",
   100  	".F25",
   101  	".F26",
   102  	".F27",
   103  	".F28",
   104  	".F29",
   105  	".F30",
   106  	".F31",
   107  }
   108  
   109  func regnames(n *int) []string {
   110  	*n = NREGVAR
   111  	return regname
   112  }
   113  
   114  func excludedregs() uint64 {
   115  	// Exclude registers with fixed functions in [R8, REG_MAX] range.
   116  	regbits := RtoB(sparc64.REG_RSP) | RtoB(sparc64.REG_OLR) | RtoB(sparc64.REG_TMP2)
   117  
   118  	// Exclude G0 - G7.
   119  	for r := sparc64.REG_G0; r <= sparc64.REG_G7; r++ {
   120  		regbits |= RtoB(r)
   121  	}
   122  	// Exclude I6 - I7.
   123  	for r := sparc64.REG_MAX + 1; r <= sparc64.REG_I7; r++ {
   124  		regbits |= RtoB(r)
   125  	}
   126  
   127  	// Exclude I0 - I7, for debugging.
   128  	// TODO(aram): revisit this.
   129  	for r := sparc64.REG_I0; r <= sparc64.REG_I7; r++ {
   130  		regbits |= RtoB(r)
   131  	}
   132  
   133  	// Exclude floating point registers with fixed functions
   134  	regbits |= RtoB(sparc64.REG_YTMP) | RtoB(sparc64.REG_YTWO)
   135  
   136  	// Exclude Y16-Y31, since they don't exist.
   137  	for r := sparc64.REG_Y15 + 1; r <= (sparc64.REG_Y0 + 31); r++ {
   138  		regbits |= RtoB(r)
   139  	}
   140  
   141  	return regbits
   142  }
   143  
   144  func doregbits(r int) uint64 {
   145  	return 0
   146  }
   147  
   148  /*
   149   * track register variables including external registers:
   150   *	bit	reg
   151   *	0	R0 (G0)
   152   *	1	R1 (G1)
   153   *	...	...
   154   *	31	R31 (I7)
   155   *	32+0	Y0
   156   *	32+1	Y1
   157   *	...	...
   158   *	32+15	Y15
   159   *	...	unused
   160   */
   161  func RtoB(r int) uint64 {
   162  	if r >= sparc64.REG_G0 && r <= sparc64.REG_I7 {
   163  		return 1 << uint(r-sparc64.REG_G0)
   164  	}
   165  	if r >= sparc64.REG_Y0 && r <= sparc64.REG_Y0+31 {
   166  		return 1 << uint(32+r-sparc64.REG_Y0)
   167  	}
   168  	return 0
   169  }
   170  
   171  func BtoR(b uint64) int {
   172  	b &= 0xffffffff
   173  	if b == 0 {
   174  		return 0
   175  	}
   176  	return gc.Bitno(b) + sparc64.REG_G0
   177  }
   178  
   179  func BtoF(b uint64) int {
   180  	b >>= 32
   181  	if b == 0 {
   182  		return 0
   183  	}
   184  	return gc.Bitno(b) + sparc64.REG_Y0
   185  }