For those of us not yet fluent in reading assembly, code_native
output could be enhanced with human-readable annotations of what the opcodes represent. This will save us from constantly searching through docs to find meanings of the more obscure opcodes.
Are there any existing annotation tools? I searched and did not find anything. I’m surprised that no one already built a simple web app that annotates blobs of assembly.
This doesn’t seem too difficult to introduce to Julia’s code_native
function. Biggest challenge seems to be handling different arg counts and types for some opcodes, and manually writing concise descriptions for all the opcodes. First version could just be a simple opcode lookup.
Here’s the proposal:
# Existing original output
julia> code_native(summation, (UInt64,); debuginfo=:none, syntax=:intel)
.text
test rdi, rdi
je L32
lea rdx, [rdi - 1]
lea rax, [rdi - 2]
mulx rcx, rax, rax
shld rcx, rax, 63
lea rax, [rcx + 2*rdi]
add rax, -1
ret
L32:
xor eax, eax
ret
nop word ptr cs:[rax + rax]
# Proposed annotated output with intel_annotate flag
julia> code_native(summation, (UInt64,); debuginfo=:none, syntax=:intel_annotate)
.text
test rdi, rdi ; test S1, S2 Set flags to result of S2 AND S2
je L32 ; je L Jump to label if equal/zero
lea rdx, [rdi - 1] ; lea D, S Load effective address of source into destination
lea rax, [rdi - 2] ; lea D, S Load effective address of source into destination
mulx rcx, rax, rax ; mulx D1, D2, S Multiply S by rdx. Product upper half to D2, lower half to D2
shld rcx, rax, 63 ; shld D R N Shift D left N bits and shift in R
lea rax, [rcx + 2*rdi] ; lea D, S Load effective address of source into destination
add rax, -1 ; add D, S Add source to destination
ret ; ret Return from procedure
L32:
xor eax, eax ; xor D, S Exclusive OR. Store in D
ret ; ret Return from procedure
nop word ptr cs:[rax + rax] ; nop No operation