jslong.c revision 6b15695578f07a3f72c4c9475c1a261a3021472a
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsstddef.h"
#include "jstypes.h"
#include "jslong.h"
#ifdef HAVE_WATCOM_BUG_2
JSLL_MaxInt(void) { return ll_maxint; }
JSLL_MinInt(void) { return ll_minint; }
#else
#endif
#ifndef JS_HAVE_LONG_LONG
/*
** Divide 64-bit a by 32-bit b, which must be normalized so its high bit is 1.
*/
{
if (r1 < m) {
if (r1 >= b /* i.e., we didn't get a carry when adding to r1 */
&& r1 < m) {
}
}
r1 -= m;
if (r0 < m) {
if (r0 >= b
&& r0 < m) {
}
}
}
{
JSUint32 t;
JSUint32 r = 32;
if ((t = a >> 16) != 0)
r -= 16, a = t;
if ((t = a >> 8) != 0)
r -= 8, a = t;
if ((t = a >> 4) != 0)
r -= 4, a = t;
if ((t = a >> 2) != 0)
r -= 2, a = t;
if ((t = a >> 1) != 0)
r -= 1, a = t;
if (a & 1)
r--;
return r;
}
{
if (b.hi == 0) {
/* (0 q0) = (n1 n0) / (0 D0) */
if (lsh) {
/*
* Normalize, i.e. make the most significant bit of the
* denominator be set.
*/
}
q1 = 0;
/* remainder is in n0 >> lsh */
} else {
/* (q1 q0) = (n1 n0) / (0 d0) */
if (b.lo == 0) /* user wants to divide by zero! */
if (lsh == 0) {
/*
* From (n1 >= b.lo)
* && (the most significant bit of b.lo is set),
* conclude that
* (the most significant bit of n1 is set)
* && (the leading quotient digit q1 = 1).
*
* This special case is necessary, not an optimization
* (Shifts counts of 32 are undefined).
*/
q1 = 1;
} else {
/*
* Normalize.
*/
}
/* n1 != b.lo... */
/* remainder in n0 >> lsh */
}
if (rp) {
}
} else {
/* (0 0) = (n1 n0) / (D1 d0) */
q0 = 0;
q1 = 0;
/* remainder in (n1 n0) */
if (rp) {
}
} else {
/* (0 q0) = (n1 n0) / (d1 d0) */
if (lsh == 0) {
/*
* From (n1 >= b.hi)
* && (the most significant bit of b.hi is set),
* conclude that
* (the most significant bit of n1 is set)
* && (the quotient digit q0 = 0 or 1).
*
* This special case is necessary, not an optimization.
*/
/*
* The condition on the next line takes advantage of that
* n1 >= b.hi (true due to control flow).
*/
q0 = 1;
JSLL_SUB(a, a, b);
} else {
q0 = 0;
}
q1 = 0;
if (rp) {
}
} else {
JSInt64 m;
/*
* Normalize.
*/
q0--;
JSLL_SUB(m, m, b);
}
q1 = 0;
/* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
if (rp) {
JSLL_SUB(a, a, m);
}
}
}
}
if (qp) {
}
}
#endif /* !JS_HAVE_LONG_LONG */