Article View: comp.arch
Article #550Re: two's complement and Flags (Re: arithmetic and endian history)
From: Terje Mathisen
Date: Fri, 06 Nov 2026 11:08
Date: Fri, 06 Nov 2026 11:08
57 lines
3908 bytes
3908 bytes
Anton Ertl wrote: > John Levine <johnl@taugh.com> writes: > [PDP-4] >> They >> added two's complement arithmetic because the users wanted to do >> multiple precision and floating point arithmetic with more than 18 >> bits which is a lot easier to do in two's complement. It also added a >> "link" bit to hold the carry out of the accumulator, and instructions >> to test it so you could do something like this for a two word addition >> >> CLA A / low part >> TAD B / carry is in the link bit >> DAC C >> >> CLA A+1 / high part >> SZL / skip on zero link >> IAC / add 1 to AC if there was a carry >> TAD B+1 >> DAC C+1 > > That's good enough for double-precision integer arithmetic, but for > multiple-precision integers, an add with carry-in and carry-out is > needed. The first sequence only does carry-out, the second only > carry-in; the second produces a carry, but it does not reflect a > possible carry-out of the IAC. > > I am sure that one can do an addition with carry-in and carry-out on > the PDP-4, but the sequence is even longer than the five-instruction > sequence of MIPS, Alpha, and RISC-V. This is an interesting contrast > to the 6502, where the only addition available is an addition with > carry-in and carry-out (likewise for subtraction), and if you do not > want the carry-in, you ensure that the carry-bit is clear before the > ADC instructon (e.g., with the CLC instruction). If the main reason > for the TAD instruction in the PDP-4 is double-precision or > multiple-precision integer arithmetics, it probably would have been > better to go for a TADC (two's-complement addition with carry-in and > carry-out) instead. On Alpha you needed to play tricks with predicated instructions, afair you had two forms of ADD, one that just added two registers and one that did the same plus an extra increment which represented an incoming carry. Even on x86/x64 you get into similar situations when you need to add multiple parts together, it is easy to get stuck with long manual carry chains. Possibly the best primitive is MAA (Mul Add Add) representing (sumlo, sumhi) = muladdadd(f1, f2, a1, a2); since this can never overflow the two-element result? Terje -- - <Terje.Mathisen at tmsw.no> "almost all programming can be viewed as an exercise in caching"
Technical Details
Message-ID:
<11ckcg9$2f7hg$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<10uks4f$1dqo$1@gal.iecc.com> <11cai8f$32ue7$1@dont-email.me> <11caljv$jeo$1@gal.iecc.com> <6ae8eec0.35320218@news.eternal-september.org> <11cjh58$1flq$4@gal.iecc.com> <2026Nov6.072410@mips.complang.tuwien.ac.at>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Terje Mathisen <terje.mathisen@tmsw.no> Newsgroups: comp.arch Subject: Re: two's complement and Flags (Re: arithmetic and endian history) Date: Fri, 6 Nov 2026 12:08:56 +0100 Organization: A noiseless patient Spider Lines: 57 Message-ID: <11ckcg9$2f7hg$1@dont-email.me> References: <10uks4f$1dqo$1@gal.iecc.com> <11cai8f$32ue7$1@dont-email.me> <11caljv$jeo$1@gal.iecc.com> <6ae8eec0.35320218@news.eternal-september.org> <11cjh58$1flq$4@gal.iecc.com> <2026Nov6.072410@mips.complang.tuwien.ac.at> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 06 Nov 2026 11:08:58 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2596400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1Ea5btEuPe4LO9GCbzYj0cW/GfaO3Z+jlVUjJoOZ85Q=="; posting-host="bb659f4a201f7cfda51d4b84a7302338" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:BnzojiPr1VT3R6f95un5iQpjoAg= sha256:/hdUWA0NaJTPwJvtesi7TuetQLhDIP6WFUBVzjC0f2w= sha1:830HF/E9+rFgvWqzHnkphVgqZO0= sha256:Axa19PD/g/bljEZqKVgvMc5tqFjq4+BCXILlI9zSoCw= In-Reply-To: <2026Nov6.072410@mips.complang.tuwien.ac.at>