/// does it. int gcc_modet::doit() { if(cmdline.isset('?') || cmdline.isset("help")) { help(); return EX_OK; } native_tool_name= act_as_ld ? linker_name(cmdline, base_name) : compiler_name(cmdline, base_name); unsigned int verbosity=1; bool act_as_bcc= base_name=="bcc" || base_name.find("goto-bcc")!=std::string::npos; if((cmdline.isset('v') && cmdline.have_infile_arg()) || (cmdline.isset("version") && !produce_hybrid_binary)) { // "-v" a) prints the version and b) increases verbosity. // Compilation continues, don't exit! if(act_as_ld) std::cout << "GNU ld version 2.16.91 20050610 (goto-cc " CBMC_VERSION << ")\n"; else if(act_as_bcc) std::cout << "bcc: version 0.16.17 (goto-cc " CBMC_VERSION ")\n"; else std::cout << "gcc version 3.4.4 (goto-cc " CBMC_VERSION ")\n"; } if(cmdline.isset("version")) { if(produce_hybrid_binary) return run_gcc(); std::cout << '\n' << "Copyright (C) 2006-2014 Daniel Kroening, Christoph Wintersteiger\n" << "CBMC version: " CBMC_VERSION << '\n' << "Architecture: " << config.this_architecture() << '\n' << "OS: " << config.this_operating_system() << '\n'; return EX_OK; // Exit! } if(cmdline.isset("dumpversion")) { if(produce_hybrid_binary) return run_gcc(); std::cout << "3.4.4\n"; return EX_OK; } if(cmdline.isset("Wall") || cmdline.isset("Wextra")) verbosity=2; if(cmdline.isset("verbosity")) verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity")); gcc_message_handler.set_verbosity(verbosity); if(act_as_ld) { if(produce_hybrid_binary) debug() << "LD mode (hybrid)" << eom; else debug() << "LD mode" << eom; } else if(act_as_bcc) { if(produce_hybrid_binary) debug() << "BCC mode (hybrid)" << eom; else debug() << "BCC mode" << eom; } else { if(produce_hybrid_binary) debug() << "GCC mode (hybrid)" << eom; else debug() << "GCC mode" << eom; } // In gcc mode, we have just pass on to gcc to handle the following: // * if -M or -MM is given, we do dependencies only // * preprocessing (-E) // * no input files given if(act_as_ld) { } else if(cmdline.isset('M') || cmdline.isset("MM") || cmdline.isset('E') || !cmdline.have_infile_arg()) return run_gcc(); // exit! // get configuration config.set(cmdline); // Intel-specific // in GCC, m16 is 32-bit (!), as documented here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59672 if(cmdline.isset("m16") || cmdline.isset("m32") || cmdline.isset("mx32")) { config.ansi_c.arch="i386"; config.ansi_c.set_arch_spec_i386(); } else if(cmdline.isset("m64")) { config.ansi_c.arch="x86_64"; config.ansi_c.set_arch_spec_x86_64(); } // ARM-specific if(cmdline.isset("mbig-endian") || cmdline.isset("mbig")) config.ansi_c.endianness=configt::ansi_ct::endiannesst::IS_BIG_ENDIAN; else if(cmdline.isset("little-endian") || cmdline.isset("mlittle")) config.ansi_c.endianness=configt::ansi_ct::endiannesst::IS_LITTLE_ENDIAN; if(cmdline.isset("mthumb") || cmdline.isset("mthumb-interwork")) config.ansi_c.set_arch_spec_arm("armhf"); // -mcpu sets both the arch and tune, but should only be used if // neither -march nor -mtune are passed on the command line. std::string target_cpu= cmdline.isset("march") ? cmdline.get_value("march") : cmdline.isset("mtune") ? cmdline.get_value("mtune") : cmdline.isset("mcpu") ? cmdline.get_value("mcpu") : ""; if(target_cpu!="") { // Work out what CPROVER architecture we should target. for(auto &pair : arch_map) for(auto &processor : pair.second) if(processor==target_cpu) { if(pair.first.find("mips")==std::string::npos) config.set_arch(pair.first); else { // Targeting a MIPS processor. MIPS is special; we also need // to know the endianness. -EB (big-endian) is the default. if(cmdline.isset("EL")) { if(pair.first=="mips32o") config.set_arch("mipsel"); else if(pair.first=="mips32n") config.set_arch("mipsn32el"); else config.set_arch("mips64el"); } else { if(pair.first=="mips32o") config.set_arch("mips"); else if(pair.first=="mips32n") config.set_arch("mipsn32"); else config.set_arch("mips64"); } } } } // -fshort-wchar makes wchar_t "short unsigned int" if(cmdline.isset("fshort-wchar")) { config.ansi_c.wchar_t_width=config.ansi_c.short_int_width; config.ansi_c.wchar_t_is_unsigned=true; } // -fsingle-precision-constant makes floating-point constants "float" // instead of double if(cmdline.isset("-fsingle-precision-constant")) config.ansi_c.single_precision_constant=true; // -fshort-double makes double the same as float if(cmdline.isset("fshort-double")) config.ansi_c.double_width=config.ansi_c.single_width; // determine actions to be undertaken compilet compiler(cmdline, gcc_message_handler, cmdline.isset("Werror") && cmdline.isset("Wextra") && !cmdline.isset("Wno-error")); if(act_as_ld) compiler.mode=compilet::LINK_LIBRARY; else if(cmdline.isset('S')) compiler.mode=compilet::ASSEMBLE_ONLY; else if(cmdline.isset('c')) compiler.mode=compilet::COMPILE_ONLY; else if(cmdline.isset('E')) { compiler.mode=compilet::PREPROCESS_ONLY; UNREACHABLE; } else if(cmdline.isset("shared") || cmdline.isset('r')) // really not well documented compiler.mode=compilet::COMPILE_LINK; else compiler.mode=compilet::COMPILE_LINK_EXECUTABLE; switch(compiler.mode) { case compilet::LINK_LIBRARY: debug() << "Linking a library only" << eom; break; case compilet::COMPILE_ONLY: debug() << "Compiling only" << eom; break; case compilet::ASSEMBLE_ONLY: debug() << "Assembling only" << eom; break; case compilet::PREPROCESS_ONLY: debug() << "Preprocessing only" << eom; break; case compilet::COMPILE_LINK: debug() << "Compiling and linking a library" << eom; break; case compilet::COMPILE_LINK_EXECUTABLE: debug() << "Compiling and linking an executable" << eom; break; } if(cmdline.isset("i386-win32") || cmdline.isset("winx64")) { // We may wish to reconsider the below. config.ansi_c.mode=configt::ansi_ct::flavourt::VISUAL_STUDIO; debug() << "Enabling Visual Studio syntax" << eom; } else if(config.this_operating_system()=="macos") config.ansi_c.mode=configt::ansi_ct::flavourt::APPLE; else config.ansi_c.mode=configt::ansi_ct::flavourt::GCC; if(compiler.mode==compilet::ASSEMBLE_ONLY) compiler.object_file_extension="s"; else compiler.object_file_extension="o"; if(cmdline.isset("std")) { std::string std_string=cmdline.get_value("std"); if(std_string=="gnu89" || std_string=="c89") config.ansi_c.set_c89(); if(std_string=="gnu99" || std_string=="c99" || std_string=="iso9899:1999" || std_string=="gnu9x" || std_string=="c9x" || std_string=="iso9899:199x") config.ansi_c.set_c99(); if(std_string=="gnu11" || std_string=="c11" || std_string=="gnu1x" || std_string=="c1x") config.ansi_c.set_c11(); if(std_string=="c++11" || std_string=="c++1x" || std_string=="gnu++11" || std_string=="gnu++1x" || std_string=="c++1y" || std_string=="gnu++1y") config.cpp.set_cpp11(); if(std_string=="gnu++14" || std_string=="c++14") config.cpp.set_cpp14(); } // gcc's default is 32 bits for wchar_t if(cmdline.isset("short-wchar")) config.ansi_c.wchar_t_width=16; // gcc's default is 64 bits for double if(cmdline.isset("short-double")) config.ansi_c.double_width=32; // gcc's default is signed chars on most architectures if(cmdline.isset("funsigned-char")) config.ansi_c.char_is_unsigned=true; if(cmdline.isset("fsigned-char")) config.ansi_c.char_is_unsigned=false; if(cmdline.isset('U')) config.ansi_c.undefines=cmdline.get_values('U'); if(cmdline.isset("undef")) config.ansi_c.preprocessor_options.push_back("-undef"); if(cmdline.isset("nostdinc")) config.ansi_c.preprocessor_options.push_back("-nostdinc"); if(cmdline.isset('L')) compiler.library_paths=cmdline.get_values('L'); // Don't add the system paths! if(cmdline.isset('l')) compiler.libraries=cmdline.get_values('l'); if(cmdline.isset("static")) compiler.libraries.push_back("c"); if(cmdline.isset("pthread")) compiler.libraries.push_back("pthread"); if(cmdline.isset('o')) { // given gcc -o file1 -o file2, // gcc will output to file2, not file1 compiler.output_file_object=cmdline.get_values('o').back(); compiler.output_file_executable=cmdline.get_values('o').back(); } else { compiler.output_file_object=""; compiler.output_file_executable="a.out"; } // We now iterate over any input files temp_dirt temp_dir("goto-cc-XXXXXX"); { std::string language; for(goto_cc_cmdlinet::parsed_argvt::iterator arg_it=cmdline.parsed_argv.begin(); arg_it!=cmdline.parsed_argv.end(); arg_it++) { if(arg_it->is_infile_name) { // do any preprocessing needed if(language=="cpp-output" || language=="c++-cpp-output") { compiler.add_input_file(arg_it->arg); } else if(language=="c" || language=="c++" || (language=="" && needs_preprocessing(arg_it->arg))) { std::string new_suffix; if(language=="c") new_suffix=".i"; else if(language=="c++") new_suffix=".ii"; else new_suffix=has_suffix(arg_it->arg, ".c")?".i":".ii"; std::string new_name= get_base_name(arg_it->arg, true)+new_suffix; std::string dest=temp_dir(new_name); int exit_code= preprocess(language, arg_it->arg, dest, act_as_bcc); if(exit_code!=0) { error() << "preprocessing has failed" << eom; return exit_code; } compiler.add_input_file(dest); } else compiler.add_input_file(arg_it->arg); } else if(arg_it->arg=="-x") { arg_it++; if(arg_it!=cmdline.parsed_argv.end()) { language=arg_it->arg; if(language=="none") language=""; } } else if(has_prefix(arg_it->arg, "-x")) { language=std::string(arg_it->arg, 2, std::string::npos); if(language=="none") language=""; } } } // Revert to gcc in case there is no source to compile // and no binary to link. if(compiler.source_files.empty() && compiler.object_files.empty()) return run_gcc(); // exit! if(compiler.mode==compilet::ASSEMBLE_ONLY) return asm_output(act_as_bcc, compiler.source_files); // do all the rest if(compiler.doit()) return 1; // GCC exit code for all kinds of errors // We can generate hybrid ELF and Mach-O binaries // containing both executable machine code and the goto-binary. if(produce_hybrid_binary && !act_as_bcc) return gcc_hybrid_binary(); return EX_OK; }
int gcc_modet::gcc_hybrid_binary() { { bool have_files=false; for(goto_cc_cmdlinet::parsed_argvt::const_iterator it=cmdline.parsed_argv.begin(); it!=cmdline.parsed_argv.end(); it++) if(it->is_infile_name) have_files=true; if(!have_files) return EX_OK; } std::list<std::string> output_files; if(cmdline.isset('c')) { if(cmdline.isset('o')) { // there should be only one input file output_files.push_back(cmdline.get_value('o')); } else { for(goto_cc_cmdlinet::parsed_argvt::const_iterator i_it=cmdline.parsed_argv.begin(); i_it!=cmdline.parsed_argv.end(); i_it++) if(i_it->is_infile_name && needs_preprocessing(i_it->arg)) output_files.push_back(get_base_name(i_it->arg, true)+".o"); } } else { // -c is not given if(cmdline.isset('o')) output_files.push_back(cmdline.get_value('o')); else output_files.push_back("a.out"); } if(output_files.empty() || (output_files.size()==1 && output_files.front()=="/dev/null")) return run_gcc(); debug() << "Running " << native_tool_name << " to generate hybrid binary" << eom; // save the goto-cc output files for(std::list<std::string>::const_iterator it=output_files.begin(); it!=output_files.end(); it++) { rename(it->c_str(), (*it+".goto-cc-saved").c_str()); } std::string objcopy_cmd; if(has_suffix(linker_name(cmdline, base_name), "-ld")) { objcopy_cmd=linker_name(cmdline, base_name); objcopy_cmd.erase(objcopy_cmd.size()-2); } else if(has_suffix(compiler_name(cmdline, base_name), "-gcc")) { objcopy_cmd=compiler_name(cmdline, base_name); objcopy_cmd.erase(objcopy_cmd.size()-3); } objcopy_cmd+="objcopy"; int result=run_gcc(); // merge output from gcc with goto-binaries // using objcopy, or do cleanup if an earlier call failed for(std::list<std::string>::const_iterator it=output_files.begin(); it!=output_files.end(); it++) { debug() << "merging " << *it << eom; std::string saved=*it+".goto-cc-saved"; #ifdef __linux__ if(result==0 && !cmdline.isset('c')) { // remove any existing goto-cc section std::vector<std::string> objcopy_argv; objcopy_argv.push_back(objcopy_cmd); objcopy_argv.push_back("--remove-section=goto-cc"); objcopy_argv.push_back(*it); result=run(objcopy_argv[0], objcopy_argv, "", ""); } if(result==0) { // now add goto-binary as goto-cc section std::vector<std::string> objcopy_argv; objcopy_argv.push_back(objcopy_cmd); objcopy_argv.push_back("--add-section"); objcopy_argv.push_back("goto-cc="+saved); objcopy_argv.push_back(*it); result=run(objcopy_argv[0], objcopy_argv, "", ""); } remove(saved.c_str()); #elif defined(__APPLE__) // Mac if(result==0) { std::vector<std::string> lipo_argv; // now add goto-binary as hppa7100LC section lipo_argv.push_back("lipo"); lipo_argv.push_back(*it); lipo_argv.push_back("-create"); lipo_argv.push_back("-arch"); lipo_argv.push_back("hppa7100LC"); lipo_argv.push_back(saved); lipo_argv.push_back("-output"); lipo_argv.push_back(*it); result=run(lipo_argv[0], lipo_argv, "", ""); } remove(saved.c_str()); #else error() << "binary merging not implemented for this platform" << eom; return 1; #endif } return result; }
int main() { #include "ellint_pi3_data.ipp" #include "ellint_pi3_large_data.ipp" add_data(data1); add_data(ellint_pi3_data); add_data(ellint_pi3_large_data); unsigned data_total = data.size(); std::cout << "Screening boost data:\n"; screen_data([](const std::vector<double>& v){ return boost::math::ellint_3(v[2], v[0], v[1]); }, [](const std::vector<double>& v){ return v[3]; }); #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) std::cout << "Screening libstdc++ data:\n"; screen_data([](const std::vector<double>& v){ return std::tr1 ::ellint_3(v[2], -v[0], v[1]); }, [](const std::vector<double>& v){ return v[3]; }); #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) std::cout << "Screening libstdc++ data:\n"; screen_data([](const std::vector<double>& v){ return gsl_sf_ellint_P(v[1], v[2], -v[0], GSL_PREC_DOUBLE); }, [](const std::vector<double>& v){ return v[3]; }); #endif unsigned data_used = data.size(); std::string function = "ellint_3[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "ellint_3"; double time; time = exec_timed_test([](const std::vector<double>& v){ return boost::math::ellint_3(v[2], v[0], v[1]); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); // // Boost again, but with promotion to long double turned off: // #if !defined(COMPILER_COMPARISON_TABLES) if(sizeof(long double) != sizeof(double)) { time = exec_timed_test([](const std::vector<double>& v){ return boost::math::ellint_3(v[2], v[0], v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>"); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>"); } #endif #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::ellint_3(v[2], -v[0], v[1]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath"); #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_ellint_P(v[1], v[2], -v[0], GSL_PREC_DOUBLE); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION); #endif return 0; }
static std::string compiler_id() { return compiler_name() + '-' + compiler_version(); }
int main() { #include "bessel_k_int_data.ipp" add_data(k0_data); add_data(k1_data); add_data(kn_data); add_data(bessel_k_int_data); unsigned data_total = data.size(); screen_data([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; }); #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return std::tr1::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; }); #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Kn(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; }); #endif #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return bessel_k(v[1], static_cast<int>(v[0]), 1); }, [](const std::vector<double>& v){ return v[2]; }); #endif unsigned data_used = data.size(); std::string function = "cyl_bessel_k (integer order)[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "cyl_bessel_k (integer order)"; double time; time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); // // Boost again, but with promotion to long double turned off: // #if !defined(COMPILER_COMPARISON_TABLES) if(sizeof(long double) != sizeof(double)) { time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(static_cast<int>(v[0]), v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>"); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>"); } #endif #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath"); #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Kn(static_cast<int>(v[0]), v[1]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION); #endif #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return bessel_k(v[1], static_cast<int>(v[0]), 1); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING); #endif return 0; }
int main() { typedef double T; #define SC_(x) static_cast<double>(x) # include "../../test/cbrt_data.ipp" add_data(cbrt_data); unsigned data_total = data.size(); screen_data([](const std::vector<double>& v){ return boost::math::cbrt(v[1]); }, [](const std::vector<double>& v){ return v[0]; }); #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return ::cbrt(v[1]); }, [](const std::vector<double>& v){ return v[0]; }); #endif #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return std::tr1::cbrt(v[1]); }, [](const std::vector<double>& v){ return v[0]; }); #endif unsigned data_used = data.size(); std::string function = "cbrt[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "cbrt"; double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cbrt(v[1]); }); std::cout << time << std::endl; #if defined(COMPILER_COMPARISON_TABLES) report_execution_time(time, std::string("Compiler Option Comparison on ") + platform_name(), "boost::math::cbrt", get_compiler_options_name()); #else #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); #endif // // Boost again, but with promotion to long double turned off: // #if !defined(COMPILER_COMPARISON_TABLES) if(sizeof(long double) != sizeof(double)) { double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cbrt(v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>"); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>"); } #endif #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return ::cbrt(v[1]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "math.h"); #endif #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cbrt(v[1]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath"); #endif return 0; }
int main() { typedef double T; #define SC_(x) static_cast<double>(x) # include "digamma_data.ipp" # include "digamma_root_data.ipp" # include "digamma_small_data.ipp" # include "digamma_neg_data.ipp" static const boost::array<boost::array<T, 2>, 5> digamma_bugs = {{ // Test cases from Rocco Romeo: {{ static_cast<T>(std::ldexp(1.0, -100)), SC_(-1.26765060022822940149670320537657721566490153286060651209008e30) }}, {{ static_cast<T>(-std::ldexp(1.0, -100)), SC_(1.26765060022822940149670320537542278433509846713939348790992e30) }}, {{ static_cast<T>(1), SC_(-0.577215664901532860606512090082402431042159335939923598805767) }}, {{ static_cast<T>(-1) + static_cast<T>(std::ldexp(1.0, -20)), SC_(-1.04857557721314249602848739817764518743062133735858753112190e6) }}, {{ static_cast<T>(-1) - static_cast<T>(std::ldexp(1.0, -20)), SC_(1.04857642278181269259522681939281063878220298942888100442172e6) }}, }}; static const boost::array<boost::array<T, 2>, 40> digamma_integers = { { { 1, SC_(-0.57721566490153286060651209008240243) }, { 2, SC_(0.42278433509846713939348790991759757) }, { 3, SC_(0.92278433509846713939348790991759757) }, { 4, SC_(1.2561176684318004727268212432509309) }, { 5, SC_(1.5061176684318004727268212432509309) }, { 6, SC_(1.7061176684318004727268212432509309) }, { 7, SC_(1.8727843350984671393934879099175976) }, { 8, SC_(2.0156414779556099965363450527747404) }, { 9, SC_(2.1406414779556099965363450527747404) }, { SC_(10.0), SC_(2.2517525890667211076474561638858515) }, { SC_(11.0), SC_(2.3517525890667211076474561638858515) }, { SC_(12.0), SC_(2.4426616799758120167383652547949424) }, { SC_(13.0), SC_(2.5259950133091453500716985881282758) }, { SC_(14.0), SC_(2.6029180902322222731486216650513527) }, { SC_(15.0), SC_(2.6743466616607937017200502364799241) }, { SC_(16.0), SC_(2.7410133283274603683867169031465908) }, { SC_(17.0), SC_(2.8035133283274603683867169031465908) }, { SC_(18.0), SC_(2.8623368577392250742690698443230614) }, { SC_(19.0), SC_(2.9178924132947806298246253998786169) }, { SC_(20.0), SC_(2.9705239922421490508772569788259854) }, { SC_(21.0), SC_(3.0205239922421490508772569788259854) }, { SC_(22.0), SC_(3.0681430398611966699248760264450330) }, { SC_(23.0), SC_(3.1135975853157421244703305718995784) }, { SC_(24.0), SC_(3.1570758461853073418616349197256654) }, { SC_(25.0), SC_(3.1987425128519740085283015863923321) }, { SC_(26.0), SC_(3.2387425128519740085283015863923321) }, { SC_(27.0), SC_(3.2772040513135124700667631248538705) }, { SC_(28.0), SC_(3.3142410883505495071038001618909076) }, { SC_(29.0), SC_(3.3499553740648352213895144476051933) }, { SC_(30.0), SC_(3.3844381326855248765619282407086415) }, { SC_(31.0), SC_(3.4177714660188582098952615740419749) }, { SC_(32.0), SC_(3.4500295305349872421533260901710071) }, { SC_(33.0), SC_(3.4812795305349872421533260901710071) }, { SC_(34.0), SC_(3.5115825608380175451836291204740374) }, { SC_(35.0), SC_(3.5409943255438998981248055910622727) }, { SC_(36.0), SC_(3.5695657541153284695533770196337013) }, { SC_(37.0), SC_(3.5973435318931062473311547974114791) }, { SC_(38.0), SC_(3.6243705589201332743581818244385061) }, { SC_(39.0), SC_(3.6506863483938174848844976139121903) }, { SC_(40.0), SC_(3.6763273740348431259101386395532160) } } }; static const boost::array<boost::array<T, 2>, 41> digamma_half_integers = { { { SC_(0.5), SC_(-1.9635100260214234794409763329987556) }, { SC_(1.5), SC_(0.036489973978576520559023667001244433) }, { SC_(2.5), SC_(0.70315664064524318722569033366791110) }, { SC_(3.5), SC_(1.1031566406452431872256903336679111) }, { SC_(4.5), SC_(1.3888709263595289015114046193821968) }, { SC_(5.5), SC_(1.6110931485817511237336268416044190) }, { SC_(6.5), SC_(1.7929113303999329419154450234226009) }, { SC_(7.5), SC_(1.9467574842460867880692911772687547) }, { SC_(8.5), SC_(2.0800908175794201214026245106020880) }, { SC_(9.5), SC_(2.1977378764029495331673303929550292) }, { SC_(10.5), SC_(2.3030010342976863752725935508497661) }, { SC_(11.5), SC_(2.3982391295357816133678316460878613) }, { SC_(12.5), SC_(2.4851956512749120481504403417400352) }, { SC_(13.5), SC_(2.5651956512749120481504403417400352) }, { SC_(14.5), SC_(2.6392697253489861222245144158141093) }, { SC_(15.5), SC_(2.7082352425903654325693420020210058) }, { SC_(16.5), SC_(2.7727513716226234970854710342790703) }, { SC_(17.5), SC_(2.8333574322286841031460770948851310) }, { SC_(18.5), SC_(2.8905002893715412460032199520279881) }, { SC_(19.5), SC_(2.9445543434255953000572740060820421) }, { SC_(20.5), SC_(2.9958363947076465821085560573640934) }, { SC_(21.5), SC_(3.0446168825125246308890438622421422) }, { SC_(22.5), SC_(3.0911285104195013750750903738700492) }, { SC_(23.5), SC_(3.1355729548639458195195348183144936) }, { SC_(24.5), SC_(3.1781261463533075216471943927825787) }, { SC_(25.5), SC_(3.2189424728839197665451535764560481) }, { SC_(26.5), SC_(3.2581581591584295704667222039070285) }, { SC_(27.5), SC_(3.2958940082150333440516278642843870) }, { SC_(28.5), SC_(3.3322576445786697076879915006480234) }, { SC_(29.5), SC_(3.3673453638769153217230792199462690) }, { SC_(30.5), SC_(3.4012436689616610844349436267259300) }, { SC_(31.5), SC_(3.4340305542075627237792059218078972) }, { SC_(32.5), SC_(3.4657765859535944698109519535539290) }, { SC_(33.5), SC_(3.4965458167228252390417211843231597) }, { SC_(34.5), SC_(3.5263965629914819554596316320843538) }, { SC_(35.5), SC_(3.5553820702378587670538345306350784) }, { SC_(36.5), SC_(3.5835510843223658093073556573956418) }, { SC_(37.5), SC_(3.6109483445963384120470816847929021) }, { SC_(38.5), SC_(3.6376150112630050787137483514595687) }, { SC_(39.5), SC_(3.6635890372370310527397223774335947) }, { SC_(40.5), SC_(3.6889054929332335843852919976867593) } } }; add_data(digamma_data); add_data(digamma_root_data); add_data(digamma_small_data); add_data(digamma_neg_data); add_data(digamma_bugs); add_data(digamma_integers); add_data(digamma_half_integers); unsigned data_total = data.size(); screen_data([](const std::vector<double>& v){ return boost::math::digamma(v[0]); }, [](const std::vector<double>& v){ return v[1]; }); #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return gsl_sf_psi(v[0]); }, [](const std::vector<double>& v){ return v[1]; }); #endif #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return ::digamma(v[0]); }, [](const std::vector<double>& v){ return v[1]; }); #endif unsigned data_used = data.size(); std::string function = "digamma[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "digamma"; double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::digamma(v[0]); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); // // Boost again, but with promotion to long double turned off: // #if !defined(COMPILER_COMPARISON_TABLES) if(sizeof(long double) != sizeof(double)) { double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::digamma(v[0], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>"); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>"); } #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_psi(v[0]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION); #endif #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return ::digamma(v[0]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING); #endif return 0; }
int main() { #include "jacobi_elliptic.ipp" #include "jacobi_elliptic_small.ipp" #include "jacobi_near_1.ipp" #include "jacobi_large_phi.ipp" add_data(data1); add_data(jacobi_elliptic); add_data(jacobi_elliptic_small); add_data(jacobi_near_1); add_data(jacobi_large_phi); unsigned data_total = data.size(); std::cout << "Screening Boost data:\n"; screen_data([](const std::vector<double>& v) { return boost::math::jacobi_dn(v[1], v[0]); }, [](const std::vector<double>& v) { return v[4]; }); #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) std::cout << "Screening GSL data:\n"; screen_data([](const std::vector<double>& v) { double s, c, d; gsl_sf_elljac_e(v[0], v[1] * v[1], &s, &c, &d); return d; }, [](const std::vector<double>& v) { return v[4]; }); #endif unsigned data_used = data.size(); std::string function = "jacobi_dn[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "jacobi_dn"; double time; time = exec_timed_test([](const std::vector<double>& v) { return boost::math::jacobi_dn(v[1], v[2]); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); // // Boost again, but with promotion to long double turned off: // #if !defined(COMPILER_COMPARISON_TABLES) if(sizeof(long double) != sizeof(double)) { time = exec_timed_test([](const std::vector<double>& v) { return boost::math::jacobi_dn(v[1], v[0], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>"); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>"); } #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v) { double s, c, d; gsl_sf_elljac_e(v[0], v[1] * v[1], &s, &c, &d); return d; }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION); #endif return 0; }
int main() { # include "igamma_med_data.ipp" # include "igamma_small_data.ipp" # include "igamma_big_data.ipp" # include "igamma_int_data.ipp" add_data(igamma_med_data); add_data(igamma_small_data); add_data(igamma_big_data); add_data(igamma_int_data); unsigned data_total = data.size(); std::cout << "Screening Boost data:\n"; screen_data([](const std::vector<double>& v){ return boost::math::gamma_q(v[0], v[1]); }, [](const std::vector<double>& v){ return v[3]; }); #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) std::cout << "Screening GSL data:\n"; screen_data([](const std::vector<double>& v){ return gsl_sf_gamma_inc_Q(v[0], v[1]); }, [](const std::vector<double>& v){ return v[3]; }); #endif #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) std::cout << "Screening GSL data:\n"; screen_data([](const std::vector<double>& v){ return pgamma(v[1], v[0], 1.0, 0, 0); }, [](const std::vector<double>& v){ return v[3]; }); #endif unsigned data_used = data.size(); std::string function = "gamma_q[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "gamma_q"; double time; time = exec_timed_test([](const std::vector<double>& v){ return boost::math::gamma_q(v[0], v[1]); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); // // Boost again, but with promotion to long double turned off: // #if !defined(COMPILER_COMPARISON_TABLES) if(sizeof(long double) != sizeof(double)) { time = exec_timed_test([](const std::vector<double>& v){ return boost::math::gamma_q(v[0], v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>"); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>"); } #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_gamma_inc_Q(v[0], v[1]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION); #endif #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return pgamma(v[1], v[0], 1.0, 0, 0); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING); #endif return 0; }