hotspot/src/share/vm/asm/register.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2002 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Use AbstractRegister as shortcut
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
class AbstractRegisterImpl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
typedef AbstractRegisterImpl* AbstractRegister;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// The super class for platform specific registers. Instead of using value objects,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// registers are implemented as pointers. Subclassing is used so all registers can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// use the debugging suport below. No virtual functions are used for efficiency.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// They are canonicalized; i.e., registers are equal if their pointers are equal,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// and vice versa. A concrete implementation may just map the register onto 'this'.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
class AbstractRegisterImpl {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  int value() const                              { return (int)(intx)this; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// Macros for use in defining Register instances.  We'd like to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// able to simply define const instances of the RegisterImpl* for each
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// of the registers needed on a system in a header file.  However many
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// compilers don't handle this very well and end up producing a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// private definition in every file which includes the header file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Along with the static constructors necessary for initialization it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// can consume a significant amount of space in the result library.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// The following macros allow us to declare the instance in a .hpp and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// produce an enumeration value which has the same number.  Then in a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// .cpp the the register instance can be defined using the enumeration
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// value.  This avoids the use of static constructors and multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// definitions per .cpp.  In addition #defines for the register can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// produced so that the constant registers can be inlined.  These
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// macros should not be used inside other macros, because you may get
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// multiple evaluations of the macros which can give bad results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// Here are some example uses and expansions.  Note that the macro
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// invocation is terminated with a ;.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// CONSTANT_REGISTER_DECLARATION(Register, G0, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
// extern const Register G0 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// enum { G0_RegisterEnumValue = 0 } ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// REGISTER_DECLARATION(Register, Gmethod, G5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// extern const Register Gmethod ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// enum { Gmethod_RegisterEnumValue = G5_RegisterEnumValue } ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
// REGISTER_DEFINITION(Register, G0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// const Register G0 = ( ( Register ) G0_RegisterEnumValue ) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
#define AS_REGISTER(type,name)         ((type)name##_##type##EnumValue)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
#define CONSTANT_REGISTER_DECLARATION(type, name, value) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
extern const type name;                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
enum { name##_##type##EnumValue = (value) }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
#define REGISTER_DECLARATION(type, name, value) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
extern const type name;                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
enum { name##_##type##EnumValue = value##_##type##EnumValue }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
#define REGISTER_DEFINITION(type, name) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
const type name = ((type)name##_##type##EnumValue)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// Debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
inline void assert_different_registers(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  AbstractRegister a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  AbstractRegister b
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  assert(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    a != b,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    "registers must be different"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
inline void assert_different_registers(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  AbstractRegister a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  AbstractRegister b,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  AbstractRegister c
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  assert(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    a != b && a != c
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
           && b != c,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    "registers must be different"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
inline void assert_different_registers(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  AbstractRegister a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  AbstractRegister b,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  AbstractRegister c,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  AbstractRegister d
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  assert(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    a != b && a != c && a != d
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
           && b != c && b != d
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                     && c != d,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    "registers must be different"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
inline void assert_different_registers(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  AbstractRegister a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  AbstractRegister b,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  AbstractRegister c,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  AbstractRegister d,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  AbstractRegister e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  assert(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    a != b && a != c && a != d && a != e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
           && b != c && b != d && b != e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
                     && c != d && c != e
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
                               && d != e,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    "registers must be different"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
inline void assert_different_registers(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  AbstractRegister a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  AbstractRegister b,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  AbstractRegister c,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  AbstractRegister d,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  AbstractRegister e,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  AbstractRegister f
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  assert(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    a != b && a != c && a != d && a != e && a != f
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
           && b != c && b != d && b != e && b != f
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
                     && c != d && c != e && c != f
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                               && d != e && d != f
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                                         && e != f,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    "registers must be different"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
inline void assert_different_registers(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  AbstractRegister a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  AbstractRegister b,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  AbstractRegister c,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  AbstractRegister d,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  AbstractRegister e,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  AbstractRegister f,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  AbstractRegister g
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  assert(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    a != b && a != c && a != d && a != e && a != f && a != g
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
           && b != c && b != d && b != e && b != f && b != g
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
                     && c != d && c != e && c != f && c != g
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
                               && d != e && d != f && d != g
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
                                         && e != f && e != g
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
                                                   && f != g,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    "registers must be different"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
inline void assert_different_registers(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  AbstractRegister a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  AbstractRegister b,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  AbstractRegister c,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  AbstractRegister d,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  AbstractRegister e,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  AbstractRegister f,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  AbstractRegister g,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  AbstractRegister h
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  assert(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    a != b && a != c && a != d && a != e && a != f && a != g && a != h
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
           && b != c && b != d && b != e && b != f && b != g && b != h
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                     && c != d && c != e && c != f && c != g && c != h
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                               && d != e && d != f && d != g && d != h
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                                         && e != f && e != g && e != h
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
                                                   && f != g && f != h
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                                                             && g != h,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    "registers must be different"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}