Here's a simple function that gives the UInt32 words of a Float64:
function words(x::Float64)
y = reinterpret(UInt64, x)
y % UInt32, (y >> 32) % UInt32
end
julia> words(1.23)
(0x7ae147ae,0x3ff3ae14)
julia> @code_native words(1.23)
.section __TEXT,__text,regular,pure_instructions
Filename: none
Source line: 2
Source line: [inline] essentials.jl:119
pushq %rbp
movq %rsp, %rbp
Source line: 2
Source line: [inline] essentials.jl:119
movd %xmm0, %rax
Source line: 3
Source line: [inline] int.jl:177
movq %rax, %rdx
shrq $32, %rdx
popq %rbp
ret
That's about as efficient as the code for this is going to get. Moreover if
you use it to just access to high or low word it will get inlined and much
of the code eliminated:
lo(x::Float64) = words(x)[1]
julia> lo(1.23)
0x7ae147ae
julia> @code_native lo(1.23)
.section __TEXT,__text,regular,pure_instructions
Filename: none
Source line: 2
Source line: [inline] essentials.jl:119
pushq %rbp
movq %rsp, %rbp
Source line: 2
Source line: [inline] essentials.jl:119
movd %xmm0, %rax
Source line: 3
Source line: [inline] tuple.jl:8
popq %rbp
ret
On Mon, Oct 19, 2015 at 3:47 PM, Uliano Guerrini <[email protected]>
wrote:
>
>
> Il giorno lunedì 19 ottobre 2015 11:29:36 UTC+2, Gunnar Farnebäck ha
> scritto:
>>
>>
>>
>> Is this good enough?
>>
>> julia> immutable Words32
>> hi::Int32
>> lo::Int32
>> end
>>
>> julia> a = 0x7fffffff3fffffff
>> 0x7fffffff3fffffff
>>
>> julia> reinterpret(Words32, [a])
>> 1-element Array{Words32,1}:
>> Words32(1073741823,2147483647)
>>
>
> It seems to me (I have no expertise to evaluate llvm or machine code) that
> there is a considerable overload in getting the array of a and then
> dereferencing the array of what I get. In my example C/C++ does all this
> ahead of time, I'm not sure that Julia would.
>