1 /* generic_math_int64.h - Native methods for 64bit math operations 2 Copyright (C) 1998 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 /* 39 Description: generic target defintions of int/int64 constants/ 40 macros/functions 41 Systems : all 42 */ 43 44 #ifndef __TARGET_GENERIC_MATH_INT__ 45 #define __TARGET_GENERIC_MATH_INT__ 46 47 /* check if target_native_math_int.h included */ 48 #ifndef __TARGET_NATIVE_MATH_INT__ 49 #error Do NOT INCLUDE generic target files! Include the corresponding native target files instead! 50 #endif 51 52 /****************************** Includes *******************************/ 53 /* do not move; needed here because of some macro definitions */ 54 #include "config.h" 55 56 #include <stdlib.h> 57 #include <assert.h> 58 59 /****************** Conditional compilation switches *******************/ 60 61 /***************************** Constants *******************************/ 62 #ifndef TARGET_NATIVE_MATH_INT_INT64_CONST_0 63 #define TARGET_NATIVE_MATH_INT_INT64_CONST_0 0LL 64 #endif 65 #ifndef TARGET_NATIVE_MATH_INT_INT64_CONST_1 66 #define TARGET_NATIVE_MATH_INT_INT64_CONST_1 1LL 67 #endif 68 #ifndef TARGET_NATIVE_MATH_INT_INT64_CONST_MINUS_1 69 #define TARGET_NATIVE_MATH_INT_INT64_CONST_MINUS_1 -1LL 70 #endif 71 72 /***************************** Datatypes *******************************/ 73 74 /***************************** Variables *******************************/ 75 76 /****************************** Macros *********************************/ 77 78 /* math operations */ 79 #ifndef TARGET_NATIVE_MATH_INT_INT64_ADD 80 #define TARGET_NATIVE_MATH_INT_INT64_ADD(v1,v2) ((v1)+(v2)) 81 #endif 82 #ifndef TARGET_NATIVE_MATH_INT_INT64_SUB 83 #define TARGET_NATIVE_MATH_INT_INT64_SUB(v1,v2) ((v1)-(v2)) 84 #endif 85 #ifndef TARGET_NATIVE_MATH_INT_INT64_MUL 86 #define TARGET_NATIVE_MATH_INT_INT64_MUL(v1,v2) ((v1)*(v2)) 87 #endif 88 #ifndef TARGET_NATIVE_MATH_INT_INT64_DIV 89 #define TARGET_NATIVE_MATH_INT_INT64_DIV(v1,v2) ((v1)/(v2)) 90 #endif 91 #ifndef TARGET_NATIVE_MATH_INT_INT64_MOD 92 #define TARGET_NATIVE_MATH_INT_INT64_MOD(v1,v2) ((v1)%(v2)) 93 #endif 94 95 #ifndef TARGET_NATIVE_MATH_INT_UINT64_ADD 96 #define TARGET_NATIVE_MATH_INT_UINT64_ADD(v1,v2) ((v1)+(v2)) 97 #endif 98 #ifndef TARGET_NATIVE_MATH_INT_UINT64_SUB 99 #define TARGET_NATIVE_MATH_INT_UINT64_SUB(v1,v2) ((v1)-(v2)) 100 #endif 101 #ifndef TARGET_NATIVE_MATH_INT_UINT64_MUL 102 #define TARGET_NATIVE_MATH_INT_UINT64_MUL(v1,v2) ((v1)*(v2)) 103 #endif 104 #ifndef TARGET_NATIVE_MATH_INT_UINT64_DIV 105 #define TARGET_NATIVE_MATH_INT_UINT64_DIV(v1,v2) ((v1)/(v2)) 106 #endif 107 #ifndef TARGET_NATIVE_MATH_INT_UINT64_MOD 108 #define TARGET_NATIVE_MATH_INT_UINT64_MOD(v1,v2) ((v1)%(v2)) 109 #endif 110 111 /* bit operations */ 112 #ifndef TARGET_NATIVE_MATH_INT_INT64_AND 113 #define TARGET_NATIVE_MATH_INT_INT64_AND(v1,v2) ((v1)&(v2)) 114 #endif 115 #ifndef TARGET_NATIVE_MATH_INT_INT64_OR 116 #define TARGET_NATIVE_MATH_INT_INT64_OR(v1,v2) ((v1)|(v2)) 117 #endif 118 #ifndef TARGET_NATIVE_MATH_INT_INT64_XOR 119 #define TARGET_NATIVE_MATH_INT_INT64_XOR(v1,v2) ((v1)^(v2)) 120 #endif 121 122 #ifndef TARGET_NATIVE_MATH_INT_UINT64_AND 123 #define TARGET_NATIVE_MATH_INT_UINT64_AND(v1,v2) ((v1)&(v2)) 124 #endif 125 #ifndef TARGET_NATIVE_MATH_INT_UINT64_OR 126 #define TARGET_NATIVE_MATH_INT_UINT64_OR(v1,v2) ((v1)|(v2)) 127 #endif 128 #ifndef TARGET_NATIVE_MATH_INT_UINT64_XOR 129 #define TARGET_NATIVE_MATH_INT_UINT64_XOR(v1,v2) ((v1)^(v2)) 130 #endif 131 132 /* shift operations */ 133 #ifndef TARGET_NATIVE_MATH_INT_INT64_SHIFTL 134 #define TARGET_NATIVE_MATH_INT_INT64_SHIFTL(v,l) ((v)<<(l)) 135 #endif 136 #ifndef TARGET_NATIVE_MATH_INT_INT64_SHIFTR 137 #define TARGET_NATIVE_MATH_INT_INT64_SHIFTR(v,l) (((v)>>(l)) | (((v)>=0) ? 0 : (0xffffFFFFffffFFFFLL << (64-(l))))) 138 #endif 139 #ifndef TARGET_NATIVE_MATH_INT_UINT64_SHIFTR 140 #define TARGET_NATIVE_MATH_INT_UINT64_SHIFTR(v,l) (((v)>>(l)) & ~(((v)>=0) ? 0 : (0xffffFFFFffffFFFFLL << (64-(l))))) 141 #endif 142 143 /* negation */ 144 #ifndef TARGET_NATIVE_MATH_INT_INT64_NEG 145 #define TARGET_NATIVE_MATH_INT_INT64_NEG(v) (-(v)) 146 #endif 147 148 /* increment/decrement routines */ 149 #ifndef TARGET_NATIVE_MATH_INT_INT64_INC 150 #define TARGET_NATIVE_MATH_INT_INT64_INC(v) { v++; } 151 #endif 152 #ifndef TARGET_NATIVE_MATH_INT_INT64_DEC 153 #define TARGET_NATIVE_MATH_INT_INT64_DEC(v) { v--; } 154 #endif 155 156 #ifndef TARGET_NATIVE_MATH_INT_UINT64_INC 157 #define TARGET_NATIVE_MATH_INT_UINT64_INC(v) { v++; } 158 #endif 159 #ifndef TARGET_NATIVE_MATH_INT_UINT64_DEC 160 #define TARGET_NATIVE_MATH_INT_UINT64_DEC(v) { v--; } 161 #endif 162 163 /* comparison routines */ 164 #ifndef TARGET_NATIVE_MATH_INT_INT64_EQ 165 #define TARGET_NATIVE_MATH_INT_INT64_EQ(v1,v2) ((v1) == (v2)) 166 #endif 167 #ifndef TARGET_NATIVE_MATH_INT_INT64_NE 168 #define TARGET_NATIVE_MATH_INT_INT64_NE(v1,v2) ((v1) != (v2)) 169 #endif 170 #ifndef TARGET_NATIVE_MATH_INT_INT64_LT 171 #define TARGET_NATIVE_MATH_INT_INT64_LT(v1,v2) ((v1) < (v2)) 172 #endif 173 #ifndef TARGET_NATIVE_MATH_INT_INT64_LE 174 #define TARGET_NATIVE_MATH_INT_INT64_LE(v1,v2) ((v1) <= (v2)) 175 #endif 176 #ifndef TARGET_NATIVE_MATH_INT_INT64_GT 177 #define TARGET_NATIVE_MATH_INT_INT64_GT(v1,v2) ((v1) > (v2)) 178 #endif 179 #ifndef TARGET_NATIVE_MATH_INT_INT64_GE 180 #define TARGET_NATIVE_MATH_INT_INT64_GE(v1,v2) ((v1) >= (v2)) 181 #endif 182 183 #ifndef TARGET_NATIVE_MATH_INT_UINT64_EQ 184 #define TARGET_NATIVE_MATH_INT_UINT64_EQ(v1,v2) ((v1) == (v2)) 185 #endif 186 #ifndef TARGET_NATIVE_MATH_INT_UINT64_NE 187 #define TARGET_NATIVE_MATH_INT_UINT64_NE(v1,v2) ((v1) != (v2)) 188 #endif 189 #ifndef TARGET_NATIVE_MATH_INT_UINT64_LT 190 #define TARGET_NATIVE_MATH_INT_UINT64_LT(v1,v2) ((v1) < (v2)) 191 #endif 192 #ifndef TARGET_NATIVE_MATH_INT_UINT64_LE 193 #define TARGET_NATIVE_MATH_INT_UINT64_LE(v1,v2) ((v1) <= (v2)) 194 #endif 195 #ifndef TARGET_NATIVE_MATH_INT_UINT64_GT 196 #define TARGET_NATIVE_MATH_INT_UINT64_GT(v1,v2) ((v1) > (v2)) 197 #endif 198 #ifndef TARGET_NATIVE_MATH_INT_UINT64_GE 199 #define TARGET_NATIVE_MATH_INT_UINT64_GE(v1,v2) ((v1) >= (v2)) 200 #endif 201 202 /* type conversion routines */ 203 #ifndef TARGET_NATIVE_MATH_INT_INT32_TO_INT64 204 #define TARGET_NATIVE_MATH_INT_INT32_TO_INT64(v) ((jlong)(v)) 205 #endif 206 #ifndef TARGET_NATIVE_MATH_INT_UINT32_TO_UINT64 207 #define TARGET_NATIVE_MATH_INT_UINT32_TO_UINT64(v) ((jlong)(v)) 208 #endif 209 #ifndef TARGET_NATIVE_MATH_INT_INT64_TO_INT32 210 #define TARGET_NATIVE_MATH_INT_INT64_TO_INT32(v) ((jint )(v)) 211 #endif 212 #ifndef TARGET_NATIVE_MATH_INT_UINT64_TO_UINT32 213 #define TARGET_NATIVE_MATH_INT_UINT64_TO_UINT32(v) ((jint)(v)) 214 #endif 215 #ifndef TARGET_NATIVE_MATH_INT_INT64_TO_DOUBLE 216 #define TARGET_NATIVE_MATH_INT_INT64_TO_DOUBLE(v) ((jdouble)(v)) 217 #endif 218 219 /* combine/split int32 low/high values <-> int64 values */ 220 #ifndef TARGET_NATIVE_MATH_INT_INT32_LOW_HIGH_TO_INT64 221 #define TARGET_NATIVE_MATH_INT_INT32_LOW_HIGH_TO_INT64(low,high,v) \ 222 do { \ 223 (v)=((((jlong)(high)) << 32) | ((((jlong)(low)) << 0) & 0x00000000ffffFFFFLL)); \ 224 } while (0) 225 #endif 226 #ifndef TARGET_NATIVE_MATH_INT_UINT32_LOW_HIGH_TO_UINT64 227 #define TARGET_NATIVE_MATH_INT_UINT32_LOW_HIGH_TO_UINT64(low,high,v) \ 228 do { \ 229 (v)=((((jlong)(high)) << 32) | ((((jlong)(low)) << 0) & 0x00000000ffffFFFFLL)); \ 230 } while (0) 231 #endif 232 #ifndef TARGET_NATIVE_MATH_INT_INT64_TO_INT32_LOW_HIGH 233 #define TARGET_NATIVE_MATH_INT_INT64_TO_INT32_LOW_HIGH(v,low,high) \ 234 do { \ 235 (high)=((v) & 0xFFFFffff00000000L) >> 32; \ 236 (low) =((v) & 0x00000000FFFFffffL) >> 0; \ 237 } while (0) 238 #endif 239 #ifndef TARGET_NATIVE_MATH_INT_UINT64_TO_UINT32_LOW_HIGH 240 #define TARGET_NATIVE_MATH_INT_UINT64_TO_UINT32_LOW_HIGH(v,low,high) \ 241 do { \ 242 (high)=((v) & 0xFFFFffff00000000L) >> 32; \ 243 (low) =((v) & 0x00000000FFFFffffL) >> 0; \ 244 } while (0) 245 #endif 246 247 /***************************** Functions *******************************/ 248 249 #ifdef __cplusplus 250 extern "C" 251 #endif 252 253 #ifdef __cplusplus 254 } 255 #endif 256 257 #endif /* __TARGET_GENERIC_MATH_INT__ */ 258 259 /* end of file */ 260 261