github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/src/cmd/compile/internal/ppc64/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 ppc64 32 33 import "cmd/internal/obj/ppc64" 34 import "cmd/compile/internal/gc" 35 36 const ( 37 NREGVAR = 64 /* 32 general + 32 floating */ 38 ) 39 40 var regname = []string{ 41 ".R0", 42 ".R1", 43 ".R2", 44 ".R3", 45 ".R4", 46 ".R5", 47 ".R6", 48 ".R7", 49 ".R8", 50 ".R9", 51 ".R10", 52 ".R11", 53 ".R12", 54 ".R13", 55 ".R14", 56 ".R15", 57 ".R16", 58 ".R17", 59 ".R18", 60 ".R19", 61 ".R20", 62 ".R21", 63 ".R22", 64 ".R23", 65 ".R24", 66 ".R25", 67 ".R26", 68 ".R27", 69 ".R28", 70 ".R29", 71 ".R30", 72 ".R31", 73 ".F0", 74 ".F1", 75 ".F2", 76 ".F3", 77 ".F4", 78 ".F5", 79 ".F6", 80 ".F7", 81 ".F8", 82 ".F9", 83 ".F10", 84 ".F11", 85 ".F12", 86 ".F13", 87 ".F14", 88 ".F15", 89 ".F16", 90 ".F17", 91 ".F18", 92 ".F19", 93 ".F20", 94 ".F21", 95 ".F22", 96 ".F23", 97 ".F24", 98 ".F25", 99 ".F26", 100 ".F27", 101 ".F28", 102 ".F29", 103 ".F30", 104 ".F31", 105 } 106 107 func regnames(n *int) []string { 108 *n = NREGVAR 109 return regname 110 } 111 112 func excludedregs() uint64 { 113 // Exclude registers with fixed functions 114 regbits := uint64(1<<0 | RtoB(ppc64.REGSP) | RtoB(ppc64.REGG) | RtoB(ppc64.REGTLS) | RtoB(ppc64.REGTMP)) 115 116 if gc.Ctxt.Flag_shared != 0 { 117 // When compiling Go into PIC, R2 is reserved to be the TOC pointer 118 // and R12 so that calls via function pointer can stomp on it. 119 regbits |= RtoB(ppc64.REG_R2) 120 regbits |= RtoB(ppc64.REG_R12) 121 } 122 // Also exclude floating point registers with fixed constants 123 regbits |= RtoB(ppc64.REG_F27) | RtoB(ppc64.REG_F28) | RtoB(ppc64.REG_F29) | RtoB(ppc64.REG_F30) | RtoB(ppc64.REG_F31) 124 125 return regbits 126 } 127 128 func doregbits(r int) uint64 { 129 return 0 130 } 131 132 /* 133 * track register variables including external registers: 134 * bit reg 135 * 0 R0 136 * 1 R1 137 * ... ... 138 * 31 R31 139 * 32+0 F0 140 * 32+1 F1 141 * ... ... 142 * 32+31 F31 143 */ 144 func RtoB(r int) uint64 { 145 if r > ppc64.REG_R0 && r <= ppc64.REG_R31 { 146 return 1 << uint(r-ppc64.REG_R0) 147 } 148 if r >= ppc64.REG_F0 && r <= ppc64.REG_F31 { 149 return 1 << uint(32+r-ppc64.REG_F0) 150 } 151 return 0 152 } 153 154 func BtoR(b uint64) int { 155 b &= 0xffffffff 156 if b == 0 { 157 return 0 158 } 159 return gc.Bitno(b) + ppc64.REG_R0 160 } 161 162 func BtoF(b uint64) int { 163 b >>= 32 164 if b == 0 { 165 return 0 166 } 167 return gc.Bitno(b) + ppc64.REG_F0 168 }