Notes |
|
(0001085)
|
wangp
|
2020-04-29 16:26
|
|
The two checks are supposed to be performed using a single unsigned comparison on the shift amount, so is there anything to gain?
I don't think the new operators would be used enough to justify them. Also, Java has >>> meaning logical right shift (I had to look that up) -- it would be best not to introduce operators that conflict with operators in well known languages. |
|
|
(0001086)
|
zs
|
2020-04-29 16:39
|
|
The gain I am after is not efficiency. The gain is being able to write code
such as "1u <<u NumBits" instead of "1u << uint.cast_to_int(NumBits)".
I am working on a version of du_type_layout.m that would work at
"create .int file" time instead of code generation time, and that code
is full of things that cannot be negative: number of arguments in a functor,
word lengths, bitfield sizes, shift amount etc. It is a pain having to choose
between
(a) using ints, and losing the >= 0 invariant, and
(b) using uints, and having to pepper calls to most library functions
with casts, because those functions take only signed ints, to the extent
that the casts obscure the actual logic of the code. |
|
|
(0001087)
|
zs
|
2020-04-29 16:40
|
|
On the topic of avoiding >>>, I agree; if we don't have to create
such conflicts of notation, we shouldn't. |
|
|
(0001088)
|
wangp
|
2020-04-29 17:03
|
|
You could define an overload in a compiler module to improve clarity:
:- func uint << uint = uint.
X << Y = uint.(X << cast_to_int(Y)).
That is not to say we should not add named functions taking unsigned shift amounts to the standard library. |
|
|
|
Java only has >>> for logical right shifts because it doesn't support unsigned types but does provide (some) unsigned operations on its signed types. AFAIK, it is the only well known language that has that.
I'd be fine with unchecked_{left, right}_ushift for the unchecked versions. I'm not really a fan of things like >>u and <<u, but I can probably live with them. (I guess just having the functions left_ushift and right_ushift is too ungainly?) |
|