Zig 2024 roadmap
Zig 2024 roadmap
Posted Feb 5, 2024 14:53 UTC (Mon) by pbonzini (subscriber, #60935)In reply to: Zig 2024 roadmap by khim
Parent article: Zig 2024 roadmap
Posted Feb 5, 2024 15:01 UTC (Mon)
by farnz (subscriber, #17727)
[Link] (1 responses)
That then makes x >> y and x << y a multiple instruction sequence, not a single instruction sequence. On AArch64, for example, LSL x1, x2, x3 is defined as "take the bottom 6 bits of x3, shift x2 left by that amount"; this ignores the sign bit completely, and to implement the behaviour you're suggesting, I'd have to check the sign bit of x3, then choose whether to do an LSL, LSR, or ASR instruction based on signedness of x2's current contents and sign bit of x3.
Posted Feb 5, 2024 15:17 UTC (Mon)
by khim (subscriber, #9252)
[Link]
Posted Feb 5, 2024 15:18 UTC (Mon)
by khim (subscriber, #9252)
[Link] (4 responses)
P1236R1 changed definition to precisely what you say in C++20. Are you sure C23 haven't picked up that change?
Posted Feb 5, 2024 15:24 UTC (Mon)
by pbonzini (subscriber, #60935)
[Link]
Posted Feb 6, 2024 9:02 UTC (Tue)
by pbonzini (subscriber, #60935)
[Link] (2 responses)
> 6.5.7 Bitwise shift operators
Posted Feb 6, 2024 10:13 UTC (Tue)
by khim (subscriber, #9252)
[Link] (1 responses)
Ugh. I think someone should propose to fix it, then. C++ have finally removed “undefined behavior” from there (crazy values still trigger undefined behavior when E2, the right operand is “strange”, but anything is accepted as E1, the left operand — starting from C++20), thus in practice compilers already have code to handle everything properly
Posted Feb 6, 2024 15:25 UTC (Tue)
by pbonzini (subscriber, #60935)
[Link]
Zig 2024 roadmap
You are talking about right argument, pbonzini talks about left one.
Zig 2024 roadmap
Zig 2024 roadmap
Zig 2024 roadmap
Zig 2024 roadmap
>
> [...] 4 The result of E1 << E2 is E1 left-shifted E2 bit positions [...] if E1 has a signed type and nonnegative value, and E1 * 2^E2 is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined
>
> 5 The result of E1 >> E2 is E1 right-shifted E2 bit positions [...] If E1 has a signed type and a negative value, the resulting value is implementation-defined
> Nope:
Zig 2024 roadmap
Zig 2024 roadmap