diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp index 23ee19b..a9df320 100644 --- a/include/mcl/op.hpp +++ b/include/mcl/op.hpp @@ -70,6 +70,24 @@ static inline const char *ModeToStr(Mode mode) } } +static inline Mode StrToMode(const std::string& s) +{ + static const struct { + const char *s; + Mode mode; + } tbl[] = { + { "auto", FP_AUTO }, + { "gmp", FP_GMP }, + { "llvm", FP_LLVM }, + { "llvm_mont", FP_LLVM_MONT }, + { "xbyak", FP_XBYAK }, + }; + for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { + if (s == tbl[i].s) return tbl[i].mode; + } + throw cybozu::Exception("StrToMode") << s; +} + struct Op { mpz_class mp; mcl::SquareRoot sq;