javaop.h 5.34 KB
Newer Older
Anthony Green committed
1 2
/* Utility macros to handle Java(TM) byte codes.

3
   Copyright (C) 1996, 1998, 1999, 2003 Free Software Foundation, Inc.
Anthony Green committed
4

5 6 7
This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
Anthony Green committed
8 9 10 11
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

12
GCC is distributed in the hope that it will be useful,
Anthony Green committed
13 14 15 16 17
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING.  If not, write to
Kelley Cook committed
19 20
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  
Anthony Green committed
21 22 23 24 25 26 27

Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc.  */

/* Written by Per Bothner <bothner@cygnus.com>, February 1996. */

28 29
#ifndef GCC_JAVAOP_H
#define GCC_JAVAOP_H
Anthony Green committed
30 31 32

typedef	unsigned char	uint8;
#ifndef int16
33
#if __SHRT_MAX__ == 32767
Anthony Green committed
34
#define int16 short
35 36 37 38 39 40 41
#elif __INT_MAX__ == 32767
#define int16 int
#elif __LONG_MAX__ == 32767
#define int16 long
#else
#define int16 short
#endif
Anthony Green committed
42 43 44 45
#endif
typedef unsigned int16	uint16;

#ifndef int32
46 47 48
#if __INT_MAX__ == 2147483647
#define int32 int
#elif __LONG_MAX__ == 2147483647
Anthony Green committed
49
#define int32 long
50 51 52 53 54
#elif __SHRT_MAX__ == 2147483647
#define int32 short
#else
#define int32 int
#endif
Anthony Green committed
55 56 57
#endif
typedef unsigned int32	uint32;

58
/* A signed 64-bit (or more) integral type, suitable for Java's 'long'.  */
Anthony Green committed
59
#ifndef int64
60 61 62
#if __LONG_MAX__ == 9223372036854775807LL
#define int64 long
#elif __LONG_LONG_MAX__ == 9223372036854775807LL
Anthony Green committed
63
#define int64 long long
64 65 66
#else
#define int64 long long
#endif
Anthony Green committed
67 68 69 70 71 72 73
#endif
/* An unsigned 64-bit (or more) integral type, same length as int64. */
#ifndef uint64
#define uint64 unsigned int64
#endif

typedef uint16			jchar;
74
typedef	signed char		jbyte;
Anthony Green committed
75 76 77 78 79
typedef int16                   jshort;
typedef int32                   jint;
typedef int64                   jlong;
typedef void*                   jref;

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
/* A 32-bit big-endian IEEE single-precision float. */
typedef struct _jfloat {
  unsigned int negative : 1;
  unsigned int exponent : 8;
  unsigned int mantissa : 23;
} jfloat;
#define JFLOAT_FINITE(f) ((f).exponent != 0xFF)
#define JFLOAT_QNAN_MASK 0x400000
#define JFLOAT_EXP_BIAS 0x7f

/* A 32-bit big-endian IEEE double-precision float. */
typedef struct _jdouble {
  unsigned int negative : 1;
  unsigned int exponent : 11;
  unsigned int mantissa0: 20;
  unsigned int mantissa1: 32;
} jdouble;
#define JDOUBLE_FINITE(f) ((f).exponent != 0x7FF)
#define JDOUBLE_QNAN_MASK 0x80000  /* apply to mantissa0 */
#define JDOUBLE_EXP_BIAS 0x3ff
Anthony Green committed
100 101 102 103 104 105 106

/* A jword is an unsigned integral type big enough for a 32-bit jint
   or jfloat *or* a pointer.  It is the type appropriate for stack
   locations and local variables in a Java interpreter. */


#ifndef jword
107 108 109 110 111 112
#if defined (__LP64__) || defined (__alpha__) || defined (__MMIX__) \
    || (defined (_ARCH_PPC) && defined (__64BIT__)) \
    || defined (__powerpc64__) || defined (__s390x__) || defined (__x86_64__) \
    || defined (__sparcv9) || (defined (__sparc__) && defined (__arch64__))
#define jword uint64
#else
Anthony Green committed
113 114
#define jword uint32
#endif
115
#endif
Anthony Green committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

#ifndef IMMEDIATE_u1
#define IMMEDIATE_u1 (PC++, CHECK_PC_IN_RANGE(PC), BCODE[PC-1])
#endif
#ifndef IMMEDIATE_s1
#define IMMEDIATE_s1 (PC++, CHECK_PC_IN_RANGE(PC), (signed char)BCODE[PC-1])
#endif
#ifndef IMMEDIATE_s2
#define IMMEDIATE_s2 (PC+=2, CHECK_PC_IN_RANGE(PC), \
  (signed char) BCODE[PC-2] * 256 + BCODE[PC-1])
#endif
#ifndef IMMEDIATE_u2
#define IMMEDIATE_u2 (PC+=2, CHECK_PC_IN_RANGE(PC),\
  (BCODE[PC-2] * 256 + BCODE[PC-1]))
#endif
#ifndef IMMEDIATE_s4
#define IMMEDIATE_s4 (PC+=4, CHECK_PC_IN_RANGE(PC), \
133
  (WORD_TO_INT((BCODE[PC-4] << 24) | (BCODE[PC-3] << 16) \
Anthony Green committed
134 135 136
         | (BCODE[PC-2] << 8) | (BCODE[PC-1]))))
#endif

137
static inline jfloat
Anthony Green committed
138
WORD_TO_FLOAT(jword w)
139 140 141 142 143 144 145 146
{
  jfloat f;

  f.negative = (w & 0x80000000) >> 31;
  f.exponent = (w & 0x7f800000) >> 23;
  f.mantissa = (w & 0x007fffff);

  return f;
Anthony Green committed
147 148
} 

149 150 151 152
/* Sign extend w.  If the host on which this cross-compiler runs uses
   a 64-bit type for jword the appropriate sign extension is
   performed; if it's a 32-bit type the arithmetic does nothing but is
   harmless.  */
153 154 155
static inline jint
WORD_TO_INT(jword w)
{
156
  jint n = w & 0xffffffff; /* Mask lower 32 bits.  */
157
  n ^= (jint)1 << 31;
158
  n -= (jint)1 << 31; /* Sign extend lower 32 bits to upper.  */
159 160 161
  return n;
} 

162
static inline jlong
Anthony Green committed
163 164 165 166 167
WORDS_TO_LONG(jword hi, jword lo)
{
  return ((jlong) hi << 32) | ((jlong)lo & (((jlong)1 << 32) -1));
}

168
static inline jdouble
Anthony Green committed
169
WORDS_TO_DOUBLE(jword hi, jword lo)
170 171 172 173 174 175 176 177 178
{
  jdouble d;

  d.negative  = (hi & 0x80000000) >> 31;
  d.exponent  = (hi & 0x7ff00000) >> 20;
  d.mantissa0 = (hi & 0x000fffff);
  d.mantissa1 = lo;

  return d;
Anthony Green committed
179 180 181 182 183 184 185 186 187 188 189 190
} 

/* If PREFIX_CHAR is the first character of the Utf8 encoding of a character,
   return the number of bytes taken by the encoding.
   Return -1 for a continuation character.  */
#define UT8_CHAR_LENGTH(PREFIX_CHAR) \
  ((unsigned char)(PREFIX_CHAR) < 128 ? 1 \
   : ((PREFIX_CHAR) & 0x40) == 0 ? -1 \
   : ((PREFIX_CHAR) & 0x20) == 0 ? 2 \
   : ((PREFIX_CHAR) & 0x10) == 0 ? 3 \
   : ((PREFIX_CHAR) & 0x08) == 0 ? 4 : 5)

191
#endif /* ! GCC_JAVAOP_H */