Skip to content

Commit 74345ec

Browse files
committed
Merge #20: Make built field sizes configurable
1e3abc3 Remove a few unnecessary includes (Pieter Wuille) 2818397 Compile less when all of a module's fields are disabled (Pieter Wuille) b6f01a8 Test configured field sizes in CI (Pieter Wuille) a0c7977 Clean up CI configuration (Pieter Wuille) dd914ce Permit disabling of certain field sizes (Pieter Wuille) Pull request description: This adds a `--enable-fields=LIST` configure options, which takes a list of integers. The default is all supported field sizes (currently 2 through 64 inclusive). Binary sizes and compile time go down significantly when reducing the list. ACKs for top commit: gmaxwell: ACK 1e3abc3 much better. Tree-SHA512: 6f2ab388b20e5c094bdda860a2acbfe28ade69c001abb1680144bc8536b0012e1b3a75ee79dc86c0fd5d319ebf5e01e4e35d30e23c5c905c1d3ec131a8e88184
2 parents 901bbd3 + 1e3abc3 commit 74345ec

23 files changed

+902
-74
lines changed

.cirrus.yml

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ env:
55
BENCH: yes
66
TESTRUNS:
77
EXEC_CMD:
8+
ENABLE_FIELDS:
89

910
cat_logs_snippet: &CAT_LOGS
1011
on_failure:
12+
cat_test_log_script:
13+
- cat test-suite.log || true
1114
cat_config_log_script:
1215
- cat config.log || true
1316
cat_test_env_script:
@@ -23,25 +26,50 @@ merge_base_script_snippet: &MERGE_BASE
2326
- git config --global user.name "ci"
2427
- git merge FETCH_HEAD # Merge base to detect silent merge conflicts
2528

29+
env_matrix_snippet: &ENV_MATRIX_VALGRIND
30+
- env:
31+
ENABLE_FIELDS: "7,32,58"
32+
- env:
33+
BUILD: distcheck
34+
- env:
35+
EXEC_CMD: valgrind --error-exitcode=42
36+
TESTRUNS: 1
37+
BUILD:
38+
39+
env_matrix_snippet: &ENV_MATRIX_SAN
40+
- env:
41+
ENABLE_FIELDS: 28
42+
- env:
43+
BUILD: distcheck
44+
- env:
45+
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
46+
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
47+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
48+
BENCH: no
49+
50+
env_matrix_snippet: &ENV_MATRIX_SAN_VALGRIND
51+
- env:
52+
ENABLE_FIELDS: "11,64,37"
53+
- env:
54+
BUILD: distcheck
55+
- env:
56+
EXEC_CMD: valgrind --error-exitcode=42
57+
TESTRUNS: 1
58+
BUILD:
59+
- env:
60+
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
61+
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
62+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
63+
BENCH: no
64+
2665
task:
2766
name: "x86_64: Linux (Debian stable)"
2867
container:
2968
dockerfile: ci/linux-debian.Dockerfile
3069
memory: 2G
3170
cpu: 4
32-
matrix: &ENV_MATRIX
33-
- env:
34-
- env:
35-
BUILD: distcheck
36-
- env:
37-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
38-
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
39-
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
40-
BENCH: no
41-
- env:
42-
EXEC_CMD: valgrind --error-exitcode=42
43-
TESTRUNS: 1
44-
BUILD:
71+
matrix:
72+
<< : *ENV_MATRIX_SAN_VALGRIND
4573
matrix:
4674
- env:
4775
CC: gcc
@@ -60,6 +88,8 @@ task:
6088
cpu: 4
6189
env:
6290
HOST: i686-linux-gnu
91+
matrix:
92+
<< : *ENV_MATRIX_VALGRIND
6393
matrix:
6494
- env:
6595
CC: i686-linux-gnu-gcc
@@ -77,12 +107,7 @@ task:
77107
# Cirrus gives us a fixed number of 12 virtual CPUs.
78108
MAKEFLAGS: -j13
79109
matrix:
80-
- env: {}
81-
- env: {BUILD: distcheck}
82-
- env:
83-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
84-
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
85-
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
110+
<< : *ENV_MATRIX_SAN
86111
matrix:
87112
- env:
88113
CC: gcc-9

ci/cirrus.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ valgrind --version || true
1212

1313
./autogen.sh
1414

15-
./configure --host="$HOST" --enable-benchmark="$BENCH"
15+
FIELDS=
16+
if [ -n "$ENABLE_FIELDS" ]; then
17+
FIELDS="--enable-fields=$ENABLE_FIELDS"
18+
fi
19+
./configure --host="$HOST" --enable-benchmark="$BENCH" $FIELDS
1620

1721
# We have set "-j<n>" in MAKEFLAGS.
1822
make

configure.ac

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ AC_ARG_ENABLE(benchmark,
3030
[use_benchmark=$enableval],
3131
[use_benchmark=no])
3232

33+
m4_define([SUPPORTED_FIELDS], [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64])
34+
35+
AC_MSG_CHECKING([which field sizes to build])
36+
AC_ARG_ENABLE([fields], AS_HELP_STRING([--enable-fields=LIST], [Comma-separated list of field sizes to build. Default=all. Available sizes:] m4_translit(m4_defn([SUPPORTED_FIELDS]), [,], [ ])), [], [enable_fields=SUPPORTED_FIELDS])
37+
have_disabled_fields=no
38+
have_enabled_fields=no
39+
m4_foreach([FIELD], [SUPPORTED_FIELDS], [
40+
case ",$enable_fields," in
41+
*,FIELD,*)
42+
have_enabled_fields=yes
43+
;;
44+
*)
45+
AC_DEFINE(DISABLE_FIELD_[]FIELD, [1],
46+
[Define to 1 to remove support for field size] FIELD [.])
47+
have_disabled_fields=yes
48+
;;
49+
esac
50+
])
51+
AC_MSG_RESULT([$enable_fields])
52+
if test "x$have_enabled_fields" = xno; then
53+
AC_MSG_ERROR([No field sizes are enabled.])
54+
fi
55+
3356
AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
3457

3558
AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
@@ -116,3 +139,8 @@ echo " CXX = $CXX"
116139
echo " CXXFLAGS = $CXXFLAGS"
117140
echo " CPPFLAGS = $CPPFLAGS"
118141
echo " LDFLAGS = $LDFLAGS"
142+
if test "$have_disabled_fields" = "yes"; then
143+
echo
144+
echo "Only compiling in support for field sizes: $enable_fields"
145+
echo "WARNING: this means the library will lack support for other field sizes entirely"
146+
fi

doc/gen_params.sage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,18 @@ def print_result(bits, style):
312312
assert(False)
313313

314314
for bits in range(2, 65):
315+
print("#ifndef DISABLE_FIELD_%i" % bits)
315316
print("// %i bit field" % bits)
316317
print_result(bits, INT)
318+
print("#endif")
317319
print("")
318320

319321
for bits in range(2, 65):
322+
print("#ifndef DISABLE_FIELD_%i" % bits)
320323
print("// %i bit field" % bits)
321324
print_result(bits, CLMUL)
322325
print_result(bits, CLMUL_TRI)
326+
print("#endif")
323327
print("")
324328

325329
for bits in range(2, 65):

src/fields/clmul_1byte.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,113 @@
66

77
/* This file was substantially auto-generated by doc/gen_params.sage. */
88

9-
#include <stdint.h>
9+
#if !defined(DISABLE_FIELD_2) || !defined(DISABLE_FIELD_3) || !defined(DISABLE_FIELD_4) || !defined(DISABLE_FIELD_5) || !defined(DISABLE_FIELD_6) || !defined(DISABLE_FIELD_7) || !defined(DISABLE_FIELD_8)
1010

1111
#include "clmul_common_impl.h"
1212

1313
#include "../int_utils.h"
1414
#include "../lintrans.h"
1515
#include "../sketch_impl.h"
16+
17+
#endif
18+
1619
#include "../sketch.h"
1720

1821
namespace {
19-
22+
#ifndef DISABLE_FIELD_2
2023
// 2 bit field
2124
typedef RecLinTrans<uint8_t, 2> StatTableTRI2;
2225
constexpr StatTableTRI2 SQR_TABLE_TRI2({0x1, 0x3});
2326
constexpr StatTableTRI2 QRT_TABLE_TRI2({0x2, 0});
2427
typedef FieldTri<uint8_t, 2, 1, StatTableTRI2, &SQR_TABLE_TRI2, nullptr, nullptr, nullptr, nullptr, &QRT_TABLE_TRI2, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri2;
28+
#endif
2529

30+
#ifndef DISABLE_FIELD_3
2631
// 3 bit field
2732
typedef RecLinTrans<uint8_t, 3> StatTableTRI3;
2833
constexpr StatTableTRI3 SQR_TABLE_TRI3({0x1, 0x4, 0x6});
2934
constexpr StatTableTRI3 QRT_TABLE_TRI3({0, 0x4, 0x6});
3035
typedef FieldTri<uint8_t, 3, 1, StatTableTRI3, &SQR_TABLE_TRI3, nullptr, nullptr, nullptr, nullptr, &QRT_TABLE_TRI3, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri3;
36+
#endif
3137

38+
#ifndef DISABLE_FIELD_4
3239
// 4 bit field
3340
typedef RecLinTrans<uint8_t, 4> StatTableTRI4;
3441
constexpr StatTableTRI4 SQR_TABLE_TRI4({0x1, 0x4, 0x3, 0xc});
3542
constexpr StatTableTRI4 QRT_TABLE_TRI4({0x6, 0xa, 0x8, 0});
3643
typedef FieldTri<uint8_t, 4, 1, StatTableTRI4, &SQR_TABLE_TRI4, nullptr, nullptr, nullptr, nullptr, &QRT_TABLE_TRI4, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri4;
44+
#endif
3745

46+
#ifndef DISABLE_FIELD_5
3847
// 5 bit field
3948
typedef RecLinTrans<uint8_t, 5> StatTable5;
4049
constexpr StatTable5 SQR_TABLE_5({0x1, 0x4, 0x10, 0xa, 0xd});
4150
constexpr StatTable5 SQR2_TABLE_5({0x1, 0x10, 0xd, 0xe, 0x1b});
4251
constexpr StatTable5 QRT_TABLE_5({0x14, 0x8, 0xa, 0, 0xe});
4352
typedef Field<uint8_t, 5, 5, StatTable5, &SQR_TABLE_5, &SQR2_TABLE_5, nullptr, nullptr, nullptr, &QRT_TABLE_5, IdTrans, &ID_TRANS, &ID_TRANS> Field5;
4453
typedef FieldTri<uint8_t, 5, 2, RecLinTrans<uint8_t, 5>, &SQR_TABLE_5, &SQR2_TABLE_5, nullptr, nullptr, nullptr, &QRT_TABLE_5, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri5;
54+
#endif
4555

56+
#ifndef DISABLE_FIELD_6
4657
// 6 bit field
4758
typedef RecLinTrans<uint8_t, 6> StatTableTRI6;
4859
constexpr StatTableTRI6 SQR_TABLE_TRI6({0x1, 0x4, 0x10, 0x3, 0xc, 0x30});
4960
constexpr StatTableTRI6 SQR2_TABLE_TRI6({0x1, 0x10, 0xc, 0x5, 0x13, 0x3c});
5061
constexpr StatTableTRI6 QRT_TABLE_TRI6({0x3a, 0x26, 0x24, 0x14, 0x20, 0});
5162
typedef FieldTri<uint8_t, 6, 1, StatTableTRI6, &SQR_TABLE_TRI6, &SQR2_TABLE_TRI6, nullptr, nullptr, nullptr, &QRT_TABLE_TRI6, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri6;
63+
#endif
5264

65+
#ifndef DISABLE_FIELD_7
5366
// 7 bit field
5467
typedef RecLinTrans<uint8_t, 4, 3> StatTableTRI7;
5568
constexpr StatTableTRI7 SQR_TABLE_TRI7({0x1, 0x4, 0x10, 0x40, 0x6, 0x18, 0x60});
5669
constexpr StatTableTRI7 SQR2_TABLE_TRI7({0x1, 0x10, 0x6, 0x60, 0x14, 0x46, 0x78});
5770
constexpr StatTableTRI7 QRT_TABLE_TRI7({0, 0x14, 0x16, 0x72, 0x12, 0x40, 0x7a});
5871
typedef FieldTri<uint8_t, 7, 1, StatTableTRI7, &SQR_TABLE_TRI7, &SQR2_TABLE_TRI7, nullptr, nullptr, nullptr, &QRT_TABLE_TRI7, IdTrans, &ID_TRANS, &ID_TRANS> FieldTri7;
72+
#endif
5973

74+
#ifndef DISABLE_FIELD_8
6075
// 8 bit field
6176
typedef RecLinTrans<uint8_t, 4, 4> StatTable8;
6277
constexpr StatTable8 SQR_TABLE_8({0x1, 0x4, 0x10, 0x40, 0x1b, 0x6c, 0xab, 0x9a});
6378
constexpr StatTable8 SQR2_TABLE_8({0x1, 0x10, 0x1b, 0xab, 0x5e, 0x97, 0xb3, 0xc5});
6479
constexpr StatTable8 QRT_TABLE_8({0xbc, 0x2a, 0x28, 0x86, 0x2c, 0xde, 0x8e, 0});
6580
typedef Field<uint8_t, 8, 27, StatTable8, &SQR_TABLE_8, &SQR2_TABLE_8, nullptr, nullptr, nullptr, &QRT_TABLE_8, IdTrans, &ID_TRANS, &ID_TRANS> Field8;
66-
81+
#endif
6782
}
6883

6984
Sketch* ConstructClMul1Byte(int bits, int implementation) {
7085
switch (bits) {
86+
#ifndef DISABLE_FIELD_5
7187
case 5: return new SketchImpl<Field5>(implementation, 5);
88+
#endif
89+
#ifndef DISABLE_FIELD_8
7290
case 8: return new SketchImpl<Field8>(implementation, 8);
91+
#endif
7392
}
7493
return nullptr;
7594
}
7695

7796
Sketch* ConstructClMulTri1Byte(int bits, int implementation) {
7897
switch (bits) {
98+
#ifndef DISABLE_FIELD_2
7999
case 2: return new SketchImpl<FieldTri2>(implementation, 2);
100+
#endif
101+
#ifndef DISABLE_FIELD_3
80102
case 3: return new SketchImpl<FieldTri3>(implementation, 3);
103+
#endif
104+
#ifndef DISABLE_FIELD_4
81105
case 4: return new SketchImpl<FieldTri4>(implementation, 4);
106+
#endif
107+
#ifndef DISABLE_FIELD_5
82108
case 5: return new SketchImpl<FieldTri5>(implementation, 5);
109+
#endif
110+
#ifndef DISABLE_FIELD_6
83111
case 6: return new SketchImpl<FieldTri6>(implementation, 6);
112+
#endif
113+
#ifndef DISABLE_FIELD_7
84114
case 7: return new SketchImpl<FieldTri7>(implementation, 7);
115+
#endif
85116
}
86117
return nullptr;
87118
}

0 commit comments

Comments
 (0)