Path: blob/master/src/hotspot/share/opto/countbitsnode.cpp
40930 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "opto/countbitsnode.hpp"26#include "opto/opcodes.hpp"27#include "opto/phaseX.hpp"28#include "opto/type.hpp"2930//------------------------------Value------------------------------------------31const Type* CountLeadingZerosINode::Value(PhaseGVN* phase) const {32const Type* t = phase->type(in(1));33if (t == Type::TOP) return Type::TOP;34const TypeInt* ti = t->isa_int();35if (ti && ti->is_con()) {36jint i = ti->get_con();37// HD, Figure 5-638if (i == 0)39return TypeInt::make(BitsPerInt);40int n = 1;41unsigned int x = i;42if (x >> 16 == 0) { n += 16; x <<= 16; }43if (x >> 24 == 0) { n += 8; x <<= 8; }44if (x >> 28 == 0) { n += 4; x <<= 4; }45if (x >> 30 == 0) { n += 2; x <<= 2; }46n -= x >> 31;47return TypeInt::make(n);48}49return TypeInt::INT;50}5152//------------------------------Value------------------------------------------53const Type* CountLeadingZerosLNode::Value(PhaseGVN* phase) const {54const Type* t = phase->type(in(1));55if (t == Type::TOP) return Type::TOP;56const TypeLong* tl = t->isa_long();57if (tl && tl->is_con()) {58jlong l = tl->get_con();59// HD, Figure 5-660if (l == 0)61return TypeInt::make(BitsPerLong);62int n = 1;63unsigned int x = (((julong) l) >> 32);64if (x == 0) { n += 32; x = (int) l; }65if (x >> 16 == 0) { n += 16; x <<= 16; }66if (x >> 24 == 0) { n += 8; x <<= 8; }67if (x >> 28 == 0) { n += 4; x <<= 4; }68if (x >> 30 == 0) { n += 2; x <<= 2; }69n -= x >> 31;70return TypeInt::make(n);71}72return TypeInt::INT;73}7475//------------------------------Value------------------------------------------76const Type* CountTrailingZerosINode::Value(PhaseGVN* phase) const {77const Type* t = phase->type(in(1));78if (t == Type::TOP) return Type::TOP;79const TypeInt* ti = t->isa_int();80if (ti && ti->is_con()) {81jint i = ti->get_con();82// HD, Figure 5-1483int y;84if (i == 0)85return TypeInt::make(BitsPerInt);86int n = 31;87y = i << 16; if (y != 0) { n = n - 16; i = y; }88y = i << 8; if (y != 0) { n = n - 8; i = y; }89y = i << 4; if (y != 0) { n = n - 4; i = y; }90y = i << 2; if (y != 0) { n = n - 2; i = y; }91y = i << 1; if (y != 0) { n = n - 1; }92return TypeInt::make(n);93}94return TypeInt::INT;95}9697//------------------------------Value------------------------------------------98const Type* CountTrailingZerosLNode::Value(PhaseGVN* phase) const {99const Type* t = phase->type(in(1));100if (t == Type::TOP) return Type::TOP;101const TypeLong* tl = t->isa_long();102if (tl && tl->is_con()) {103jlong l = tl->get_con();104// HD, Figure 5-14105int x, y;106if (l == 0)107return TypeInt::make(BitsPerLong);108int n = 63;109y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32);110y = x << 16; if (y != 0) { n = n - 16; x = y; }111y = x << 8; if (y != 0) { n = n - 8; x = y; }112y = x << 4; if (y != 0) { n = n - 4; x = y; }113y = x << 2; if (y != 0) { n = n - 2; x = y; }114y = x << 1; if (y != 0) { n = n - 1; }115return TypeInt::make(n);116}117return TypeInt::INT;118}119120121