comparison src/share/vm/libadt/port.cpp @ 0:a61af66fc99e jdk7-b24

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