From b5c5d95b689979780ea01ed4c8d4fdb40602535b Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 16 Jun 2022 03:41:27 +0200 Subject: [PATCH] wasm: use newer WebAssembly features This commit will start to use a few more WebAssembly features, such as bulk memory operations. This results in a significant code size saving. How much it saves varies a lot but it's typically around 1300 bytes. This change is possible by bumping our minimum Node.js version to 14. The previous LTS version (12) has been marked end of life, so we can start to depend on features in the current oldest LTS version, which is version 14. Browsers have been supporting these features for a long time now, it's just Node.js that prevented us doing this before. --- .github/workflows/linux.yml | 2 +- Makefile | 2 +- targets/wasi.json | 6 ++++++ targets/wasm.json | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 458cfd24..ae77fe51 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -167,7 +167,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v2 with: - node-version: '12' + node-version: '14' - name: Install wasmtime run: | curl https://wasmtime.dev/install.sh -sSf | bash diff --git a/Makefile b/Makefile index 15680433..9f56bf5b 100644 --- a/Makefile +++ b/Makefile @@ -234,7 +234,7 @@ endif wasi-libc: lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a: @if [ ! -e lib/wasi-libc/Makefile ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi - cd lib/wasi-libc && make -j4 WASM_CFLAGS="-O2 -g -DNDEBUG" MALLOC_IMPL=none CC=$(CLANG) AR=$(LLVM_AR) NM=$(LLVM_NM) + cd lib/wasi-libc && make -j4 WASM_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC=$(CLANG) AR=$(LLVM_AR) NM=$(LLVM_NM) # Build the Go compiler. diff --git a/targets/wasi.json b/targets/wasi.json index 8ff4c3a2..64d86469 100644 --- a/targets/wasi.json +++ b/targets/wasi.json @@ -1,6 +1,7 @@ { "llvm-target": "wasm32-unknown-wasi", "cpu": "generic", + "features": "+bulk-memory,+nontrapping-fptoint,+sign-ext", "build-tags": ["tinygo.wasm", "wasi"], "goos": "linux", "goarch": "arm", @@ -8,6 +9,11 @@ "libc": "wasi-libc", "scheduler": "asyncify", "default-stack-size": 16384, + "cflags": [ + "-mbulk-memory", + "-mnontrapping-fptoint", + "-msign-ext" + ], "ldflags": [ "--allow-undefined", "--stack-first", diff --git a/targets/wasm.json b/targets/wasm.json index 1cc3410d..c668a68c 100644 --- a/targets/wasm.json +++ b/targets/wasm.json @@ -1,6 +1,7 @@ { "llvm-target": "wasm32-unknown-wasi", "cpu": "generic", + "features": "+bulk-memory,+nontrapping-fptoint,+sign-ext", "build-tags": ["tinygo.wasm"], "goos": "js", "goarch": "wasm", @@ -8,6 +9,11 @@ "libc": "wasi-libc", "scheduler": "asyncify", "default-stack-size": 16384, + "cflags": [ + "-mbulk-memory", + "-mnontrapping-fptoint", + "-msign-ext" + ], "ldflags": [ "--allow-undefined", "--stack-first",