diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-06-12 01:10:16 +0200 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-06-12 01:10:16 +0200 |
commit | ff95406571e810d99553cb543418ea83addfb1a5 (patch) | |
tree | 5c8bb10c6d9c6725e8e9eb4bf98bbebdb95e0b33 /gmp-impl.h | |
parent | 649517fcdf487399d2ad5c0932bbef3a09318939 (diff) | |
download | gmp-ff95406571e810d99553cb543418ea83addfb1a5.tar.gz |
* gmp-impl.h (__builtin_constant_p): Add dummy for non-gcc.
(mpn_incr_u, mpn_decr_u): Recognise incr==1 at compile time in the
generic code on gcc.
If gcc was extremely smart it could detect that incr==1 ends up with
pretty much the same chunk of code before and within the mpn_incr_u
loop, and merge them itself, but I guess one wouldn't want it wasting
time looking for such unlikely optimizations. Give it a helping hand
instead.
Diffstat (limited to 'gmp-impl.h')
-rw-r--r-- | gmp-impl.h | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/gmp-impl.h b/gmp-impl.h index f9296965e..14e2ebb47 100644 --- a/gmp-impl.h +++ b/gmp-impl.h @@ -296,6 +296,12 @@ void __gmp_default_free _PROTO ((void *, size_t)); #endif +/* Dummy for non-gcc, code involving it will go dead. */ +#ifndef __GNUC__ +#define __builtin_constant_p(x) 0 +#endif + + /* In gcc 2.96 and up on i386, tail calls are optimized to jumps if the stack usage is compatible. __attribute__ ((regparm (N))) helps by putting leading parameters in registers, avoiding extra stack. */ @@ -1051,24 +1057,44 @@ void mpn_xnor_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); #endif #ifndef mpn_incr_u -#define mpn_incr_u(p,incr) \ - do { mp_limb_t __x; mp_ptr __p = (p); \ - __x = *__p + (incr); \ - *__p = __x; \ - if (__x < (incr)) \ - while (++(*(++__p)) == 0) \ - ; \ +#define mpn_incr_u(p,incr) \ + do { \ + mp_limb_t __x; \ + mp_ptr __p = (p); \ + if (__builtin_constant_p (incr) && (incr) == 1) \ + { \ + while (++(*(__p++)) == 0) \ + ; \ + } \ + else \ + { \ + __x = *__p + (incr); \ + *__p = __x; \ + if (__x < (incr)) \ + while (++(*(++__p)) == 0) \ + ; \ + } \ } while (0) #endif #ifndef mpn_decr_u -#define mpn_decr_u(p,incr) \ - do { mp_limb_t __x; mp_ptr __p = (p); \ - __x = *__p; \ - *__p = __x - (incr); \ - if (__x < (incr)) \ - while ((*(++__p))-- == 0) \ - ; \ +#define mpn_decr_u(p,incr) \ + do { \ + mp_limb_t __x; \ + mp_ptr __p = (p); \ + if (__builtin_constant_p (incr) && (incr) == 1) \ + { \ + while ((*(__p++))-- == 0) \ + ; \ + } \ + else \ + { \ + __x = *__p; \ + *__p = __x - (incr); \ + if (__x < (incr)) \ + while ((*(++__p))-- == 0) \ + ; \ + } \ } while (0) #endif |