/* * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
staticbool will_overflow(NativeType value1, NativeType value2) {
NativeType result = value1 + value2; // Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result if (((value1 ^ result) & (value2 ^ result)) >= 0) { returnfalse;
} returntrue;
}
staticbool will_overflow(NativeType value1, NativeType value2) {
NativeType result = value1 - value2; // hacker's delight 2-12 overflow iff the arguments have different signs and // the sign of the result is different than the sign of arg1 if (((value1 ^ value2) & (value1 ^ result)) >= 0) { returnfalse;
} returntrue;
}
bool OverflowMulLNode::is_overflow(jlong val1, jlong val2) { // x * { 0, 1 } will never overflow. Even for x = min_jlong if (val1 == 0 || val2 == 0 || val1 == 1 || val2 == 1) { returnfalse;
}
// x * min_jlong for x not in { 0, 1 } overflows // even -1 as -1 * min_jlong is an overflow if (val1 == min_jlong || val2 == min_jlong) { returntrue;
}
// if (x * y) / y == x there is no overflow // // the multiplication here is done as unsigned to avoid undefined behaviour which // can be used by the compiler to assume that the check further down (result / val2 != val1) // is always false and breaks the overflow check
julong v1 = (julong) val1;
julong v2 = (julong) val2;
julong tmp = v1 * v2;
jlong result = (jlong) tmp;
const Type* OverflowNode::sub(const Type* t1, const Type* t2) const {
fatal("sub() should not be called for '%s'", NodeClassNames[this->Opcode()]); return TypeInt::CC;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.