I’m often curious whether small changes to functions have any effect on the compiled output. This leads to a lot of cursory inspection of @code_native
output, where I’m just looking at the line count and last few lines.
Is there an existing automated way to do this?
Something like the following would be ideal:
julia> @code_native_diff (1+1) (0x1 + 0x1)
false
This workflow would also be good:
julia> original = @code_native_str myfunc(myarg);
# make some inconsequential changes to myfunc
julia> original == @code_native_str myfunc(myarg);
true
Wanted to check here before spending more time on these macros. I’d also be happy to see anyone else’s proposed solution.
Here’s my current progress, which is inflexible and not very user-friendly. I’m also wondering if there’s a better way to capture stdout
to a string.
function func_to_str(f, args...; kwargs...)
let old_stdout = stdout
rd, = redirect_stdout()
try
f(args...; kwargs...)
finally
redirect_stdout(old_stdout) # restore original stdout
end
output = String(readavailable(rd))
return output
end
end
julia> int_add = func_to_str(code_native, +, (Int,); debuginfo=:none)
"\t.text\n\tmovq\t%rdi, %rax\n\tretq\n\tnopw\t%cs:(%rax,%rax)\n"
julia> uint_add = func_to_str(code_native, +, (UInt,); debuginfo=:none)
"\t.text\n\tmovq\t%rdi, %rax\n\tretq\n\tnopw\t%cs:(%rax,%rax)\n"
julia> float_add = func_to_str(code_native, +, (Float64,); debuginfo=:none)
"\t.text\n\tretq\n\tnopw\t%cs:(%rax,%rax)\n"
julia> int_add == uint_add
true
julia> int_add == float_add
false