Re: [PATCH] left shift of negative value do_binop src/arith_yacc.c:111:12
Harald van Dijk <[email protected]> Wed, 20 Aug 2025 20:51:52 +0100
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
On 20/08/2025 15:49, Steffen Nurpmeso wrote: > Harald van Dijk wrote in > <[email protected]>: > |This is what I was referring to with "subtly changing behaviour that > |differed across architectures". This behaved differently across > |architectures, taking only the low bits of the shift count is what x86 > |does but is not universal, and I did not think it would be sensible to > |implement that on other platforms where it never worked that way. The > |behaviour I picked is what would have been the result if excessive shift > |counts hadn't been explicitly undefined, it's simply that e.g. a shift > |by 123 is equivalent to 123 shifts by 1. > > Ok, but i am not with you regarding that then. (Do you can name > "other platforms"?) It has been about six years since I looked at that so I don't remember exactly. I think it was most likely 32-bit ARM where $(( 1 << 65 )) would result in 0. > I think the other shells are not either. > As a little bit laxe one regarding all that i want to point to > the email [1] (thread start [2], if you really want and do not > read it anyway), especially > > I hear and understand what you're saying. I think what I'm > trying to point out, is that in C, as it was originally > implemented, in expressions "a + b", "a >> 1", "++a", C > "does what the machine does". That's a very different thing > from having rational, safe, predictable language semantics > for operations on types - but it was also a strength, and a > simple way to describe what C would do, deferring to machine > semantics. I believe one place in C89/C90 where this is stated > explicitly, as "do what the machine does" If I had seen any way to implement that, I would have. But I saw no such way, so went with the behaviour that I felt was easiest to justify. Cheers, Harald van Dijk