[basic] c -> asm.js compilation(without WASM)?

45 views
Skip to first unread message

Ivan Zvonimir Horvat

unread,
May 24, 2020, 11:15:39 AM5/24/20
to emscripten-discuss
EMCC version 1.38.31

How to properly compile C to asm.js, with a sample from Wikipedia.

// input.c
int f(int i) {
 
return i + 1;
}


Expected result:
// output.js
function f(i) {
 
"use asm";
  i
= i | 0;
 
return (i + 1) | 0;
}

I have tried to compile it with(see below) and generates huge JavaScript file with ~5K lines of code

emcc input.c -o output.js \
 
-s INVOKE_RUN=0 \
 
-s EXPORTED_FUNCTIONS="['_f']" \
 
-s WASM=0 # causes the compiler to target asm.js


Jukka Jylänki

unread,
May 24, 2020, 12:47:16 PM5/24/20
to emscripte...@googlegroups.com
Try adding one or more of -s linker flags listed in
https://github.com/emscripten-core/emscripten/blob/852ca4eb34b316d69f9999b7602e69a249422e63/tests/test_other.py#L9329
. Those can trim down the build output from the default size.

Also while debug builds are large, adding -O3 (or -Oz), and --closure
1 to help trim the size down.

Although current default builds target "wasm2js" when building to -s
WASM=0, which is somewhat larger than what it would need to be.
Installing the "fastcomp" toolchain from emsdk allows targeting
asm.js.

With those, the smallest hello world will be a few hundred bytes big
with no extraneous characters in the output.

su 24. toukok. 2020 klo 18.15 Ivan Zvonimir Horvat
(ivanzvoni...@gmail.com) kirjoitti:
> --
> You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/ab23c223-21a0-4d3b-abaf-954b547cd8a9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages