0N/A/*
1879N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "libadt/port.hpp"
1879N/A
0N/A// Code for portable compiling
0N/A
0N/A#ifdef __GNUC__
0N/A#pragma implementation
0N/A#endif
0N/A
0N/A// %%%%% includes not needed with AVM framework - Ungar
0N/A// #include "port.hpp"
0N/A
0N/A// This is only used if turboc is used and it causes problems with
0N/A// gcc.
0N/A#ifdef __TURBOC__
0N/A#include <iostream.h>
0N/A#endif
0N/A
0N/A#include <stdio.h>
0N/A
0N/A//------------------------------gcd--------------------------------------------
0N/A// Greatest common divisor
0N/Auint32 gcd( register uint32 x, register uint32 y )
0N/A{
0N/A register uint32 tmp;
0N/A while( x ) { // While not zero
0N/A tmp = x; // Hold onto smaller x value
0N/A x = y % x; // Compute modulus; since y>=x, 0 <= mod < x
0N/A y = tmp; // y = old x
0N/A }
0N/A return y;
0N/A}
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Find first 1, or return 32 if empty
0N/Aint ff1( uint32 mask )
0N/A{
0N/A unsigned i, n = 0;
0N/A
0N/A for( i=1, n=0; i; i<<=1, n++)
0N/A if( mask&i ) return n;
0N/A return 32;
0N/A}
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Find highest 1, or return 32 if empty
0N/Aint fh1( uint32 mask )
0N/A{
0N/A unsigned i, n = 0;
0N/A
0N/A for( i=((uint32)1<<31), n=31; i; i>>=1, n--)
0N/A if( mask&i ) return n;
0N/A return 32;
0N/A}
0N/A
0N/A//------------------------------rotate32---------------------------------------
0N/A// Rotate 32bits. Postive rotates left (bits move toward high-order bit),
0N/A// negative rotates right.
0N/Auint32 rotate32( register uint32 x, register int32 cnt )
0N/A{
0N/A if( cnt >= 0 ) { // Positive rotates left
0N/A cnt &= 31; // Mask off extra shift bits
0N/A } else { // Negative rotates right
0N/A cnt = (-cnt)&31; // Flip sign; mask extra shift bits
0N/A cnt = 32-cnt; // Rotate right by big left rotation
0N/A }
0N/A return (x << cnt) | (x >> (32-cnt));
0N/A}
0N/A
0N/A/* Disabled - we have another log2 in the system.
0N/A This function doesn't work if used as substitute
0N/A for the existing log2. Keep around until we have
0N/A verified all uses of log2 do the correct thing!
0N/A//------------------------------log2-------------------------------------------
0N/A// Log base 2. Might also be called 'count leading zeros'. Log2(x) returns
0N/A// an l such that (1L<<l) <= x < (2L<<l). log2(x) returns 32.
0N/Auint log2( uint32 x )
0N/A{
0N/A register uint l = 32; // Log bits
0N/A register int32 sx = x; // Treat as signed number
0N/A while( sx >= 0 ) // While high bit is clear
0N/A sx <<= 1, l--; // Shift bits left, count down log2
0N/A return l;
0N/A}
0N/A*/
0N/A
0N/A//------------------------------print------------------------------------------
0N/A// Print a pointer without modifying the contents
0N/A#ifdef __TURBOC__
0N/Aostream &ostream::operator << (const void *ptr)
0N/A{
0N/A return (*this) << "0x" << hex << (uint)ptr << dec;
0N/A}
0N/A#else
0N/A/*ostream &operator << (ostream &os, const void *ptr)
0N/A{
0N/A return os << "0x" << hex << (uint)ptr << dec;
0N/A}*/
0N/A#endif