Skip to content

Commit e58e132

Browse files
committed
Update minisketch subtree to latest master
2 parents 0de63b8 + 1eea10a commit e58e132

File tree

5 files changed

+64
-47
lines changed

5 files changed

+64
-47
lines changed

src/minisketch/.cirrus.yml

+30-27
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ env_matrix_snippet: &ENV_MATRIX_VALGRIND
3636
TESTRUNS: 1
3737
BUILD:
3838

39-
env_matrix_snippet: &ENV_MATRIX_SAN
40-
- env:
41-
ENABLE_FIELDS: 28
42-
- env:
43-
BUILD: distcheck
44-
- env:
45-
CXXFLAGS: "-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-
5039
env_matrix_snippet: &ENV_MATRIX_SAN_VALGRIND
5140
- env:
5241
ENABLE_FIELDS: "11,64,37"
@@ -72,9 +61,9 @@ task:
7261
<< : *ENV_MATRIX_SAN_VALGRIND
7362
matrix:
7463
- env:
75-
CC: gcc
64+
CXX: g++
7665
- env:
77-
CC: clang
66+
CXX: clang++ -gdwarf-4
7867
<< : *MERGE_BASE
7968
test_script:
8069
- ./ci/cirrus.sh
@@ -92,30 +81,45 @@ task:
9281
<< : *ENV_MATRIX_VALGRIND
9382
matrix:
9483
- env:
95-
CC: i686-linux-gnu-gcc
84+
CXX: i686-linux-gnu-g++
9685
- env:
97-
CC: clang --target=i686-pc-linux-gnu -isystem /usr/i686-linux-gnu/include
86+
CXX: clang++ --target=i686-linux-gnu -gdwarf-4
87+
CXXFLAGS: -g -O2 -isystem /usr/i686-linux-gnu/include -isystem /usr/i686-linux-gnu/include/c++/10/i686-linux-gnu
9888
test_script:
9989
- ./ci/cirrus.sh
10090
<< : *CAT_LOGS
10191

10292
task:
103-
name: "x86_64: macOS Catalina"
93+
name: "arm64: macOS Monterey"
10494
macos_instance:
105-
image: catalina-base
95+
image: ghcr.io/cirruslabs/macos-monterey-base:latest
10696
env:
107-
# Cirrus gives us a fixed number of 12 virtual CPUs.
108-
MAKEFLAGS: -j13
109-
matrix:
110-
<< : *ENV_MATRIX_SAN
97+
# Cirrus gives us a fixed number of 4 virtual CPUs.
98+
MAKEFLAGS: -j5
11199
matrix:
112100
- env:
113-
CC: gcc-9
101+
CXX: g++-11
102+
# Homebrew's gcc for arm64 has no libubsan.
103+
matrix:
104+
- env:
105+
ENABLE_FIELDS: 28
106+
- env:
107+
BUILD: distcheck
114108
- env:
115-
CC: clang
109+
CXX: clang++
110+
matrix:
111+
- env:
112+
ENABLE_FIELDS: 28
113+
- env:
114+
BUILD: distcheck
115+
- env:
116+
CXXFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
117+
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
118+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
119+
BENCH: no
116120
brew_script:
117121
- brew update
118-
- brew install automake libtool gcc@9
122+
- brew install automake libtool gcc@11
119123
<< : *MERGE_BASE
120124
test_script:
121125
- ./ci/cirrus.sh
@@ -128,13 +132,11 @@ task:
128132
cpu: 4
129133
memory: 2G
130134
env:
131-
EXEC_CMD: qemu-s390x -L /usr/s390x-linux-gnu
135+
EXEC_CMD: qemu-s390x
132136
HOST: s390x-linux-gnu
133137
BUILD:
134138
<< : *MERGE_BASE
135139
test_script:
136-
# https://sourceware.org/bugzilla/show_bug.cgi?id=27008
137-
- rm /etc/ld.so.cache
138140
- ./ci/cirrus.sh
139141
<< : *CAT_LOGS
140142

@@ -146,6 +148,7 @@ task:
146148
memory: 2G
147149
env:
148150
EXEC_CMD: wine
151+
EXEC_EXT: .exe
149152
HOST: x86_64-w64-mingw32
150153
BUILD:
151154
<< : *MERGE_BASE

src/minisketch/ci/cirrus.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export LC_ALL=C
77

88
env >> test_env.log
99

10-
$CC -v || true
10+
$CXX -v || true
1111
valgrind --version || true
1212

1313
./autogen.sh
@@ -32,10 +32,10 @@ then
3232
fi
3333

3434
if [ -n "$EXEC_CMD" ]; then
35-
$EXEC_CMD ./test $TESTRUNS
36-
$EXEC_CMD ./test-verify $TESTRUNS
35+
$EXEC_CMD "./test$EXEC_EXT" $TESTRUNS
36+
$EXEC_CMD "./test-verify$EXEC_EXT" $TESTRUNS
3737
fi
3838

3939
if [ "$BENCH" = "yes" ]; then
40-
$EXEC_CMD ./bench
40+
$EXEC_CMD "./bench$EXEC_EXT"
4141
fi

src/minisketch/ci/linux-debian.Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ RUN apt-get update
88
RUN apt-get install --no-install-recommends --no-upgrade -y \
99
git ca-certificates \
1010
make automake libtool pkg-config dpkg-dev valgrind qemu-user \
11-
gcc g++ clang libc6-dbg \
11+
gcc g++ clang libclang-rt-dev libc6-dbg \
1212
gcc-i686-linux-gnu g++-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 \
13-
g++-s390x-linux-gnu gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
14-
wine g++-mingw-w64-x86-64
13+
g++-s390x-linux-gnu libstdc++6:s390x gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
14+
wine wine64 g++-mingw-w64-x86-64
1515

1616
# Run a dummy command in wine to make it set up configuration
1717
RUN wine true || true

src/minisketch/configure.ac

-6
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ esac
104104
AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
105105
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[CXXFLAGS="$CXXFLAGS -fvisibility=hidden"],[],[$CXXFLAG_WERROR])
106106

107-
## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
108-
## unknown options if any other warning is produced. Test the -Wfoo case, and
109-
## set the -Wno-foo case if it works.
110-
AX_CHECK_COMPILE_FLAG([-Wshift-count-overflow],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-shift-count-overflow"],,[[$CXXFLAG_WERROR]])
111-
112107
if test "x$use_ccache" != "xno"; then
113108
AC_MSG_CHECKING(if ccache should be used)
114109
if test x$CCACHE = x; then
@@ -119,7 +114,6 @@ if test "x$use_ccache" != "xno"; then
119114
fi
120115
else
121116
use_ccache=yes
122-
CC="$ac_cv_path_CCACHE $CC"
123117
CXX="$ac_cv_path_CCACHE $CXX"
124118
fi
125119
AC_MSG_RESULT($use_ccache)

src/minisketch/src/int_utils.h

+27-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
#ifndef _MINISKETCH_INT_UTILS_H_
88
#define _MINISKETCH_INT_UTILS_H_
99

10+
#include <stdint.h>
1011
#include <stdlib.h>
1112

1213
#include <limits>
1314
#include <algorithm>
1415
#include <type_traits>
1516

16-
#ifdef _MSC_VER
17+
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
18+
# include <bit>
19+
#elif defined(_MSC_VER)
1720
# include <intrin.h>
1821
#endif
1922

@@ -54,11 +57,10 @@ class BitWriter {
5457
int offset = 0;
5558
unsigned char* out;
5659

57-
public:
58-
BitWriter(unsigned char* output) : out(output) {}
59-
6060
template<int BITS, typename I>
61-
inline void Write(I val) {
61+
inline void WriteInner(I val) {
62+
// We right shift by up to 8 bits below. Verify that's well defined for the type I.
63+
static_assert(std::numeric_limits<I>::digits > 8, "BitWriter::WriteInner needs I > 8 bits");
6264
int bits = BITS;
6365
if (bits + offset >= 8) {
6466
state |= ((val & ((I(1) << (8 - offset)) - 1)) << offset);
@@ -77,6 +79,19 @@ class BitWriter {
7779
offset += bits;
7880
}
7981

82+
83+
public:
84+
BitWriter(unsigned char* output) : out(output) {}
85+
86+
template<int BITS, typename I>
87+
inline void Write(I val) {
88+
// If I is smaller than an unsigned int, invoke WriteInner with argument converted to unsigned.
89+
using compute_type = typename std::conditional<
90+
(std::numeric_limits<I>::digits < std::numeric_limits<unsigned>::digits),
91+
unsigned, I>::type;
92+
return WriteInner<BITS, compute_type>(val);
93+
}
94+
8095
inline void Flush() {
8196
if (offset) {
8297
*(out++) = state;
@@ -129,7 +144,11 @@ constexpr inline I Mask() { return ((I((I(-1)) << (std::numeric_limits<I>::digit
129144
/** Compute the smallest power of two that is larger than val. */
130145
template<typename I>
131146
static inline int CountBits(I val, int max) {
132-
#ifdef _MSC_VER
147+
#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
148+
// c++20 impl
149+
(void)max;
150+
return std::bit_width(val);
151+
#elif defined(_MSC_VER)
133152
(void)max;
134153
unsigned long index;
135154
unsigned char ret;
@@ -175,6 +194,7 @@ class BitsInt {
175194
}
176195

177196
static constexpr inline bool IsZero(I a) { return a == 0; }
197+
static constexpr inline bool IsOne(I a) { return a == 1; }
178198
static constexpr inline I Mask(I val) { return val & MASK; }
179199
static constexpr inline I Shift(I val, int bits) { return ((val << bits) & MASK); }
180200
static constexpr inline I UnsafeShift(I val, int bits) { return (val << bits); }
@@ -233,7 +253,7 @@ template<typename I, int N, typename L, typename F> inline constexpr I GFMul(con
233253
template<typename I, typename F, int BITS, uint32_t MOD>
234254
inline I InvExtGCD(I x)
235255
{
236-
if (F::IsZero(x)) return x;
256+
if (F::IsZero(x) || F::IsOne(x)) return x;
237257
I t(0), newt(1);
238258
I r(MOD), newr = x;
239259
int rlen = BITS + 1, newrlen = F::Bits(newr, BITS);

0 commit comments

Comments
 (0)