Skip to content

Commit aa00a6b

Browse files
real-or-randomsipa
authored andcommitted
Introduce CEIL_DIV macro and use it
1 parent d831168 commit aa00a6b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/ecmult_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#endif
4343

4444
#define WNAF_BITS 128
45-
#define WNAF_SIZE_BITS(bits, w) (((bits) + (w) - 1) / (w))
45+
#define WNAF_SIZE_BITS(bits, w) CEIL_DIV(bits, w)
4646
#define WNAF_SIZE(w) WNAF_SIZE_BITS(WNAF_BITS, w)
4747

4848
/* The number of objects allocated on the scratch space for ecmult_multi algorithms */
@@ -808,8 +808,8 @@ static int secp256k1_ecmult_multi_batch_size_helper(size_t *n_batches, size_t *n
808808
return 1;
809809
}
810810
/* Compute ceil(n/max_n_batch_points) and ceil(n/n_batches) */
811-
*n_batches = 1 + (n - 1) / max_n_batch_points;
812-
*n_batch_points = 1 + (n - 1) / *n_batches;
811+
*n_batches = CEIL_DIV(n, max_n_batch_points);
812+
*n_batch_points = CEIL_DIV(n, *n_batches);
813813
return 1;
814814
}
815815

src/util.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ static SECP256K1_INLINE void *checked_malloc(const secp256k1_callback* cb, size_
170170
#define ALIGNMENT 16
171171
#endif
172172

173-
#define ROUND_TO_ALIGN(size) ((((size) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT)
173+
/* ceil(x/y) for integers x > 0 and y > 0. Here, / denotes rational division. */
174+
#define CEIL_DIV(x, y) (1 + ((x) - 1) / (y))
175+
176+
#define ROUND_TO_ALIGN(size) (CEIL_DIV(size, ALIGNMENT) * ALIGNMENT)
174177

175178
/* Macro for restrict, when available and not in a VERIFY build. */
176179
#if defined(SECP256K1_BUILD) && defined(VERIFY)

0 commit comments

Comments
 (0)