summaryrefslogtreecommitdiff
path: root/src/cairo-wideint.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-10-05 10:15:49 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-10-06 12:07:41 +0100
commit76dd4603d01068b1b377312ced6b44fe5419794f (patch)
tree1b7bf8fb229e46a30c6ff74ae45871b66d8f62cf /src/cairo-wideint.c
parent6eead4a5f746e182eabfcda9959cd9cc53d95a89 (diff)
[tessellator] Replace open-coding _cairo_int64_cmp().
We often use the construct: if (_cairo_int64_lt (A, B) return -1; if (_cairo_int64_gt (A, B) return 1; return 0; to compare two large integers (int64, or int128) which does twice the required work on CPUs without large integer support. So replace it with a single wideint function _cairo_int64_cmp() and therefore allow opportunities to both shrink the code size and write a more efficient comparison. (The primarily motivation is to simply replace each block with a single more expressive line.)
Diffstat (limited to 'src/cairo-wideint.c')
-rw-r--r--src/cairo-wideint.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/cairo-wideint.c b/src/cairo-wideint.c
index e8d3ab69..45655938 100644
--- a/src/cairo-wideint.c
+++ b/src/cairo-wideint.c
@@ -235,6 +235,32 @@ _cairo_int64_lt (cairo_int64_t a, cairo_int64_t b)
return _cairo_uint64_lt (a, b);
}
+int
+_cairo_uint64_cmp (cairo_uint64_t a, cairo_uint64_t b)
+{
+ if (a.hi < b.hi)
+ return -1;
+ else if (a.hi > b.hi)
+ return 1;
+ else if (a.lo < b.lo)
+ return -1;
+ else if (a.lo > b.lo)
+ return 1;
+ else
+ return 0;
+}
+
+int
+_cairo_int64_cmp (cairo_int64_t a, cairo_int64_t b)
+{
+ if (_cairo_int64_negative (a) && !_cairo_int64_negative (b))
+ return -1;
+ if (!_cairo_int64_negative (a) && _cairo_int64_negative (b))
+ return 1;
+
+ return _cairo_uint64_cmp (a, b);
+}
+
cairo_uint64_t
_cairo_uint64_not (cairo_uint64_t a)
{
@@ -570,6 +596,28 @@ _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b)
}
int
+_cairo_uint128_cmp (cairo_uint128_t a, cairo_uint128_t b)
+{
+ int cmp;
+
+ cmp = _cairo_uint64_cmp (a.hi, b.hi);
+ if (cmp)
+ return cmp;
+ return _cairo_uint64_cmp (a.lo, b.lo);
+}
+
+int
+_cairo_int128_cmp (cairo_int128_t a, cairo_int128_t b)
+{
+ if (_cairo_int128_negative (a) && !_cairo_int128_negative (b))
+ return -1;
+ if (!_cairo_int128_negative (a) && _cairo_int128_negative (b))
+ return 1;
+
+ return _cairo_uint128_cmp (a, b);
+}
+
+int
_cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b)
{
return (_cairo_uint64_eq (a.hi, b.hi) &&