Home | History | Annotate | Download | only in x86
      1 // Do not edit. Bootstrap copy of /Volumes/Android/buildbot/src/android/build-tools/out/obj/go/src/cmd/compile/internal/x86/reg.go
      2 
      3 //line /Volumes/Android/buildbot/src/android/build-tools/out/obj/go/src/cmd/compile/internal/x86/reg.go:1
      4 // Derived from Inferno utils/6c/reg.c
      5 // http://code.google.com/p/inferno-os/source/browse/utils/6c/reg.c
      6 //
      7 //	Copyright  1994-1999 Lucent Technologies Inc.  All rights reserved.
      8 //	Portions Copyright  1995-1997 C H Forsyth (forsyth (a] terzarima.net)
      9 //	Portions Copyright  1997-1999 Vita Nuova Limited
     10 //	Portions Copyright  2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
     11 //	Portions Copyright  2004,2006 Bruce Ellis
     12 //	Portions Copyright  2005-2007 C H Forsyth (forsyth (a] terzarima.net)
     13 //	Revisions Copyright  2000-2007 Lucent Technologies Inc. and others
     14 //	Portions Copyright  2009 The Go Authors.  All rights reserved.
     15 //
     16 // Permission is hereby granted, free of charge, to any person obtaining a copy
     17 // of this software and associated documentation files (the "Software"), to deal
     18 // in the Software without restriction, including without limitation the rights
     19 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     20 // copies of the Software, and to permit persons to whom the Software is
     21 // furnished to do so, subject to the following conditions:
     22 //
     23 // The above copyright notice and this permission notice shall be included in
     24 // all copies or substantial portions of the Software.
     25 //
     26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     27 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     28 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     29 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     30 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     31 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     32 // THE SOFTWARE.
     33 
     34 package x86
     35 
     36 import "bootstrap/internal/obj/x86"
     37 import "bootstrap/compile/internal/gc"
     38 
     39 const (
     40 	NREGVAR = 16 /* 8 integer + 8 floating */
     41 )
     42 
     43 var regname = []string{
     44 	".ax",
     45 	".cx",
     46 	".dx",
     47 	".bx",
     48 	".sp",
     49 	".bp",
     50 	".si",
     51 	".di",
     52 	".x0",
     53 	".x1",
     54 	".x2",
     55 	".x3",
     56 	".x4",
     57 	".x5",
     58 	".x6",
     59 	".x7",
     60 }
     61 
     62 func regnames(n *int) []string {
     63 	*n = NREGVAR
     64 	return regname
     65 }
     66 
     67 func excludedregs() uint64 {
     68 	return RtoB(x86.REG_SP)
     69 }
     70 
     71 func doregbits(r int) uint64 {
     72 	b := uint64(0)
     73 	if r >= x86.REG_AX && r <= x86.REG_DI {
     74 		b |= RtoB(r)
     75 	} else if r >= x86.REG_AL && r <= x86.REG_BL {
     76 		b |= RtoB(r - x86.REG_AL + x86.REG_AX)
     77 	} else if r >= x86.REG_AH && r <= x86.REG_BH {
     78 		b |= RtoB(r - x86.REG_AH + x86.REG_AX)
     79 	} else if r >= x86.REG_X0 && r <= x86.REG_X0+7 {
     80 		b |= FtoB(r)
     81 	}
     82 	return b
     83 }
     84 
     85 func RtoB(r int) uint64 {
     86 	if r < x86.REG_AX || r > x86.REG_DI {
     87 		return 0
     88 	}
     89 	return 1 << uint(r-x86.REG_AX)
     90 }
     91 
     92 func BtoR(b uint64) int {
     93 	b &= 0xff
     94 	if b == 0 {
     95 		return 0
     96 	}
     97 	return gc.Bitno(b) + x86.REG_AX
     98 }
     99 
    100 func FtoB(f int) uint64 {
    101 	if f < x86.REG_X0 || f > x86.REG_X7 {
    102 		return 0
    103 	}
    104 	return 1 << uint(f-x86.REG_X0+8)
    105 }
    106 
    107 func BtoF(b uint64) int {
    108 	b &= 0xFF00
    109 	if b == 0 {
    110 		return 0
    111 	}
    112 	return gc.Bitno(b) - 8 + x86.REG_X0
    113 }
    114