From 417bf50cf78bcf8b468b6bd295a572715ecfe5d8 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 15 Nov 2016 15:35:31 +0900 Subject: [PATCH] split fp_proto.hpp into proto.hpp and low_func.hpp --- misc/karatsuba.cpp | 2 +- sample/large.cpp | 2 +- src/fp.cpp | 3 +- src/{fp_proto.hpp => low_func.hpp} | 62 +--------------------------- src/proto.hpp | 65 ++++++++++++++++++++++++++++++ test/fp_test.cpp | 3 +- test/low_test.cpp | 2 +- 7 files changed, 73 insertions(+), 66 deletions(-) rename src/{fp_proto.hpp => low_func.hpp} (83%) create mode 100644 src/proto.hpp diff --git a/misc/karatsuba.cpp b/misc/karatsuba.cpp index 1a8f3dc..5b18f3d 100644 --- a/misc/karatsuba.cpp +++ b/misc/karatsuba.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "../src/fp_proto.hpp" +#include "../src/low_func.hpp" #ifdef MCL_USE_LLVM #include "../src/fp_llvm.hpp" #endif diff --git a/sample/large.cpp b/sample/large.cpp index 9991bd5..3c83c2c 100644 --- a/sample/large.cpp +++ b/sample/large.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "../src/fp_proto.hpp" +#include "../src/low_func.hpp" typedef mcl::FpT<> Fp; diff --git a/src/fp.cpp b/src/fp.cpp index 2f5b12d..6c42abb 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -4,8 +4,9 @@ #ifdef MCL_USE_XBYAK #include "fp_generator.hpp" #endif -#include "fp_proto.hpp" +#include "low_func.hpp" #ifdef MCL_USE_LLVM +#include "proto.hpp" #include "fp_llvm.hpp" #endif diff --git a/src/fp_proto.hpp b/src/low_func.hpp similarity index 83% rename from src/fp_proto.hpp rename to src/low_func.hpp index 7c755b6..559f25f 100644 --- a/src/fp_proto.hpp +++ b/src/low_func.hpp @@ -1,7 +1,7 @@ #pragma once /** @file - @brief prototype of asm function + @brief generic function for each N @author MITSUNARI Shigeo(@herumi) @license modified new BSD license http://opensource.org/licenses/BSD-3-Clause @@ -523,68 +523,8 @@ struct Sqr { template const void3u Sqr::f = Sqr::func; - } } // mcl::fp -#ifdef MCL_USE_LLVM - -#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_addPre ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \ -mcl::fp::Unit mcl_fp_subPre ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \ -void mcl_fp_mulUnitPre ## 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 */); \ -void mcl_fp_mulNIST_P192 ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* /* dummy */); \ -void mcl_fp_sqr_NIST_P192 ## suf(mcl::fp::Unit* y, const mcl::fp::Unit* x, const mcl::fp::Unit* /* dummy */); \ -void mcl_fpDbl_mod_NIST_P521 ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* xy, const mcl::fp::Unit* /* dummy */); - -extern "C" { - -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_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(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) -MCL_FP_DEF_FUNC_SPECIAL(A) - -} - -#undef MCL_FP_DEF_FUNC_SUB -#undef MCL_FP_DEF_FUNC - -#endif // MCL_USE_LLVM - #ifdef _WIN32 #pragma warning(pop) #endif diff --git a/src/proto.hpp b/src/proto.hpp new file mode 100644 index 0000000..d161f8e --- /dev/null +++ b/src/proto.hpp @@ -0,0 +1,65 @@ +#pragma once +/** + @file + @brief prototype of asm function + @author MITSUNARI Shigeo(@herumi) + @license modified new BSD license + http://opensource.org/licenses/BSD-3-Clause +*/ +#include + +#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_addPre ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \ +mcl::fp::Unit mcl_fp_subPre ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y); \ +void mcl_fp_mulUnitPre ## 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 */); \ +void mcl_fp_mulNIST_P192 ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* /* dummy */); \ +void mcl_fp_sqr_NIST_P192 ## suf(mcl::fp::Unit* y, const mcl::fp::Unit* x, const mcl::fp::Unit* /* dummy */); \ +void mcl_fpDbl_mod_NIST_P521 ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* xy, const mcl::fp::Unit* /* dummy */); + +extern "C" { + +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_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(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) +MCL_FP_DEF_FUNC_SPECIAL(A) + +} + +#undef MCL_FP_DEF_FUNC_SUB +#undef MCL_FP_DEF_FUNC + diff --git a/test/fp_test.cpp b/test/fp_test.cpp index e9b9e7b..7674099 100644 --- a/test/fp_test.cpp +++ b/test/fp_test.cpp @@ -2,7 +2,8 @@ #define CYBOZU_TEST_DISABLE_AUTO_RUN #include #include -#include "../src/fp_proto.hpp" +#include "../src/low_func.hpp" +#include "../src/proto.hpp" #include #include #include diff --git a/test/low_test.cpp b/test/low_test.cpp index 316aa9d..f5e72a0 100644 --- a/test/low_test.cpp +++ b/test/low_test.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "../src/fp_proto.hpp" +#include "../src/low_func.hpp" #include cybozu::XorShift rg;