Article View: comp.arch
Article #653Re: vector length CSR?
From: Anton Ertl
Date: Wed, 11 Nov 2026 22:28
Date: Wed, 11 Nov 2026 22:28
87 lines
4919 bytes
4919 bytes
MitchAlsup <user5857@newsgrouper.org.invalid> writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) posted:
>> SPARC and Power have only one add instruction. With a load-store
>> architecture, you need only one, the full-width one.
>
>If you like LLVM compilers having to constrain ADD results with
>SEXT/ZEXT, sure, and you also don't get integer overflow performed
>properly (assuming you want it done at all).
Actually, it's easier to determine overflow of, e.g., half-width
addition, if you use full-width addition to do it: If the result of,
e.g., d=a+b+c does not have the same values for bits 31..63, there has
been an overflow. It's a checking analogon of sign extension. And
the cool thing is that it only checks the end result, not intermediate
operations.
But if you think it's reasonable to trap on an immediate overflow even
if the end result is in range, nobody forbids doing the check after
every step. Or, if you prefer flags, have flags not just for
full-width overflow, but also for half-width overflow, for
quarter-width overflow, and for byte overflow.
>LLVM takes the (somewhat convoluted) vision that a result in a
>register is range limited to the exact value-set as one stored
>in memory.
Let's test that theory:
int foo(int a, int b, int c)
{
return a+b+c;
}
Use clang-19 on a Power9 machine to compile this, and disassemble the
result:
clang -O3 -c xxx.c && objdump -d xxx.o
Here's the disassembly of foo():
0000000000000000 <foo>:
0: 14 1a 64 7c add r3,r4,r3
4: 14 2a 63 7c add r3,r3,r5
8: b4 07 63 7c extsw r3,r3
c: 20 00 80 4e blr
I get the same result when foo() is defined as:
int foo(int a, int b, int c)
{
int d=a+b;
return d+c;
}
Nope, no sign-extending every result in a register. Only the end
result is sign-extended, because the ABI of Power demands sign
extension for signed ints. With current C coding practices, using
don't-care extension when returning ints might be possible, but in the
1990s when the Power 64-bit ABI was designed, there were enough
function calls without or with wrong prototypes that requiring
sign-extension for signed ints resulted in significantly less
breakage.
>> Only with
>> load-and-add instructions, you need to specify the width in the
>> addition, and whether you want the loaded value to be sign-extended or
>> zero-extended (although I think most have only one variant of every
>> length). You also then have to ask yourself if you want to perform
>> the addition to the full width of the register, or just the width of
>> the loaded value, and sign- or zero-extend the result. I see no good
>> reason to add only to the width of the loaded value, but that's how
>> AMD64 works.
>
>Any language that requires the register-allocated variable to be range
>constrained exactly like those residing in memory has that property.
Apart from assembly languages, I don't know any languages that have
any requirements for "register-allocated variable". As for the
requirement for variables in general, they usually do not specify what
the bits beyond the bits needed to represent the type should look
like. ABIs do, but they are all over the place, and only relevant at
call boundaries.
- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID:
<2026Nov11.232844@mips.complang.tuwien.ac.at>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11cpqih$acf5$1@dont-email.me> <11cr2g5$q796$2@dont-email.me> <2026Nov9.071302@mips.complang.tuwien.ac.at> <11cru1e$11qpi$1@dont-email.me> <2026Nov9.091404@mips.complang.tuwien.ac.at> <11cti0c$1lilf$4@dont-email.me> <2026Nov10.084131@mips.complang.tuwien.ac.at> <1794340629-5857@newsgrouper.org> <2026Nov10.221543@mips.complang.tuwien.ac.at> <1794357251-5857@newsgrouper.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.arch Subject: Re: vector length CSR? Date: Wed, 11 Nov 2026 22:28:44 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Lines: 87 Message-ID: <2026Nov11.232844@mips.complang.tuwien.ac.at> References: <11cpqih$acf5$1@dont-email.me> <11cr2g5$q796$2@dont-email.me> <2026Nov9.071302@mips.complang.tuwien.ac.at> <11cru1e$11qpi$1@dont-email.me> <2026Nov9.091404@mips.complang.tuwien.ac.at> <11cti0c$1lilf$4@dont-email.me> <2026Nov10.084131@mips.complang.tuwien.ac.at> <1794340629-5857@newsgrouper.org> <2026Nov10.221543@mips.complang.tuwien.ac.at> <1794357251-5857@newsgrouper.org> Injection-Date: Wed, 11 Nov 2026 22:59:49 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3656682"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lnkXnzkFsJKXcKFYp4QGe"; posting-host="9be58ce66f14ec876e6ac91941122637" Cancel-Lock: sha1:aNm068i8aofGpc2QhQ71ct21cfc= sha256:e+PRaNB2Jp/G5S76+ZBZk8JkaEs0laxrTNf84Q4j4gM= sha1:oXKGvxpL2tA4pZE5Awc/+4BemQQ= sha256:3vury4D+v2VmO1Jl5ocWiJf6IYoMdTVQqNOP256NouU= X-newsreader: xrn 10.11