diff options
| author | Richard Musiol <mail@richard-musiol.de> | 2019-03-24 12:14:27 +0100 |
|---|---|---|
| committer | Richard Musiol <neelance@gmail.com> | 2019-04-04 16:10:12 +0000 |
| commit | cf8cc7f63c7ddefb666a6e8d99a4843d3277db9f (patch) | |
| tree | edc59cd956160ff6683a60e8848cacf841a20a3b /src/cmd/internal/obj/wasm | |
| parent | 1abf3aa55bb8b346bb1575ac8db5022f215df65a (diff) | |
| download | go-cf8cc7f63c7ddefb666a6e8d99a4843d3277db9f.tar.xz | |
cmd/compile: add saturating conversions on wasm
This change adds the GOWASM option "satconv" to enable the generation
of experimental saturating (non-trapping) float-to-int conversions.
It improves the performance of the conversion by 42%.
Previously the conversions had already been augmented with helper
functions to have saturating behavior. Now Wasm.rules is always using
the new operation names and wasm/ssa.go is falling back to the helpers
if the feature is not enabled.
The feature is in phase 4 of the WebAssembly proposal process:
https://github.com/WebAssembly/meetings/blob/master/process/phases.md
More information on the feature can be found at:
https://github.com/WebAssembly/nontrapping-float-to-int-conversions/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
Change-Id: Ic6c3688017054ede804b02b6b0ffd4a02ef33ad7
Reviewed-on: https://go-review.googlesource.com/c/go/+/170119
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/internal/obj/wasm')
| -rw-r--r-- | src/cmd/internal/obj/wasm/a.out.go | 9 | ||||
| -rw-r--r-- | src/cmd/internal/obj/wasm/anames.go | 8 | ||||
| -rw-r--r-- | src/cmd/internal/obj/wasm/wasmobj.go | 9 |
3 files changed, 24 insertions, 2 deletions
diff --git a/src/cmd/internal/obj/wasm/a.out.go b/src/cmd/internal/obj/wasm/a.out.go index 29ea87f3b0..c686f1d6f0 100644 --- a/src/cmd/internal/obj/wasm/a.out.go +++ b/src/cmd/internal/obj/wasm/a.out.go @@ -216,6 +216,15 @@ const ( AI64Extend16S AI64Extend32S + AI32TruncSatF32S // opcode 0xFC 0x00 + AI32TruncSatF32U + AI32TruncSatF64S + AI32TruncSatF64U + AI64TruncSatF32S + AI64TruncSatF32U + AI64TruncSatF64S + AI64TruncSatF64U + ALast // Sentinel: End of low-level WebAssembly instructions. ARESUMEPOINT diff --git a/src/cmd/internal/obj/wasm/anames.go b/src/cmd/internal/obj/wasm/anames.go index fb4b72c398..c8552e7f18 100644 --- a/src/cmd/internal/obj/wasm/anames.go +++ b/src/cmd/internal/obj/wasm/anames.go @@ -182,6 +182,14 @@ var Anames = []string{ "I64Extend8S", "I64Extend16S", "I64Extend32S", + "I32TruncSatF32S", + "I32TruncSatF32U", + "I32TruncSatF64S", + "I32TruncSatF64U", + "I64TruncSatF32S", + "I64TruncSatF32U", + "I64TruncSatF64S", + "I64TruncSatF64U", "Last", "RESUMEPOINT", "CALLNORESUME", diff --git a/src/cmd/internal/obj/wasm/wasmobj.go b/src/cmd/internal/obj/wasm/wasmobj.go index dded62a4be..0474e3b4b1 100644 --- a/src/cmd/internal/obj/wasm/wasmobj.go +++ b/src/cmd/internal/obj/wasm/wasmobj.go @@ -886,7 +886,7 @@ func assemble(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) { } switch { - case p.As < AUnreachable || p.As >= ALast: + case p.As < AUnreachable: panic(fmt.Sprintf("unexpected assembler op: %s", p.As)) case p.As < AEnd: w.WriteByte(byte(p.As - AUnreachable + 0x00)) @@ -894,8 +894,13 @@ func assemble(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) { w.WriteByte(byte(p.As - AEnd + 0x0B)) case p.As < AI32Load: w.WriteByte(byte(p.As - ADrop + 0x1A)) - default: + case p.As < AI32TruncSatF32S: w.WriteByte(byte(p.As - AI32Load + 0x28)) + case p.As < ALast: + w.WriteByte(0xFC) + w.WriteByte(byte(p.As - AI32TruncSatF32S + 0x00)) + default: + panic(fmt.Sprintf("unexpected assembler op: %s", p.As)) } switch p.As { |
