src/share/vm/libadt/port.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/libadt/port.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,123 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "libadt/port.hpp"
    1.30 +
    1.31 +// Code for portable compiling
    1.32 +
    1.33 +#ifdef __GNUC__
    1.34 +#pragma implementation
    1.35 +#endif
    1.36 +
    1.37 +// %%%%% includes not needed with AVM framework - Ungar
    1.38 +// #include "port.hpp"
    1.39 +
    1.40 +// This is only used if turboc is used and it causes problems with
    1.41 +// gcc.
    1.42 +#ifdef __TURBOC__
    1.43 +#include <iostream.h>
    1.44 +#endif
    1.45 +
    1.46 +#include <stdio.h>
    1.47 +
    1.48 +//------------------------------gcd--------------------------------------------
    1.49 +// Greatest common divisor
    1.50 +uint32 gcd( register uint32 x, register uint32 y )
    1.51 +{
    1.52 +  register uint32 tmp;
    1.53 +  while( x ) {                  // While not zero
    1.54 +    tmp = x;                    // Hold onto smaller x value
    1.55 +    x = y % x;                  // Compute modulus; since y>=x, 0 <= mod < x
    1.56 +    y = tmp;                    // y = old x
    1.57 +  }
    1.58 +  return y;
    1.59 +}
    1.60 +
    1.61 +//-----------------------------------------------------------------------------
    1.62 +// Find first 1, or return 32 if empty
    1.63 +int ff1( uint32 mask )
    1.64 +{
    1.65 +  unsigned i, n = 0;
    1.66 +
    1.67 +  for( i=1, n=0; i; i<<=1, n++)
    1.68 +    if( mask&i ) return n;
    1.69 +  return 32;
    1.70 +}
    1.71 +
    1.72 +//-----------------------------------------------------------------------------
    1.73 +// Find highest 1, or return 32 if empty
    1.74 +int fh1( uint32 mask )
    1.75 +{
    1.76 +  unsigned i, n = 0;
    1.77 +
    1.78 +  for( i=((uint32)1<<31), n=31; i; i>>=1, n--)
    1.79 +    if( mask&i ) return n;
    1.80 +  return 32;
    1.81 +}
    1.82 +
    1.83 +//------------------------------rotate32---------------------------------------
    1.84 +// Rotate 32bits.  Postive rotates left (bits move toward high-order bit),
    1.85 +// negative rotates right.
    1.86 +uint32 rotate32( register uint32 x, register int32 cnt )
    1.87 +{
    1.88 +  if( cnt >= 0 ) {              // Positive rotates left
    1.89 +    cnt &= 31;                  // Mask off extra shift bits
    1.90 +  } else {                      // Negative rotates right
    1.91 +    cnt = (-cnt)&31;            // Flip sign; mask extra shift bits
    1.92 +    cnt = 32-cnt;               // Rotate right by big left rotation
    1.93 +  }
    1.94 +  return (x << cnt) | (x >> (32-cnt));
    1.95 +}
    1.96 +
    1.97 +/* Disabled - we have another log2 in the system.
    1.98 +   This function doesn't work if used as substitute
    1.99 +   for the existing log2. Keep around until we have
   1.100 +   verified all uses of log2 do the correct thing!
   1.101 +//------------------------------log2-------------------------------------------
   1.102 +// Log base 2.  Might also be called 'count leading zeros'.  Log2(x) returns
   1.103 +// an l such that (1L<<l) <= x < (2L<<l).  log2(x) returns 32.
   1.104 +uint log2( uint32 x )
   1.105 +{
   1.106 +  register uint l = 32;         // Log bits
   1.107 +  register int32 sx = x;        // Treat as signed number
   1.108 +  while( sx >= 0 )              // While high bit is clear
   1.109 +    sx <<= 1, l--;              // Shift bits left, count down log2
   1.110 +  return l;
   1.111 +}
   1.112 +*/
   1.113 +
   1.114 +//------------------------------print------------------------------------------
   1.115 +// Print a pointer without modifying the contents
   1.116 +#ifdef __TURBOC__
   1.117 +ostream &ostream::operator << (const void *ptr)
   1.118 +{
   1.119 +  return (*this) << "0x" << hex << (uint)ptr << dec;
   1.120 +}
   1.121 +#else
   1.122 +/*ostream &operator << (ostream &os, const void *ptr)
   1.123 +{
   1.124 +  return os << "0x" << hex << (uint)ptr << dec;
   1.125 +}*/
   1.126 +#endif

mercurial