Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8183574: Unify the is_power_of_2 functions
Browse files Browse the repository at this point in the history
Reviewed-by: kbarrett, redestad
  • Loading branch information
stefank committed Feb 17, 2020
1 parent 248b617 commit e4b27a4
Show file tree
Hide file tree
Showing 100 changed files with 183 additions and 75 deletions.
6 changes: 3 additions & 3 deletions src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp
Expand Up @@ -40,10 +40,10 @@
#include "oops/objArrayKlass.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_aarch64.inline.hpp"



#ifndef PRODUCT
#define COMMENT(x) do { __ block_comment(x); } while (0)
#else
Expand Down Expand Up @@ -1747,7 +1747,7 @@ void LIR_Assembler::arith_op(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Opr
code == lir_add ? __ add(dreg, lreg_lo, c) : __ sub(dreg, lreg_lo, c);
break;
case lir_div:
assert(c > 0 && is_power_of_2_long(c), "divisor must be power-of-2 constant");
assert(c > 0 && is_power_of_2(c), "divisor must be power-of-2 constant");
if (c == 1) {
// move lreg_lo to dreg if divisor is 1
__ mov(dreg, lreg_lo);
Expand All @@ -1760,7 +1760,7 @@ void LIR_Assembler::arith_op(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Opr
}
break;
case lir_rem:
assert(c > 0 && is_power_of_2_long(c), "divisor must be power-of-2 constant");
assert(c > 0 && is_power_of_2(c), "divisor must be power-of-2 constant");
if (c == 1) {
// move 0 to dreg if divisor is 1
__ mov(dreg, zr);
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp
Expand Up @@ -37,6 +37,7 @@
#include "ci/ciTypeArrayKlass.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_aarch64.inline.hpp"

#ifdef ASSERT
Expand Down Expand Up @@ -447,7 +448,7 @@ void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
// no need to do div-by-zero check if the divisor is a non-zero constant
if (c != 0) need_zero_check = false;
// do not load right if the divisor is a power-of-2 constant
if (c > 0 && is_power_of_2_long(c)) {
if (c > 0 && is_power_of_2(c)) {
right.dont_load_item();
} else {
right.load_item();
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp
Expand Up @@ -43,6 +43,7 @@
#include "runtime/signature.hpp"
#include "runtime/vframe.hpp"
#include "runtime/vframeArray.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_aarch64.inline.hpp"


Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp
Expand Up @@ -43,7 +43,7 @@
#include "runtime/safepointMechanism.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/thread.inline.hpp"

#include "utilities/powerOfTwo.hpp"

void InterpreterMacroAssembler::narrow(Register result) {

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
Expand Up @@ -47,6 +47,7 @@
#include "runtime/jniHandles.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/thread.hpp"
#include "utilities/powerOfTwo.hpp"
#ifdef COMPILER1
#include "c1/c1_LIRAssembler.hpp"
#endif
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
Expand Up @@ -28,6 +28,7 @@

#include "asm/assembler.hpp"
#include "oops/compressedOops.hpp"
#include "utilities/powerOfTwo.hpp"

// MacroAssembler extends Assembler by frequently used macros.
//
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
Expand Up @@ -43,6 +43,7 @@
#include "runtime/stubRoutines.hpp"
#include "runtime/thread.inline.hpp"
#include "utilities/align.hpp"
#include "utilities/powerOfTwo.hpp"
#ifdef COMPILER2
#include "opto/runtime.hpp"
#endif
Expand Down
Expand Up @@ -49,6 +49,7 @@
#include "runtime/timer.hpp"
#include "runtime/vframeArray.hpp"
#include "utilities/debug.hpp"
#include "utilities/powerOfTwo.hpp"
#include <sys/types.h>

#ifndef PRODUCT
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/aarch64/templateTable_aarch64.cpp
Expand Up @@ -40,6 +40,7 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "utilities/powerOfTwo.hpp"

#define __ _masm->

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/c1_LIRAssembler_arm.cpp
Expand Up @@ -37,6 +37,7 @@
#include "oops/objArrayKlass.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_arm.inline.hpp"

#define __ _masm->
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/c1_LIRGenerator_arm.cpp
Expand Up @@ -40,6 +40,7 @@
#include "gc/shared/cardTableBarrierSet.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_arm.inline.hpp"

#ifdef ASSERT
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/c1_MacroAssembler_arm.cpp
Expand Up @@ -35,6 +35,7 @@
#include "runtime/os.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/powerOfTwo.hpp"

// Note: Rtemp usage is this file should not impact C2 and should be
// correct as long as it is not implicitly used in lower layers (the
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/interp_masm_arm.cpp
Expand Up @@ -44,6 +44,7 @@
#include "runtime/frame.inline.hpp"
#include "runtime/safepointMechanism.hpp"
#include "runtime/sharedRuntime.hpp"
#include "utilities/powerOfTwo.hpp"

//--------------------------------------------------------------------
// Implementation of InterpreterMacroAssembler
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/macroAssembler_arm.cpp
Expand Up @@ -46,6 +46,7 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"

// Implementation of AddressLiteral

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/macroAssembler_arm.hpp
Expand Up @@ -26,6 +26,7 @@
#define CPU_ARM_MACROASSEMBLER_ARM_HPP

#include "code/relocInfo.hpp"
#include "utilities/powerOfTwo.hpp"

class BiasedLockingCounters;

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/sharedRuntime_arm.cpp
Expand Up @@ -37,6 +37,7 @@
#include "runtime/safepointMechanism.hpp"
#include "runtime/vframeArray.hpp"
#include "utilities/align.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_arm.inline.hpp"
#ifdef COMPILER1
#include "c1/c1_Runtime1.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/stubGenerator_arm.cpp
Expand Up @@ -41,6 +41,7 @@
#include "runtime/stubCodeGenerator.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/align.hpp"
#include "utilities/powerOfTwo.hpp"
#ifdef COMPILER2
#include "opto/runtime.hpp"
#endif
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/arm/templateTable_arm.cpp
Expand Up @@ -39,6 +39,7 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "utilities/powerOfTwo.hpp"

#define __ _masm->

Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/cpu/ppc/assembler_ppc.cpp
Expand Up @@ -37,6 +37,7 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"

#ifdef PRODUCT
#define BLOCK_COMMENT(str) // nothing
Expand Down Expand Up @@ -78,13 +79,13 @@ int Assembler::branch_destination(int inst, int pos) {

// Low-level andi-one-instruction-macro.
void Assembler::andi(Register a, Register s, const long ui16) {
if (is_power_of_2_long(((jlong) ui16)+1)) {
if (is_power_of_2(((jlong) ui16)+1)) {
// pow2minus1
clrldi(a, s, 64-log2_long((((jlong) ui16)+1)));
} else if (is_power_of_2_long((jlong) ui16)) {
clrldi(a, s, 64-log2((((jlong) ui16)+1)));
} else if (is_power_of_2((jlong) ui16)) {
// pow2
rlwinm(a, s, 0, 31-log2_long((jlong) ui16), 31-log2_long((jlong) ui16));
} else if (is_power_of_2_long((jlong)-ui16)) {
} else if (is_power_of_2((jlong)-ui16)) {
// negpow2
clrrdi(a, s, log2_long((jlong)-ui16));
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp
Expand Up @@ -40,6 +40,7 @@
#include "runtime/frame.inline.hpp"
#include "runtime/safepointMechanism.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "utilities/powerOfTwo.hpp"

#define __ _masm->

Expand Down Expand Up @@ -1762,7 +1763,7 @@ void LIR_Assembler::logic_op(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Opr

switch (code) {
case lir_logic_and:
if (uimmss != 0 || (uimms != 0 && (uimm & 0xFFFF) != 0) || is_power_of_2_long(uimm)) {
if (uimmss != 0 || (uimms != 0 && (uimm & 0xFFFF) != 0) || is_power_of_2(uimm)) {
__ andi(d, l, uimm); // special cases
} else if (uimms != 0) { __ andis_(d, l, uimms); }
else { __ andi_(d, l, uimm); }
Expand Down
13 changes: 7 additions & 6 deletions src/hotspot/cpu/ppc/c1_LIRGenerator_ppc.cpp
Expand Up @@ -37,6 +37,7 @@
#include "ci/ciTypeArrayKlass.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_ppc.inline.hpp"

#ifdef ASSERT
Expand Down Expand Up @@ -574,13 +575,13 @@ inline bool can_handle_logic_op_as_uimm(ValueType *type, Bytecodes::Code bc) {

// see Assembler::andi
if (bc == Bytecodes::_iand &&
(is_power_of_2_long(int_or_long_const+1) ||
is_power_of_2_long(int_or_long_const) ||
is_power_of_2_long(-int_or_long_const))) return true;
(is_power_of_2(int_or_long_const+1) ||
is_power_of_2(int_or_long_const) ||
is_power_of_2(-int_or_long_const))) return true;
if (bc == Bytecodes::_land &&
(is_power_of_2_long(int_or_long_const+1) ||
(Assembler::is_uimm(int_or_long_const, 32) && is_power_of_2_long(int_or_long_const)) ||
(int_or_long_const != min_jlong && is_power_of_2_long(-int_or_long_const)))) return true;
(is_power_of_2(int_or_long_const+1) ||
(Assembler::is_uimm(int_or_long_const, 32) && is_power_of_2(int_or_long_const)) ||
(int_or_long_const != min_jlong && is_power_of_2(-int_or_long_const)))) return true;

// special case: xor -1
if ((bc == Bytecodes::_ixor || bc == Bytecodes::_lxor) &&
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp
Expand Up @@ -38,7 +38,7 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/align.hpp"

#include "utilities/powerOfTwo.hpp"

void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
const Register temp_reg = R12_scratch2;
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/ppc/c1_Runtime1_ppc.cpp
Expand Up @@ -42,6 +42,7 @@
#include "runtime/vframeArray.hpp"
#include "utilities/align.hpp"
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_ppc.inline.hpp"

// Implementation of StubAssembler
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
Expand Up @@ -34,6 +34,7 @@
#include "runtime/frame.inline.hpp"
#include "runtime/safepointMechanism.hpp"
#include "runtime/sharedRuntime.hpp"
#include "utilities/powerOfTwo.hpp"

// Implementation of InterpreterMacroAssembler.

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/ppc/macroAssembler_ppc.cpp
Expand Up @@ -44,6 +44,7 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"
#ifdef COMPILER2
#include "opto/intrinsicnode.hpp"
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/cpu/ppc/macroAssembler_ppc.inline.hpp
Expand Up @@ -35,6 +35,7 @@
#include "oops/accessDecorators.hpp"
#include "oops/compressedOops.hpp"
#include "runtime/safepointMechanism.hpp"
#include "utilities/powerOfTwo.hpp"

inline bool MacroAssembler::is_ld_largeoffset(address a) {
const int inst1 = *(int *)a;
Expand All @@ -56,7 +57,7 @@ inline int MacroAssembler::get_ld_largeoffset_offset(address a) {
}

inline void MacroAssembler::round_to(Register r, int modulus) {
assert(is_power_of_2_long((jlong)modulus), "must be power of 2");
assert(is_power_of_2((jlong)modulus), "must be power of 2");
addi(r, r, modulus-1);
clrrdi(r, r, log2_long((jlong)modulus));
}
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/cpu/ppc/ppc.ad
Expand Up @@ -4350,23 +4350,23 @@ operand immIhi16() %{
%}

operand immInegpow2() %{
predicate(is_power_of_2_long((jlong) (julong) (juint) (-(n->get_int()))));
predicate(is_power_of_2((jlong) (julong) (juint) (-(n->get_int()))));
match(ConI);
op_cost(0);
format %{ %}
interface(CONST_INTER);
%}

operand immIpow2minus1() %{
predicate(is_power_of_2_long((((jlong) (n->get_int()))+1)));
predicate(is_power_of_2((((jlong) (n->get_int()))+1)));
match(ConI);
op_cost(0);
format %{ %}
interface(CONST_INTER);
%}

operand immIpowerOf2() %{
predicate(is_power_of_2_long((((jlong) (julong) (juint) (n->get_int())))));
predicate(is_power_of_2((((jlong) (julong) (juint) (n->get_int())))));
match(ConI);
op_cost(0);
format %{ %}
Expand Down Expand Up @@ -4600,15 +4600,15 @@ operand immLhighest16() %{
%}

operand immLnegpow2() %{
predicate(is_power_of_2_long((jlong)-(n->get_long())));
predicate(is_power_of_2((jlong)-(n->get_long())));
match(ConL);
op_cost(0);
format %{ %}
interface(CONST_INTER);
%}

operand immLpow2minus1() %{
predicate(is_power_of_2_long((((jlong) (n->get_long()))+1)) &&
predicate(is_power_of_2((((jlong) (n->get_long()))+1)) &&
(n->get_long() != (jlong)0xffffffffffffffffL));
match(ConL);
op_cost(0);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/ppc/stubGenerator_ppc.cpp
Expand Up @@ -41,6 +41,7 @@
#include "runtime/stubRoutines.hpp"
#include "runtime/thread.inline.hpp"
#include "utilities/align.hpp"
#include "utilities/powerOfTwo.hpp"

// Declaration and definition of StubGenerator (no .hpp file).
// For a more detailed description of the stub routine structure
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/ppc/templateTable_ppc_64.cpp
Expand Up @@ -42,6 +42,7 @@
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"

#undef __
#define __ _masm->
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/ppc/vm_version_ppc.cpp
Expand Up @@ -36,6 +36,7 @@
#include "utilities/align.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/powerOfTwo.hpp"

#include <sys/sysinfo.h>
#if defined(_AIX)
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp
Expand Up @@ -39,6 +39,7 @@
#include "runtime/frame.inline.hpp"
#include "runtime/safepointMechanism.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "utilities/powerOfTwo.hpp"
#include "vmreg_s390.inline.hpp"

#define __ _masm->
Expand Down Expand Up @@ -1798,7 +1799,7 @@ void LIR_Assembler::arithmetic_idiv(LIR_Code code, LIR_Opr left, LIR_Opr right,
if (left->is_double_cpu()) {
// 64 bit integer case
assert(left->is_double_cpu(), "left must be register");
assert(right->is_double_cpu() || is_power_of_2_long(right->as_jlong()),
assert(right->is_double_cpu() || is_power_of_2(right->as_jlong()),
"right must be register or power of 2 constant");
assert(result->is_double_cpu(), "result must be register");

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp
Expand Up @@ -37,6 +37,7 @@
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "vmreg_s390.inline.hpp"
#include "utilities/powerOfTwo.hpp"

#ifdef ASSERT
#define __ gen()->lir(__FILE__, __LINE__)->
Expand Down

0 comments on commit e4b27a4

Please sign in to comment.