Last active
June 20, 2019 19:57
-
-
Save chfast/6b3052eebcf616eb823a9f38cbed01d4 to your computer and use it in GitHub Desktop.
768-bit multiplication implemented in wasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; C ABI: void mul768(uint64_t* product, const uint64_t* a, const uint64_t* b) | |
(module | |
(type (;0;) (func (param i32 i32 i32))) | |
(import "env" "memory" (memory (;0;) 256 256)) | |
(func (;0;) (type 0) (param i32 i32 i32) | |
(local i32 i32 i32 i32 i32 i32 i64 i64 i64 i64 i64 i64 i64 i64) | |
i32.const 11 | |
local.set 5 | |
loop ;; label = @1 | |
local.get 3 | |
i32.const 3 | |
i32.shl | |
local.get 2 | |
i32.add | |
local.set 6 | |
i32.const 12 | |
local.get 3 | |
i32.sub | |
local.tee 7 | |
i32.const 1 | |
i32.gt_u | |
if ;; label = @2 | |
i32.const 0 | |
local.set 4 | |
i64.const 0 | |
local.set 11 | |
loop ;; label = @3 | |
local.get 4 | |
i32.const 3 | |
i32.shl | |
local.get 1 | |
i32.add | |
i64.load | |
local.tee 9 | |
i64.const 4294967295 | |
i64.and | |
local.set 10 | |
local.get 6 | |
i64.load | |
local.tee 12 | |
i64.const 4294967295 | |
i64.and | |
local.tee 13 | |
local.get 9 | |
i64.const 32 | |
i64.shr_u | |
local.tee 14 | |
i64.mul | |
local.get 10 | |
local.get 13 | |
i64.mul | |
local.tee 9 | |
i64.const 32 | |
i64.shr_u | |
i64.add | |
local.tee 13 | |
i64.const 4294967295 | |
i64.and | |
local.get 10 | |
local.get 12 | |
i64.const 32 | |
i64.shr_u | |
local.tee 15 | |
i64.mul | |
i64.add | |
local.set 10 | |
local.get 9 | |
i64.const 4294967295 | |
i64.and | |
local.get 10 | |
i64.const 32 | |
i64.shl | |
i64.or | |
local.tee 16 | |
local.get 3 | |
local.get 4 | |
i32.add | |
i32.const 3 | |
i32.shl | |
local.get 0 | |
i32.add | |
local.tee 8 | |
i64.load | |
i64.add | |
local.tee 9 | |
local.get 11 | |
i64.add | |
local.set 12 | |
local.get 9 | |
local.get 12 | |
i64.gt_u | |
i64.extend_i32_u | |
local.get 16 | |
local.get 9 | |
i64.gt_u | |
i64.extend_i32_u | |
local.get 14 | |
local.get 15 | |
i64.mul | |
local.get 13 | |
i64.const 32 | |
i64.shr_u | |
i64.add | |
local.get 10 | |
i64.const 32 | |
i64.shr_u | |
i64.add | |
i64.add | |
i64.add | |
local.set 11 | |
local.get 8 | |
local.get 12 | |
i64.store | |
local.get 5 | |
local.get 4 | |
i32.const 1 | |
i32.add | |
local.tee 4 | |
i32.ne | |
br_if 0 (;@3;) | |
end | |
else | |
i64.const 0 | |
local.set 11 | |
end | |
local.get 0 | |
local.get 0 | |
i64.load offset=88 | |
local.get 11 | |
local.get 7 | |
i32.const -1 | |
i32.add | |
i32.const 3 | |
i32.shl | |
local.get 1 | |
i32.add | |
i64.load | |
local.get 6 | |
i64.load | |
i64.mul | |
i64.add | |
i64.add | |
i64.store offset=88 | |
local.get 5 | |
i32.const -1 | |
i32.add | |
local.set 5 | |
local.get 3 | |
i32.const 1 | |
i32.add | |
local.tee 3 | |
i32.const 12 | |
i32.ne | |
br_if 0 (;@1;) | |
end) | |
(export "mul768" (func 0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment