Created
May 28, 2019 23:24
-
-
Save fengb/648e6eb0f8999e861dfcf5e4ecce0468 to your computer and use it in GitHub Desktop.
@memcpy vs std.mem.cpy
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
const std = @import("std"); | |
const size = 64; | |
var targetBase: [size]u8 = undefined; | |
var srcBase: [size]u8 = []u8{42} ** size; | |
export var target = targetBase[0..size]; | |
export var src = srcBase[0..size]; | |
export fn at_memcpy() [*]u8 { | |
@memcpy(target.ptr, src.ptr, size); | |
return target.ptr; | |
} | |
export fn std_mem_copy() [*]u8 { | |
std.mem.copy(u8, target, src); | |
return target.ptr; | |
} |
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 | |
(type (;0;) (func)) | |
(type (;1;) (func (result i32))) | |
(func $__wasm_call_ctors (type 0)) | |
(func $at_memcpy (type 1) (result i32) | |
(local i32 i32) | |
i32.const 0 | |
i32.load offset=1088 | |
local.tee 0 | |
i32.const 0 | |
i32.load offset=1160 | |
local.tee 1 | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0 | |
i32.const 8 | |
i32.add | |
local.get 1 | |
i32.const 8 | |
i32.add | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0 | |
i32.const 16 | |
i32.add | |
local.get 1 | |
i32.const 16 | |
i32.add | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0 | |
i32.const 24 | |
i32.add | |
local.get 1 | |
i32.const 24 | |
i32.add | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0 | |
i32.const 32 | |
i32.add | |
local.get 1 | |
i32.const 32 | |
i32.add | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0 | |
i32.const 40 | |
i32.add | |
local.get 1 | |
i32.const 40 | |
i32.add | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0 | |
i32.const 48 | |
i32.add | |
local.get 1 | |
i32.const 48 | |
i32.add | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0 | |
i32.const 56 | |
i32.add | |
local.get 1 | |
i32.const 56 | |
i32.add | |
i64.load align=1 | |
i64.store align=1 | |
local.get 0) | |
(func $std_mem_copy (type 1) (result i32) | |
(local i32 i32) | |
block ;; label = @1 | |
i32.const 0 | |
i32.load offset=1164 | |
local.tee 0 | |
i32.eqz | |
br_if 0 (;@1;) | |
i32.const 0 | |
local.set 1 | |
loop ;; label = @2 | |
i32.const 0 | |
i32.load offset=1088 | |
local.get 1 | |
i32.add | |
i32.const 0 | |
i32.load offset=1160 | |
local.get 1 | |
i32.add | |
i32.load8_u | |
i32.store8 | |
local.get 0 | |
local.get 1 | |
i32.const 1 | |
i32.add | |
local.tee 1 | |
i32.ne | |
br_if 0 (;@2;) | |
end | |
end | |
i32.const 0 | |
i32.load offset=1088) | |
(table (;0;) 1 1 funcref) | |
(memory (;0;) 2) | |
(global (;0;) (mut i32) (i32.const 66704)) | |
(global (;1;) i32 (i32.const 66704)) | |
(global (;2;) i32 (i32.const 1168)) | |
(global (;3;) i32 (i32.const 1088)) | |
(global (;4;) i32 (i32.const 1160)) | |
(export "memory" (memory 0)) | |
(export "__heap_base" (global 1)) | |
(export "__data_end" (global 2)) | |
(export "at_memcpy" (func $at_memcpy)) | |
(export "target" (global 3)) | |
(export "src" (global 4)) | |
(export "std_mem_copy" (func $std_mem_copy)) | |
(data (;0;) (i32.const 1024) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") | |
(data (;1;) (i32.const 1088) "\00\04\00\00@\00\00\00****************************************************************H\04\00\00@\00\00\00")) |
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
Shallow Bytes │ Shallow % │ Item | |
───────────────┼───────────┼────────────────────────────── | |
148 ┊ 24.63% ┊ at_memcpy | |
86 ┊ 14.31% ┊ data[1] | |
80 ┊ 13.31% ┊ std_mem_copy | |
70 ┊ 11.65% ┊ data[0] | |
47 ┊ 7.82% ┊ "function names" subsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment