From 11a752cb6cefded11603a54d5be594fd81626a44 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Thu, 17 Sep 2020 10:41:07 +0900 Subject: [PATCH] Fr, Fp, Fp2 test ok --- Makefile | 2 +- src/fp_generator.hpp | 10 +++----- test/static_code_test.cpp | 53 +++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index dbc2a41..9e37876 100644 --- a/Makefile +++ b/Makefile @@ -238,7 +238,7 @@ $(GEN_EXE): src/gen.cpp src/llvm_gen.hpp $(CXX) -o $@ $< $(CFLAGS) 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 $< > $@ diff --git a/src/fp_generator.hpp b/src/fp_generator.hpp index f4a626a..b5d4628 100644 --- a/src/fp_generator.hpp +++ b/src/fp_generator.hpp @@ -410,7 +410,9 @@ private: align(16); op.fp_negA_ = gen_fp_neg(); 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); op.fp_mulA_ = gen_mul(); setFuncInfo(prof_, suf, "_mul", op.fp_mulA_, getCurr()); @@ -454,10 +456,6 @@ private: op.fpDbl_sqrPreA_ = gen_fpDbl_sqrPre(); 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); op.fp2_addA_ = gen_fp2_add(); setFuncInfo(prof_, suf, "2_add", op.fp2_addA_, getCurr()); @@ -493,7 +491,7 @@ private: #ifdef MCL_STATIC_JIT if (op.xi_a) { - // Fp, sizeof(Fp) = 48 + // Fp, sizeof(Fp) = 48, supports Fp2 op.fp_addPre = mclx_Fp_addPre; op.fp_subPre = mclx_Fp_subPre; op.fp_addA_ = mclx_Fp_add; diff --git a/test/static_code_test.cpp b/test/static_code_test.cpp index e69fda7..8238e48 100644 --- a/test/static_code_test.cpp +++ b/test/static_code_test.cpp @@ -1,40 +1,45 @@ +#include #include 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; y = 5; - z = x + y; - printf("x=%s\n", x.getStr().c_str()); - printf("y=%s\n", y.getStr().c_str()); - 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()); + CYBOZU_TEST_EQUAL(x + y, 8); + CYBOZU_TEST_EQUAL(x - y, -2); + CYBOZU_TEST_EQUAL(x * y, 15); } -void testFp() +CYBOZU_TEST_AUTO(Fp) { - Fp x, y, z; + Fp x, y; x = 3; y = 5; - z = x + y; - printf("x=%s\n", x.getStr().c_str()); - printf("y=%s\n", y.getStr().c_str()); - 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()); + CYBOZU_TEST_EQUAL(x + y, 8); + CYBOZU_TEST_EQUAL(x - y, -2); + CYBOZU_TEST_EQUAL(x * y, 15); } -int main() +CYBOZU_TEST_AUTO(Fp2) { - initPairing(mcl::BLS12_381); - testFr(); - testFp(); + Fp2 x, y; + x.a = 3; + 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)); } +