summaryrefslogtreecommitdiff
path: root/src/cairo-wideint.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cairo-wideint.c')
-rw-r--r--src/cairo-wideint.c148
1 files changed, 93 insertions, 55 deletions
diff --git a/src/cairo-wideint.c b/src/cairo-wideint.c
index 67ba3f9b9..953108339 100644
--- a/src/cairo-wideint.c
+++ b/src/cairo-wideint.c
@@ -1,25 +1,37 @@
/*
- * $Id: cairo-wideint.c,v 1.1 2004-05-28 19:37:15 keithp Exp $
+ * $Id: cairo-wideint.c,v 1.4 2005-01-19 15:07:00 cworth Exp $
*
* Copyright © 2004 Keith Packard
*
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. Keith Packard makes no
- * representations about the suitability of this software for any purpose. It
- * is provided "as is" without express or implied warranty.
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
*
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.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
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is Keith Packard
+ *
+ * Contributor(s):
+ * Keith R. Packard <keithp@keithp.com>
*/
#include "cairoint.h"
@@ -44,7 +56,7 @@ static const unsigned char top_bit[256] =
#define _cairo_uint32s_to_uint64(h,l) ((uint64_t) (h) << 32 | (l))
-const cairo_uquorem64_t
+cairo_uquorem64_t
_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den)
{
cairo_uquorem64_t qr;
@@ -56,7 +68,7 @@ _cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den)
#else
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint32_to_uint64 (uint32_t i)
{
cairo_uint64_t q;
@@ -66,7 +78,7 @@ _cairo_uint32_to_uint64 (uint32_t i)
return q;
}
-const cairo_int64_t
+cairo_int64_t
_cairo_int32_to_int64 (int32_t i)
{
cairo_uint64_t q;
@@ -86,7 +98,7 @@ _cairo_uint32s_to_uint64 (uint32_t h, uint32_t l)
return q;
}
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b)
{
cairo_uint64_t s;
@@ -98,7 +110,7 @@ _cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b)
return s;
}
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b)
{
cairo_uint64_t s;
@@ -114,7 +126,7 @@ _cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b)
#define uint32_hi(i) ((i) >> 16)
#define uint32_carry16 ((1) << 16)
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint32x32_64_mul (uint32_t a, uint32_t b)
{
cairo_uint64_t s;
@@ -142,7 +154,18 @@ _cairo_uint32x32_64_mul (uint32_t a, uint32_t b)
return s;
}
-const cairo_uint64_t
+cairo_int64_t
+_cairo_int32x32_64_mul (int32_t a, int32_t b)
+{
+ s = _cairo_uint32x32_64_mul ((uint32_t) a, (uint32_t b));
+ if (a < 0)
+ s.hi -= b;
+ if (b < 0)
+ s.hi -= a;
+ return s;
+}
+
+cairo_uint64_t
_cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b)
{
cairo_uint64_t s;
@@ -152,7 +175,7 @@ _cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b)
return s;
}
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint64_lsl (cairo_uint64_t a, int shift)
{
if (shift >= 32)
@@ -169,7 +192,7 @@ _cairo_uint64_lsl (cairo_uint64_t a, int shift)
return a;
}
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint64_rsl (cairo_uint64_t a, int shift)
{
if (shift >= 32)
@@ -188,7 +211,7 @@ _cairo_uint64_rsl (cairo_uint64_t a, int shift)
#define _cairo_uint32_rsa(a,n) ((uint32_t) (((int32_t) (a)) >> (n)))
-const cairo_int64_t
+cairo_int64_t
_cairo_uint64_rsa (cairo_int64_t a, int shift)
{
if (shift >= 32)
@@ -205,20 +228,20 @@ _cairo_uint64_rsa (cairo_int64_t a, int shift)
return a;
}
-const int
+int
_cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b)
{
return (a.hi < b.hi ||
(a.hi == b.hi && a.lo < b.lo));
}
-const int
+int
_cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b)
{
return a.hi == b.hi && a.lo == b.lo;
}
-const int
+int
_cairo_int64_lt (cairo_int64_t a, cairo_int64_t b)
{
if (_cairo_int64_negative (a) && !_cairo_int64_negative (b))
@@ -228,7 +251,7 @@ _cairo_int64_lt (cairo_int64_t a, cairo_int64_t b)
return _cairo_uint64_lt (a, b);
}
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint64_not (cairo_uint64_t a)
{
a.lo = ~a.lo;
@@ -236,7 +259,7 @@ _cairo_uint64_not (cairo_uint64_t a)
return a;
}
-const cairo_uint64_t
+cairo_uint64_t
_cairo_uint64_negate (cairo_uint64_t a)
{
a.lo = ~a.lo;
@@ -325,7 +348,7 @@ _cairo_uint64x32_normalized_divrem (cairo_uint64_t num, uint32_t den)
return qr;
}
-const cairo_uquorem64_t
+cairo_uquorem64_t
_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den)
{
cairo_uquorem32_t qr32;
@@ -444,7 +467,7 @@ _cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den)
#endif /* !HAVE_UINT64_T */
-const cairo_quorem64_t
+cairo_quorem64_t
_cairo_int64_divrem (cairo_int64_t num, cairo_int64_t den)
{
int num_neg = _cairo_int64_negative (num);
@@ -470,7 +493,7 @@ _cairo_int64_divrem (cairo_int64_t num, cairo_int64_t den)
#if HAVE_UINT128_T
-const cairo_uquorem128_t
+cairo_uquorem128_t
_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den)
{
cairo_uquorem128_t qr;
@@ -482,7 +505,7 @@ _cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den)
#else
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint32_to_uint128 (uint32_t i)
{
cairo_uint128_t q;
@@ -492,7 +515,7 @@ _cairo_uint32_to_uint128 (uint32_t i)
return q;
}
-const cairo_int128_t
+cairo_int128_t
_cairo_int32_to_int128 (int32_t i)
{
cairo_int128_t q;
@@ -502,7 +525,7 @@ _cairo_int32_to_int128 (int32_t i)
return q;
}
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint64_to_uint128 (cairo_uint64_t i)
{
cairo_uint128_t q;
@@ -512,7 +535,7 @@ _cairo_uint64_to_uint128 (cairo_uint64_t i)
return q;
}
-const cairo_int128_t
+cairo_int128_t
_cairo_int64_to_int128 (cairo_int64_t i)
{
cairo_int128_t q;
@@ -522,7 +545,7 @@ _cairo_int64_to_int128 (cairo_int64_t i)
return q;
}
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b)
{
cairo_uint128_t s;
@@ -534,7 +557,7 @@ _cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b)
return s;
}
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b)
{
cairo_uint128_t s;
@@ -594,7 +617,7 @@ static const cairo_uint64_t uint64_carry32 = { 0, 1 };
#endif
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b)
{
cairo_uint128_t s;
@@ -622,7 +645,22 @@ _cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b)
return s;
}
-const cairo_uint128_t
+cairo_int128_t
+_cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b)
+{
+ cairo_int128_t s;
+ s = _cairo_uint64x64_128_mul (_cairo_int64_to_uint64(a),
+ _cairo_int64_to_uint64(b));
+ if (_cairo_int64_negative (a))
+ s.hi = _cairo_uint64_sub (s.hi,
+ _cairo_int64_to_uint64 (b));
+ if (_cairo_int64_negative (b))
+ s.hi = _cairo_uint64_sub (s.hi,
+ _cairo_int64_to_uint64 (a));
+ return s;
+}
+
+cairo_uint128_t
_cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b)
{
cairo_uint128_t s;
@@ -635,7 +673,7 @@ _cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b)
return s;
}
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint128_lsl (cairo_uint128_t a, int shift)
{
if (shift >= 64)
@@ -653,7 +691,7 @@ _cairo_uint128_lsl (cairo_uint128_t a, int shift)
return a;
}
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint128_rsl (cairo_uint128_t a, int shift)
{
if (shift >= 64)
@@ -671,7 +709,7 @@ _cairo_uint128_rsl (cairo_uint128_t a, int shift)
return a;
}
-const cairo_uint128_t
+cairo_uint128_t
_cairo_uint128_rsa (cairo_int128_t a, int shift)
{
if (shift >= 64)
@@ -689,7 +727,7 @@ _cairo_uint128_rsa (cairo_int128_t a, int shift)
return a;
}
-const int
+int
_cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b)
{
return (_cairo_uint64_lt (a.hi, b.hi) ||
@@ -697,7 +735,7 @@ _cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b)
_cairo_uint64_lt (a.lo, b.lo)));
}
-const int
+int
_cairo_int128_lt (cairo_int128_t a, cairo_int128_t b)
{
if (_cairo_int128_negative (a) && !_cairo_int128_negative (b))
@@ -707,7 +745,7 @@ _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b)
return _cairo_uint128_lt (a, b);
}
-const int
+int
_cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b)
{
return (_cairo_uint64_eq (a.hi, b.hi) &&
@@ -722,7 +760,7 @@ _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b)
/*
* den >= num.hi
*/
-static const cairo_uquorem64_t
+static cairo_uquorem64_t
_cairo_uint128x64_normalized_divrem (cairo_uint128_t num, cairo_uint64_t den)
{
cairo_uquorem64_t qr64;
@@ -786,7 +824,7 @@ _cairo_uint128x64_normalized_divrem (cairo_uint128_t num, cairo_uint64_t den)
#if HAVE_UINT64_T
-static const int
+static int
_cairo_leading_zeros64 (cairo_uint64_t q)
{
int top = 0;
@@ -823,7 +861,7 @@ _cairo_leading_zeros64 (cairo_uint64_t d)
#endif
-const cairo_uquorem128_t
+cairo_uquorem128_t
_cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den)
{
cairo_uquorem64_t qr64;
@@ -943,7 +981,7 @@ _cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den)
return qr;
}
-const cairo_int128_t
+cairo_int128_t
_cairo_int128_negate (cairo_int128_t a)
{
a.lo = _cairo_uint64_not (a.lo);
@@ -951,7 +989,7 @@ _cairo_int128_negate (cairo_int128_t a)
return _cairo_uint128_add (a, _cairo_uint32_to_uint128 (1));
}
-const cairo_int128_t
+cairo_int128_t
_cairo_int128_not (cairo_int128_t a)
{
a.lo = _cairo_uint64_not (a.lo);
@@ -961,7 +999,7 @@ _cairo_int128_not (cairo_int128_t a)
#endif /* !HAVE_UINT128_T */
-const cairo_quorem128_t
+cairo_quorem128_t
_cairo_int128_divrem (cairo_int128_t num, cairo_int128_t den)
{
int num_neg = _cairo_int128_negative (num);