src/share/vm/asm/register.hpp

Fri, 30 Nov 2012 15:23:16 -0800

author
twisti
date
Fri, 30 Nov 2012 15:23:16 -0800
changeset 4318
cd3d6a6b95d9
parent 4153
b9a9ed0f8eeb
child 4323
f0c2369fda5a
permissions
-rw-r--r--

8003240: x86: move MacroAssembler into separate file
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_ASM_REGISTER_HPP
    26 #define SHARE_VM_ASM_REGISTER_HPP
    28 #include "utilities/top.hpp"
    30 // Use AbstractRegister as shortcut
    31 class AbstractRegisterImpl;
    32 typedef AbstractRegisterImpl* AbstractRegister;
    35 // The super class for platform specific registers. Instead of using value objects,
    36 // registers are implemented as pointers. Subclassing is used so all registers can
    37 // use the debugging suport below. No virtual functions are used for efficiency.
    38 // They are canonicalized; i.e., registers are equal if their pointers are equal,
    39 // and vice versa. A concrete implementation may just map the register onto 'this'.
    41 class AbstractRegisterImpl {
    42  protected:
    43   int value() const                              { return (int)(intx)this; }
    44 };
    47 //
    48 // Macros for use in defining Register instances.  We'd like to be
    49 // able to simply define const instances of the RegisterImpl* for each
    50 // of the registers needed on a system in a header file.  However many
    51 // compilers don't handle this very well and end up producing a
    52 // private definition in every file which includes the header file.
    53 // Along with the static constructors necessary for initialization it
    54 // can consume a significant amount of space in the result library.
    55 //
    56 // The following macros allow us to declare the instance in a .hpp and
    57 // produce an enumeration value which has the same number.  Then in a
    58 // .cpp the the register instance can be defined using the enumeration
    59 // value.  This avoids the use of static constructors and multiple
    60 // definitions per .cpp.  In addition #defines for the register can be
    61 // produced so that the constant registers can be inlined.  These
    62 // macros should not be used inside other macros, because you may get
    63 // multiple evaluations of the macros which can give bad results.
    64 //
    65 // Here are some example uses and expansions.  Note that the macro
    66 // invocation is terminated with a ;.
    67 //
    68 // CONSTANT_REGISTER_DECLARATION(Register, G0, 0);
    69 //
    70 // extern const Register G0 ;
    71 // enum { G0_RegisterEnumValue = 0 } ;
    72 //
    73 // REGISTER_DECLARATION(Register, Gmethod, G5);
    74 //
    75 // extern const Register Gmethod ;
    76 // enum { Gmethod_RegisterEnumValue = G5_RegisterEnumValue } ;
    77 //
    78 // REGISTER_DEFINITION(Register, G0);
    79 //
    80 // const Register G0 = ( ( Register ) G0_RegisterEnumValue ) ;
    81 //
    83 #define AS_REGISTER(type,name)         ((type)name##_##type##EnumValue)
    85 #define CONSTANT_REGISTER_DECLARATION(type, name, value) \
    86 extern const type name;                                  \
    87 enum { name##_##type##EnumValue = (value) }
    89 #define REGISTER_DECLARATION(type, name, value) \
    90 extern const type name;                         \
    91 enum { name##_##type##EnumValue = value##_##type##EnumValue }
    93 #define REGISTER_DEFINITION(type, name) \
    94 const type name = ((type)name##_##type##EnumValue)
    98 // Debugging support
   100 inline void assert_different_registers(
   101   AbstractRegister a,
   102   AbstractRegister b
   103 ) {
   104   assert(
   105     a != b,
   106     err_msg_res("registers must be different: a=%d, b=%d",
   107                 a, b)
   108   );
   109 }
   112 inline void assert_different_registers(
   113   AbstractRegister a,
   114   AbstractRegister b,
   115   AbstractRegister c
   116 ) {
   117   assert(
   118     a != b && a != c
   119            && b != c,
   120     err_msg_res("registers must be different: a=%d, b=%d, c=%d",
   121                 a, b, c)
   122   );
   123 }
   126 inline void assert_different_registers(
   127   AbstractRegister a,
   128   AbstractRegister b,
   129   AbstractRegister c,
   130   AbstractRegister d
   131 ) {
   132   assert(
   133     a != b && a != c && a != d
   134            && b != c && b != d
   135                      && c != d,
   136     err_msg_res("registers must be different: a=%d, b=%d, c=%d, d=%d",
   137                 a, b, c, d)
   138   );
   139 }
   142 inline void assert_different_registers(
   143   AbstractRegister a,
   144   AbstractRegister b,
   145   AbstractRegister c,
   146   AbstractRegister d,
   147   AbstractRegister e
   148 ) {
   149   assert(
   150     a != b && a != c && a != d && a != e
   151            && b != c && b != d && b != e
   152                      && c != d && c != e
   153                                && d != e,
   154     err_msg_res("registers must be different: a=%d, b=%d, c=%d, d=%d, e=%d",
   155                 a, b, c, d, e)
   156   );
   157 }
   160 inline void assert_different_registers(
   161   AbstractRegister a,
   162   AbstractRegister b,
   163   AbstractRegister c,
   164   AbstractRegister d,
   165   AbstractRegister e,
   166   AbstractRegister f
   167 ) {
   168   assert(
   169     a != b && a != c && a != d && a != e && a != f
   170            && b != c && b != d && b != e && b != f
   171                      && c != d && c != e && c != f
   172                                && d != e && d != f
   173                                          && e != f,
   174     err_msg_res("registers must be different: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d",
   175                 a, b, c, d, e, f)
   176   );
   177 }
   180 inline void assert_different_registers(
   181   AbstractRegister a,
   182   AbstractRegister b,
   183   AbstractRegister c,
   184   AbstractRegister d,
   185   AbstractRegister e,
   186   AbstractRegister f,
   187   AbstractRegister g
   188 ) {
   189   assert(
   190     a != b && a != c && a != d && a != e && a != f && a != g
   191            && b != c && b != d && b != e && b != f && b != g
   192                      && c != d && c != e && c != f && c != g
   193                                && d != e && d != f && d != g
   194                                          && e != f && e != g
   195                                                    && f != g,
   196     err_msg_res("registers must be different: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d",
   197                 a, b, c, d, e, f, g)
   198   );
   199 }
   202 inline void assert_different_registers(
   203   AbstractRegister a,
   204   AbstractRegister b,
   205   AbstractRegister c,
   206   AbstractRegister d,
   207   AbstractRegister e,
   208   AbstractRegister f,
   209   AbstractRegister g,
   210   AbstractRegister h
   211 ) {
   212   assert(
   213     a != b && a != c && a != d && a != e && a != f && a != g && a != h
   214            && b != c && b != d && b != e && b != f && b != g && b != h
   215                      && c != d && c != e && c != f && c != g && c != h
   216                                && d != e && d != f && d != g && d != h
   217                                          && e != f && e != g && e != h
   218                                                    && f != g && f != h
   219                                                              && g != h,
   220     err_msg_res("registers must be different: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d",
   221                 a, b, c, d, e, f, g, h)
   222   );
   223 }
   226 inline void assert_different_registers(
   227   AbstractRegister a,
   228   AbstractRegister b,
   229   AbstractRegister c,
   230   AbstractRegister d,
   231   AbstractRegister e,
   232   AbstractRegister f,
   233   AbstractRegister g,
   234   AbstractRegister h,
   235   AbstractRegister i
   236 ) {
   237   assert(
   238     a != b && a != c && a != d && a != e && a != f && a != g && a != h && a != i
   239            && b != c && b != d && b != e && b != f && b != g && b != h && b != i
   240                      && c != d && c != e && c != f && c != g && c != h && c != i
   241                                && d != e && d != f && d != g && d != h && d != i
   242                                          && e != f && e != g && e != h && e != i
   243                                                    && f != g && f != h && f != i
   244                                                              && g != h && g != i
   245                                                                        && h != i,
   246     err_msg_res("registers must be different: a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d",
   247                 a, b, c, d, e, f, g, h, i)
   248   );
   249 }
   251 #endif // SHARE_VM_ASM_REGISTER_HPP

mercurial