-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
Some performance sensitive libraries use likely / unlikely for branch prediction.
I am discovering crystal like two weeks or so, I have no idea what is the correct way to implement and test.
Here is what I found so far.
https://llvm.org/docs/LangRef.html#id766
declare i1 @llvm.expect.i1(i1 <val>, i1 <expected_val>)
declare i32 @llvm.expect.i32(i32 <val>, i32 <expected_val>)
declare i64 @llvm.expect.i64(i64 <val>, i64 <expected_val>)
Rust: core: add likely and unlikely intrinsics
Something like this in crystal will correctly works?
lib Intrinsics
fun inspect1 = "llvm.expect.i1"(val : Bool, expected_val : Bool) : Bool
fun inspect32 = "llvm.expect.i32"(val : Int32, expected_val : Int32) : Int32
fun inspect64 = "llvm.expect.i64"(val : Int64, expected_val : Int64) : Int64
end
def likely(val)
Intrinsics.inspect1(val, true)
end
def unlikely(val)
Intrinsics.inspect1(val, false)
end
oprypin
Metadata
Metadata
Assignees
Labels
No labels