diff --git a/Makefile b/Makefile index 346be6a..75cca34 100644 --- a/Makefile +++ b/Makefile @@ -237,6 +237,9 @@ endif $(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_FREEZE_JIT -DMCL_MAX_BIT_SIZE=384 -DMCL_DONT_USE_OPENSSL -DMCL_USE_VINT -DMCL_SIZEOF_UNIT=8 -DMCL_VINT_FIXED_BUFFER + asm: $(LLVM_SRC) $(LLVM_OPT) -O3 -o - $(LLVM_SRC) | $(LLVM_LLC) -O3 $(LLVM_FLAGS) -x86-asm-syntax=intel diff --git a/src/dump_code.cpp b/src/dump_code.cpp new file mode 100644 index 0000000..f1655e9 --- /dev/null +++ b/src/dump_code.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + mcl::bn::initPairing(mcl::BLS12_381); +} + diff --git a/src/fp_generator.hpp b/src/fp_generator.hpp index 08d5844..5b00fa6 100644 --- a/src/fp_generator.hpp +++ b/src/fp_generator.hpp @@ -28,28 +28,31 @@ namespace mcl { #ifdef MCL_FREEZE_JIT +// not profiler, but dump jit code struct Profiler { FILE *fp_; const uint8_t *prev_; std::string suf_; Profiler() - : fp_(0) + : fp_(stdout) , prev_(0) { } ~Profiler() { - if (fp_) fclose(fp_); +// if (fp_) fclose(fp_); } +#if 0 void open(const std::string& fileName) { fp_ = fopen(fileName.c_str(), "wb"); } +#endif void setStartAddr(const uint8_t *addr) { prev_ = addr; } - void setNameSuffix(const char *suf) + void setNameSuffix(const std::string& suf) { suf_ = suf; } @@ -71,6 +74,18 @@ struct Profiler { } prev_ = end; } + void dumpData(const void *begin, const void *end) + { + fprintf(fp_, "align 16\n"); + fprintf(fp_, "dq "); + const uint64_t *p = (const uint64_t*)begin; + const uint64_t *pe = (const uint64_t*)end; + const size_t n = pe - p; + for (size_t i = 0; i < n; i++) { + fprintf(fp_, "0x%016llx,", (unsigned long long)*p++); + } + fprintf(fp_, "\n"); + } }; #else typedef Xbyak::util::Profiler Profiler; @@ -314,6 +329,11 @@ private: for (size_t i = 0; i < op.N; i++) { dq(op.p[i]); } +#ifdef MCL_FREEZE_JIT + prof_.dumpData(p_, getCurr()); + prof_.setStartAddr(getCurr()); + prof_.setNameSuffix(std::string("mclx_") + suf); +#endif rp_ = fp::getMontgomeryCoeff(p_[0]); pn_ = (int)op.N; FpByte_ = int(op.maxN * sizeof(uint64_t));