since x86-64 does not have such an instruction (only one for s64 -> r64)
we should probably rewrite this at the IR level
cvt dst:r64 = src:u64
would become
if top bit of src:u64 is set:
shr dst2:u64 src:u64 1 # clears the top bit by halving the input
cvt dst3:s64 dst2:u64 # nop at the machine level
cvt dst:r64 dst3:s64 # use the available instruction
add dst:r64 dst:r64 dst:r64 # double the output
else:
cvt dst2:s64 dst:u64 # nop at the machine level
cvt dst:r64 dst2:s64 # use the available instruction
r64 only has about 52 significant bit so throwing one is no big deal
since x86-64 does not have such an instruction (only one for s64 -> r64)
we should probably rewrite this at the IR level
cvt dst:r64 = src:u64
would become
if top bit of src:u64 is set:
shr dst2:u64 src:u64 1 # clears the top bit by halving the input
cvt dst3:s64 dst2:u64 # nop at the machine level
cvt dst:r64 dst3:s64 # use the available instruction
add dst:r64 dst:r64 dst:r64 # double the output
else:
cvt dst2:s64 dst:u64 # nop at the machine level
cvt dst:r64 dst2:s64 # use the available instruction
r64 only has about 52 significant bit so throwing one is no big deal