Skip to content

Instantly share code, notes, and snippets.

@dinfuehr
Last active May 2, 2017 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinfuehr/9e1c2f28d0f912eae5e595207cb835c2 to your computer and use it in GitHub Desktop.
Save dinfuehr/9e1c2f28d0f912eae5e595207cb835c2 to your computer and use it in GitHub Desktop.
output all logical immediate values with n, immr and imms
def get_imms(size, length)
length | case size
when 2 then 0b111100
when 4 then 0b111000
when 8 then 0b110000
when 16 then 0b100000
when 32 then 0b000000
when 64 then 0b000000
end
end
def disasm(val)
content = ".section .text\n.globl _start\n_start:\nand x0, x0, 0x#{val.to_s(16)}\n"
File.open("disasm.s", "w") do |f|
f.write(content)
end
system("aarch64-linux-gnu-as disasm.s -o disasm.o")
result = `aarch64-linux-gnu-objdump -d disasm.o`
for line in result.lines
cols = line.split
if cols[0] == "0:"
return (cols[1].to_i(16) >> 10) & 0x1fff
end
end
raise "line not found"
end
for size in 1..6
size = 1 << size
for length in 0...size-1
result = (1 << (length + 1)) - 1
e = size
while e < 64
result = result | (result << e)
e = e * 2
end
for rotation in 0...size
n = size == 64 ? 1 : 0
immr = rotation
imms = get_imms(size, length)
value = n << 12 | immr << 6 | imms
disasm_value = disasm(result)
if value != disasm_value
puts "FAIL: %013b != %013b" % [value, disasm_value]
raise "wrong encoding"
end
puts "%016x %064b size=%02d length=%02d rotation=%02d N=%01b immr=%06b imms=%06b" % [result, result, size, length, rotation, n, immr, imms]
result = (((result & 1) << 63) | (result >> 1)) & 0xFFFFFFFF_FFFFFFFF
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment