-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib] Optimize normalize_index for unsigned types #3957
base: main
Are you sure you want to change the base?
Conversation
Optimize normalize_index for UInt Indexer type. Signed-off-by: Yinon Burgansky <[email protected]>
I didn't use it in inline_array since the current implementation doesn't perform bound checks at all and since normalize_index does bound checks with |
Maybe to make it more generic, a change to the signature taking the length directly instead of the sized container, might be needed. |
With regards to
|
As a side note: fn main():
# binary operators use the method of left side type
print(Int(-1) < UInt(1<<63)) # False
print(UInt(1<<63) > Int(-1)) # False
print(UInt(1) > Int(-1)) # False
print(Int(-1) < UInt(1)) # True |
The second commit addresses all of the issues above. In the future, if needed this pattern can be extended to support SIMD sized containers without upcasting and/or normalizing multiple indexes at once using SIMD. |
33892b4
to
3cbdfbb
Compare
Signed-off-by: Yinon Burgansky <[email protected]>
3cbdfbb
to
08417d9
Compare
I've found out that by doing the bounds check after the index normalization we can avoid a comparison This is also True for SIMD so if needed we can add support UInt8.MAX sized containers and use negative Int8 indexes without upcasting or doing more expensive bounds check, the only cost is the normalization which can be done branchless. |
581dcd7
to
8878984
Compare
Signed-off-by: Yinon Burgansky <[email protected]>
8878984
to
2581aa0
Compare
Use the
Indexer
trait innormalize_index
to optimize forUInt
,UInt8
,UInt16
,UInt32
, andUInt64
types.