[cairo-commit] 2 commits - src/cairo-bentley-ottmann.c src/cairo-wideint-private.h

Chris Wilson ickle at kemper.freedesktop.org
Tue Oct 7 14:26:25 PDT 2008


 src/cairo-bentley-ottmann.c |   34 +++++++++++++++++-----------------
 src/cairo-wideint-private.h |   10 +++++++++-
 2 files changed, 26 insertions(+), 18 deletions(-)

New commits:
commit cf572b58e1197dac0ff1795b27b142c3e044cf45
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Oct 7 09:55:03 2008 +0100

    [tessellator] Compile fixes for !HAVE_INT64_T
    
    Fixup a couple of instances of implicit down-casting to 32bits from a
    64bit wide integer and add a new is_zero() predicate.

diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index b98cb62..c657dd9 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -204,8 +204,8 @@ _slope_compare (cairo_bo_edge_t *a,
     } else {
 	int32_t ady = a->bottom.y - a->top.y;
 	int32_t bdy = b->bottom.y - b->top.y;
-	int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy);
-	int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady);
+	cairo_int64_t adx_bdy = _cairo_int32x32_64_mul (adx, bdy);
+	cairo_int64_t bdx_ady = _cairo_int32x32_64_mul (bdx, ady);
 
 	return _cairo_int64_cmp (adx_bdy, bdx_ady);
     }
@@ -627,7 +627,7 @@ intersect_lines (cairo_bo_edge_t		*a,
     cairo_int64_t den_det = det32_64 (dx1, dy1, dx2, dy2);
     cairo_quorem64_t qr;
 
-    if (_cairo_int64_eq (den_det, 0))
+    if (_cairo_int64_is_zero (den_det))
 	return CAIRO_BO_STATUS_PARALLEL;
 
     a_det = det32_64 (a->top.x, a->top.y,
@@ -641,8 +641,8 @@ intersect_lines (cairo_bo_edge_t		*a,
 					 den_det);
     if (_cairo_int64_eq (qr.rem, den_det))
 	return CAIRO_BO_STATUS_NO_INTERSECTION;
-    intersection->x.ordinate = qr.quo;
-    intersection->x.exactness = qr.rem ? INEXACT : EXACT;
+    intersection->x.ordinate = _cairo_int64_to_int32 (qr.quo);
+    intersection->x.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT;
 
     /* y = det (a_det, dy1, b_det, dy2) / den_det */
     qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1,
@@ -650,8 +650,8 @@ intersect_lines (cairo_bo_edge_t		*a,
 					 den_det);
     if (_cairo_int64_eq (qr.rem, den_det))
 	return CAIRO_BO_STATUS_NO_INTERSECTION;
-    intersection->y.ordinate = qr.quo;
-    intersection->y.exactness = qr.rem ? INEXACT : EXACT;
+    intersection->y.ordinate = _cairo_int64_to_int32 (qr.quo);
+    intersection->y.exactness = _cairo_int64_is_zero (qr.rem) ? EXACT : INEXACT;
 
     return CAIRO_BO_STATUS_INTERSECTION;
 }
diff --git a/src/cairo-wideint-private.h b/src/cairo-wideint-private.h
index f2f6d20..f5aac28 100644
--- a/src/cairo-wideint-private.h
+++ b/src/cairo-wideint-private.h
@@ -64,6 +64,7 @@ int	       I	_cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b);
 int	       I	_cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b);
 int	       I	_cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b);
 cairo_uint64_t I	_cairo_uint64_negate (cairo_uint64_t a);
+#define			_cairo_uint64_is_zero(a) ((a).hi == 0 && (a).lo == 0)
 #define			_cairo_uint64_negative(a)   (((int32_t) ((a).hi)) < 0)
 cairo_uint64_t I	_cairo_uint64_not (cairo_uint64_t a);
 
@@ -78,6 +79,7 @@ cairo_int64_t  I	_cairo_int32_to_int64(int32_t i);
 cairo_int64_t  I	_cairo_int32x32_64_mul (int32_t a, int32_t b);
 int	       I	_cairo_int64_lt (cairo_int64_t a, cairo_int64_t b);
 int	       I	_cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b);
+#define			_cairo_int64_is_zero(a)	    _cairo_uint64_is_zero (a)
 #define			_cairo_int64_eq(a,b)	    _cairo_uint64_eq (a,b)
 #define			_cairo_int64_lsl(a,b)	    _cairo_uint64_lsl (a,b)
 #define			_cairo_int64_rsl(a,b)	    _cairo_uint64_rsl (a,b)
@@ -99,6 +101,7 @@ int	       I	_cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b);
 #define			_cairo_uint64_rsa(a,b)	    ((uint64_t) ((int64_t) (a) >> (b)))
 #define			_cairo_uint64_lt(a,b)	    ((a) < (b))
 #define                 _cairo_uint64_cmp(a,b)       ((a) == (b) ? 0 : (a) < (b) ? -1 : 1)
+#define			_cairo_uint64_is_zero(a)    ((a) == 0)
 #define			_cairo_uint64_eq(a,b)	    ((a) == (b))
 #define			_cairo_uint64_negate(a)	    ((uint64_t) -((int64_t) (a)))
 #define			_cairo_uint64_negative(a)   ((int64_t) (a) < 0)
@@ -115,6 +118,7 @@ int	       I	_cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b);
 #define			_cairo_int32x32_64_mul(a,b) ((int64_t) (a) * (b))
 #define			_cairo_int64_lt(a,b)	    ((a) < (b))
 #define                 _cairo_int64_cmp(a,b)       ((a) == (b) ? 0 : (a) < (b) ? -1 : 1)
+#define			_cairo_int64_is_zero(a)     ((a) == 0)
 #define			_cairo_int64_eq(a,b)	    ((a) == (b))
 #define			_cairo_int64_lsl(a,b)	    ((a) << (b))
 #define			_cairo_int64_rsl(a,b)	    ((int64_t) ((uint64_t) (a) >> (b)))
@@ -171,6 +175,7 @@ cairo_uint128_t I	_cairo_uint128_rsa (cairo_uint128_t a, int shift);
 int	        I	_cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b);
 int	        I	_cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b);
 int	        I	_cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b);
+#define			_cairo_uint128_is_zero(a) (_cairo_uint64_is_zero ((a).hi) && _cairo_uint64_is_zero ((a).lo))
 cairo_uint128_t I	_cairo_uint128_negate (cairo_uint128_t a);
 #define			_cairo_uint128_negative(a)  (_cairo_uint64_negative(a.hi))
 cairo_uint128_t I	_cairo_uint128_not (cairo_uint128_t a);
@@ -191,7 +196,8 @@ cairo_int128_t I _cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b);
 #define			_cairo_int128_rsl(a,b)	    _cairo_uint128_rsl(a,b)
 #define			_cairo_int128_rsa(a,b)	    _cairo_uint128_rsa(a,b)
 int 	        I	_cairo_int128_lt (cairo_int128_t a, cairo_int128_t b);
-int 	        I	_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b);
+int	        I	_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b);
+#define			_cairo_int128_is_zero(a)    _cairo_uint128_is_zero (a)
 #define			_cairo_int128_eq(a,b)	    _cairo_uint128_eq (a,b)
 #define			_cairo_int128_negate(a)	    _cairo_uint128_negate(a)
 #define			_cairo_int128_negative(a)   (_cairo_uint128_negative(a))
@@ -212,6 +218,7 @@ int 	        I	_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b);
 #define			_cairo_uint128_rsa(a,b)	    ((uint128_t) ((int128_t) (a) >> (b)))
 #define			_cairo_uint128_lt(a,b)	    ((a) < (b))
 #define			_cairo_uint128_cmp(a,b)	    ((a) == (b) ? 0 : (a) < (b) ? -1 : 1)
+#define			_cairo_uint128_is_zero(a)   ((a) == 0)
 #define			_cairo_uint128_eq(a,b)	    ((a) == (b))
 #define			_cairo_uint128_negate(a)    ((uint128_t) -((int128_t) (a)))
 #define			_cairo_uint128_negative(a)  ((int128_t) (a) < 0)
@@ -230,6 +237,7 @@ int 	        I	_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b);
 #define			_cairo_int64x64_128_mul(a,b) ((int128_t) (a) * (b))
 #define			_cairo_int128_lt(a,b)	    ((a) < (b))
 #define			_cairo_int128_cmp(a,b)	    ((a) == (b) ? 0 : (a) < (b) ? -1 : 1)
+#define			_cairo_int128_is_zero(a)    ((a) == 0)
 #define			_cairo_int128_eq(a,b)	    ((a) == (b))
 #define			_cairo_int128_lsl(a,b)	    ((a) << (b))
 #define			_cairo_int128_rsl(a,b)	    ((int128_t) ((uint128_t) (a) >> (b)))
commit 6b8c0559620ab23c4df1f381d2e95ffc307d2e2f
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Oct 7 09:43:45 2008 +0100

    [tessellator] Avoid implicit promotion to 64bit integer.
    
    Avoid passing a 32bit integer as a cairo_int64_t in case we do not have a
    64bit native integral type. As a side-effect this means we can also use a
    narrower multiply.

diff --git a/src/cairo-bentley-ottmann.c b/src/cairo-bentley-ottmann.c
index 47ee833..b98cb62 100644
--- a/src/cairo-bentley-ottmann.c
+++ b/src/cairo-bentley-ottmann.c
@@ -584,17 +584,17 @@ det32_64 (int32_t a,
 }
 
 static inline cairo_int128_t
-det64_128 (cairo_int64_t a,
-	   cairo_int64_t b,
-	   cairo_int64_t c,
-	   cairo_int64_t d)
+det64x32_128 (cairo_int64_t a,
+	      int32_t       b,
+	      cairo_int64_t c,
+	      int32_t       d)
 {
     cairo_int128_t ad;
     cairo_int128_t bc;
 
     /* det = a * d - b * c */
-    ad = _cairo_int64x64_128_mul (a, d);
-    bc = _cairo_int64x64_128_mul (b, c);
+    ad = _cairo_int64x32_128_mul (a, d);
+    bc = _cairo_int64x32_128_mul (c, b);
 
     return _cairo_int128_sub (ad, bc);
 }
@@ -636,8 +636,8 @@ intersect_lines (cairo_bo_edge_t		*a,
 		      b->bottom.x, b->bottom.y);
 
     /* x = det (a_det, dx1, b_det, dx2) / den_det */
-    qr = _cairo_int_96by64_32x64_divrem (det64_128 (a_det, dx1,
-						    b_det, dx2),
+    qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dx1,
+						       b_det, dx2),
 					 den_det);
     if (_cairo_int64_eq (qr.rem, den_det))
 	return CAIRO_BO_STATUS_NO_INTERSECTION;
@@ -645,8 +645,8 @@ intersect_lines (cairo_bo_edge_t		*a,
     intersection->x.exactness = qr.rem ? INEXACT : EXACT;
 
     /* y = det (a_det, dy1, b_det, dy2) / den_det */
-    qr = _cairo_int_96by64_32x64_divrem (det64_128 (a_det, dy1,
-						    b_det, dy2),
+    qr = _cairo_int_96by64_32x64_divrem (det64x32_128 (a_det, dy1,
+						       b_det, dy2),
 					 den_det);
     if (_cairo_int64_eq (qr.rem, den_det))
 	return CAIRO_BO_STATUS_NO_INTERSECTION;


More information about the cairo-commit mailing list