Skip to content

Commit cb5e74a

Browse files
committed
change name of PBC assert for API preconditions to HPBC_CLOCKWORK_API_PRECONDITION
1 parent 2cb2dc6 commit cb5e74a

File tree

17 files changed

+66
-58
lines changed

17 files changed

+66
-58
lines changed

modular_arithmetic/include/hurchalla/modular_arithmetic/absolute_value_difference.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ template <typename T> HURCHALLA_FORCE_INLINE
2424
T absolute_value_difference(T a, T b)
2525
{
2626
static_assert(ut_numeric_limits<T>::is_integer, "");
27-
HPBC_CLOCKWORK_PRECONDITION(a >= 0);
28-
HPBC_CLOCKWORK_PRECONDITION(b >= 0);
27+
HPBC_CLOCKWORK_API_PRECONDITION(a >= 0);
28+
HPBC_CLOCKWORK_API_PRECONDITION(b >= 0);
2929

3030
T result = detail::impl_absolute_value_difference<T>::call(a, b);
3131

modular_arithmetic/include/hurchalla/modular_arithmetic/detail/clockwork_programming_by_contract.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818

1919

20-
#if defined(HURCHALLA_CLOCKWORK_ENABLE_ASSERTS) || defined(CLOCKWORK_CHECK_API_PRECONDITIONS)
20+
#if defined(HURCHALLA_CLOCKWORK_ENABLE_ASSERTS) || \
21+
defined(CLOCKWORK_CHECK_API_PRECONDITIONS)
2122

2223
# include <cstdio>
2324
# include <cstdlib>
24-
2525
/* We can (probably) detect if exceptions are enabled by checking the
2626
gcc/clang macro __EXCEPTIONS, msvc's macro _CPPUNWIND, and the official
2727
but not always supported C++98 macro __cpp_exceptions. */
@@ -51,19 +51,20 @@
5151
} while(0)
5252
# endif
5353

54-
# define HPBC_CLOCKWORK_PRECONDITION(...) do { \
54+
# define HPBC_CLOCKWORK_API_PRECONDITION(...) do { \
5555
HPBC_CLOCKWORK_BASIC_ASSERT(__VA_ARGS__); } while(0)
5656

5757
#else
58-
# define HPBC_CLOCKWORK_PRECONDITION(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
58+
# define HPBC_CLOCKWORK_API_PRECONDITION(...) \
59+
HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
5960

6061
#endif
6162

6263

6364

6465
#if !defined(HURCHALLA_CLOCKWORK_ENABLE_ASSERTS)
6566

66-
# define HPBC_CLOCKWORK_PRECONDITION1(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
67+
# define HPBC_CLOCKWORK_PRECONDITION(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
6768
# define HPBC_CLOCKWORK_PRECONDITION2(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
6869
# define HPBC_CLOCKWORK_PRECONDITION3(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
6970
# define HPBC_CLOCKWORK_POSTCONDITION(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
@@ -81,7 +82,7 @@
8182
# else
8283
# define HPBC_CLOCKWORK_FALSE_VALUE (0)
8384
# endif
84-
# define HPBC_CLOCKWORK_PRECONDITION1_MACRO_IS_ACTIVE HPBC_CLOCKWORK_FALSE_VALUE
85+
# define HPBC_CLOCKWORK_PRECONDITION_MACRO_IS_ACTIVE HPBC_CLOCKWORK_FALSE_VALUE
8586
# define HPBC_CLOCKWORK_PRECONDITION2_MACRO_IS_ACTIVE HPBC_CLOCKWORK_FALSE_VALUE
8687
# define HPBC_CLOCKWORK_PRECONDITION3_MACRO_IS_ACTIVE HPBC_CLOCKWORK_FALSE_VALUE
8788
# define HPBC_CLOCKWORK_POSTCONDITION_MACRO_IS_ACTIVE HPBC_CLOCKWORK_FALSE_VALUE
@@ -112,7 +113,7 @@
112113
if (HURCHALLA_CLOCKWORK_ASSERT_LEVEL >= LEVEL) { \
113114
HPBC_CLOCKWORK_BASIC_ASSERT(__VA_ARGS__); } } while(0)
114115

115-
# define HPBC_CLOCKWORK_PRECONDITION1(...) HPBC_CLOCKWORK_LEVEL_ASSERT(1, __VA_ARGS__)
116+
# define HPBC_CLOCKWORK_PRECONDITION(...) HPBC_CLOCKWORK_LEVEL_ASSERT(1, __VA_ARGS__)
116117
# define HPBC_CLOCKWORK_PRECONDITION2(...) HPBC_CLOCKWORK_LEVEL_ASSERT(2, __VA_ARGS__)
117118
# define HPBC_CLOCKWORK_PRECONDITION3(...) HPBC_CLOCKWORK_LEVEL_ASSERT(3, __VA_ARGS__)
118119
# define HPBC_CLOCKWORK_POSTCONDITION(...) HPBC_CLOCKWORK_LEVEL_ASSERT(1, __VA_ARGS__)
@@ -125,7 +126,7 @@
125126
# define HPBC_CLOCKWORK_ASSERT2(...) HPBC_CLOCKWORK_LEVEL_ASSERT(2, __VA_ARGS__)
126127
# define HPBC_CLOCKWORK_ASSERT3(...) HPBC_CLOCKWORK_LEVEL_ASSERT(3, __VA_ARGS__)
127128

128-
# define HPBC_CLOCKWORK_PRECONDITION1_MACRO_IS_ACTIVE (HURCHALLA_CLOCKWORK_ASSERT_LEVEL >= 1)
129+
# define HPBC_CLOCKWORK_PRECONDITION_MACRO_IS_ACTIVE (HURCHALLA_CLOCKWORK_ASSERT_LEVEL >= 1)
129130
# define HPBC_CLOCKWORK_PRECONDITION2_MACRO_IS_ACTIVE (HURCHALLA_CLOCKWORK_ASSERT_LEVEL >= 2)
130131
# define HPBC_CLOCKWORK_PRECONDITION3_MACRO_IS_ACTIVE (HURCHALLA_CLOCKWORK_ASSERT_LEVEL >= 3)
131132
# define HPBC_CLOCKWORK_POSTCONDITION_MACRO_IS_ACTIVE (HURCHALLA_CLOCKWORK_ASSERT_LEVEL >= 1)
@@ -142,7 +143,7 @@
142143

143144

144145

145-
#if defined(__cplusplus)
146+
#if defined(HURCHALLA_CLOCKWORK_ENABLE_ASSERTS)
146147
// this section was adapted from the ideas in
147148
// https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
148149
// https://gist.github.com/oliora/928424f7675d58fadf49c70fdba70d2f
@@ -172,6 +173,13 @@
172173
# define HPBC_CLOCKWORK_CONSTEXPR_PRECONDITION(...) HPBC_CLOCKWORK_CONSTEXPR_ASSERT(__VA_ARGS__)
173174
# define HPBC_CLOCKWORK_CONSTEXPR_POSTCONDITION(...) HPBC_CLOCKWORK_CONSTEXPR_ASSERT(__VA_ARGS__)
174175
# define HPBC_CLOCKWORK_CONSTEXPR_INVARIANT(...) HPBC_CLOCKWORK_CONSTEXPR_ASSERT(__VA_ARGS__)
176+
177+
#else
178+
179+
# define HPBC_CLOCKWORK_CONSTEXPR_PRECONDITION(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
180+
# define HPBC_CLOCKWORK_CONSTEXPR_POSTCONDITION(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
181+
# define HPBC_CLOCKWORK_CONSTEXPR_INVARIANT(...) HPBC_CLOCKWORK_DO_NOTHING(__VA_ARGS__)
182+
175183
#endif
176184

177185

modular_arithmetic/include/hurchalla/modular_arithmetic/modular_addition.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ template <typename T> HURCHALLA_FORCE_INLINE
2222
T modular_addition_prereduced_inputs(T a, T b, T modulus)
2323
{
2424
static_assert(ut_numeric_limits<T>::is_integer, "");
25-
HPBC_CLOCKWORK_PRECONDITION(modulus > 0);
26-
HPBC_CLOCKWORK_PRECONDITION(0<=a && a<modulus); // i.e. the input must be prereduced
27-
HPBC_CLOCKWORK_PRECONDITION(0<=b && b<modulus); // i.e. the input must be prereduced
25+
HPBC_CLOCKWORK_API_PRECONDITION(modulus > 0);
26+
HPBC_CLOCKWORK_API_PRECONDITION(0<=a && a<modulus); // i.e. the input must be prereduced
27+
HPBC_CLOCKWORK_API_PRECONDITION(0<=b && b<modulus); // i.e. the input must be prereduced
2828

2929
T result = detail::impl_modular_addition<T>::call(a, b, modulus);
3030

modular_arithmetic/include/hurchalla/modular_arithmetic/modular_multiplication.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ T modular_multiplication_prereduced_inputs(T a, T b, T modulus)
2929
{
3030
static_assert(ut_numeric_limits<T>::is_integer, "");
3131
static_assert(!(ut_numeric_limits<T>::is_signed), "");
32-
HPBC_CLOCKWORK_PRECONDITION(modulus>0);
33-
HPBC_CLOCKWORK_PRECONDITION(a<modulus); // i.e. the input must be prereduced
34-
HPBC_CLOCKWORK_PRECONDITION(b<modulus); // i.e. the input must be prereduced
32+
HPBC_CLOCKWORK_API_PRECONDITION(modulus>0);
33+
HPBC_CLOCKWORK_API_PRECONDITION(a<modulus); // i.e. the input must be prereduced
34+
HPBC_CLOCKWORK_API_PRECONDITION(b<modulus); // i.e. the input must be prereduced
3535

3636
T result = detail::impl_modular_multiplication<T>::call(a, b, modulus);
3737

modular_arithmetic/include/hurchalla/modular_arithmetic/modular_multiplicative_inverse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ T modular_multiplicative_inverse(T a, T modulus, T& gcd)
3030
{
3131
static_assert(ut_numeric_limits<T>::is_integer, "");
3232
static_assert(!(ut_numeric_limits<T>::is_signed), "");
33-
HPBC_CLOCKWORK_PRECONDITION(modulus > 1);
33+
HPBC_CLOCKWORK_API_PRECONDITION(modulus > 1);
3434

3535
T inv = detail::impl_modular_multiplicative_inverse::call(a, modulus, gcd);
3636

modular_arithmetic/include/hurchalla/modular_arithmetic/modular_pow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ T modular_pow(T base, U exponent, T modulus)
2828
static_assert(!(ut_numeric_limits<T>::is_signed), "");
2929
static_assert(ut_numeric_limits<U>::is_integer, "");
3030
static_assert(!(ut_numeric_limits<U>::is_signed), "");
31-
HPBC_CLOCKWORK_PRECONDITION(modulus > 1);
31+
HPBC_CLOCKWORK_API_PRECONDITION(modulus > 1);
3232

3333
T result = detail::impl_modular_pow::call(base, exponent, modulus);
3434

modular_arithmetic/include/hurchalla/modular_arithmetic/modular_subtraction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ T modular_subtraction_prereduced_inputs(T a, T b, T modulus)
2626
static_assert(ut_numeric_limits<T>::is_integer, "");
2727
static_assert(std::is_same<PTAG,LowlatencyTag>::value ||
2828
std::is_same<PTAG,LowuopsTag>::value, "");
29-
HPBC_CLOCKWORK_PRECONDITION(modulus > 0);
30-
HPBC_CLOCKWORK_PRECONDITION(0<=a && a<modulus); // i.e. the input must be prereduced
31-
HPBC_CLOCKWORK_PRECONDITION(0<=b && b<modulus); // i.e. the input must be prereduced
29+
HPBC_CLOCKWORK_API_PRECONDITION(modulus > 0);
30+
HPBC_CLOCKWORK_API_PRECONDITION(0<=a && a<modulus); // i.e. the input must be prereduced
31+
HPBC_CLOCKWORK_API_PRECONDITION(0<=b && b<modulus); // i.e. the input must be prereduced
3232

3333
T result = detail::impl_modular_subtraction<T,PTAG>::call(a, b, modulus);
3434

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/MontgomeryForm.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class MontgomeryForm final {
8484
// type doesn't actually do Montgomery arithmetic. However, to maintain
8585
// compatibility with the normal MontyTypes, it's recommended to always
8686
// use an odd modulus even in that case.]
87-
//HPBC_CLOCKWORK_PRECONDITION(modulus % 2 == 1);
88-
HPBC_CLOCKWORK_PRECONDITION(modulus > 1);
87+
//HPBC_CLOCKWORK_API_PRECONDITION(modulus % 2 == 1);
88+
HPBC_CLOCKWORK_API_PRECONDITION(modulus > 1);
8989
}
9090

9191
// Returns the largest valid modulus allowed for the constructor.
@@ -113,7 +113,7 @@ class MontgomeryForm final {
113113
HURCHALLA_FORCE_INLINE
114114
MontgomeryValue convertIn(T a) const
115115
{
116-
HPBC_CLOCKWORK_PRECONDITION(a >= 0);
116+
HPBC_CLOCKWORK_API_PRECONDITION(a >= 0);
117117
return impl.convertIn(a);
118118
}
119119

@@ -480,7 +480,7 @@ class MontgomeryForm final {
480480
HURCHALLA_FORCE_INLINE
481481
MontgomeryValue pow(MontgomeryValue base, T exponent) const
482482
{
483-
HPBC_CLOCKWORK_PRECONDITION(exponent >= 0);
483+
HPBC_CLOCKWORK_API_PRECONDITION(exponent >= 0);
484484
std::array<MontgomeryValue, 1> bases = {{ base }};
485485
std::array<MontgomeryValue, 1> result =
486486
detail::montgomery_array_pow<MontyTag,
@@ -495,7 +495,7 @@ class MontgomeryForm final {
495495
HURCHALLA_FORCE_INLINE
496496
MontgomeryValue two_pow(T exponent) const
497497
{
498-
HPBC_CLOCKWORK_PRECONDITION(exponent >= 0);
498+
HPBC_CLOCKWORK_API_PRECONDITION(exponent >= 0);
499499
MontgomeryValue result =
500500
detail::montgomery_two_pow::call(*this, exponent);
501501
HPBC_CLOCKWORK_POSTCONDITION(getCanonicalValue(result) ==
@@ -528,7 +528,7 @@ class MontgomeryForm final {
528528
std::array<MontgomeryValue, NUM_BASES>
529529
pow(const std::array<MontgomeryValue, NUM_BASES>& bases, T exponent) const
530530
{
531-
HPBC_CLOCKWORK_PRECONDITION(exponent >= 0);
531+
HPBC_CLOCKWORK_API_PRECONDITION(exponent >= 0);
532532
return detail::montgomery_array_pow<MontyTag,
533533
MontgomeryForm>::pow(*this, bases, exponent);
534534
}
@@ -557,7 +557,7 @@ class MontgomeryForm final {
557557
// even if your CPU has extremely fast division (like many new CPUs).
558558
HURCHALLA_FORCE_INLINE T remainder(T a) const
559559
{
560-
HPBC_CLOCKWORK_PRECONDITION(a >= 0);
560+
HPBC_CLOCKWORK_API_PRECONDITION(a >= 0);
561561
return impl.remainder(a);
562562
}
563563

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/ImplMontgomeryForm.contents

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public:
236236
HURCHALLA_IMF_MAYBE_FORCE_INLINE
237237
T remainder(T a) const
238238
{
239-
HPBC_CLOCKWORK_PRECONDITION1(a >= 0);
239+
HPBC_CLOCKWORK_PRECONDITION(a >= 0);
240240
return static_cast<T>(impl.remainder(static_cast<U>(a)));
241241
}
242242

montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/MontgomeryFormExtensions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct MontgomeryFormExtensions final {
4949
static MontgomeryValue
5050
convertInExtended_aTimesR(const MF& mf, RU a, RU magicValue)
5151
{
52-
HPBC_CLOCKWORK_PRECONDITION1(magicValue == getMagicValue(mf));
52+
HPBC_CLOCKWORK_PRECONDITION(magicValue == getMagicValue(mf));
5353
return mf.impl.template convertInExtended_aTimesR<PTAG>(a, magicValue);
5454
}
5555

@@ -61,7 +61,7 @@ struct MontgomeryFormExtensions final {
6161
HURCHALLA_FORCE_INLINE
6262
static MontgomeryValue twoPowLimited(const MF& mf, size_t exponent)
6363
{
64-
HPBC_CLOCKWORK_PRECONDITION1(exponent < ut_numeric_limits<RU>::digits);
64+
HPBC_CLOCKWORK_PRECONDITION(exponent < ut_numeric_limits<RU>::digits);
6565
return mf.impl.template twoPowLimited<PTAG>(exponent);
6666
}
6767

@@ -73,7 +73,7 @@ struct MontgomeryFormExtensions final {
7373
static MontgomeryValue
7474
RTimesTwoPowLimited(const MF& mf, size_t exponent, RU magicValue)
7575
{
76-
HPBC_CLOCKWORK_PRECONDITION1(exponent < ut_numeric_limits<RU>::digits);
76+
HPBC_CLOCKWORK_PRECONDITION(exponent < ut_numeric_limits<RU>::digits);
7777
return mf.impl.template RTimesTwoPowLimited<PTAG>(exponent, magicValue);
7878
}
7979
};

0 commit comments

Comments
 (0)