rename function from bit to N

dev
MITSUNARI Shigeo 8 years ago
parent 2ee5bd3b4e
commit 74620cb7a4
  1. 2
      readme.md
  2. 62
      src/fp.cpp
  3. 76
      src/fp_proto.hpp
  4. 92
      src/gen.cpp

@ -35,7 +35,7 @@ make sample
Build openssl and gmp for 32-bit mode and install <lib32>
```
cd mcl
make BIT=32 CFLAGS_USER="-I <lib32>/include" LDFLAGS_USER="-L <lib32>/lib -Wl,-rpath,<lib32>/lib"
make ARCH=x86 CFLAGS_USER="-I <lib32>/include" LDFLAGS_USER="-L <lib32>/lib -Wl,-rpath,<lib32>/lib"
```
## Build for 64-bit Windows

@ -109,18 +109,18 @@ Mode StrToMode(const std::string& s)
#ifdef MCL_USE_LLVM
#define MCL_DEF_LLVM_FUNC(bit) \
template<>const u3u AddNC<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fp_addNC ## bit ## L; \
template<>const u3u SubNC<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fp_subNC ## bit ## L; \
template<>const void3u MulPre<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fpDbl_mulPre ## bit ## L; \
template<>const void2u SqrPre<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fpDbl_sqrPre ## bit ## L; \
template<>const void2uI Mul_UnitPre<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fp_mul_UnitPre ## bit ## L; \
template<>const void4u Add<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fp_add ## bit ## L; \
template<>const void4u Sub<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fp_sub ## bit ## L; \
template<>const void4u Mont<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fp_mont ## bit ## L; \
template<>const void3u MontRed<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fp_montRed ## bit ## L; \
template<>const void4u DblAdd<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fpDbl_add ## bit ## L; \
template<>const void4u DblSub<bit / mcl::fp::UnitBitSize, Ltag>::f = &mcl_fpDbl_sub ## bit ## L; \
#define MCL_DEF_LLVM_FUNC(n) \
template<>const u3u AddNC<n, Ltag>::f = &mcl_fp_addNC ## n ## L; \
template<>const u3u SubNC<n, Ltag>::f = &mcl_fp_subNC ## n ## L; \
template<>const void3u MulPre<n, Ltag>::f = &mcl_fpDbl_mulPre ## n ## L; \
template<>const void2u SqrPre<n, Ltag>::f = &mcl_fpDbl_sqrPre ## n ## L; \
template<>const void2uI Mul_UnitPre<n, Ltag>::f = &mcl_fp_mul_UnitPre ## n ## L; \
template<>const void4u Add<n, Ltag>::f = &mcl_fp_add ## n ## L; \
template<>const void4u Sub<n, Ltag>::f = &mcl_fp_sub ## n ## L; \
template<>const void4u Mont<n, Ltag>::f = &mcl_fp_mont ## n ## L; \
template<>const void3u MontRed<n, Ltag>::f = &mcl_fp_montRed ## n ## L; \
template<>const void4u DblAdd<n, Ltag>::f = &mcl_fpDbl_add ## n ## L; \
template<>const void4u DblSub<n, Ltag>::f = &mcl_fpDbl_sub ## n ## L; \
template<size_t N>
struct Mul<N, Ltag> {
@ -150,26 +150,26 @@ struct Sqr<N, Ltag> {
template<size_t N>
const void3u Sqr<N, Ltag>::f = Sqr<N, Ltag>::func;
MCL_DEF_LLVM_FUNC(64)
MCL_DEF_LLVM_FUNC(128)
MCL_DEF_LLVM_FUNC(192)
MCL_DEF_LLVM_FUNC(256)
MCL_DEF_LLVM_FUNC(320)
MCL_DEF_LLVM_FUNC(384)
MCL_DEF_LLVM_FUNC(448)
MCL_DEF_LLVM_FUNC(512)
MCL_DEF_LLVM_FUNC(1)
MCL_DEF_LLVM_FUNC(2)
MCL_DEF_LLVM_FUNC(3)
MCL_DEF_LLVM_FUNC(4)
MCL_DEF_LLVM_FUNC(5)
MCL_DEF_LLVM_FUNC(6)
MCL_DEF_LLVM_FUNC(7)
MCL_DEF_LLVM_FUNC(8)
MCL_DEF_LLVM_FUNC(9)
#if CYBOZU_OS_BIT == 32 || MCL_MAX_OP_BIT_SIZE == 768
MCL_DEF_LLVM_FUNC(10)
MCL_DEF_LLVM_FUNC(11)
MCL_DEF_LLVM_FUNC(12)
#endif
#if CYBOZU_OS_BIT == 32
MCL_DEF_LLVM_FUNC(32)
MCL_DEF_LLVM_FUNC(96)
MCL_DEF_LLVM_FUNC(160)
MCL_DEF_LLVM_FUNC(224)
MCL_DEF_LLVM_FUNC(288)
MCL_DEF_LLVM_FUNC(352)
MCL_DEF_LLVM_FUNC(416)
MCL_DEF_LLVM_FUNC(480)
MCL_DEF_LLVM_FUNC(544)
#else
MCL_DEF_LLVM_FUNC(576)
MCL_DEF_LLVM_FUNC(13)
MCL_DEF_LLVM_FUNC(14)
MCL_DEF_LLVM_FUNC(15)
MCL_DEF_LLVM_FUNC(16)
MCL_DEF_LLVM_FUNC(17)
#endif
#endif

@ -123,22 +123,22 @@ const void4u DblSub<N, Tag>::f = DblSub<N, Tag>::func;
#ifdef MCL_USE_LLVM
#define MCL_FP_DEF_FUNC_SUB(len, suf) \
void mcl_fp_add ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fp_sub ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
mcl::fp::Unit mcl_fp_addNC ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \
mcl::fp::Unit mcl_fp_subNC ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \
void mcl_fp_mul_UnitPre ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, mcl::fp::Unit y); \
void mcl_fpDbl_mulPre ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \
void mcl_fpDbl_sqrPre ## len ## suf(mcl::fp::Unit* y, const mcl::fp::Unit* x); \
void mcl_fp_mont ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fp_montRed ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* xy, const mcl::fp::Unit* p); \
void mcl_fpDbl_add ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fpDbl_sub ## len ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p);
#define MCL_FP_DEF_FUNC(len) \
MCL_FP_DEF_FUNC_SUB(len, L) \
MCL_FP_DEF_FUNC_SUB(len, A)
#define MCL_FP_DEF_FUNC_SUB(n, suf) \
void mcl_fp_add ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fp_sub ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
mcl::fp::Unit mcl_fp_addNC ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \
mcl::fp::Unit mcl_fp_subNC ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \
void mcl_fp_mul_UnitPre ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, mcl::fp::Unit y); \
void mcl_fpDbl_mulPre ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \
void mcl_fpDbl_sqrPre ## n ## suf(mcl::fp::Unit* y, const mcl::fp::Unit* x); \
void mcl_fp_mont ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fp_montRed ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* xy, const mcl::fp::Unit* p); \
void mcl_fpDbl_add ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fpDbl_sub ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p);
#define MCL_FP_DEF_FUNC(n) \
MCL_FP_DEF_FUNC_SUB(n, L) \
MCL_FP_DEF_FUNC_SUB(n, A)
#define MCL_FP_DEF_FUNC_SPECIAL(suf) \
void mcl_fpDbl_mod_NIST_P192 ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* xy, const mcl::fp::Unit* /* dummy */); \
@ -148,32 +148,26 @@ void mcl_fpDbl_mod_NIST_P521 ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* xy, c
extern "C" {
MCL_FP_DEF_FUNC(64)
MCL_FP_DEF_FUNC(128)
MCL_FP_DEF_FUNC(192)
MCL_FP_DEF_FUNC(256)
MCL_FP_DEF_FUNC(320)
MCL_FP_DEF_FUNC(384)
MCL_FP_DEF_FUNC(448)
MCL_FP_DEF_FUNC(512)
MCL_FP_DEF_FUNC(1)
MCL_FP_DEF_FUNC(2)
MCL_FP_DEF_FUNC(3)
MCL_FP_DEF_FUNC(4)
MCL_FP_DEF_FUNC(5)
MCL_FP_DEF_FUNC(6)
MCL_FP_DEF_FUNC(7)
MCL_FP_DEF_FUNC(8)
MCL_FP_DEF_FUNC(9)
#if CYBOZU_OS_BIT == 32 || MCL_MAX_OP_BIT_SIZE == 768
MCL_FP_DEF_FUNC(10)
MCL_FP_DEF_FUNC(11)
MCL_FP_DEF_FUNC(12)
#endif
#if CYBOZU_OS_BIT == 32
MCL_FP_DEF_FUNC(160)
MCL_FP_DEF_FUNC(224)
MCL_FP_DEF_FUNC(288)
MCL_FP_DEF_FUNC(352)
MCL_FP_DEF_FUNC(416)
MCL_FP_DEF_FUNC(480)
MCL_FP_DEF_FUNC(544)
#else
MCL_FP_DEF_FUNC(576)
MCL_FP_DEF_FUNC(640)
MCL_FP_DEF_FUNC(704)
MCL_FP_DEF_FUNC(768)
MCL_FP_DEF_FUNC(1024)
MCL_FP_DEF_FUNC(1152)
MCL_FP_DEF_FUNC(1280)
MCL_FP_DEF_FUNC(1408)
MCL_FP_DEF_FUNC(1536)
MCL_FP_DEF_FUNC(13)
MCL_FP_DEF_FUNC(14)
MCL_FP_DEF_FUNC(15)
MCL_FP_DEF_FUNC(16)
MCL_FP_DEF_FUNC(17)
#endif
MCL_FP_DEF_FUNC_SPECIAL(L)

@ -252,8 +252,8 @@ struct Code : public mcl::Generator {
Operand buf = _alloca(192, 2);
Operand p = bitcast(buf, Operand(IntPtr, unit)); // QQQ : use makeType()
// QQQ define later
Function mcl_fpDbl_sqrPre192("mcl_fpDbl_sqrPre192L", Void, p, px);
call(mcl_fpDbl_sqrPre192, p, px);
Function mcl_fpDbl_sqrPre("mcl_fpDbl_sqrPre" + cybozu::itoa(192 / unit) + "L", Void, p, px);
call(mcl_fpDbl_sqrPre, p, px);
call(mcl_fpDbl_mod_NIST_P192, py, buf);
ret(Void);
endFunc();
@ -270,8 +270,8 @@ struct Code : public mcl::Generator {
Operand buf = _alloca(192, 2);
Operand p = bitcast(buf, Operand(IntPtr, unit)); // QQQ : use makeType()
// QQQ define later
Function mcl_fpDbl_mulPre192("mcl_fpDbl_mulPre192L", Void, p, px, py);
call(mcl_fpDbl_mulPre192, p, px, py);
Function mcl_fpDbl_mulPre("mcl_fpDbl_mulPre" + cybozu::itoa(192 / unit) + "L", Void, p, px, py);
call(mcl_fpDbl_mulPre, p, px, py);
call(mcl_fpDbl_mod_NIST_P192, pz, buf);
ret(Void);
endFunc();
@ -302,15 +302,15 @@ struct Code : public mcl::Generator {
Operand py(IntPtr, bit);
std::string name;
if (isAdd) {
name = "mcl_fp_addNC" + cybozu::itoa(bit) + "L";
mcl_fp_addNCM[bit] = Function(name, r, pz, px, py);
verifyAndSetPrivate(mcl_fp_addNCM[bit]);
beginFunc(mcl_fp_addNCM[bit]);
name = "mcl_fp_addNC" + cybozu::itoa(N) + "L";
mcl_fp_addNCM[N] = Function(name, r, pz, px, py);
verifyAndSetPrivate(mcl_fp_addNCM[N]);
beginFunc(mcl_fp_addNCM[N]);
} else {
name = "mcl_fp_subNC" + cybozu::itoa(bit) + "L";
mcl_fp_subNCM[bit] = Function(name, r, pz, px, py);
verifyAndSetPrivate(mcl_fp_subNCM[bit]);
beginFunc(mcl_fp_subNCM[bit]);
name = "mcl_fp_subNC" + cybozu::itoa(N) + "L";
mcl_fp_subNCM[N] = Function(name, r, pz, px, py);
verifyAndSetPrivate(mcl_fp_subNCM[N]);
beginFunc(mcl_fp_subNCM[N]);
}
Operand x = zext(load(px), bit + unit);
Operand y = zext(load(py), bit + unit);
@ -366,10 +366,10 @@ struct Code : public mcl::Generator {
Operand px(IntPtr, bit);
Operand py(IntPtr, bit);
Operand pp(IntPtr, bit);
std::string name = "mcl_fp_add" + cybozu::itoa(bit) + "L";
mcl_fp_addM[bit] = Function(name, Void, pz, px, py, pp);
verifyAndSetPrivate(mcl_fp_addM[bit]);
beginFunc(mcl_fp_addM[bit]);
std::string name = "mcl_fp_add" + cybozu::itoa(N) + "L";
mcl_fp_addM[N] = Function(name, Void, pz, px, py, pp);
verifyAndSetPrivate(mcl_fp_addM[N]);
beginFunc(mcl_fp_addM[N]);
Operand x = load(px);
Operand y = load(py);
Operand p = load(pp);
@ -400,10 +400,10 @@ struct Code : public mcl::Generator {
Operand px(IntPtr, bit);
Operand py(IntPtr, bit);
Operand pp(IntPtr, bit);
std::string name = "mcl_fp_sub" + cybozu::itoa(bit) + "L";
mcl_fp_subM[bit] = Function(name, Void, pz, px, py, pp);
verifyAndSetPrivate(mcl_fp_subM[bit]);
beginFunc(mcl_fp_subM[bit]);
std::string name = "mcl_fp_sub" + cybozu::itoa(N) + "L";
mcl_fp_subM[N] = Function(name, Void, pz, px, py, pp);
verifyAndSetPrivate(mcl_fp_subM[N]);
beginFunc(mcl_fp_subM[N]);
Operand x = load(px);
Operand y = load(py);
x = zext(x, bit + unit);
@ -436,7 +436,7 @@ struct Code : public mcl::Generator {
Operand px(IntPtr, b2);
Operand py(IntPtr, b2);
Operand pp(IntPtr, bit);
std::string name = "mcl_fpDbl_add" + cybozu::itoa(bit) + "L";
std::string name = "mcl_fpDbl_add" + cybozu::itoa(N) + "L";
Function f(name, Void, pz, px, py, pp);
verifyAndSetPrivate(f);
beginFunc(f);
@ -472,7 +472,7 @@ struct Code : public mcl::Generator {
Operand px(IntPtr, b2);
Operand py(IntPtr, b2);
Operand pp(IntPtr, bit);
std::string name = "mcl_fpDbl_sub" + cybozu::itoa(bit) + "L";
std::string name = "mcl_fpDbl_sub" + cybozu::itoa(N) + "L";
Function f(name, Void, pz, px, py, pp);
verifyAndSetPrivate(f);
beginFunc(f);
@ -549,10 +549,10 @@ struct Code : public mcl::Generator {
Operand pz(IntPtr, bu);
Operand px(IntPtr, unit);
Operand y(Int, unit);
std::string name = "mcl_fp_mul_UnitPre" + cybozu::itoa(bit) + "L";
mcl_fp_mul_UnitPreM[bit] = Function(name, Void, pz, px, y);
verifyAndSetPrivate(mcl_fp_mul_UnitPreM[bit]);
beginFunc(mcl_fp_mul_UnitPreM[bit]);
std::string name = "mcl_fp_mul_UnitPre" + cybozu::itoa(N) + "L";
mcl_fp_mul_UnitPreM[N] = Function(name, Void, pz, px, y);
verifyAndSetPrivate(mcl_fp_mul_UnitPreM[N]);
beginFunc(mcl_fp_mul_UnitPreM[N]);
Operand z = call(mulPvM[bit], px, y);
store(z, pz);
ret(Void);
@ -578,8 +578,8 @@ struct Code : public mcl::Generator {
Operand pxW = getelementptr(px, makeImm(32, N / 2));
Operand pyW = getelementptr(py, makeImm(32, N / 2));
Operand pzWW = getelementptr(pz, makeImm(32, N));
call(mcl_fpDbl_mulPreM[half], pz, px, py); // bd
call(mcl_fpDbl_mulPreM[half], pzWW, pxW, pyW); // ac
call(mcl_fpDbl_mulPreM[N / 2], pz, px, py); // bd
call(mcl_fpDbl_mulPreM[N / 2], pzWW, pxW, pyW); // ac
Operand pa = bitcast(pxW, Operand(IntPtr, half));
Operand pb = bitcast(px, Operand(IntPtr, half));
@ -605,7 +605,7 @@ struct Code : public mcl::Generator {
store(t2L, buf2);
buf1 = bitcast(buf1, Operand(IntPtr, unit));
buf2 = bitcast(buf2, Operand(IntPtr, unit));
call(mcl_fpDbl_mulPreM[half], buf, buf1, buf2);
call(mcl_fpDbl_mulPreM[N / 2], buf, buf1, buf2);
buf = bitcast(buf, Operand(IntPtr, bit));
Operand t = load(buf);
t = zext(t, bit + unit);
@ -660,10 +660,10 @@ struct Code : public mcl::Generator {
Operand pz(IntPtr, unit);
Operand px(IntPtr, unit);
Operand py(IntPtr, unit);
std::string name = "mcl_fpDbl_mulPre" + cybozu::itoa(bit) + "L";
mcl_fpDbl_mulPreM[bit] = Function(name, Void, pz, px, py);
verifyAndSetPrivate(mcl_fpDbl_mulPreM[bit]);
beginFunc(mcl_fpDbl_mulPreM[bit]);
std::string name = "mcl_fpDbl_mulPre" + cybozu::itoa(N) + "L";
mcl_fpDbl_mulPreM[N] = Function(name, Void, pz, px, py);
verifyAndSetPrivate(mcl_fpDbl_mulPreM[N]);
beginFunc(mcl_fpDbl_mulPreM[N]);
generic_fpDbl_mul(pz, px, py);
endFunc();
}
@ -672,10 +672,10 @@ struct Code : public mcl::Generator {
resetGlobalIdx();
Operand py(IntPtr, unit);
Operand px(IntPtr, unit);
std::string name = "mcl_fpDbl_sqrPre" + cybozu::itoa(bit) + "L";
mcl_fpDbl_sqrPreM[bit] = Function(name, Void, py, px);
verifyAndSetPrivate(mcl_fpDbl_sqrPreM[bit]);
beginFunc(mcl_fpDbl_sqrPreM[bit]);
std::string name = "mcl_fpDbl_sqrPre" + cybozu::itoa(N) + "L";
mcl_fpDbl_sqrPreM[N] = Function(name, Void, py, px);
verifyAndSetPrivate(mcl_fpDbl_sqrPreM[N]);
beginFunc(mcl_fpDbl_sqrPreM[N]);
generic_fpDbl_mul(py, px, px);
endFunc();
}
@ -688,11 +688,11 @@ struct Code : public mcl::Generator {
Operand px(IntPtr, unit);
Operand py(IntPtr, unit);
Operand pp(IntPtr, unit);
std::string name = "mcl_fp_mont" + cybozu::itoa(bit) + "L";
mcl_fp_montM[bit] = Function(name, Void, pz, px, py, pp);
mcl_fp_montM[bit].setAlias();
verifyAndSetPrivate(mcl_fp_montM[bit]);
beginFunc(mcl_fp_montM[bit]);
std::string name = "mcl_fp_mont" + cybozu::itoa(N) + "L";
mcl_fp_montM[N] = Function(name, Void, pz, px, py, pp);
mcl_fp_montM[N].setAlias();
verifyAndSetPrivate(mcl_fp_montM[N]);
beginFunc(mcl_fp_montM[N]);
Operand rp = load(getelementptr(pp, makeImm(unit, -1)));
Operand p = load(bitcast(pp, Operand(IntPtr, bit)));
Operand z, s, a;
@ -733,10 +733,10 @@ struct Code : public mcl::Generator {
Operand pz(IntPtr, bit);
Operand pxy(IntPtr, b2);
Operand pp(IntPtr, unit);
std::string name = "mcl_fp_montRed" + cybozu::itoa(bit) + "L";
mcl_fp_montRedM[bit] = Function(name, Void, pz, pxy, pp);
verifyAndSetPrivate(mcl_fp_montRedM[bit]);
beginFunc(mcl_fp_montRedM[bit]);
std::string name = "mcl_fp_montRed" + cybozu::itoa(N) + "L";
mcl_fp_montRedM[N] = Function(name, Void, pz, pxy, pp);
verifyAndSetPrivate(mcl_fp_montRedM[N]);
beginFunc(mcl_fp_montRedM[N]);
Operand rp = load(getelementptr(pp, makeImm(unit, -1)));
Operand p = load(bitcast(pp, Operand(IntPtr, bit)));
Operand xy = load(pxy);

Loading…
Cancel
Save