static tb_void_t tb_fixed_test_sin() { #if 1 __tb_volatile__ tb_int_t i = 0; __tb_volatile__ tb_int_t n = 10000000 / 360; __tb_volatile__ tb_fixed_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 0; i < 360; i++) r = tb_fixed_sin(tb_fixed_test_angle[i]); } t = tb_mclock() - t; for (i = 0; i < 360; i++) { r = tb_fixed_sin(tb_fixed_test_angle[i]); tb_printf("[fixed]: sin(%f) = %f, angle: %d\n", tb_fixed_to_float(tb_fixed_test_angle[i]), tb_fixed_to_float(r), i); } tb_printf("[fixed]: sin(0 - 360), %lld ms\n", t); #else tb_int_t i = 0; for (i = 0; i < 360; i++) { tb_printf(",\t0x%x\n", tb_float_to_fixed(i * TB_DOUBLE_PI / 180)); } #endif }
static tb_void_t tb_float_test_atan() { __tb_volatile__ tb_long_t i = 0; __tb_volatile__ tb_long_t n = 10000000 / 100; __tb_volatile__ tb_float_t r = 0; __tb_volatile__ tb_float_t a = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = -50; i <= 50; i++) { a = tb_float_test_atan_a[i + 50]; r = tb_atanf(a); } } t = tb_mclock() - t; for (i = -50; i <= 50; i++) { a = tb_float_test_atan_a[i + 50]; r = tb_atanf(a); tb_printf("[float]: atan(%f) = %f\n", (a), (r)); } tb_printf("[float]: atan, %lld ms\n", t); }
static tb_void_t tb_float_test_sin() { #if 1 __tb_volatile__ tb_long_t i = 0; __tb_volatile__ tb_long_t n = 10000000 / 360; __tb_volatile__ tb_float_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 0; i < 360; i++) r = tb_sinf(tb_float_test_angle[i]); } t = tb_mclock() - t; for (i = 0; i < 360; i++) { r = tb_sinf(tb_float_test_angle[i]); tb_printf("[float]: sin(%f) = %f, angle: %ld\n", (tb_float_test_angle[i]), (r), i); } tb_printf("[float]: sin(0 - 360), %lld ms\n", t); #else tb_long_t i = 0; for (i = 0; i < 360; i++) { tb_printf(",\t%f\n", (i * TB_PI / 180)); } #endif }
tb_int_t xm_machine_main(xm_machine_ref_t machine, tb_int_t argc, tb_char_t** argv) { // check xm_machine_impl_t* impl = (xm_machine_impl_t*)machine; tb_assert_and_check_return_val(impl && impl->lua, -1); // save main arguments to the global variable: _ARGV if (!xm_machine_main_save_arguments(impl, argc, argv)) return -1; // get the project directory tb_char_t path[TB_PATH_MAXN] = {0}; if (!xm_machine_main_get_project_directory(impl, path, sizeof(path))) return -1; // get the program directory if (!xm_machine_main_get_program_directory(impl, path, sizeof(path))) return -1; // append the main script path tb_strcat(path, "/core/_xmake_main.lua"); // exists this script? if (!tb_file_info(path, tb_null)) { // error tb_printf("not found main script: %s\n", path); // failed return -1; } // trace tb_trace_d("main: %s", path); // load and execute the main script if (luaL_dofile(impl->lua, path)) { // error tb_printf("error: %s\n", lua_tostring(impl->lua, -1)); // failed return -1; } // set the error function lua_getglobal(impl->lua, "debug"); lua_getfield(impl->lua, -1, "traceback"); // call the main function lua_getglobal(impl->lua, "_xmake_main"); if (lua_pcall(impl->lua, 0, 1, -2)) { // error tb_printf("error: %s\n", lua_tostring(impl->lua, -1)); // failed return -1; } // get the error code return (tb_int_t)lua_tonumber(impl->lua, -1); }
static void tb_autoprint(void) { if ((tb_control->pos == 0) && (tb_control->count)) { if (tb_control->options & TB_OPTION_PRINTONCE) { tb_printf(); tb_reset_option(TB_OPTION_PRINTONCE); } else if (tb_control->options & TB_OPTION_AUTOPRINT) { tb_printf(); } } }
static tb_void_t tb_check_tolower() { tb_int_t i = 0; for (i = 0; i < 256; i++) { if ((tb_tolower(i)? 1 : 0) != (tolower(i)? 1 : 0)) tb_printf("[e] tolower: 0x%02x = 0x%02x\n", i, tolower(i)); } }
static tb_void_t tb_make_isalpha_table() { tb_int_t i = 0; for (i = 0; i < 256; i++) { if (isalpha(i)) tb_printf("0x%02x\n", i); } }
static tb_void_t tb_fixed_test_constant() { tb_printf("[fixed]: one = %f\n", tb_fixed_to_float(TB_FIXED_ONE)); tb_printf("[fixed]: half = %f\n", tb_fixed_to_float(TB_FIXED_HALF)); tb_printf("[fixed]: max = %f\n", tb_fixed_to_float(TB_FIXED_MAX)); tb_printf("[fixed]: min = %f\n", tb_fixed_to_float(TB_FIXED_MIN)); tb_printf("[fixed]: nan = %f\n", tb_fixed_to_float(TB_FIXED_NAN)); tb_printf("[fixed]: inf = %f\n", tb_fixed_to_float(TB_FIXED_INF)); tb_printf("[fixed]: pi = %f\n", tb_fixed_to_float(TB_FIXED_PI)); tb_printf("[fixed]: sqrt2 = %f\n", tb_fixed_to_float(TB_FIXED_SQRT2)); }
static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl, tb_char_t* path, tb_size_t maxn) { // check tb_assert_and_check_return_val(impl && path && maxn, tb_false); // done tb_bool_t ok = tb_false; do { #ifdef TB_CONFIG_OS_WINDOWS // get the program directory tb_size_t size = GetModuleFileName(tb_null, path, maxn); tb_assert_and_check_break(size < maxn); // end path[size] = '\0'; // get the directory while (size-- > 0) { if (path[size] == '\\') { path[size] = '\0'; break; } } #else // get it from the environment variable tb_char_t data[TB_PATH_MAXN] = {0}; if (!tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data))) { // error tb_printf("error: please set XMAKE_PROGRAM_DIR first!\n"); break; } // get the full path if (!tb_path_absolute(data, path, maxn)) break; #endif // trace tb_trace_d("program: %s", path); // save the directory to the global variable: _PROGRAM_DIR lua_pushstring(impl->lua, path); lua_setglobal(impl->lua, "_PROGRAM_DIR"); // ok ok = tb_true; } while (0); // ok? return ok; }
static tb_void_t tb_fixed_test_cos() { __tb_volatile__ tb_int_t i = 0; __tb_volatile__ tb_int_t n = 10000000 / 360; __tb_volatile__ tb_fixed_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 0; i < 360; i++) r = tb_fixed_cos(tb_fixed_test_angle[i]); } t = tb_mclock() - t; for (i = 0; i < 360; i++) { r = tb_fixed_cos(tb_fixed_test_angle[i]); tb_printf("[fixed]: cos(%f) = %f, angle: %d\n", tb_fixed_to_float(tb_fixed_test_angle[i]), tb_fixed_to_float(r), i); } tb_printf("[fixed]: cos(0 - 360), %lld ms\n", t); }
static tb_void_t tb_float_test_tan() { __tb_volatile__ tb_long_t i = 0; __tb_volatile__ tb_long_t n = 10000000 / 360; __tb_volatile__ tb_float_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 0; i < 360; i++) r = tb_tanf(tb_float_test_angle[i]); } t = tb_mclock() - t; for (i = 0; i < 360; i++) { r = tb_tanf(tb_float_test_angle[i]); tb_printf("[float]: tan(%f) = %f, angle: %ld\n", (tb_float_test_angle[i]), (r), i); } tb_printf("[float]: tan(0 - 360), %lld ms\n", t); }
static tb_void_t tb_float_test_ceil(tb_float_t x) { __tb_volatile__ tb_long_t n = 10000000; __tb_volatile__ tb_long_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_ceil(x); } t = tb_mclock() - t; tb_printf("[float]: ceil(%f): %ld, %lld ms\n", (x), r, t); }
static tb_void_t tb_float_test_exp(tb_float_t x) { __tb_volatile__ tb_long_t n = 10000000; __tb_volatile__ tb_float_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_expf(x); } t = tb_mclock() - t; tb_printf("[float]: exp(%f) = %f, %lld ms\n", (x), r, t); }
static tb_void_t tb_fixed_test_ceil(tb_fixed_t x) { __tb_volatile__ tb_int_t n = 10000000; __tb_volatile__ tb_int_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_fixed_ceil(x); } t = tb_mclock() - t; tb_printf("[fixed]: ceil(%f): %d, %lld ms\n", tb_fixed_to_float(x), r, t); }
static tb_void_t tb_test_stricmp(tb_char_t const* s1, tb_char_t const* s2) { __tb_volatile__ tb_long_t n = 1000000; __tb_volatile__ tb_long_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_stricmp(s1, s2); } t = tb_mclock() - t; tb_printf("%lld ms, tb_test_stricmp(%s, %s) = %ld\n", t, s1, s2, r); }
static tb_void_t tb_test_strncpy(tb_char_t const* s2, tb_size_t size) { __tb_volatile__ tb_int_t n = 1000000; tb_char_t s1[4096]; tb_hong_t t = tb_mclock(); while (n--) { tb_strlcpy(s1, s2, size); } t = tb_mclock() - t; tb_printf("%lld ms, tb_test_strncpy(%s, %d) = %s\n", t, s2, size, s1); }
static tb_void_t tb_fixed_test_exp(tb_fixed_t x) { __tb_volatile__ tb_int_t n = 10000000; __tb_volatile__ tb_fixed_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_fixed_exp(x); } t = tb_mclock() - t; tb_printf("[fixed]: exp(%f) = %f, %lld ms\n", tb_fixed_to_float(x), tb_fixed_to_float(r), t); }
static tb_void_t tb_fixed_test_ilog2(tb_fixed_t x) { __tb_volatile__ tb_int_t n = 10000000; __tb_volatile__ tb_uint32_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_fixed_ilog2(x); } t = tb_mclock() - t; tb_printf("[fixed]: ilog2(%f) = %d, %lld ms\n", tb_fixed_to_float(x), r, t); }
static tb_void_t tb_fixed_test_div(tb_fixed_t a, tb_fixed_t b) { __tb_volatile__ tb_int_t n = 10000000; __tb_volatile__ tb_fixed_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_fixed_div(a, b); } t = tb_mclock() - t; tb_printf("[fixed]: div(%f, %f): %f, %lld ms\n", tb_fixed_to_float(a), tb_fixed_to_float(b), tb_fixed_to_float(r), t); }
static tb_void_t tb_float_test_div(tb_float_t a, tb_float_t b) { __tb_volatile__ tb_long_t n = 10000000; __tb_volatile__ tb_float_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = a / b; } t = tb_mclock() - t; tb_printf("[float]: div(%f, %f): %f, %lld ms\n", (a), (b), (r), t); }
static tb_void_t tb_test_strnlen(tb_char_t const* s, tb_size_t size) { __tb_volatile__ tb_long_t n = 1000000; __tb_volatile__ tb_long_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { r = tb_strnlen(s, size); } t = tb_mclock() - t; tb_printf("%lld ms, tb_test_strnlen(%s, %u) = %ld\n", t, s, size, r); }
tb_object_ref_t tb_object_dump(tb_object_ref_t object, tb_size_t format) { // check tb_assert_and_check_return_val(object, tb_null); // data tb_object_ref_t odata = tb_object_data(object, format); if (odata) { // the data and size tb_byte_t const* data = (tb_byte_t const*)tb_object_data_getp(odata); tb_size_t size = tb_object_data_size(odata); if (data && size) { // done tb_char_t const* p = (tb_char_t const*)data; tb_char_t const* e = (tb_char_t const*)data + size; tb_char_t b[4096 + 1]; if (p && p < e) { while (p < e && *p && tb_isspace(*p)) p++; while (p < e && *p) { tb_char_t* q = b; tb_char_t const* d = b + 4096; for (; p < e && q < d && *p; p++, q++) *q = *p; *q = '\0'; tb_printf("%s", b); } tb_printf("\n"); } } // exit data tb_object_exit(odata); } // the object return object; }
static tb_void_t tb_fixed_test_atan2() { __tb_volatile__ tb_int_t i = 0; __tb_volatile__ tb_int_t j = 0; __tb_volatile__ tb_int_t n = 10000000 / 100; __tb_volatile__ tb_fixed_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 50; i < 55; i++) { for (j = 50; j < 55; j++) { r = tb_fixed_atan2(i, j); r = tb_fixed_atan2(i, -j); r = tb_fixed_atan2(-i, -j); r = tb_fixed_atan2(-i, j); } } } t = tb_mclock() - t; for (i = 50; i < 55; i++) { for (j = 50; j < 55; j++) { r = tb_fixed_atan2(i, j); tb_printf("[fixed]: atan2(%d, %d) = %f\n", i, j, tb_fixed_to_float(r)); r = tb_fixed_atan2(i, -j); tb_printf("[fixed]: atan2(%d, %d) = %f\n", i, -j, tb_fixed_to_float(r)); r = tb_fixed_atan2(-i, -j); tb_printf("[fixed]: atan2(%d, %d) = %f\n", -i, -j, tb_fixed_to_float(r)); r = tb_fixed_atan2(-i, j); tb_printf("[fixed]: atan2(%d, %d) = %f\n", -i, j, tb_fixed_to_float(r)); } } tb_printf("[fixed]: atan2(), %lld ms\n", t); }
tb_object_ref_t tb_object_dump(tb_object_ref_t object) { // check tb_assert_and_check_return_val(object, tb_null); // data tb_object_ref_t odata = tb_object_data(object, TB_OBJECT_FORMAT_XML); if (odata) { // data & size tb_byte_t const* data = (tb_byte_t const*)tb_object_data_getp(odata); tb_size_t size = tb_object_data_size(odata); if (data && size) { tb_char_t const* p = tb_strstr((tb_char_t const*)data, "?>"); tb_char_t const* e = (tb_char_t const*)data + size; tb_char_t b[4096 + 1]; if (p && p + 2 < e) { p += 2; while (p < e && *p && tb_isspace(*p)) p++; while (p < e && *p) { tb_char_t* q = b; tb_char_t const* d = b + 4096; for (; p < e && q < d && *p; p++, q++) *q = *p; *q = '\0'; tb_printf("%s", b); } tb_printf("\n"); } } // exit data tb_object_exit(odata); } return object; }
static tb_void_t tb_float_test_atan2() { __tb_volatile__ tb_long_t i = 0; __tb_volatile__ tb_long_t j = 0; __tb_volatile__ tb_long_t n = 10000000 / 100; __tb_volatile__ tb_float_t r = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 50; i < 55; i++) { for (j = 50; j < 55; j++) { r = tb_atan2f((tb_float_t)i, (tb_float_t)j); r = tb_atan2f((tb_float_t)i, (tb_float_t)-j); r = tb_atan2f((tb_float_t)-i, (tb_float_t)-j); r = tb_atan2f((tb_float_t)-i, (tb_float_t)j); } } } t = tb_mclock() - t; for (i = 50; i < 55; i++) { for (j = 50; j < 55; j++) { r = tb_atan2f((tb_float_t)i, (tb_float_t)j); tb_printf("[float]: atan2(%ld, %ld) = %f\n", i, j, (r)); r = tb_atan2f((tb_float_t)i, (tb_float_t)-j); tb_printf("[float]: atan2(%ld, %ld) = %f\n", i, -j, (r)); r = tb_atan2f((tb_float_t)-i, (tb_float_t)-j); tb_printf("[float]: atan2(%ld, %ld) = %f\n", -i, -j, (r)); r = tb_atan2f((tb_float_t)-i, (tb_float_t)j); tb_printf("[float]: atan2(%ld, %ld) = %f\n", -i, j, (r)); } } tb_printf("[float]: atan2(), %lld ms\n", t); }
/* ////////////////////////////////////////////////////////////////////////////////////// * main */ tb_int_t tb_demo_utils_md5_main(tb_int_t argc, tb_char_t** argv) { tb_byte_t ob[16]; tb_size_t on = tb_md5_encode((tb_byte_t const*)argv[1], tb_strlen(argv[1]), ob, 16); if (on != 16) return 0; tb_size_t i = 0; tb_char_t md5[256] = {0}; for (i = 0; i < 16; ++i) tb_snprintf(md5 + (i << 1), 3, "%02X", ob[i]); tb_printf("%s: %lu\n", md5, on); return 0; }
/* ////////////////////////////////////////////////////////////////////////////////////// * test */ static tb_void_t tb_float_test_constant() { tb_printf("[float]: max = %f\n", (tb_float_t)TB_MAF); tb_printf("[float]: min = %f\n", (tb_float_t)TB_MIF); tb_printf("[float]: nan = %f\n", (tb_float_t)TB_NAN); tb_printf("[float]: inf = %f\n", (tb_float_t)TB_INF); tb_printf("[float]: isinf = %ld\n", tb_isinff((tb_float_t)TB_INF)); tb_printf("[float]: isnan = %ld\n", tb_isnanf((tb_float_t)TB_NAN)); }
static tb_void_t tb_float_test_acos() { __tb_volatile__ tb_long_t i = 0; __tb_volatile__ tb_long_t j = 0; __tb_volatile__ tb_long_t n = 10000000 / 50; __tb_volatile__ tb_float_t r = 0; __tb_volatile__ tb_float_t a = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { a = tb_float_test_arc[i][j]; r = tb_acosf(a); r = tb_acosf(-a); } } } t = tb_mclock() - t; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { a = tb_float_test_arc[i][j]; r = tb_acosf(a); tb_printf("[float]: acos(%f) = %f\n", (a), (r)); r = tb_acosf(-a); tb_printf("[float]: acos(%f) = %f\n", (-a), (r)); } } tb_printf("[float]: acos, %lld ms\n", t); }
static tb_void_t tb_fixed_test_asin() { __tb_volatile__ tb_int_t i = 0; __tb_volatile__ tb_int_t j = 0; __tb_volatile__ tb_int_t n = 10000000 / 50; __tb_volatile__ tb_fixed_t r = 0; __tb_volatile__ tb_fixed_t a = 0; tb_hong_t t = tb_mclock(); while (n--) { for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { a = tb_fixed_test_arc[i][j]; r = tb_fixed_asin(a); r = tb_fixed_asin(-a); } } } t = tb_mclock() - t; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { a = tb_fixed_test_arc[i][j]; r = tb_fixed_asin(a); tb_printf("[fixed]: asin(%f) = %f\n", tb_fixed_to_float(a), tb_fixed_to_float(r)); r = tb_fixed_asin(-a); tb_printf("[fixed]: asin(%f) = %f\n", tb_fixed_to_float(-a), tb_fixed_to_float(r)); } } tb_printf("[fixed]: asin, %lld ms\n", t); }
static tb_void_t tb_check_is() { tb_int_t i = 0; for (i = 0; i < 256; i++) { if ((tb_isspace(i)? 1 : 0) != (isspace(i)? 1 : 0)) tb_printf("[e] isspace: 0x%02x\n", i); if ((tb_isalpha(i)? 1 : 0) != (isalpha(i)? 1 : 0)) tb_printf("[e] isalpha: 0x%02x\n", i); if ((tb_isdigit(i)? 1 : 0) != (isdigit(i)? 1 : 0)) tb_printf("[e] isdigit: 0x%02x\n", i); if ((tb_isupper(i)? 1 : 0) != (isupper(i)? 1 : 0)) tb_printf("[e] isupper: 0x%02x\n", i); if ((tb_islower(i)? 1 : 0) != (islower(i)? 1 : 0)) tb_printf("[e] islower: 0x%02x\n", i); if ((tb_isascii(i)? 1 : 0) != (isascii(i)? 1 : 0)) tb_printf("[e] isascii: 0x%02x\n", i); } }