Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Jun 12, 2024
2 parents 7af8ea7 + 0f69ad2 commit a0c23dd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ $(OBJ_DIR)/$(MSM)_test.o: src/$(MSM).cpp
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -mavx512f -mavx512ifma -std=c++11 $(CFLAGS_USER) -DMCL_MSM_TEST
MSM_TEST_OBJ=$(OBJ_DIR)/$(MSM)_test.o $(filter-out $(OBJ_DIR)/msm_avx.o,$(LIB_OBJ))
$(EXE_DIR)/msm_test.exe: $(MSM_TEST_OBJ)
$(PRE)$(CXX) -o $@ $(LDFLAGS) $(MSM_TEST_OBJ)
$(PRE)$(CXX) -o $@ $(MSM_TEST_OBJ) $(LDFLAGS)
-include $(OBJ_DIR)/msm_test.d

make_tbl:
Expand Down
8 changes: 6 additions & 2 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ CFLAGS+=$(CFLAGS_USER)
ifneq ($(MCL_SIZEOF_UNIT),)
CFLAGS+=-DMCL_SIZEOF_UNIT=$(MCL_SIZEOF_UNIT)
endif
MCL_USE_GMP?=1
MCL_USE_GMP?=0
ifeq ($(MCL_USE_GMP),1)
CFLAGS+=-DMCL_USE_GMP=1
MCL_USE_GMP_LIB=1
endif
MCL_USE_GMP_LIB?=1
ifeq ($(MCL_USE_GMP_LIB),1)
GMP_LIB=-lgmp -lgmpxx
ifeq ($(UNAME_S),Darwin)
GMP_DIR?=/opt/homebrew/
Expand All @@ -138,7 +143,6 @@ ifeq ($(MCL_USE_GMP),1)
CFLAGS+=-I$(GMP_DIR)/include
LDFLAGS+=-L$(GMP_DIR)/lib
endif
# CFLAGS+=-DMCL_USE_GMP=1
endif
ifeq ($(MCL_STATIC_CODE),1)
MCL_USE_XBYAK=0
Expand Down
8 changes: 6 additions & 2 deletions include/mcl/gmp_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ template<class T>
void getArray(bool *pb, T *buf, size_t maxSize, const mpz_class& x)
{
#ifdef MCL_USE_VINT
if (x.isNegative()) {
*pb = false;
return;
}
const Unit *src = x.getUnit();
const size_t n = x.getUnitSize();
*pb = fp::convertArrayAsLE(buf, maxSize, src, n);
#else
int n = x.get_mpz_t()->_mp_size;
if (n < 0) {
*pb = false;
return;
}
*pb = fp::convertArrayAsLE(buf, maxSize, x.get_mpz_t()->_mp_d, n);
const Unit *src = (const Unit*)x.get_mpz_t()->_mp_d;
#endif
*pb = fp::convertArrayAsLE(buf, maxSize, src, n);
}
inline void set(mpz_class& z, uint64_t x)
{
Expand Down
2 changes: 1 addition & 1 deletion include/mcl/vint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class Vint {
bool isZero() const { return size() == 1 && buf_[0] == 0; }
bool isNegative() const { return !isZero() && isNeg_; }
uint32_t getLow32bit() const { return (uint32_t)buf_[0]; }
bool isOdd() const { return (buf_[0] & 1) == 1; }
bool isOdd() const { return size() > 0 && (buf_[0] & 1) == 1; }
bool isEven() const { return !isOdd(); }
const Unit *getUnit() const { return buf_; }
size_t getUnitSize() const { return size_; }
Expand Down
10 changes: 5 additions & 5 deletions src/msm_avx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ inline void dump(const Vec& v, const char *msg = nullptr)
}

template<size_t N, int w = W>
inline void toArray(Unit x[N], mpz_class mx)
inline void toArray(Unit x[N], const mpz_class& mx)
{
const Unit mask = getMask(w);
Unit tmp[N];
mcl::gmp::getArray(tmp, N, mx);
for (size_t i = 0; i < N; i++) {
mpz_class a = mx & mask;
x[i] = mcl::gmp::getUnit(a)[0];
mx >>= w;
x[i] = mcl::fp::getUnitAt(tmp, N, i*w) & mask;
}
}

Expand Down Expand Up @@ -1733,7 +1733,7 @@ CYBOZU_TEST_AUTO(mulEach_special)
G1::mulEach(Q, x, 8);
CYBOZU_TEST_EQUAL(R[0], Q[0]);
mpz_class L;
L.setStr("0xac45a4010001a40200000000ffffffff");
mcl::gmp::setStr(L, "0xac45a4010001a40200000000ffffffff");
mpz_class tbl[] = {
0,
1,
Expand Down

0 comments on commit a0c23dd

Please sign in to comment.