Fr, Fp, Fp2 test ok

update-fork
MITSUNARI Shigeo 4 years ago
parent df3e118538
commit 11a752cb6c
  1. 2
      Makefile
  2. 10
      src/fp_generator.hpp
  3. 53
      test/static_code_test.cpp

@ -238,7 +238,7 @@ $(GEN_EXE): src/gen.cpp src/llvm_gen.hpp
$(CXX) -o $@ $< $(CFLAGS) $(CXX) -o $@ $< $(CFLAGS)
src/dump_code: src/dump_code.cpp src/fp.cpp src/fp_generator.hpp src/dump_code: src/dump_code.cpp src/fp.cpp src/fp_generator.hpp
$(CXX) -o $@ src/dump_code.cpp src/fp.cpp -I include -DMCL_DUMP_JIT -DMCL_MAX_BIT_SIZE=384 -DMCL_DONT_USE_OPENSSL -DMCL_USE_VINT -DMCL_SIZEOF_UNIT=8 -DMCL_VINT_FIXED_BUFFER $(CXX) -o $@ src/dump_code.cpp src/fp.cpp -g -I include -DMCL_DUMP_JIT -DMCL_MAX_BIT_SIZE=384 -DMCL_DONT_USE_OPENSSL -DMCL_USE_VINT -DMCL_SIZEOF_UNIT=8 -DMCL_VINT_FIXED_BUFFER
src/static_code.asm: src/dump_code src/static_code.asm: src/dump_code
$< > $@ $< > $@

@ -410,7 +410,9 @@ private:
align(16); align(16);
op.fp_negA_ = gen_fp_neg(); op.fp_negA_ = gen_fp_neg();
setFuncInfo(prof_, suf, "_neg", op.fp_negA_, getCurr()); setFuncInfo(prof_, suf, "_neg", op.fp_negA_, getCurr());
align(16);
op.fpDbl_modA_ = gen_fpDbl_mod(op);
setFuncInfo(prof_, suf, "Dbl_mod", op.fpDbl_modA_, getCurr());
align(16); align(16);
op.fp_mulA_ = gen_mul(); op.fp_mulA_ = gen_mul();
setFuncInfo(prof_, suf, "_mul", op.fp_mulA_, getCurr()); setFuncInfo(prof_, suf, "_mul", op.fp_mulA_, getCurr());
@ -454,10 +456,6 @@ private:
op.fpDbl_sqrPreA_ = gen_fpDbl_sqrPre(); op.fpDbl_sqrPreA_ = gen_fpDbl_sqrPre();
setFuncInfo(prof_, suf, "Dbl_sqrPre", op.fpDbl_sqrPreA_, getCurr()); setFuncInfo(prof_, suf, "Dbl_sqrPre", op.fpDbl_sqrPreA_, getCurr());
align(16);
op.fpDbl_modA_ = gen_fpDbl_mod(op);
setFuncInfo(prof_, suf, "Dbl_mod", op.fpDbl_modA_, getCurr());
align(16); align(16);
op.fp2_addA_ = gen_fp2_add(); op.fp2_addA_ = gen_fp2_add();
setFuncInfo(prof_, suf, "2_add", op.fp2_addA_, getCurr()); setFuncInfo(prof_, suf, "2_add", op.fp2_addA_, getCurr());
@ -493,7 +491,7 @@ private:
#ifdef MCL_STATIC_JIT #ifdef MCL_STATIC_JIT
if (op.xi_a) { if (op.xi_a) {
// Fp, sizeof(Fp) = 48 // Fp, sizeof(Fp) = 48, supports Fp2
op.fp_addPre = mclx_Fp_addPre; op.fp_addPre = mclx_Fp_addPre;
op.fp_subPre = mclx_Fp_subPre; op.fp_subPre = mclx_Fp_subPre;
op.fp_addA_ = mclx_Fp_add; op.fp_addA_ = mclx_Fp_add;

@ -1,40 +1,45 @@
#include <cybozu/test.hpp>
#include <mcl/bls12_381.hpp> #include <mcl/bls12_381.hpp>
using namespace mcl::bn; using namespace mcl::bn;
void testFr() CYBOZU_TEST_AUTO(init)
{ {
Fr x, y, z; initPairing(mcl::BLS12_381);
}
CYBOZU_TEST_AUTO(Fr)
{
Fr x, y;
x = 3; x = 3;
y = 5; y = 5;
z = x + y; CYBOZU_TEST_EQUAL(x + y, 8);
printf("x=%s\n", x.getStr().c_str()); CYBOZU_TEST_EQUAL(x - y, -2);
printf("y=%s\n", y.getStr().c_str()); CYBOZU_TEST_EQUAL(x * y, 15);
printf("z=%s\n", z.getStr().c_str());
z = x * y;
printf("z=%s\n", z.getStr().c_str());
Fr::sqr(z, x);
printf("z=%s\n", z.getStr().c_str());
} }
void testFp() CYBOZU_TEST_AUTO(Fp)
{ {
Fp x, y, z; Fp x, y;
x = 3; x = 3;
y = 5; y = 5;
z = x + y; CYBOZU_TEST_EQUAL(x + y, 8);
printf("x=%s\n", x.getStr().c_str()); CYBOZU_TEST_EQUAL(x - y, -2);
printf("y=%s\n", y.getStr().c_str()); CYBOZU_TEST_EQUAL(x * y, 15);
printf("z=%s\n", z.getStr().c_str());
z = x * y;
printf("z=%s\n", z.getStr().c_str());
Fp::sqr(z, x);
printf("z=%s\n", z.getStr().c_str());
} }
int main() CYBOZU_TEST_AUTO(Fp2)
{ {
initPairing(mcl::BLS12_381); Fp2 x, y;
testFr(); x.a = 3;
testFp(); x.b = 2;
y.a = 1;
y.b = 4;
/*
(3+2i)(1+4i)=3-8+(12+2)i
*/
CYBOZU_TEST_EQUAL(x + y, Fp2(4, 6));
CYBOZU_TEST_EQUAL(x - y, Fp2(2, -2));
CYBOZU_TEST_EQUAL(x * y, Fp2(-5, 14));
} }

Loading…
Cancel
Save