src/share/vm/asm/register.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/asm/register.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,211 @@
     1.4 +/*
     1.5 + * Copyright 2000-2002 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// Use AbstractRegister as shortcut
    1.29 +class AbstractRegisterImpl;
    1.30 +typedef AbstractRegisterImpl* AbstractRegister;
    1.31 +
    1.32 +
    1.33 +// The super class for platform specific registers. Instead of using value objects,
    1.34 +// registers are implemented as pointers. Subclassing is used so all registers can
    1.35 +// use the debugging suport below. No virtual functions are used for efficiency.
    1.36 +// They are canonicalized; i.e., registers are equal if their pointers are equal,
    1.37 +// and vice versa. A concrete implementation may just map the register onto 'this'.
    1.38 +
    1.39 +class AbstractRegisterImpl {
    1.40 + protected:
    1.41 +  int value() const                              { return (int)(intx)this; }
    1.42 +};
    1.43 +
    1.44 +
    1.45 +//
    1.46 +// Macros for use in defining Register instances.  We'd like to be
    1.47 +// able to simply define const instances of the RegisterImpl* for each
    1.48 +// of the registers needed on a system in a header file.  However many
    1.49 +// compilers don't handle this very well and end up producing a
    1.50 +// private definition in every file which includes the header file.
    1.51 +// Along with the static constructors necessary for initialization it
    1.52 +// can consume a significant amount of space in the result library.
    1.53 +//
    1.54 +// The following macros allow us to declare the instance in a .hpp and
    1.55 +// produce an enumeration value which has the same number.  Then in a
    1.56 +// .cpp the the register instance can be defined using the enumeration
    1.57 +// value.  This avoids the use of static constructors and multiple
    1.58 +// definitions per .cpp.  In addition #defines for the register can be
    1.59 +// produced so that the constant registers can be inlined.  These
    1.60 +// macros should not be used inside other macros, because you may get
    1.61 +// multiple evaluations of the macros which can give bad results.
    1.62 +//
    1.63 +// Here are some example uses and expansions.  Note that the macro
    1.64 +// invocation is terminated with a ;.
    1.65 +//
    1.66 +// CONSTANT_REGISTER_DECLARATION(Register, G0, 0);
    1.67 +//
    1.68 +// extern const Register G0 ;
    1.69 +// enum { G0_RegisterEnumValue = 0 } ;
    1.70 +//
    1.71 +// REGISTER_DECLARATION(Register, Gmethod, G5);
    1.72 +//
    1.73 +// extern const Register Gmethod ;
    1.74 +// enum { Gmethod_RegisterEnumValue = G5_RegisterEnumValue } ;
    1.75 +//
    1.76 +// REGISTER_DEFINITION(Register, G0);
    1.77 +//
    1.78 +// const Register G0 = ( ( Register ) G0_RegisterEnumValue ) ;
    1.79 +//
    1.80 +
    1.81 +#define AS_REGISTER(type,name)         ((type)name##_##type##EnumValue)
    1.82 +
    1.83 +#define CONSTANT_REGISTER_DECLARATION(type, name, value) \
    1.84 +extern const type name;                                  \
    1.85 +enum { name##_##type##EnumValue = (value) }
    1.86 +
    1.87 +#define REGISTER_DECLARATION(type, name, value) \
    1.88 +extern const type name;                         \
    1.89 +enum { name##_##type##EnumValue = value##_##type##EnumValue }
    1.90 +
    1.91 +#define REGISTER_DEFINITION(type, name) \
    1.92 +const type name = ((type)name##_##type##EnumValue)
    1.93 +
    1.94 +
    1.95 +
    1.96 +// Debugging support
    1.97 +
    1.98 +inline void assert_different_registers(
    1.99 +  AbstractRegister a,
   1.100 +  AbstractRegister b
   1.101 +) {
   1.102 +  assert(
   1.103 +    a != b,
   1.104 +    "registers must be different"
   1.105 +  );
   1.106 +}
   1.107 +
   1.108 +
   1.109 +inline void assert_different_registers(
   1.110 +  AbstractRegister a,
   1.111 +  AbstractRegister b,
   1.112 +  AbstractRegister c
   1.113 +) {
   1.114 +  assert(
   1.115 +    a != b && a != c
   1.116 +           && b != c,
   1.117 +    "registers must be different"
   1.118 +  );
   1.119 +}
   1.120 +
   1.121 +
   1.122 +inline void assert_different_registers(
   1.123 +  AbstractRegister a,
   1.124 +  AbstractRegister b,
   1.125 +  AbstractRegister c,
   1.126 +  AbstractRegister d
   1.127 +) {
   1.128 +  assert(
   1.129 +    a != b && a != c && a != d
   1.130 +           && b != c && b != d
   1.131 +                     && c != d,
   1.132 +    "registers must be different"
   1.133 +  );
   1.134 +}
   1.135 +
   1.136 +
   1.137 +inline void assert_different_registers(
   1.138 +  AbstractRegister a,
   1.139 +  AbstractRegister b,
   1.140 +  AbstractRegister c,
   1.141 +  AbstractRegister d,
   1.142 +  AbstractRegister e
   1.143 +) {
   1.144 +  assert(
   1.145 +    a != b && a != c && a != d && a != e
   1.146 +           && b != c && b != d && b != e
   1.147 +                     && c != d && c != e
   1.148 +                               && d != e,
   1.149 +    "registers must be different"
   1.150 +  );
   1.151 +}
   1.152 +
   1.153 +
   1.154 +inline void assert_different_registers(
   1.155 +  AbstractRegister a,
   1.156 +  AbstractRegister b,
   1.157 +  AbstractRegister c,
   1.158 +  AbstractRegister d,
   1.159 +  AbstractRegister e,
   1.160 +  AbstractRegister f
   1.161 +) {
   1.162 +  assert(
   1.163 +    a != b && a != c && a != d && a != e && a != f
   1.164 +           && b != c && b != d && b != e && b != f
   1.165 +                     && c != d && c != e && c != f
   1.166 +                               && d != e && d != f
   1.167 +                                         && e != f,
   1.168 +    "registers must be different"
   1.169 +  );
   1.170 +}
   1.171 +
   1.172 +
   1.173 +inline void assert_different_registers(
   1.174 +  AbstractRegister a,
   1.175 +  AbstractRegister b,
   1.176 +  AbstractRegister c,
   1.177 +  AbstractRegister d,
   1.178 +  AbstractRegister e,
   1.179 +  AbstractRegister f,
   1.180 +  AbstractRegister g
   1.181 +) {
   1.182 +  assert(
   1.183 +    a != b && a != c && a != d && a != e && a != f && a != g
   1.184 +           && b != c && b != d && b != e && b != f && b != g
   1.185 +                     && c != d && c != e && c != f && c != g
   1.186 +                               && d != e && d != f && d != g
   1.187 +                                         && e != f && e != g
   1.188 +                                                   && f != g,
   1.189 +    "registers must be different"
   1.190 +  );
   1.191 +}
   1.192 +
   1.193 +
   1.194 +inline void assert_different_registers(
   1.195 +  AbstractRegister a,
   1.196 +  AbstractRegister b,
   1.197 +  AbstractRegister c,
   1.198 +  AbstractRegister d,
   1.199 +  AbstractRegister e,
   1.200 +  AbstractRegister f,
   1.201 +  AbstractRegister g,
   1.202 +  AbstractRegister h
   1.203 +) {
   1.204 +  assert(
   1.205 +    a != b && a != c && a != d && a != e && a != f && a != g && a != h
   1.206 +           && b != c && b != d && b != e && b != f && b != g && b != h
   1.207 +                     && c != d && c != e && c != f && c != g && c != h
   1.208 +                               && d != e && d != f && d != g && d != h
   1.209 +                                         && e != f && e != g && e != h
   1.210 +                                                   && f != g && f != h
   1.211 +                                                             && g != h,
   1.212 +    "registers must be different"
   1.213 +  );
   1.214 +}

mercurial