-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
LLVM's fptosi intrinsic is undefined for NaN, so LLVM obnoxiously and pointlessly does different things when it gets NaN as a run-time value than as a compile-time value. To avoid this shitty, pointless trap, we have to avoid calling fptosi on NaN by introducing a branch into the hashing function – even though for hashing, we don't care *what* value is produced, just as long as it's consistent. Unfortunately, this affects the performance of Float64 hashing pretty badly. I was not able to figure out any way to recover this lost performance. LLVM really needs to stop doing this.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,11 @@ end | |
## hashing small, built-in numeric types ## | ||
|
||
hx(a::Uint64, b::Float64, h::Uint) = hash_uint((3a + reinterpret(Uint64,b)) - h) | ||
const hx_NaN = hx(uint(0), NaN, uint(0)) | ||
|
||
hash(x::Uint64, h::Uint) = hx(x, float64(x), h) | ||
hash(x::Int64, h::Uint) = hx(reinterpret(Uint64,x), float64(x), h) | ||
hash(x::Float64, h::Uint) = hx(box(Uint64,fptosi(unbox(Float64,x))), ifelse(isnan(x), NaN, x), h) | ||
hash(x::Float64, h::Uint) = isnan(x) ? (hx_NaN $ h) : hx(box(Uint64,fptosi(unbox(Float64,x))), x, h) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
StefanKarpinski
Author
Member
|
||
|
||
hash(x::Union(Int8,Uint8,Int16,Uint16,Int32,Uint32), h::Uint) = hash(int64(x), h) | ||
hash(x::Float32, h::Uint) = hash(float64(x), h) | ||
|
2 comments
on commit 3696968
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would turning off some fast-math
stuff in LLVM's codegen help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so; the LLVM language spec says the answer is undefined period.
Did using
ifelse
here not work?