1108 JAVA_INTEGER_OP(-, java_subtract, jlong, julong) |
1108 JAVA_INTEGER_OP(-, java_subtract, jlong, julong) |
1109 JAVA_INTEGER_OP(*, java_multiply, jlong, julong) |
1109 JAVA_INTEGER_OP(*, java_multiply, jlong, julong) |
1110 |
1110 |
1111 #undef JAVA_INTEGER_OP |
1111 #undef JAVA_INTEGER_OP |
1112 |
1112 |
|
1113 // Provide integer shift operations with Java semantics. No overflow |
|
1114 // issues - left shifts simply discard shifted out bits. No undefined |
|
1115 // behavior for large or negative shift quantities; instead the actual |
|
1116 // shift distance is the argument modulo the lhs value's size in bits. |
|
1117 // No undefined or implementation defined behavior for shifting negative |
|
1118 // values; left shift discards bits, right shift sign extends. We use |
|
1119 // the same safe conversion technique as above for java_add and friends. |
|
1120 #define JAVA_INTEGER_SHIFT_OP(OP, NAME, TYPE, XTYPE) \ |
|
1121 inline TYPE NAME (TYPE lhs, jint rhs) { \ |
|
1122 const uint rhs_mask = (sizeof(TYPE) * 8) - 1; \ |
|
1123 STATIC_ASSERT(rhs_mask == 31 || rhs_mask == 63); \ |
|
1124 XTYPE xres = static_cast<XTYPE>(lhs); \ |
|
1125 xres OP ## = (rhs & rhs_mask); \ |
|
1126 return reinterpret_cast<TYPE&>(xres); \ |
|
1127 } |
|
1128 |
|
1129 JAVA_INTEGER_SHIFT_OP(<<, java_shift_left, jint, juint) |
|
1130 JAVA_INTEGER_SHIFT_OP(<<, java_shift_left, jlong, julong) |
|
1131 // For signed shift right, assume C++ implementation >> sign extends. |
|
1132 JAVA_INTEGER_SHIFT_OP(>>, java_shift_right, jint, jint) |
|
1133 JAVA_INTEGER_SHIFT_OP(>>, java_shift_right, jlong, jlong) |
|
1134 // For >>> use C++ unsigned >>. |
|
1135 JAVA_INTEGER_SHIFT_OP(>>, java_shift_right_unsigned, jint, juint) |
|
1136 JAVA_INTEGER_SHIFT_OP(>>, java_shift_right_unsigned, jlong, julong) |
|
1137 |
|
1138 #undef JAVA_INTEGER_SHIFT_OP |
|
1139 |
1113 //---------------------------------------------------------------------------------------------------- |
1140 //---------------------------------------------------------------------------------------------------- |
1114 // The goal of this code is to provide saturating operations for int/uint. |
1141 // The goal of this code is to provide saturating operations for int/uint. |
1115 // Checks overflow conditions and saturates the result to min_jint/max_jint. |
1142 // Checks overflow conditions and saturates the result to min_jint/max_jint. |
1116 #define SATURATED_INTEGER_OP(OP, NAME, TYPE1, TYPE2) \ |
1143 #define SATURATED_INTEGER_OP(OP, NAME, TYPE1, TYPE2) \ |
1117 inline int NAME (TYPE1 in1, TYPE2 in2) { \ |
1144 inline int NAME (TYPE1 in1, TYPE2 in2) { \ |