Re: [PATCH] left shift of negative value do_binop src/arith_yacc.c:111:12
Steffen Nurpmeso <[email protected]> Wed, 20 Aug 2025 23:11:30 +0200
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <20250820211130.r-9ZHphA@steffen%sdaoden.eu> |
Harald van Dijk wrote in <[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 see -- thanks. No 32-bit ARM all around here, i think i will finally install an AlpineLinux armv7 VM as soon as possible! |> 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. It is undefined behavior ;) .. i looked, remembering that FreeBSD wants to or already got rid of ARMv32, what RISC says. [1] says Shift Bits RV32 shift instructions use the 5 least significant bits for the shift amount (0-31); other bits are ignored. For example, left shifting by 32 does nothing (you might expect it to set the register to zero). GNU assembler errors if you try to shift by an immediate not in the range 0-31: Error: improper shift amount (32). [2] (bad one but) says on Alpha, the shift count is masked down to six bits. A longer test shows this (in tedious detail): Itanium not well well. Well. I keep it like it is now, i like that masking. You do yours :-) [1] https://projectf.io/posts/riscv-shift/ [2] https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/td-p/5054212 |Cheers, |Harald van Dijk --End of <[email protected]> Ciao, --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)