Merge from mainline.
[official-gcc.git] / gcc / java / javaop.h
blob12e001600beee6cfa394ce8ec3ac70109c66b93b
1 /* Utility macros to handle Java(TM) byte codes.
3 Copyright (C) 1996, 1998, 1999, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
28 #ifndef GCC_JAVAOP_H
29 #define GCC_JAVAOP_H
31 typedef unsigned char uint8;
32 #ifndef int16
33 #if __SHRT_MAX__ == 32767
34 #define int16 short
35 #elif __INT_MAX__ == 32767
36 #define int16 int
37 #elif __LONG_MAX__ == 32767
38 #define int16 long
39 #else
40 #define int16 short
41 #endif
42 #endif
43 typedef unsigned int16 uint16;
45 #ifndef int32
46 #if __INT_MAX__ == 2147483647
47 #define int32 int
48 #elif __LONG_MAX__ == 2147483647
49 #define int32 long
50 #elif __SHRT_MAX__ == 2147483647
51 #define int32 short
52 #else
53 #define int32 int
54 #endif
55 #endif
56 typedef unsigned int32 uint32;
58 /* A signed 64-bit (or more) integral type, suitable for Java's 'long'. */
59 #ifndef int64
60 #if __LONG_MAX__ == 9223372036854775807LL
61 #define int64 long
62 #elif __LONG_LONG_MAX__ == 9223372036854775807LL
63 #define int64 long long
64 #else
65 #define int64 long long
66 #endif
67 #endif
68 /* An unsigned 64-bit (or more) integral type, same length as int64. */
69 #ifndef uint64
70 #define uint64 unsigned int64
71 #endif
73 typedef uint16 jchar;
74 typedef signed char jbyte;
75 typedef int16 jshort;
76 typedef int32 jint;
77 typedef int64 jlong;
78 typedef void* jref;
80 /* A 32-bit big-endian IEEE single-precision float. */
81 typedef struct _jfloat {
82 unsigned int negative : 1;
83 unsigned int exponent : 8;
84 unsigned int mantissa : 23;
85 } jfloat;
86 #define JFLOAT_FINITE(f) ((f).exponent != 0xFF)
87 #define JFLOAT_QNAN_MASK 0x400000
88 #define JFLOAT_EXP_BIAS 0x7f
90 /* A 32-bit big-endian IEEE double-precision float. */
91 typedef struct _jdouble {
92 unsigned int negative : 1;
93 unsigned int exponent : 11;
94 unsigned int mantissa0: 20;
95 unsigned int mantissa1: 32;
96 } jdouble;
97 #define JDOUBLE_FINITE(f) ((f).exponent != 0x7FF)
98 #define JDOUBLE_QNAN_MASK 0x80000 /* apply to mantissa0 */
99 #define JDOUBLE_EXP_BIAS 0x3ff
101 /* A jword is an unsigned integral type big enough for a 32-bit jint
102 or jfloat *or* a pointer. It is the type appropriate for stack
103 locations and local variables in a Java interpreter. */
106 #ifndef jword
107 #if defined (__LP64__) || defined (__alpha__) || defined (__MMIX__) \
108 || (defined (_ARCH_PPC) && defined (__64BIT__)) \
109 || defined (__powerpc64__) || defined (__s390x__) || defined (__x86_64__) \
110 || defined (__sparcv9) || (defined (__sparc__) && defined (__arch64__))
111 #define jword uint64
112 #else
113 #define jword uint32
114 #endif
115 #endif
117 #ifndef IMMEDIATE_u1
118 #define IMMEDIATE_u1 (PC++, CHECK_PC_IN_RANGE(PC), BCODE[PC-1])
119 #endif
120 #ifndef IMMEDIATE_s1
121 #define IMMEDIATE_s1 (PC++, CHECK_PC_IN_RANGE(PC), (signed char)BCODE[PC-1])
122 #endif
123 #ifndef IMMEDIATE_s2
124 #define IMMEDIATE_s2 (PC+=2, CHECK_PC_IN_RANGE(PC), \
125 (signed char) BCODE[PC-2] * 256 + BCODE[PC-1])
126 #endif
127 #ifndef IMMEDIATE_u2
128 #define IMMEDIATE_u2 (PC+=2, CHECK_PC_IN_RANGE(PC),\
129 (BCODE[PC-2] * 256 + BCODE[PC-1]))
130 #endif
131 #ifndef IMMEDIATE_s4
132 #define IMMEDIATE_s4 (PC+=4, CHECK_PC_IN_RANGE(PC), \
133 (WORD_TO_INT((BCODE[PC-4] << 24) | (BCODE[PC-3] << 16) \
134 | (BCODE[PC-2] << 8) | (BCODE[PC-1]))))
135 #endif
137 static inline jfloat
138 WORD_TO_FLOAT(jword w)
140 jfloat f;
142 f.negative = (w & 0x80000000) >> 31;
143 f.exponent = (w & 0x7f800000) >> 23;
144 f.mantissa = (w & 0x007fffff);
146 return f;
149 /* Sign extend w. If the host on which this cross-compiler runs uses
150 a 64-bit type for jword the appropriate sign extension is
151 performed; if it's a 32-bit type the arithmetic does nothing but is
152 harmless. */
153 static inline jint
154 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 return n;
162 static inline jlong
163 WORDS_TO_LONG(jword hi, jword lo)
165 return ((jlong) hi << 32) | ((jlong)lo & (((jlong)1 << 32) -1));
168 static inline jdouble
169 WORDS_TO_DOUBLE(jword hi, jword lo)
171 jdouble d;
173 d.negative = (hi & 0x80000000) >> 31;
174 d.exponent = (hi & 0x7ff00000) >> 20;
175 d.mantissa0 = (hi & 0x000fffff);
176 d.mantissa1 = lo;
178 return d;
181 /* If PREFIX_CHAR is the first character of the Utf8 encoding of a character,
182 return the number of bytes taken by the encoding.
183 Return -1 for a continuation character. */
184 #define UT8_CHAR_LENGTH(PREFIX_CHAR) \
185 ((unsigned char)(PREFIX_CHAR) < 128 ? 1 \
186 : ((PREFIX_CHAR) & 0x40) == 0 ? -1 \
187 : ((PREFIX_CHAR) & 0x20) == 0 ? 2 \
188 : ((PREFIX_CHAR) & 0x10) == 0 ? 3 \
189 : ((PREFIX_CHAR) & 0x08) == 0 ? 4 : 5)
191 #endif /* ! GCC_JAVAOP_H */