port.cpp revision 1472
1472N/A * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// Code for portable compiling 0N/A#
include "incls/_precompiled.incl" 0N/A// %%%%% includes not needed with AVM framework - Ungar 0N/A// This is only used if turboc is used and it causes problems with 0N/A//------------------------------gcd-------------------------------------------- 0N/A// Greatest common divisor 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//----------------------------------------------------------------------------- 0N/A// Find first 1, or return 32 if empty 0N/A for( i=
1, n=0; i; i<<=
1, n++)
0N/A//----------------------------------------------------------------------------- 0N/A// Find highest 1, or return 32 if empty 0N/A//------------------------------rotate32--------------------------------------- 0N/A// Rotate 32bits. Postive rotates left (bits move toward high-order bit), 0N/A// negative rotates right. 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/* 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 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//------------------------------print------------------------------------------ 0N/A// Print a pointer without modifying the contents 0N/A/*ostream &operator << (ostream &os, const void *ptr) 0N/A return os << "0x" << hex << (uint)ptr << dec;