Created
August 2, 2017 18:34
-
-
Save binji/c57dc945bba60985439ef8e5b574eee0 to your computer and use it in GitHub Desktop.
memcpy.wast
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
(module | |
(import "env" "memory" (memory 1)) | |
(func $memcpy (export "memcpy") (param i32 i32 i32) (result i32) | |
(local i32) | |
(block (result i32) ;; label = @1 | |
(set_local 3 | |
(get_local 0)) | |
(if ;; label = @3 | |
(i32.eq | |
(i32.and | |
(get_local 0) | |
(i32.const 3)) | |
(i32.and | |
(get_local 1) | |
(i32.const 3))) | |
(then | |
(loop ;; label = @4 | |
(if ;; label = @5 | |
(i32.and | |
(get_local 0) | |
(i32.const 3)) | |
(then | |
(if ;; label = @6 | |
(i32.eqz | |
(get_local 2)) | |
(then | |
(return | |
(get_local 3)))) | |
(i32.store8 | |
(get_local 0) | |
(i32.load8_s | |
(get_local 1))) | |
(set_local 0 | |
(i32.add | |
(get_local 0) | |
(i32.const 1))) | |
(set_local 1 | |
(i32.add | |
(get_local 1) | |
(i32.const 1))) | |
(set_local 2 | |
(i32.sub | |
(get_local 2) | |
(i32.const 1))) | |
(br 1 (;@5;))))) | |
(loop ;; label = @7 | |
(if ;; label = @8 | |
(i32.ge_s | |
(get_local 2) | |
(i32.const 4)) | |
(then | |
(i32.store | |
(get_local 0) | |
(i32.load | |
(get_local 1))) | |
(set_local 0 | |
(i32.add | |
(get_local 0) | |
(i32.const 4))) | |
(set_local 1 | |
(i32.add | |
(get_local 1) | |
(i32.const 4))) | |
(set_local 2 | |
(i32.sub | |
(get_local 2) | |
(i32.const 4))) | |
(br 1 (;@7;))))))) | |
(loop ;; label = @9 | |
(if ;; label = @10 | |
(i32.gt_s | |
(get_local 2) | |
(i32.const 0)) | |
(then | |
(i32.store8 | |
(get_local 0) | |
(i32.load8_s | |
(get_local 1))) | |
(set_local 0 | |
(i32.add | |
(get_local 0) | |
(i32.const 1))) | |
(set_local 1 | |
(i32.add | |
(get_local 1) | |
(i32.const 1))) | |
(set_local 2 | |
(i32.sub | |
(get_local 2) | |
(i32.const 1))) | |
(br 1 (;@9;))))) | |
(get_local 3))) | |
(func $memmove (export "memmove") (param i32 i32 i32) (result i32) | |
(local i32) | |
(block (result i32) ;; label = @1 | |
(if ;; label = @2 | |
(i32.and | |
(i32.lt_s | |
(get_local 1) | |
(get_local 0)) | |
(i32.lt_s | |
(get_local 0) | |
(i32.add | |
(get_local 1) | |
(get_local 2)))) | |
(then | |
(set_local 3 | |
(get_local 0)) | |
(set_local 1 | |
(i32.add | |
(get_local 1) | |
(get_local 2))) | |
(set_local 0 | |
(i32.add | |
(get_local 0) | |
(get_local 2))) | |
(loop ;; label = @3 | |
(if ;; label = @4 | |
(i32.gt_s | |
(get_local 2) | |
(i32.const 0)) | |
(then | |
(set_local 2 | |
(i32.sub | |
(get_local 2) | |
(i32.const 1))) | |
(i32.store8 | |
(tee_local 0 | |
(i32.sub | |
(get_local 0) | |
(i32.const 1))) | |
(i32.load8_s | |
(tee_local 1 | |
(i32.sub | |
(get_local 1) | |
(i32.const 1))))) | |
(br 1 (;@3;))))) | |
(set_local 0 | |
(get_local 3))) | |
(else | |
(drop | |
(call $memcpy | |
(get_local 0) | |
(get_local 1) | |
(get_local 2))))) | |
(get_local 0))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment