-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[stdlib] Fix SIMD[..., u128/s128]
construction from UInt
#4339
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
base: main
Are you sure you want to change the base?
Conversation
alias a = rebind[UInt](-1) | ||
alias a_str = String(a) | ||
assert_equal(a_str, String(UInt128(a))) |
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.
We can't do much better than stringify due to #4049.
mojo/stdlib/src/builtin/simd.mojo
Outdated
self = Self(value.value) | ||
@parameter | ||
if bitwidthof[dtype]() > bitwidthof[DType.index](): | ||
self = Self(rebind[UInt64](value)) |
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.
Cannot use UInt64(value)
here. I think there's a compiler bug(?) where v.cast[index]().cast[int128]()
gets simplified to v.cast[int128]()
(on the pop
level), which lowers to sext
yet again. So we use rebind
to skip the constructor from index
entirely.
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.
Actually, it's probably not really a compiler bug. Suppose the target type is UInt128
. If we go through UInt64
, we get roughly the following MLIR:
var v: index = ...
var a = pop.cast[int64](v)
var b = pop.cast[int128](a)
Since index
is treated as signed (?), the first cast is a no-op, and the second is a sign extension.
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.
Question: Aren't you assuming 64 bitwidth machines by using UInt64
?
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.
Yea, I'm being lazy here. Will fix it properly when the team confirmes that rebind
is an acceptable approach.
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.
Actually, rebind[T]
doesn't work when alias T = Scalar[_unsigned_integral_type_of[DType.index]()]
, so I opted for a different fix.
fb3be68
to
e883e8b
Compare
Signed-off-by: Yiwu Chen <[email protected]>
Signed-off-by: Yiwu Chen <[email protected]>
Close #4338.