Run Coremark in default iOS example

opam-2.0.0
Vova 3 years ago
parent 92123f3778
commit 970236fb42

@ -30,8 +30,8 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
3D1B3AEF23C8E20C00142C16 /* coremark_minimal.wasm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coremark_minimal.wasm.h; sourceTree = "<group>"; };
3D1B3AEE23C8E20C00142C16 /* fib32.wasm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fib32.wasm.h; sourceTree = "<group>"; };
3D1B3AEF23C8E20C00142C16 /* fib32_tail.wasm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fib32_tail.wasm.h; sourceTree = "<group>"; };
3D1B3AF023C8E20C00142C16 /* fib64.wasm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fib64.wasm.h; sourceTree = "<group>"; };
3D1B3AF123C8E20C00142C16 /* wasi_core.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wasi_core.h; sourceTree = "<group>"; };
3D1B3AF423C8E20C00142C16 /* m3_api_libc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = m3_api_libc.c; sourceTree = "<group>"; };
@ -125,8 +125,8 @@
3D1B3AED23C8E20C00142C16 /* extra */ = {
isa = PBXGroup;
children = (
3D1B3AEF23C8E20C00142C16 /* coremark_minimal.wasm.h */,
3D1B3AEE23C8E20C00142C16 /* fib32.wasm.h */,
3D1B3AEF23C8E20C00142C16 /* fib32_tail.wasm.h */,
3D1B3AF023C8E20C00142C16 /* fib64.wasm.h */,
3D1B3AF123C8E20C00142C16 /* wasi_core.h */,
);

@ -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)

Loading…
Cancel
Save