src/share/vm/libadt/port.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "libadt/port.hpp"
aoqi@0 27
aoqi@0 28 // Code for portable compiling
aoqi@0 29
aoqi@0 30 #ifdef __GNUC__
aoqi@0 31 #pragma implementation
aoqi@0 32 #endif
aoqi@0 33
aoqi@0 34 // %%%%% includes not needed with AVM framework - Ungar
aoqi@0 35 // #include "port.hpp"
aoqi@0 36
aoqi@0 37 // This is only used if turboc is used and it causes problems with
aoqi@0 38 // gcc.
aoqi@0 39 #ifdef __TURBOC__
aoqi@0 40 #include <iostream.h>
aoqi@0 41 #endif
aoqi@0 42
aoqi@0 43 #include <stdio.h>
aoqi@0 44
aoqi@0 45 //------------------------------gcd--------------------------------------------
aoqi@0 46 // Greatest common divisor
aoqi@0 47 uint32 gcd( register uint32 x, register uint32 y )
aoqi@0 48 {
aoqi@0 49 register uint32 tmp;
aoqi@0 50 while( x ) { // While not zero
aoqi@0 51 tmp = x; // Hold onto smaller x value
aoqi@0 52 x = y % x; // Compute modulus; since y>=x, 0 <= mod < x
aoqi@0 53 y = tmp; // y = old x
aoqi@0 54 }
aoqi@0 55 return y;
aoqi@0 56 }
aoqi@0 57
aoqi@0 58 //-----------------------------------------------------------------------------
aoqi@0 59 // Find first 1, or return 32 if empty
aoqi@0 60 int ff1( uint32 mask )
aoqi@0 61 {
aoqi@0 62 unsigned i, n = 0;
aoqi@0 63
aoqi@0 64 for( i=1, n=0; i; i<<=1, n++)
aoqi@0 65 if( mask&i ) return n;
aoqi@0 66 return 32;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 //-----------------------------------------------------------------------------
aoqi@0 70 // Find highest 1, or return 32 if empty
aoqi@0 71 int fh1( uint32 mask )
aoqi@0 72 {
aoqi@0 73 unsigned i, n = 0;
aoqi@0 74
aoqi@0 75 for( i=((uint32)1<<31), n=31; i; i>>=1, n--)
aoqi@0 76 if( mask&i ) return n;
aoqi@0 77 return 32;
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 //------------------------------rotate32---------------------------------------
aoqi@0 81 // Rotate 32bits. Postive rotates left (bits move toward high-order bit),
aoqi@0 82 // negative rotates right.
aoqi@0 83 uint32 rotate32( register uint32 x, register int32 cnt )
aoqi@0 84 {
aoqi@0 85 if( cnt >= 0 ) { // Positive rotates left
aoqi@0 86 cnt &= 31; // Mask off extra shift bits
aoqi@0 87 } else { // Negative rotates right
aoqi@0 88 cnt = (-cnt)&31; // Flip sign; mask extra shift bits
aoqi@0 89 cnt = 32-cnt; // Rotate right by big left rotation
aoqi@0 90 }
aoqi@0 91 return (x << cnt) | (x >> (32-cnt));
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 /* Disabled - we have another log2 in the system.
aoqi@0 95 This function doesn't work if used as substitute
aoqi@0 96 for the existing log2. Keep around until we have
aoqi@0 97 verified all uses of log2 do the correct thing!
aoqi@0 98 //------------------------------log2-------------------------------------------
aoqi@0 99 // Log base 2. Might also be called 'count leading zeros'. Log2(x) returns
aoqi@0 100 // an l such that (1L<<l) <= x < (2L<<l). log2(x) returns 32.
aoqi@0 101 uint log2( uint32 x )
aoqi@0 102 {
aoqi@0 103 register uint l = 32; // Log bits
aoqi@0 104 register int32 sx = x; // Treat as signed number
aoqi@0 105 while( sx >= 0 ) // While high bit is clear
aoqi@0 106 sx <<= 1, l--; // Shift bits left, count down log2
aoqi@0 107 return l;
aoqi@0 108 }
aoqi@0 109 */
aoqi@0 110
aoqi@0 111 //------------------------------print------------------------------------------
aoqi@0 112 // Print a pointer without modifying the contents
aoqi@0 113 #ifdef __TURBOC__
aoqi@0 114 ostream &ostream::operator << (const void *ptr)
aoqi@0 115 {
aoqi@0 116 return (*this) << "0x" << hex << (uint)ptr << dec;
aoqi@0 117 }
aoqi@0 118 #else
aoqi@0 119 /*ostream &operator << (ostream &os, const void *ptr)
aoqi@0 120 {
aoqi@0 121 return os << "0x" << hex << (uint)ptr << dec;
aoqi@0 122 }*/
aoqi@0 123 #endif

mercurial