Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/libadt/port.cpp
32285 views
/*1* Copyright (c) 1997, 2010, 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 "libadt/port.hpp"2627// Code for portable compiling2829#ifdef __GNUC__30#pragma implementation31#endif3233// %%%%% includes not needed with AVM framework - Ungar34// #include "port.hpp"3536// This is only used if turboc is used and it causes problems with37// gcc.38#ifdef __TURBOC__39#include <iostream.h>40#endif4142#include <stdio.h>4344//------------------------------gcd--------------------------------------------45// Greatest common divisor46uint32 gcd( register uint32 x, register uint32 y )47{48register uint32 tmp;49while( x ) { // While not zero50tmp = x; // Hold onto smaller x value51x = y % x; // Compute modulus; since y>=x, 0 <= mod < x52y = tmp; // y = old x53}54return y;55}5657//-----------------------------------------------------------------------------58// Find first 1, or return 32 if empty59int ff1( uint32 mask )60{61unsigned i, n = 0;6263for( i=1, n=0; i; i<<=1, n++)64if( mask&i ) return n;65return 32;66}6768//-----------------------------------------------------------------------------69// Find highest 1, or return 32 if empty70int fh1( uint32 mask )71{72unsigned i, n = 0;7374for( i=((uint32)1<<31), n=31; i; i>>=1, n--)75if( mask&i ) return n;76return 32;77}7879//------------------------------rotate32---------------------------------------80// Rotate 32bits. Postive rotates left (bits move toward high-order bit),81// negative rotates right.82uint32 rotate32( register uint32 x, register int32 cnt )83{84if( cnt >= 0 ) { // Positive rotates left85cnt &= 31; // Mask off extra shift bits86} else { // Negative rotates right87cnt = (-cnt)&31; // Flip sign; mask extra shift bits88cnt = 32-cnt; // Rotate right by big left rotation89}90return (x << cnt) | (x >> (32-cnt));91}9293/* Disabled - we have another log2 in the system.94This function doesn't work if used as substitute95for the existing log2. Keep around until we have96verified all uses of log2 do the correct thing!97//------------------------------log2-------------------------------------------98// Log base 2. Might also be called 'count leading zeros'. Log2(x) returns99// an l such that (1L<<l) <= x < (2L<<l). log2(x) returns 32.100uint log2( uint32 x )101{102register uint l = 32; // Log bits103register int32 sx = x; // Treat as signed number104while( sx >= 0 ) // While high bit is clear105sx <<= 1, l--; // Shift bits left, count down log2106return l;107}108*/109110//------------------------------print------------------------------------------111// Print a pointer without modifying the contents112#ifdef __TURBOC__113ostream &ostream::operator << (const void *ptr)114{115return (*this) << "0x" << hex << (uint)ptr << dec;116}117#else118/*ostream &operator << (ostream &os, const void *ptr)119{120return os << "0x" << hex << (uint)ptr << dec;121}*/122#endif123124125