summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Taubert <ttaubert@mozilla.com>2016-04-27 15:28:16 +0200
committerTim Taubert <ttaubert@mozilla.com>2016-04-27 15:28:16 +0200
commit11b5666a97d46b61d2df48c9bd4887f73d92ce7b (patch)
treedf295424eb452da48db3702b2b1eb0c76dff4104
parentf115c0b6df8f825a710f106a4ce22b1c94065036 (diff)
downloadnss-hg-11b5666a97d46b61d2df48c9bd4887f73d92ce7b.tar.gz
Bug 1259052 - Remove MP_MACRO from libmpi r=franziskus,mt
-rw-r--r--lib/freebl/mpi/mpi-config.h4
-rw-r--r--lib/freebl/mpi/mpi-priv.h54
-rw-r--r--lib/freebl/mpi/mpi.c20
3 files changed, 11 insertions, 67 deletions
diff --git a/lib/freebl/mpi/mpi-config.h b/lib/freebl/mpi/mpi-config.h
index 04a9d95b8..171dacc7c 100644
--- a/lib/freebl/mpi/mpi-config.h
+++ b/lib/freebl/mpi/mpi-config.h
@@ -61,10 +61,6 @@
#define MP_DEFPREC 64 /* default precision, in digits */
#endif
-#ifndef MP_MACRO
-#define MP_MACRO 1 /* use macros for frequent calls? */
-#endif
-
#ifndef MP_SQUARE
#define MP_SQUARE 1 /* use separate squaring code? */
#endif
diff --git a/lib/freebl/mpi/mpi-priv.h b/lib/freebl/mpi/mpi-priv.h
index 7a0725f46..1fd628a8d 100644
--- a/lib/freebl/mpi/mpi-priv.h
+++ b/lib/freebl/mpi/mpi-priv.h
@@ -95,61 +95,19 @@ extern const float s_logv_2[];
/* {{{ private function declarations */
-/*
- If MP_MACRO is false, these will be defined as actual functions;
- otherwise, suitable macro definitions will be used. This works
- around the fact that ANSI C89 doesn't support an 'inline' keyword
- (although I hear C9x will ... about bloody time). At present, the
- macro definitions are identical to the function bodies, but they'll
- expand in place, instead of generating a function call.
-
- I chose these particular functions to be made into macros because
- some profiling showed they are called a lot on a typical workload,
- and yet they are primarily housekeeping.
- */
-#if MP_MACRO == 0
- void s_mp_setz(mp_digit *dp, mp_size count); /* zero digits */
- void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count); /* copy */
- void *s_mp_alloc(size_t nb, size_t ni); /* general allocator */
- void s_mp_free(void *ptr); /* general free function */
+void s_mp_setz(mp_digit *dp, mp_size count); /* zero digits */
+void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count); /* copy */
+void *s_mp_alloc(size_t nb, size_t ni); /* general allocator */
+void s_mp_free(void *ptr); /* general free function */
+
extern unsigned long mp_allocs;
extern unsigned long mp_frees;
extern unsigned long mp_copies;
-#else
-
- /* Even if these are defined as macros, we need to respect the settings
- of the MP_MEMSET and MP_MEMCPY configuration options...
- */
- #if MP_MEMSET == 0
- #define s_mp_setz(dp, count) \
- {int ix;for(ix=0;ix<(count);ix++)(dp)[ix]=0;}
- #else
- #define s_mp_setz(dp, count) memset(dp, 0, (count) * sizeof(mp_digit))
- #endif /* MP_MEMSET */
-
- #if MP_MEMCPY == 0
- #define s_mp_copy(sp, dp, count) \
- {int ix;for(ix=0;ix<(count);ix++)(dp)[ix]=(sp)[ix];}
- #else
- #define s_mp_copy(sp, dp, count) memcpy(dp, sp, (count) * sizeof(mp_digit))
- #endif /* MP_MEMCPY */
-
- #define s_mp_alloc(nb, ni) calloc(nb, ni)
- #define s_mp_free(ptr) {if(ptr) free(ptr);}
-#endif /* MP_MACRO */
mp_err s_mp_grow(mp_int *mp, mp_size min); /* increase allocated size */
mp_err s_mp_pad(mp_int *mp, mp_size min); /* left pad with zeroes */
-#if MP_MACRO == 0
- void s_mp_clamp(mp_int *mp); /* clip leading zeroes */
-#else
- #define s_mp_clamp(mp)\
- { mp_size used = MP_USED(mp); \
- while (used > 1 && DIGIT(mp, used - 1) == 0) --used; \
- MP_USED(mp) = used; \
- }
-#endif /* MP_MACRO */
+void s_mp_clamp(mp_int *mp); /* clip leading zeroes */
void s_mp_exch(mp_int *a, mp_int *b); /* swap a and b in place */
diff --git a/lib/freebl/mpi/mpi.c b/lib/freebl/mpi/mpi.c
index c5b1a5d9f..5cb8da2a2 100644
--- a/lib/freebl/mpi/mpi.c
+++ b/lib/freebl/mpi/mpi.c
@@ -2776,9 +2776,8 @@ mp_err s_mp_pad(mp_int *mp, mp_size min)
/* {{{ s_mp_setz(dp, count) */
-#if MP_MACRO == 0
/* Set 'count' digits pointed to by dp to be zeroes */
-void s_mp_setz(mp_digit *dp, mp_size count)
+inline void s_mp_setz(mp_digit *dp, mp_size count)
{
#if MP_MEMSET == 0
int ix;
@@ -2790,15 +2789,13 @@ void s_mp_setz(mp_digit *dp, mp_size count)
#endif
} /* end s_mp_setz() */
-#endif
/* }}} */
/* {{{ s_mp_copy(sp, dp, count) */
-#if MP_MACRO == 0
/* Copy 'count' digits from sp to dp */
-void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count)
+inline void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count)
{
#if MP_MEMCPY == 0
int ix;
@@ -2811,51 +2808,44 @@ void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count)
++mp_copies;
} /* end s_mp_copy() */
-#endif
/* }}} */
/* {{{ s_mp_alloc(nb, ni) */
-#if MP_MACRO == 0
/* Allocate ni records of nb bytes each, and return a pointer to that */
-void *s_mp_alloc(size_t nb, size_t ni)
+inline void *s_mp_alloc(size_t nb, size_t ni)
{
++mp_allocs;
return calloc(nb, ni);
} /* end s_mp_alloc() */
-#endif
/* }}} */
/* {{{ s_mp_free(ptr) */
-#if MP_MACRO == 0
/* Free the memory pointed to by ptr */
-void s_mp_free(void *ptr)
+inline void s_mp_free(void *ptr)
{
if(ptr) {
++mp_frees;
free(ptr);
}
} /* end s_mp_free() */
-#endif
/* }}} */
/* {{{ s_mp_clamp(mp) */
-#if MP_MACRO == 0
/* Remove leading zeroes from the given value */
-void s_mp_clamp(mp_int *mp)
+inline void s_mp_clamp(mp_int *mp)
{
mp_size used = MP_USED(mp);
while (used > 1 && DIGIT(mp, used - 1) == 0)
--used;
MP_USED(mp) = used;
} /* end s_mp_clamp() */
-#endif
/* }}} */