summaryrefslogtreecommitdiff
path: root/gmp-h.in
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2001-06-12 00:39:50 +0200
committerKevin Ryde <user42@zip.com.au>2001-06-12 00:39:50 +0200
commitf18c642bae21ec9749a88bcb01f5b24ac8c6357a (patch)
tree0155698f783c1749831430d78cc32ceebda4873e /gmp-h.in
parentc4981f11e03592cdda46df85dfb7eb7c6883f0bc (diff)
downloadgmp-f18c642bae21ec9749a88bcb01f5b24ac8c6357a.tar.gz
* gmp-h.in, gmp-impl.h: Move MPN_CMP to gmp.h as __GMPN_CMP, leave an
MPN_CMP alias in gmp-impl.h. * gmp-h.in (mpn_cmp): Add an inline version.
Diffstat (limited to 'gmp-h.in')
-rw-r--r--gmp-h.in38
1 files changed, 38 insertions, 0 deletions
diff --git a/gmp-h.in b/gmp-h.in
index de8871dde..126257340 100644
--- a/gmp-h.in
+++ b/gmp-h.in
@@ -1370,6 +1370,44 @@ mpf_size (mpf_srcptr f)
/**************** mpn inlines ****************/
+/* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or
+ negative. size==0 is allowed. On random data usually only one limb will
+ need to be examined to get a result, so it's worth having it inline. */
+#define __GMPN_CMP(result, xp, yp, size) \
+ do { \
+ mp_size_t __i; \
+ mp_limb_t __x, __y; \
+ \
+ /* ASSERT ((size) >= 0); */ \
+ \
+ (result) = 0; \
+ __i = (size); \
+ while (--__i >= 0) \
+ { \
+ __x = (xp)[__i]; \
+ __y = (yp)[__i]; \
+ if (__x != __y) \
+ { \
+ (result) = (__x > __y ? 1 : -1); \
+ break; \
+ } \
+ } \
+ } while (0)
+
+#if defined (__GMP_EXTERN_INLINE) || __GMP_FORCE_mpn_cmp
+#if ! __GMP_FORCE_mpn_cmp
+__GMP_EXTERN_INLINE
+#endif
+int
+mpn_cmp (mp_srcptr xp, mp_srcptr yp, mp_size_t size)
+{
+ int result;
+ __GMPN_CMP (result, xp, yp, size);
+ return result;
+}
+#endif
+
+
#if defined (__GNUC__) || defined (_FORCE_INLINES)
_EXTERN_INLINE mp_limb_t
mpn_add_1 (register mp_ptr res_ptr,