|
|
|
@ -17,44 +17,16 @@
|
|
|
|
|
#include "wasm3.h"
|
|
|
|
|
#include "m3_config.h"
|
|
|
|
|
|
|
|
|
|
#include "fib32.wasm.h"
|
|
|
|
|
#include "coremark_minimal.wasm.h"
|
|
|
|
|
|
|
|
|
|
#define FIB_ARG_VALUE "40"
|
|
|
|
|
#define FATAL(msg, ...) { printf("Fatal: " msg "\n", ##__VA_ARGS__); return; }
|
|
|
|
|
|
|
|
|
|
uint32_t fib_native(uint32_t n) {
|
|
|
|
|
if (n < 2) return n;
|
|
|
|
|
return fib_native(n - 1) + fib_native(n - 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// same function uses on fib.wasm so we preserve is as is.
|
|
|
|
|
// Note: for prevent precalculation FIB_ARG_VALUE on compile time we need disable inlining
|
|
|
|
|
__attribute__((noinline))
|
|
|
|
|
int parseInt(char* str) {
|
|
|
|
|
int res = 0;
|
|
|
|
|
for (int i = 0; str[i] != '\0'; ++i) {
|
|
|
|
|
res = res * 10 + str[i] - '0';
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void run_native() {
|
|
|
|
|
printf("Running fib(" FIB_ARG_VALUE ") on Native C...\n");
|
|
|
|
|
|
|
|
|
|
clock_t start = clock();
|
|
|
|
|
uint32_t result = fib_native(parseInt(FIB_ARG_VALUE));
|
|
|
|
|
clock_t end = clock();
|
|
|
|
|
|
|
|
|
|
printf("Result: %u\n", result);
|
|
|
|
|
printf("Elapsed: %ld ms\n", (end - start) * 1000 / CLOCKS_PER_SEC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void run_wasm()
|
|
|
|
|
{
|
|
|
|
|
M3Result result = m3Err_none;
|
|
|
|
|
|
|
|
|
|
uint8_t* wasm = (uint8_t*)fib32_wasm;
|
|
|
|
|
uint32_t fsize = fib32_wasm_len;
|
|
|
|
|
uint8_t* wasm = (uint8_t*)coremark_minimal_wasm;
|
|
|
|
|
size_t fsize = coremark_minimal_wasm_len;
|
|
|
|
|
|
|
|
|
|
printf("Loading WebAssembly...\n");
|
|
|
|
|
|
|
|
|
@ -72,25 +44,19 @@ void run_wasm()
|
|
|
|
|
if (result) FATAL("m3_LoadModule: %s", result);
|
|
|
|
|
|
|
|
|
|
IM3Function f;
|
|
|
|
|
result = m3_FindFunction (&f, runtime, "fib");
|
|
|
|
|
result = m3_FindFunction (&f, runtime, "run");
|
|
|
|
|
if (result) FATAL("m3_FindFunction: %s", result);
|
|
|
|
|
|
|
|
|
|
printf("Running fib(" FIB_ARG_VALUE ") on WebAssembly...\n");
|
|
|
|
|
|
|
|
|
|
const char* i_argv[2] = { FIB_ARG_VALUE, NULL };
|
|
|
|
|
|
|
|
|
|
clock_t start = clock();
|
|
|
|
|
result = m3_CallArgv (f, 1, i_argv);
|
|
|
|
|
clock_t end = clock();
|
|
|
|
|
printf("Running CoreMark 1.0...\n");
|
|
|
|
|
|
|
|
|
|
result = m3_CallV (f);
|
|
|
|
|
if (result) FATAL("m3_Call: %s", result);
|
|
|
|
|
printf("Elapsed: %ld ms\n\n", (end - start) * 1000 / CLOCKS_PER_SEC);
|
|
|
|
|
|
|
|
|
|
uint32_t value = 0;
|
|
|
|
|
float value = 0;
|
|
|
|
|
result = m3_GetResultsV (f, &value);
|
|
|
|
|
if (result) FATAL("m3_GetResults: %s", result);
|
|
|
|
|
|
|
|
|
|
printf("Result: %d\n", value);
|
|
|
|
|
printf("Result: %0.3f\n", value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void* runMain(void* ctx)
|
|
|
|
|