Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Real Programmers don't eat quiche. They eat Twinkies and Szechwan food.


devel / comp.arch / Compact representation for common integer constants

SubjectAuthor
* Compact representation for common integer constantsJohnG
+* Re: Compact representation for common integer constantsIvan Godard
|+- Re: Compact representation for common integer constantsDavid Brown
|`* Re: Compact representation for common integer constantsJohnG
| `* Re: Compact representation for common integer constantsBGB
|  `* Re: Compact representation for common integer constantsMitchAlsup
|   `* Re: Compact representation for common integer constantsBGB
|    `* Re: Compact representation for common integer constantsThomas Koenig
|     +- Re: Compact representation for common integer constantsMitchAlsup
|     `* Re: Compact representation for common integer constantsBGB
|      `* Re: Compact representation for common integer constantsMitchAlsup
|       `* Re: Compact representation for common integer constantsIvan Godard
|        +- Re: Compact representation for common integer constantsMarcus
|        +* Re: Compact representation for common integer constantsBGB
|        |`* Re: Compact representation for common integer constantsMitchAlsup
|        | +* Clamping. was: Compact representation for common integer constantsIvan Godard
|        | |+* Re: Clamping. was: Compact representation for common integer constantsMitchAlsup
|        | ||`* Re: Clamping. was: Compact representation for common integerIvan Godard
|        | || `- Re: Clamping. was: Compact representation for common integer constantsMitchAlsup
|        | |`* Re: Clamping. was: Compact representation for common integerBGB
|        | | `* Re: Clamping. was: Compact representation for common integerIvan Godard
|        | |  `- Re: Clamping. was: Compact representation for common integer constantsMitchAlsup
|        | +* Re: Compact representation for common integer constantsMarcus
|        | |`* Re: Compact representation for common integer constantsMitchAlsup
|        | | `* Re: Compact representation for common integer constantsDavid Brown
|        | |  `* Re: Compact representation for common integer constantsMitchAlsup
|        | |   +- Re: Compact representation for common integer constantsThomas Koenig
|        | |   `* Re: Compact representation for common integer constantsDavid Brown
|        | |    `- Re: Compact representation for common integer constantsMitchAlsup
|        | `* Re: Compact representation for common integer constantsThomas Koenig
|        |  +- Re: Compact representation for common integer constantsAnton Ertl
|        |  `* Re: Compact representation for common integer constantsMitchAlsup
|        |   `* Re: Compact representation for common integer constantsThomas Koenig
|        |    +* Re: Compact representation for common integer constantsAnton Ertl
|        |    |`* Re: Compact representation for common integer constantsBrian G. Lucas
|        |    | +* Re: Compact representation for common integer constantsThomas Koenig
|        |    | |`- Re: Compact representation for common integer constantsBrian G. Lucas
|        |    | +- Re: Compact representation for common integer constantsStefan Monnier
|        |    | `* Re: Compact representation for common integer constantsAnton Ertl
|        |    |  `* Re: Compact representation for common integer constantsThomas Koenig
|        |    |   +* Re: Compact representation for common integer constantsAnton Ertl
|        |    |   |`* Re: Compact representation for common integer constantsThomas Koenig
|        |    |   | `- Re: Compact representation for common integer constantsAnton Ertl
|        |    |   `* Re: Compact representation for common integer constantsTerje Mathisen
|        |    |    `- Re: Compact representation for common integer constantsAnton Ertl
|        |    `* Re: Compact representation for common integer constantsMitchAlsup
|        |     `* Re: Compact representation for common integer constantsThomas Koenig
|        |      `* Re: Compact representation for common integer constantsBrian G. Lucas
|        |       `* Re: Compact representation for common integer constantsThomas Koenig
|        |        +* Re: Compact representation for common integer constantsMitchAlsup
|        |        |`- Re: Compact representation for common integer constantsThomas Koenig
|        |        +* Re: Compact representation for common integer constantsAnton Ertl
|        |        |+* Re: Compact representation for common integer constantsThomas Koenig
|        |        ||+* Re: Compact representation for common integer constantsMitchAlsup
|        |        |||`* Re: Compact representation for common integer constantsThomas Koenig
|        |        ||| `- Re: Compact representation for common integer constantsMitchAlsup
|        |        ||`* Re: Compact representation for common integer constantsAnton Ertl
|        |        || +* Re: Compact representation for common integer constantsMitchAlsup
|        |        || |+* Re: Compact representation for common integer constantsEricP
|        |        || ||+* Re: Compact representation for common integer constantsThomas Koenig
|        |        || |||+- Re: Compact representation for common integer constantsMitchAlsup
|        |        || |||+* Re: Compact representation for common integer constantsEricP
|        |        || ||||`* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || |||| `* Re: Compact representation for common integer constantsDavid Brown
|        |        || ||||  `* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || ||||   `* Re: Compact representation for common integer constantsDavid Brown
|        |        || ||||    `- Re: Compact representation for common integer constantsTerje Mathisen
|        |        || |||`* Re: Compact representation for common integer constantsStephen Fuld
|        |        || ||| `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || |||  +- Re: Compact representation for common integer constantsStephen Fuld
|        |        || |||  `* Re: Compact representation for common integer constantsBill Findlay
|        |        || |||   `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || |||    `- Re: Compact representation for common integer constantsBill Findlay
|        |        || ||+* Re: Compact representation for common integer constantsThomas Koenig
|        |        || |||+* Re: Compact representation for common integer constantsStephen Fuld
|        |        || ||||`- Re: Compact representation for common integer constantsThomas Koenig
|        |        || |||`- Re: Compact representation for common integer constantsEricP
|        |        || ||`* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || +* Re: Compact representation for common integer constantsNiklas Holsti
|        |        || || |`* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || | `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |  `* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || |   `* Re: Compact representation for common integer constantsEricP
|        |        || || |    +* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |`* Re: Compact representation for common integer constantsEricP
|        |        || || |    | `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |  `* Re: Compact representation for common integer constantsThomas Koenig
|        |        || || |    |   +- Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |   `* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |    |    `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |     +- Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |    |     `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |    |      `- Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |    `* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || |     `* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |      +- Re: Compact representation for common integer constantsBill Findlay
|        |        || || |      +* Re: Compact representation for common integer constantsThomas Koenig
|        |        || || |      |+* Re: Compact representation for common integer constantsAnton Ertl
|        |        || || |      ||`* Re: Compact representation for common integer constantsThomas Koenig
|        |        || || |      || `- Re: Compact representation for common integer constantsAnton Ertl
|        |        || || |      |`* Re: Compact representation for common integer constantsMitchAlsup
|        |        || || |      +* Re: Compact representation for common integer constantsTerje Mathisen
|        |        || || |      `* Re: Compact representation for common integer constantsStephen Fuld
|        |        || || `* Re: Compact representation for common integer constantsEricP
|        |        || |`- Re: Compact representation for common integer constantsAnton Ertl
|        |        || `* Re: Compact representation for common integer constantsThomas Koenig
|        |        |`* Re: Compact representation for common integer constantsMitchAlsup
|        |        `* Re: Compact representation for common integer constantsBrian G. Lucas
|        `* Re: Compact representation for common integer constantsQuadibloc
+* Re: Compact representation for common integer constantsBGB
`* Re: Compact representation for common integer constantsJohn Levine

Pages:123456789101112131415
Re: Compact representation for common integer constants

<5a04b2dc-30c4-414b-9b36-73aa77b98aadn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17210&group=comp.arch#17210

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a37:f612:: with SMTP id y18mr3355433qkj.436.1622120550581; Thu, 27 May 2021 06:02:30 -0700 (PDT)
X-Received: by 2002:aca:c488:: with SMTP id u130mr2270309oif.0.1622120550338; Thu, 27 May 2021 06:02:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Thu, 27 May 2021 06:02:30 -0700 (PDT)
In-Reply-To: <s8nqlb$160s$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com> <s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de> <2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de> <2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com> <nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me> <igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me> <51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me> <26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me> <88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me> <s8nqlb$160s$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5a04b2dc-30c4-414b-9b36-73aa77b98aadn@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: already5...@yahoo.com (Michael S)
Injection-Date: Thu, 27 May 2021 13:02:30 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 100
 by: Michael S - Thu, 27 May 2021 13:02 UTC

On Thursday, May 27, 2021 at 1:01:18 PM UTC+3, Terje Mathisen wrote:
> David Brown wrote:
> > On 27/05/2021 08:10, Ivan Godard wrote:
> >> On 5/26/2021 10:52 PM, Terje Mathisen wrote:
> >>>
> >>> I.e. Intel's add_carryx_u64() returns both the full adder result and
> >>> the outgoing carry.
> >>>
> >>> Terje
> >>>
> >>
> >> Which is regrettable when without restrict and inlining, and doubtful
> >> even then.
> >>
> >> A more modern approach is to make the two values into a struct and
> >> return that. A good modern compiler will tuple-ize that into two
> >> registers. Can't speak for gcc, gave up long ago, but LLVM does and
> >> needs neither restrict nor inline.
> >
> > Modern compilers don't need the function marked as "inline", nor do they
> > need the qualifier "restrict" added - if they can see the function
> > definition when it is used, they inline automatically where appropriate.
> > That means either using LTO, or having the function within the file you
> > are using it, or having it in a header marked as either "inline" or
> > "static" (or both) to avoid duplicate definitions when linking.
> >
> > Using a struct to give multiple values as a return is, of course, a
> > perfectly good alternative - one that many people (including me) prefer.
> > gcc will follow the same pattern as clang here about how to return the
> > struct, because it is required by the ABI (and IIRC both compilers have
> > switches to let you use non-standard methods if you prefer).
> >
> > While it's common in C to pass a pointer to where the results should go
> > in cases like this, struct returns are not new - look at the "div"
> > function in the C standard library for an example as old as C.
> >
> I should have noted that it really doesn't matter in the case of those
> intrinsics: Unless you go out of your way by declaring the additional
> return as a pointer to a non-local variable, most (all?) compilers who
> know about the intrinsic will in fact generate optimal code.
>

Until few months ago gcc generated very bad code for this intrinsic.
It seems, they fixed it between 10 and 11. Now they are on par with lllvm and MSVc, if not ahead.

Unfortunately, it only works on iAMD64. I know no easy way to achieve the same from C or C++ on aarch64 or Power or SPARC, despite all three featuring similar instructions

> I.e. 128-bit unsigned add
>
> u8 carry;
> carry = _addcarryx_u64(alo, blo, &sumlo);
> _addcarryx_u64(ahi, bhi, &sumhi);
>
> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
> for b and the return back in RDX:RAX):
>
> add rax,rbx
> adc rdx,rcx
>
> I.e. optimal code needing just the minimum possible 2 cycles of latency.
>
> With the new ADCX/ADOX instructions you can even do two (long) chains of
> additions at the same time, but to use them you have to zero out the
> Overflow and Carry flags before you start:
>
> ; RSI -> first accumulator
> ; [RSI+RBX] -> second accumulator
> ; [RSI+RDI] -> first addend
> ; [RSI+RBP] -> second addend
> ; RCX = loop count
>
> xor rax,rax ; Clear C & O flags
> nextpair:
> jrcxz done
> mov rax,[rsi]
> mov rdx,[rsi+rbx]
> adcx rax,[rsi+rdi]
> adox rdx,[rsi+rbp]
> mov [rsi],rax
> mov [rsi+rbx],rdx
> lea rsi,[rsi+8]
> lea rcx,[rcx-1]
> jmp nextpair
> done:
>
> This is 4 loads and 2 stores per iteration, so possible to run in 2
> cycles on a wide enough cpu (with everything in $L1).
>
> Please note that this setup (ab)uses the flags pretty badly!
>
> ADCX will _only_ update Carry
> ADOX will _only_ update Overflow
> MOV & LEA does not update any flags
> JRCXZ neither updates nor test any flags, it is the only conditional
> branch with this distinction, but it has to be used as an inverted loop
> exit test.
> Terje
>
> --
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<adeb1d23-372c-432d-be05-550ec7a7403en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17211&group=comp.arch#17211

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ad4:5613:: with SMTP id ca19mr3673973qvb.3.1622120783657;
Thu, 27 May 2021 06:06:23 -0700 (PDT)
X-Received: by 2002:aca:1b15:: with SMTP id b21mr5505596oib.155.1622120783438;
Thu, 27 May 2021 06:06:23 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Thu, 27 May 2021 06:06:23 -0700 (PDT)
In-Reply-To: <s8nt68$ond$1@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=199.203.251.52; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 199.203.251.52
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com> <s7u338$cek$1@newsreader4.netcologne.de>
<s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me>
<q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me>
<s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me>
<s8ne5m$g8d$1@dont-email.me> <s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <adeb1d23-372c-432d-be05-550ec7a7403en@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: already5...@yahoo.com (Michael S)
Injection-Date: Thu, 27 May 2021 13:06:23 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Michael S - Thu, 27 May 2021 13:06 UTC

On Thursday, May 27, 2021 at 1:44:28 PM UTC+3, Thomas Koenig wrote:
> Terje Mathisen <terje.m...@tmsw.no> schrieb:
> > I.e. 128-bit unsigned add
> >
> > u8 carry;
> > carry = _addcarryx_u64(alo, blo, &sumlo);
> > _addcarryx_u64(ahi, bhi, &sumhi);
> >
> > will compile into something like this (assuming RDX:RAX for a, RCX:RBX
> > for b and the return back in RDX:RAX):
> >
> > add rax,rbx
> > adc rdx,rcx
> With gcc (and clang), this is not needed, there a __int128_t
> and a __uint128_t type.

Not needed in a very specific case of 128-bit. But useful for wider type.

> It is rather poorly supported, though;
> you cannot, for example, specify 128-bit integer constants in
> C directly.
>
> For Fortran, it is just another integer type (kind=16), which
> is fully uspported.

Re: Compact representation for common integer constants

<s8o945$62e$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17213&group=comp.arch#17213

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!/FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Thu, 27 May 2021 16:08:05 +0200
Organization: Aioe.org NNTP Server
Lines: 41
Message-ID: <s8o945$62e$1@gioia.aioe.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me>
<s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
NNTP-Posting-Host: /FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Thu, 27 May 2021 14:08 UTC

Thomas Koenig wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>
>> I.e. 128-bit unsigned add
>>
>> u8 carry;
>> carry = _addcarryx_u64(alo, blo, &sumlo);
>> _addcarryx_u64(ahi, bhi, &sumhi);
>>
>> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
>> for b and the return back in RDX:RAX):
>>
>> add rax,rbx
>> adc rdx,rcx
>
> With gcc (and clang), this is not needed, there a __int128_t
> and a __uint128_t type. It is rather poorly supported, though;
> you cannot, for example, specify 128-bit integer constants in
> C directly.

But you can use it to implement intermediate-size integers, like 512-bit
RSA variables by accessing the hi/lo parts to chain them together?

I.e. use them to add two 64-bit values and get the carry alongside the sum?

u128 sum128 = (u128) a64 + (u128) b64;

This still, btw, does not provide a full adder since you also need the
ability to pass in two 64-bit inputs and the incoming carry.

>
> For Fortran, it is just another integer type (kind=16), which
> is fully uspported.
>
Nice. :-)

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<s8o9ok$fr6$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17214&group=comp.arch#17214

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!/FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Thu, 27 May 2021 16:19:00 +0200
Organization: Aioe.org NNTP Server
Lines: 54
Message-ID: <s8o9ok$fr6$1@gioia.aioe.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<adeb1d23-372c-432d-be05-550ec7a7403en@googlegroups.com>
NNTP-Posting-Host: /FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Thu, 27 May 2021 14:19 UTC

Michael S wrote:
> On Thursday, May 27, 2021 at 1:44:28 PM UTC+3, Thomas Koenig wrote:
>> Terje Mathisen <terje.m...@tmsw.no> schrieb:
>>> I.e. 128-bit unsigned add
>>>
>>> u8 carry;
>>> carry = _addcarryx_u64(alo, blo, &sumlo);
>>> _addcarryx_u64(ahi, bhi, &sumhi);

Mea Culpa! I forgot the incoming carry argument to those instructions,
it should have been

u8 carry = 0;
carry = _addcarryx_u64(carry, alo, blo, &sumlo);
_addcarryx_u64(carry, ahi, bhi, &sumhi);

>>>
>>> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
>>> for b and the return back in RDX:RAX):
>>>
>>> add rax,rbx
>>> adc rdx,rcx
>> With gcc (and clang), this is not needed, there a __int128_t
>> and a __uint128_t type.
>
> Not needed in a very specific case of 128-bit. But useful for wider type.

Yeah, absolutely right.

My example above would trivially extend to 256-bit ints like this, where
using the compiler support for u128 would be a poor second choice:

u8 carry = 0;
carry = _addcarryx_u64(carry, a0, b0, &sum0);
carry = _addcarryx_u64(carry, a1, b1, &sum1);
carry = _addcarryx_u64(carry, a2, b2, &sum2);
carry = _addcarryx_u64(carry, a3, b3, &sum3);

(Carry set on output could be used as an error indication unless
wraparound was intended, and this is probably the case for crypto.)

>
>> It is rather poorly supported, though;
>> you cannot, for example, specify 128-bit integer constants in
>> C directly.

So effectively you have to use pairs of 64-bit hex constants in orer to
keep it manageable.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<T1OrI.310$G11.43@fx01.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17215&group=comp.arch#17215

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!rocksolid2!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx01.iad.POSTED!not-for-mail
From: ThatWoul...@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com> <s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de> <2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de> <2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com> <nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me> <igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me> <51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me> <26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me> <0001HW.265F073A0064EB8D700005E5438F@news.individual.net> <s8mmgd$bp2$1@dont-email.me> <0001HW.265F1AAF00697B07700005E5438F@news.individual.net> <ih8tr3Fel7hU1@mid.individual.net> <s8nojc$d5q$1@dont-email.me>
In-Reply-To: <s8nojc$d5q$1@dont-email.me>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 43
Message-ID: <T1OrI.310$G11.43@fx01.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Thu, 27 May 2021 14:30:11 UTC
Date: Thu, 27 May 2021 10:29:34 -0400
X-Received-Bytes: 3712
 by: EricP - Thu, 27 May 2021 14:29 UTC

Ivan Godard wrote:
> On 5/26/2021 11:51 PM, Niklas Holsti wrote:
>>
>> Furthermore, just to be complete, the subtraction operator "-" may
>> have been overloaded so that the computation T'(A+B) - C produces a
>> different type, which would then be the type required for X.
>>
>> Conversely, the type of X can determine which of many overloadings of
>> "-" is chosen for this computation: one that produces a result of the
>> same type as X, while taking arguments of type T and the type of C.
>> Here Ada goes further than C++; AIUI, in C++ overloading is resolved
>> based only on the argument types.

That's Ada's top-down overload resolution.
In addition to the routine or operator arguments, which bottom-up
resolution considers, top-down also considers whether the routine
is a procedure or function, and if a function then the return type.

> Yeah, I did that. It mostly follows the coercion rules of Mary2, which
> in turn were derived from Algol68. The semantics differed in one way:
> Mary2 used first-found in a search of overloads in as-declared order,
> while Ada (and C++) search all overloads and complain of ambiguities.

Long ago when I was playing with hobby language design I thought this
was a nice idea so I added top-down overload resolution to the language.

Then I tried to build it. It is insanely complex.
Because of things like default argument values,
named associations that can change the arg order,
and I had variable (ellipsis) arg lists too,
the routine signatures are totally variable,
combined with multiple nested and package name spaces,
the search space potentially explodes exponentially.

Eventually removed it from the language and went
with traditional bottom-up overload resolution.

From what I later read back then, the successful Ada overload resolvers
did a bottom up pass first to prune the lists of possibilities.
Then a top down pass to resolve the leftovers and check for ambiguities.
That's still damn complicated, just less explode-y.

Re: Compact representation for common integer constants

<f519aee1-e125-49e7-b02f-04c904a46fbbn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17218&group=comp.arch#17218

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:127b:: with SMTP id b27mr4303516qkl.104.1622134258105;
Thu, 27 May 2021 09:50:58 -0700 (PDT)
X-Received: by 2002:a9d:7494:: with SMTP id t20mr3515615otk.16.1622134257848;
Thu, 27 May 2021 09:50:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Thu, 27 May 2021 09:50:57 -0700 (PDT)
In-Reply-To: <s8nc3e$pi7$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:14ec:dfa0:a657:35a2;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:14ec:dfa0:a657:35a2
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<e29a79f4-80ba-4dcb-8079-cf2f87a86b3en@googlegroups.com> <s7svtl$qlt$1@newsreader4.netcologne.de>
<bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com> <s7u338$cek$1@newsreader4.netcologne.de>
<s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me>
<q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me>
<s8nc3e$pi7$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f519aee1-e125-49e7-b02f-04c904a46fbbn@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Thu, 27 May 2021 16:50:58 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: MitchAlsup - Thu, 27 May 2021 16:50 UTC

On Thursday, May 27, 2021 at 12:52:50 AM UTC-5, Terje Mathisen wrote:
> Ivan Godard wrote:
> > On 5/26/2021 10:04 AM, MitchAlsup wrote:
> >> On Wednesday, May 26, 2021 at 10:53:02 AM UTC-5, Stephen Fuld wrote:
> >>> On 5/21/2021 3:59 PM, MitchAlsup wrote:
> >>>> On Friday, May 21, 2021 at 5:00:17 PM UTC-5, Stephen Fuld wrote:
> >>>>> On 5/21/2021 12:40 PM, EricP wrote:
> >>>>>> Stephen Fuld wrote:
> >>>>>>> On 5/20/2021 9:34 AM, MitchAlsup wrote:
> >>>>>>>> On Thursday, May 20, 2021 at 10:08:32 AM UTC-5, Stephen Fuld wrote:
> >>>>>>>>> On 5/19/2021 11:40 PM, Niklas Holsti wrote:
> >>>>>>>>>> On 2021-05-20 3:40, Stephen Fuld wrote:
> >>>>>>>>>>> On 5/19/2021 8:47 AM, EricP wrote:
> >>>>>>>>
> >>>>>>>>> Fair enough. This sort of gets back to the question of whether
> >>>>>>>>> to add a
> >>>>>>>>> feature like this as an attribute of the variable (e.g. range)
> >>>>>>>>> or of
> >>>>>>>>> the
> >>>>>>>>> operation (e.g. bignum). I think there are arguments for each.
> >>>>>>>>>
> >>>>>>>>> BTW, I am unsure of what the requirement is here. Suppose you
> >>>>>>>>> have a
> >>>>>>>>> variable with a range of 10-90. Do you want saturation at 90?
> >>>>>>>>> That is
> >>>>>>>> <
> >>>>>>>> If the value to be written is outside of the range [10..90] you
> >>>>>>>> raise an
> >>>>>>>> exception. The raised exception decides what to do.
> >>>>>>>
> >>>>>>> Certainly true for the non-saturating case, and is what Ada does. My
> >>>>>>> question is if you define saturating variables, what to do if you
> >>>>>>> somehow define the variable with a range *and* saturating.
> >>>>>>
> >>>>>> Any variables that are smaller than the machine register size are
> >>>>>> promoted to that size by either sign or zero extension.
> >>>>>>
> >>>>>> Expressions are executed using signed or unsigned checked or
> >>>>>> saturating
> >>>>>> operations at that machine size. This detects intermediate signed or
> >>>>>> unsigned overflows of the machine size results.
> >>>>>>
> >>>>>> I have instructions for trap on unsigned carry or signed overflow.
> >>>>>> I have an ADGO Add Generate Overflow and ADGC Add Generate Carry
> >>>>>> to set a 1 in the output register for overflow or carry.
> >>>>>> Then a LIC Load Immediate Conditional loads saturation limit values.
> >>>>>> One could have arithmetic instructions that saturate.
> >>>>>>
> >>>>>> The result is copied back to the variable. If there are
> >>>>>> constraints on
> >>>>>> the variable different from the limits on the physical register
> >>>>>> then those are range checked and either saturated or trapped.
> >>>>>> A CMPGT and CMPLT with a LIC loads upper or lower saturation value..
> >>>>>>
> >>>>>> Note that setting limits on variable to be in the range 10..90 does
> >>>>>> not mean that expression intermediate results are within that range.
> >>>>>> It means an expression EITHER produces the arithmetically correct
> >>>>>> result
> >>>>>> in that range, or it saturates or traps.
> >>>> <
> >>>>> That is certainly one way to do it. All the different ways have
> >>>>> drawbacks. Mitch pointed out some of the ones for you choice in his
> >>>>> followup.
> >>>>>
> >>>>> I don't know enough to have strong feelings as to the best choice. As
> >>>>> Thomas Koening said earlier in this thread, it takes a lot of thought.
> >>>> <
> >>>> This brings to mind that the whole concept of arithmetic exceptions is
> >>>> fundamentally flawed.
> >>>> <
> >>>> It is not the arithmetic that should be checked for out-of-range values
> >>>> it is the depositing of values into containers that should be checked.
> >>> While I generally agree, there is apparently some use for checking
> >>> intermediate results in calculations. Then the question becomes what is
> >>> the best way, language syntax wise (i.e. not a question of ISA, as there
> >>> are several ways to do that depending upon ISA) to indicate that.
> >>>
> >>> Note that I am going to consider this in terms a generalized range
> >>> restriction à la Ada Range attributes, as resolving this for that case
> >>> automatically includes the cases of overflow of byte sized variables in
> >>> 64 bit registers, etc.
> >>>
> >>> Perhaps the easiest way to indicate this is the break the calculation
> >>> into individual steps, storing the intermediate results, thus triggering
> >>> the range checks.
> >>>
> >>> Lets use a simple example.
> >>>
> >>> X = A + B - C where A+B might be out of range, but after C is subtracted
> >>> X is within range.
> >>>
> >>> You could code this as
> >>>
> >>> X = A + B
> >>> X = X - C
> >> <
> >> In general, I am a great fan of shorter assignment statements (as above)
> >> and while there are more assignments, there may be fewer instructions
> >> created, and the programmer himself can see the common sub-expressions..
> >>>
> >>> Of course, the compiler would have to recognize that X had a range and
> >>> actually do the check, even if it doesn't actually do the first store..
> >>>
> >>> Another alternative is the use a "function" to indicate that the check
> >>> should be done. This is a generalization of the cast mechanism in C.
> >>>
> >>> i.e. something like
> >>>
> >>> X = Rangechk (A + B) - C ; Rangechk tests the bounds of X
> >>>
> >>>
> >>> Another alternative is back to the discussion of whether the checking of
> >>> intermediate values should be a property of the variable (like Range
> >>> itself) or the calculation. If it is a property of the variable you
> >>> could have syntax to indicate that, i.e. add RangeIVC (for intermediate
> >>> value checked), which would indicate to check the intermediate values
> >>> for any expression that assigns a value to the variable with that
> >>> attribute.
> >>>
> >>> I don't have a strong feeling about what is the best solution, and there
> >>> may be better ones than what I have suggested.
> >> <
> >> May I suggest a whip instead of a language addition !! That is the code
> >> review process should not allow x = a + b - c; into production code if
> >> there is any reason to believe it can behave maliciously !! or unbox
> >> the nasal demons of destruction !
> >> <
> >> There are codes which depend on the HW not caring that something
> >> has lost precision on one end (integral) or the other (FP). For example
> >> Knuth's TwoSum::
> >> <
> >> {double, double} TwoSum( double a, double b )
> >> { // Knuth
> >> x = a + b ;
> >> q = x - a ;
> >> r = x - q ;
> >> s = b - q ;
> >> t = a - r ;
> >> y = s + t ;
> >> return { x, y };
> >> }
> >> <
> >> This subroutine performs addition and puts all of the bits of a+b that
> >> fit into x, and all of the bits that do not fit into y, branchlessly. The
> >> numerical analyst went to great trouble to align all the arithmetic
> >> so that precisely this would be the result.
> >> <
> >> An "optimizing" might come to the conclusion that q == b and ruin
> >> the whole sequence !!
> >> <
> >> On the other hand I designed My 66000 so that one can write this as::
> >> <
> >> {double, double} TwoSum( double a, double b )
> >> {
> >> return {double, double} = a + b;
> >> }
> >
> >
> > Does your actual compiler currently accept this as source? If not, what
> > do you actually have to write to get the requisite machine code from
> > your implemented compiler?
> The traditional C way, as exemplified by lots of compiler intrinsics, is
> to use a pointer to any additional return values:
>
> double AugmentedAddition(double a, double b, double *lopart)
> {
> // Knuth
> x = a + b ;
> q = x - a ;
> r = x - q ;
> s = b - q ;
> t = a - r ;
> *lopart = s + t ;
> return x;
> }
<
Unnecessary:: x and y have the properties::
x contains all of the bits (properly rounded) that made it into a+b
y contains all of the bits that did not make it into x.
<
In the case a and b are disjoint (exponents differ by more than 53)
x gets the larger magnitude, and y gets the smaller magnitude.
That is:: there are no "lopart" left.
>
> I.e. Intel's add_carryx_u64() returns both the full adder result and the
> outgoing carry.
> Terje
>
> --
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"


Click here to read the complete article
Re: Compact representation for common integer constants

<s8oj0e$4b1$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17219&group=comp.arch#17219

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Thu, 27 May 2021 16:56:46 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8oj0e$4b1$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7v6j1$qns$1@dont-email.me> <s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org>
Injection-Date: Thu, 27 May 2021 16:56:46 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:501b:0:7285:c2ff:fe6c:992d";
logging-data="4449"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Thu, 27 May 2021 16:56 UTC

Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
> Thomas Koenig wrote:
>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>
>>> I.e. 128-bit unsigned add
>>>
>>> u8 carry;
>>> carry = _addcarryx_u64(alo, blo, &sumlo);
>>> _addcarryx_u64(ahi, bhi, &sumhi);
>>>
>>> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
>>> for b and the return back in RDX:RAX):
>>>
>>> add rax,rbx
>>> adc rdx,rcx
>>
>> With gcc (and clang), this is not needed, there a __int128_t
>> and a __uint128_t type. It is rather poorly supported, though;
>> you cannot, for example, specify 128-bit integer constants in
>> C directly.
>
> But you can use it to implement intermediate-size integers, like 512-bit
> RSA variables by accessing the hi/lo parts to chain them together?

Sure.

> I.e. use them to add two 64-bit values and get the carry alongside the sum?

You could use __builtin_add_overflow for that, instead:

int main()
{ int n1, n2;
__uint128_t a, b, res;
scanf ("%d %d", &n1, &n2);
a = ((__uint128_t) 1) << n1;
b = ((__uint128_t) 1) << n2;
if (__builtin_add_overflow (a, b, &res))
printf ("Overflow!\n");
else
printf ("No overflow!\n");
return 0;
}

and then chain this further. However, if your hardware does
not support 128-bit integers natively, you are probably better
off using 64-bit words and use the carry that way. There
is no particular advantage to using 128-bit types, and
at least gcc has some issues with register allocation for
those types.

The best way would probably be to use 64-bit unsigned ints,
and then to do

int c_old; c_new;
c_old = 0;
for (i=0; i<n; i++) {
c_new = __builtin_add_overflow (a[i], b[i], res+i);
res[i] += c_old;
c_old = c_new;
}

For doing a high /low multiplication, you can indeed use the 128-bit
types:

__uint128_t tmp;
uint64_t high, low;
tmp = (__uint128_t) a * (__uint128_t) b;
low = tmp;
high = tmp >> 64;

Re: Compact representation for common integer constants

<s8ojhh$4b1$2@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17220&group=comp.arch#17220

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Thu, 27 May 2021 17:05:53 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8ojhh$4b1$2@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <2021May27.113439@mips.complang.tuwien.ac.at>
Injection-Date: Thu, 27 May 2021 17:05:53 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:501b:0:7285:c2ff:fe6c:992d";
logging-data="4449"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Thu, 27 May 2021 17:05 UTC

Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb:

> Gcc has had -freg-struct-return for at least 30 years, but it's
> incompatible with the way PCC returned structs, so you cannot link
> code that uses reg-struct-return with code that uses pcc-struct-return
> if there is such a return between code using different conventions.

The Itanium ABI fixed that.

Rather than quote chapter and verse, here is a short example:

$ cat ret.c
typedef struct foo
{ int a;
int b;
} foo;

foo bar()
{ return ((foo){.a = 42, .b=21});
} $ gcc -O3 -S ret.c
$ cat ret.s
.file "ret.c"
.text
.p2align 4
.globl bar
.type bar, @function
bar:
..LFB0:
.cfi_startproc
movabsq $90194313258, %rax
ret
.cfi_endproc
..LFE0:
.size bar, .-bar
.ident "GCC: (GNU) 12.0.0 20210525 (experimental) [master revision e87559d202d:f4e6da6e8ac:36ec54aac7da134441c83248e14825381b8d6f17]"
.section .note.GNU-stack,"",@progbits

Re: Compact representation for common integer constants

<jwv35u8km6t.fsf-monnier+comp.arch@gnu.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17225&group=comp.arch#17225

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monn...@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Thu, 27 May 2021 15:39:40 -0400
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <jwv35u8km6t.fsf-monnier+comp.arch@gnu.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<0001HW.265F073A0064EB8D700005E5438F@news.individual.net>
<s8mmgd$bp2$1@dont-email.me>
<0001HW.265F1AAF00697B07700005E5438F@news.individual.net>
<ih8tr3Fel7hU1@mid.individual.net> <s8nojc$d5q$1@dont-email.me>
<T1OrI.310$G11.43@fx01.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="da159ba45eae5e55b828a73b15785bd6";
logging-data="28771"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Lg/xfol4L1MKoBHa1y+H6"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Cancel-Lock: sha1:9xx0G+d2cEQ7CZCcWQMn04Te2Yo=
sha1:8rtx4rlEerUhljSte82QV4k4Ebc=
 by: Stefan Monnier - Thu, 27 May 2021 19:39 UTC

> Then I tried to build it. It is insanely complex.
> Because of things like default argument values,
> named associations that can change the arg order,
> and I had variable (ellipsis) arg lists too,
> the routine signatures are totally variable,
> combined with multiple nested and package name spaces,
> the search space potentially explodes exponentially.

Indeed, it can get terribly complex. I think in terms of design, this
complexity is a problem not just for the implementation but for the
human reader as well.

So you generally want to tweak your language design in order to reduce
this complexity.

One way to do that, for example, is it to make it so overloading
resolution does not affect types, it only chooses which implementation
to call (or signal an error if there's no candidate that matches).
This is what was happens for example with Haskell's single-parameter
type classes.

Stefan

Re: Compact representation for common integer constants

<9da22211-79e9-4bdb-8c08-7c99fe81a116n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17226&group=comp.arch#17226

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:1fc:: with SMTP id x28mr123706qkn.269.1622144677625;
Thu, 27 May 2021 12:44:37 -0700 (PDT)
X-Received: by 2002:aca:c488:: with SMTP id u130mr3513806oif.0.1622144677455;
Thu, 27 May 2021 12:44:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!fdcspool3.netnews.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Thu, 27 May 2021 12:44:37 -0700 (PDT)
In-Reply-To: <jwv35u8km6t.fsf-monnier+comp.arch@gnu.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:14ec:dfa0:a657:35a2;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:14ec:dfa0:a657:35a2
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May18.183723@mips.complang.tuwien.ac.at> <s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me>
<q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me>
<0001HW.265F073A0064EB8D700005E5438F@news.individual.net> <s8mmgd$bp2$1@dont-email.me>
<0001HW.265F1AAF00697B07700005E5438F@news.individual.net> <ih8tr3Fel7hU1@mid.individual.net>
<s8nojc$d5q$1@dont-email.me> <T1OrI.310$G11.43@fx01.iad> <jwv35u8km6t.fsf-monnier+comp.arch@gnu.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9da22211-79e9-4bdb-8c08-7c99fe81a116n@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Thu, 27 May 2021 19:44:37 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3125
 by: MitchAlsup - Thu, 27 May 2021 19:44 UTC

On Thursday, May 27, 2021 at 2:39:45 PM UTC-5, Stefan Monnier wrote:
> > Then I tried to build it. It is insanely complex.
> > Because of things like default argument values,
> > named associations that can change the arg order,
> > and I had variable (ellipsis) arg lists too,
> > the routine signatures are totally variable,
> > combined with multiple nested and package name spaces,
> > the search space potentially explodes exponentially.
> Indeed, it can get terribly complex. I think in terms of design, this
> complexity is a problem not just for the implementation but for the
> human reader as well.
>
> So you generally want to tweak your language design in order to reduce
> this complexity.
>
> One way to do that, for example, is it to make it so overloading
> resolution does not affect types, it only chooses which implementation
> to call (or signal an error if there's no candidate that matches).
<
There should be another error if more than on implementations match.
<
> This is what was happens for example with Haskell's single-parameter
> type classes.
>
>
> Stefan

Re: Compact representation for common integer constants

<s8ou0o$7pg$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17228&group=comp.arch#17228

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!/FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Thu, 27 May 2021 22:04:42 +0200
Organization: Aioe.org NNTP Server
Lines: 193
Message-ID: <s8ou0o$7pg$1@gioia.aioe.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<bcd3dd9a-cfcd-4691-9163-842ddf1f483dn@googlegroups.com>
<s7u338$cek$1@newsreader4.netcologne.de> <s7v6j1$qns$1@dont-email.me>
<s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<f519aee1-e125-49e7-b02f-04c904a46fbbn@googlegroups.com>
NNTP-Posting-Host: /FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Thu, 27 May 2021 20:04 UTC

MitchAlsup wrote:
> On Thursday, May 27, 2021 at 12:52:50 AM UTC-5, Terje Mathisen wrote:
>> Ivan Godard wrote:
>>> On 5/26/2021 10:04 AM, MitchAlsup wrote:
>>>> On Wednesday, May 26, 2021 at 10:53:02 AM UTC-5, Stephen Fuld wrote:
>>>>> On 5/21/2021 3:59 PM, MitchAlsup wrote:
>>>>>> On Friday, May 21, 2021 at 5:00:17 PM UTC-5, Stephen Fuld wrote:
>>>>>>> On 5/21/2021 12:40 PM, EricP wrote:
>>>>>>>> Stephen Fuld wrote:
>>>>>>>>> On 5/20/2021 9:34 AM, MitchAlsup wrote:
>>>>>>>>>> On Thursday, May 20, 2021 at 10:08:32 AM UTC-5, Stephen Fuld wrote:
>>>>>>>>>>> On 5/19/2021 11:40 PM, Niklas Holsti wrote:
>>>>>>>>>>>> On 2021-05-20 3:40, Stephen Fuld wrote:
>>>>>>>>>>>>> On 5/19/2021 8:47 AM, EricP wrote:
>>>>>>>>>>
>>>>>>>>>>> Fair enough. This sort of gets back to the question of whether
>>>>>>>>>>> to add a
>>>>>>>>>>> feature like this as an attribute of the variable (e.g. range)
>>>>>>>>>>> or of
>>>>>>>>>>> the
>>>>>>>>>>> operation (e.g. bignum). I think there are arguments for each.
>>>>>>>>>>>
>>>>>>>>>>> BTW, I am unsure of what the requirement is here. Suppose you
>>>>>>>>>>> have a
>>>>>>>>>>> variable with a range of 10-90. Do you want saturation at 90?
>>>>>>>>>>> That is
>>>>>>>>>> <
>>>>>>>>>> If the value to be written is outside of the range [10..90] you
>>>>>>>>>> raise an
>>>>>>>>>> exception. The raised exception decides what to do.
>>>>>>>>>
>>>>>>>>> Certainly true for the non-saturating case, and is what Ada does. My
>>>>>>>>> question is if you define saturating variables, what to do if you
>>>>>>>>> somehow define the variable with a range *and* saturating.
>>>>>>>>
>>>>>>>> Any variables that are smaller than the machine register size are
>>>>>>>> promoted to that size by either sign or zero extension.
>>>>>>>>
>>>>>>>> Expressions are executed using signed or unsigned checked or
>>>>>>>> saturating
>>>>>>>> operations at that machine size. This detects intermediate signed or
>>>>>>>> unsigned overflows of the machine size results.
>>>>>>>>
>>>>>>>> I have instructions for trap on unsigned carry or signed overflow.
>>>>>>>> I have an ADGO Add Generate Overflow and ADGC Add Generate Carry
>>>>>>>> to set a 1 in the output register for overflow or carry.
>>>>>>>> Then a LIC Load Immediate Conditional loads saturation limit values.
>>>>>>>> One could have arithmetic instructions that saturate.
>>>>>>>>
>>>>>>>> The result is copied back to the variable. If there are
>>>>>>>> constraints on
>>>>>>>> the variable different from the limits on the physical register
>>>>>>>> then those are range checked and either saturated or trapped.
>>>>>>>> A CMPGT and CMPLT with a LIC loads upper or lower saturation value.
>>>>>>>>
>>>>>>>> Note that setting limits on variable to be in the range 10..90 does
>>>>>>>> not mean that expression intermediate results are within that range.
>>>>>>>> It means an expression EITHER produces the arithmetically correct
>>>>>>>> result
>>>>>>>> in that range, or it saturates or traps.
>>>>>> <
>>>>>>> That is certainly one way to do it. All the different ways have
>>>>>>> drawbacks. Mitch pointed out some of the ones for you choice in his
>>>>>>> followup.
>>>>>>>
>>>>>>> I don't know enough to have strong feelings as to the best choice. As
>>>>>>> Thomas Koening said earlier in this thread, it takes a lot of thought.
>>>>>> <
>>>>>> This brings to mind that the whole concept of arithmetic exceptions is
>>>>>> fundamentally flawed.
>>>>>> <
>>>>>> It is not the arithmetic that should be checked for out-of-range values
>>>>>> it is the depositing of values into containers that should be checked.
>>>>> While I generally agree, there is apparently some use for checking
>>>>> intermediate results in calculations. Then the question becomes what is
>>>>> the best way, language syntax wise (i.e. not a question of ISA, as there
>>>>> are several ways to do that depending upon ISA) to indicate that.
>>>>>
>>>>> Note that I am going to consider this in terms a generalized range
>>>>> restriction à la Ada Range attributes, as resolving this for that case
>>>>> automatically includes the cases of overflow of byte sized variables in
>>>>> 64 bit registers, etc.
>>>>>
>>>>> Perhaps the easiest way to indicate this is the break the calculation
>>>>> into individual steps, storing the intermediate results, thus triggering
>>>>> the range checks.
>>>>>
>>>>> Lets use a simple example.
>>>>>
>>>>> X = A + B - C where A+B might be out of range, but after C is subtracted
>>>>> X is within range.
>>>>>
>>>>> You could code this as
>>>>>
>>>>> X = A + B
>>>>> X = X - C
>>>> <
>>>> In general, I am a great fan of shorter assignment statements (as above)
>>>> and while there are more assignments, there may be fewer instructions
>>>> created, and the programmer himself can see the common sub-expressions.
>>>>>
>>>>> Of course, the compiler would have to recognize that X had a range and
>>>>> actually do the check, even if it doesn't actually do the first store.
>>>>>
>>>>> Another alternative is the use a "function" to indicate that the check
>>>>> should be done. This is a generalization of the cast mechanism in C.
>>>>>
>>>>> i.e. something like
>>>>>
>>>>> X = Rangechk (A + B) - C ; Rangechk tests the bounds of X
>>>>>
>>>>>
>>>>> Another alternative is back to the discussion of whether the checking of
>>>>> intermediate values should be a property of the variable (like Range
>>>>> itself) or the calculation. If it is a property of the variable you
>>>>> could have syntax to indicate that, i.e. add RangeIVC (for intermediate
>>>>> value checked), which would indicate to check the intermediate values
>>>>> for any expression that assigns a value to the variable with that
>>>>> attribute.
>>>>>
>>>>> I don't have a strong feeling about what is the best solution, and there
>>>>> may be better ones than what I have suggested.
>>>> <
>>>> May I suggest a whip instead of a language addition !! That is the code
>>>> review process should not allow x = a + b - c; into production code if
>>>> there is any reason to believe it can behave maliciously !! or unbox
>>>> the nasal demons of destruction !
>>>> <
>>>> There are codes which depend on the HW not caring that something
>>>> has lost precision on one end (integral) or the other (FP). For example
>>>> Knuth's TwoSum::
>>>> <
>>>> {double, double} TwoSum( double a, double b )
>>>> { // Knuth
>>>> x = a + b ;
>>>> q = x - a ;
>>>> r = x - q ;
>>>> s = b - q ;
>>>> t = a - r ;
>>>> y = s + t ;
>>>> return { x, y };
>>>> }
>>>> <
>>>> This subroutine performs addition and puts all of the bits of a+b that
>>>> fit into x, and all of the bits that do not fit into y, branchlessly. The
>>>> numerical analyst went to great trouble to align all the arithmetic
>>>> so that precisely this would be the result.
>>>> <
>>>> An "optimizing" might come to the conclusion that q == b and ruin
>>>> the whole sequence !!
>>>> <
>>>> On the other hand I designed My 66000 so that one can write this as::
>>>> <
>>>> {double, double} TwoSum( double a, double b )
>>>> {
>>>> return {double, double} = a + b;
>>>> }
>>>
>>>
>>> Does your actual compiler currently accept this as source? If not, what
>>> do you actually have to write to get the requisite machine code from
>>> your implemented compiler?
>> The traditional C way, as exemplified by lots of compiler intrinsics, is
>> to use a pointer to any additional return values:
>>
>> double AugmentedAddition(double a, double b, double *lopart)
>> {
>> // Knuth
>> x = a + b ;
>> q = x - a ;
>> r = x - q ;
>> s = b - q ;
>> t = a - r ;
>> *lopart = s + t ;
>> return x;
>> }
> <
> Unnecessary:: x and y have the properties::
> x contains all of the bits (properly rounded) that made it into a+b
> y contains all of the bits that did not make it into x.
> <
> In the case a and b are disjoint (exponents differ by more than 53)
> x gets the larger magnitude, and y gets the smaller magnitude.
> That is:: there are no "lopart" left.


Click here to read the complete article
Re: Compact representation for common integer constants

<s8oudj$frs$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17229&group=comp.arch#17229

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!/FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Thu, 27 May 2021 22:11:33 +0200
Organization: Aioe.org NNTP Server
Lines: 87
Message-ID: <s8oudj$frs$1@gioia.aioe.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s7vn9p$bfu$1@newsreader4.netcologne.de>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de>
NNTP-Posting-Host: /FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Thu, 27 May 2021 20:11 UTC

Thomas Koenig wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>> Thomas Koenig wrote:
>>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>>
>>>> I.e. 128-bit unsigned add
>>>>
>>>> u8 carry;
>>>> carry = _addcarryx_u64(alo, blo, &sumlo);
>>>> _addcarryx_u64(ahi, bhi, &sumhi);
>>>>
>>>> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
>>>> for b and the return back in RDX:RAX):
>>>>
>>>> add rax,rbx
>>>> adc rdx,rcx
>>>
>>> With gcc (and clang), this is not needed, there a __int128_t
>>> and a __uint128_t type. It is rather poorly supported, though;
>>> you cannot, for example, specify 128-bit integer constants in
>>> C directly.
>>
>> But you can use it to implement intermediate-size integers, like 512-bit
>> RSA variables by accessing the hi/lo parts to chain them together?
>
> Sure.
>
>> I.e. use them to add two 64-bit values and get the carry alongside the sum?
>
> You could use __builtin_add_overflow for that, instead:
>
> int main()
> {
> int n1, n2;
> __uint128_t a, b, res;
> scanf ("%d %d", &n1, &n2);
> a = ((__uint128_t) 1) << n1;
> b = ((__uint128_t) 1) << n2;
> if (__builtin_add_overflow (a, b, &res))
> printf ("Overflow!\n");
> else
> printf ("No overflow!\n");
> return 0;
> }
>
> and then chain this further. However, if your hardware does
> not support 128-bit integers natively, you are probably better
> off using 64-bit words and use the carry that way. There
> is no particular advantage to using 128-bit types, and
> at least gcc has some issues with register allocation for
> those types.
>
> The best way would probably be to use 64-bit unsigned ints,
> and then to do
>
> int c_old; c_new;
> c_old = 0;
> for (i=0; i<n; i++) {
> c_new = __builtin_add_overflow (a[i], b[i], res+i);
> res[i] += c_old;

That does not work:

You have to also handle the case where res[i] += c_old causes a new carry!

I.e. you need

c0 = __builtin_add_overflow (a[i], b[i], &temp);
c1 = __builtin_add_overflow (temp, c_old, res+i);
c_old = c0 | c1;

> For doing a high /low multiplication, you can indeed use the 128-bit
> types:
>
> __uint128_t tmp;
> uint64_t high, low;
> tmp = (__uint128_t) a * (__uint128_t) b;
> low = tmp;
> high = tmp >> 64;
>
Hopefully the compiler will recognize this and make the two last lines NOPs.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<s8q19m$1ar$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17231&group=comp.arch#17231

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 06:06:46 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8q19m$1ar$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May18.183723@mips.complang.tuwien.ac.at>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de>
<s8oudj$frs$1@gioia.aioe.org>
Injection-Date: Fri, 28 May 2021 06:06:46 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:501b:0:7285:c2ff:fe6c:992d";
logging-data="1371"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 28 May 2021 06:06 UTC

Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
> Thomas Koenig wrote:
>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>> Thomas Koenig wrote:
>>>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>>>
>>>>> I.e. 128-bit unsigned add
>>>>>
>>>>> u8 carry;
>>>>> carry = _addcarryx_u64(alo, blo, &sumlo);
>>>>> _addcarryx_u64(ahi, bhi, &sumhi);
>>>>>
>>>>> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
>>>>> for b and the return back in RDX:RAX):
>>>>>
>>>>> add rax,rbx
>>>>> adc rdx,rcx
>>>>
>>>> With gcc (and clang), this is not needed, there a __int128_t
>>>> and a __uint128_t type. It is rather poorly supported, though;
>>>> you cannot, for example, specify 128-bit integer constants in
>>>> C directly.
>>>
>>> But you can use it to implement intermediate-size integers, like 512-bit
>>> RSA variables by accessing the hi/lo parts to chain them together?
>>
>> Sure.
>>
>>> I.e. use them to add two 64-bit values and get the carry alongside the sum?
>>
>> You could use __builtin_add_overflow for that, instead:
>>
>> int main()
>> {
>> int n1, n2;
>> __uint128_t a, b, res;
>> scanf ("%d %d", &n1, &n2);
>> a = ((__uint128_t) 1) << n1;
>> b = ((__uint128_t) 1) << n2;
>> if (__builtin_add_overflow (a, b, &res))
>> printf ("Overflow!\n");
>> else
>> printf ("No overflow!\n");
>> return 0;
>> }
>>
>> and then chain this further. However, if your hardware does
>> not support 128-bit integers natively, you are probably better
>> off using 64-bit words and use the carry that way. There
>> is no particular advantage to using 128-bit types, and
>> at least gcc has some issues with register allocation for
>> those types.
>>
>> The best way would probably be to use 64-bit unsigned ints,
>> and then to do
>>
>> int c_old; c_new;
>> c_old = 0;
>> for (i=0; i<n; i++) {
>> c_new = __builtin_add_overflow (a[i], b[i], res+i);
>> res[i] += c_old;
>
> That does not work:
>
> You have to also handle the case where res[i] += c_old causes a new carry!

How?

(Assuming 8-bit to save on some typing)

If a[i] and b[i] are both 0xff, the maximum sum is 0x1fe. Then,
c_new is 1, res is 0xfe, and adding c_old, which has a maximum of 1,
can go to 0xff as a maximum.

Or am I missing something?

Re: Compact representation for common integer constants

<s8q3te$2lh$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17233&group=comp.arch#17233

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 06:51:26 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8q3te$2lh$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de>
<s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de>
Injection-Date: Fri, 28 May 2021 06:51:26 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:501b:0:7285:c2ff:fe6c:992d";
logging-data="2737"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 28 May 2021 06:51 UTC

Thomas Koenig <tkoenig@netcologne.de> schrieb:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>> Thomas Koenig wrote:
>>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>>> Thomas Koenig wrote:
>>>>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>>>>
>>>>>> I.e. 128-bit unsigned add
>>>>>>
>>>>>> u8 carry;
>>>>>> carry = _addcarryx_u64(alo, blo, &sumlo);
>>>>>> _addcarryx_u64(ahi, bhi, &sumhi);
>>>>>>
>>>>>> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
>>>>>> for b and the return back in RDX:RAX):
>>>>>>
>>>>>> add rax,rbx
>>>>>> adc rdx,rcx
>>>>>
>>>>> With gcc (and clang), this is not needed, there a __int128_t
>>>>> and a __uint128_t type. It is rather poorly supported, though;
>>>>> you cannot, for example, specify 128-bit integer constants in
>>>>> C directly.
>>>>
>>>> But you can use it to implement intermediate-size integers, like 512-bit
>>>> RSA variables by accessing the hi/lo parts to chain them together?
>>>
>>> Sure.
>>>
>>>> I.e. use them to add two 64-bit values and get the carry alongside the sum?
>>>
>>> You could use __builtin_add_overflow for that, instead:
>>>
>>> int main()
>>> {
>>> int n1, n2;
>>> __uint128_t a, b, res;
>>> scanf ("%d %d", &n1, &n2);
>>> a = ((__uint128_t) 1) << n1;
>>> b = ((__uint128_t) 1) << n2;
>>> if (__builtin_add_overflow (a, b, &res))
>>> printf ("Overflow!\n");
>>> else
>>> printf ("No overflow!\n");
>>> return 0;
>>> }
>>>
>>> and then chain this further. However, if your hardware does
>>> not support 128-bit integers natively, you are probably better
>>> off using 64-bit words and use the carry that way. There
>>> is no particular advantage to using 128-bit types, and
>>> at least gcc has some issues with register allocation for
>>> those types.
>>>
>>> The best way would probably be to use 64-bit unsigned ints,
>>> and then to do
>>>
>>> int c_old; c_new;
>>> c_old = 0;
>>> for (i=0; i<n; i++) {
>>> c_new = __builtin_add_overflow (a[i], b[i], res+i);
>>> res[i] += c_old;
>>
>> That does not work:
>>
>> You have to also handle the case where res[i] += c_old causes a new carry!
>
> How?
>
> (Assuming 8-bit to save on some typing)
>
> If a[i] and b[i] are both 0xff, the maximum sum is 0x1fe. Then,
> c_new is 1, res is 0xfe, and adding c_old, which has a maximum of 1,
> can go to 0xff as a maximum.
>
> Or am I missing something?

Never mind, I found my error myself :-)

Re: Compact representation for common integer constants

<s8q6n5$1hv5$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17234&group=comp.arch#17234

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!/FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 09:39:16 +0200
Organization: Aioe.org NNTP Server
Lines: 105
Message-ID: <s8q6n5$1hv5$1@gioia.aioe.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de>
<s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de>
NNTP-Posting-Host: /FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Fri, 28 May 2021 07:39 UTC

Thomas Koenig wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>> Thomas Koenig wrote:
>>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>>> Thomas Koenig wrote:
>>>>> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>>>>>
>>>>>> I.e. 128-bit unsigned add
>>>>>>
>>>>>> u8 carry;
>>>>>> carry = _addcarryx_u64(alo, blo, &sumlo);
>>>>>> _addcarryx_u64(ahi, bhi, &sumhi);
>>>>>>
>>>>>> will compile into something like this (assuming RDX:RAX for a, RCX:RBX
>>>>>> for b and the return back in RDX:RAX):
>>>>>>
>>>>>> add rax,rbx
>>>>>> adc rdx,rcx
>>>>>
>>>>> With gcc (and clang), this is not needed, there a __int128_t
>>>>> and a __uint128_t type. It is rather poorly supported, though;
>>>>> you cannot, for example, specify 128-bit integer constants in
>>>>> C directly.
>>>>
>>>> But you can use it to implement intermediate-size integers, like 512-bit
>>>> RSA variables by accessing the hi/lo parts to chain them together?
>>>
>>> Sure.
>>>
>>>> I.e. use them to add two 64-bit values and get the carry alongside the sum?
>>>
>>> You could use __builtin_add_overflow for that, instead:
>>>
>>> int main()
>>> {
>>> int n1, n2;
>>> __uint128_t a, b, res;
>>> scanf ("%d %d", &n1, &n2);
>>> a = ((__uint128_t) 1) << n1;
>>> b = ((__uint128_t) 1) << n2;
>>> if (__builtin_add_overflow (a, b, &res))
>>> printf ("Overflow!\n");
>>> else
>>> printf ("No overflow!\n");
>>> return 0;
>>> }
>>>
>>> and then chain this further. However, if your hardware does
>>> not support 128-bit integers natively, you are probably better
>>> off using 64-bit words and use the carry that way. There
>>> is no particular advantage to using 128-bit types, and
>>> at least gcc has some issues with register allocation for
>>> those types.
>>>
>>> The best way would probably be to use 64-bit unsigned ints,
>>> and then to do
>>>
>>> int c_old; c_new;
>>> c_old = 0;
>>> for (i=0; i<n; i++) {
>>> c_new = __builtin_add_overflow (a[i], b[i], res+i);
>>> res[i] += c_old;
>>
>> That does not work:
>>
>> You have to also handle the case where res[i] += c_old causes a new carry!
>
> How?
>
> (Assuming 8-bit to save on some typing)
>
> If a[i] and b[i] are both 0xff, the maximum sum is 0x1fe. Then,
> c_new is 1, res is 0xfe, and adding c_old, which has a maximum of 1,
> can go to 0xff as a maximum.
>
> Or am I missing something?
>
Yes:

Assume a[i] = 0x80, b[i] = 0x7f, and res[i] becomes 0xff. Adding c_old
(== 1) increments this to 0x100, so c_new must be set.

I.e. there really isn't a good way to do full 3-in 2-out adders without
having an actual full adder available. :-(

I see you already figured this out, but I'm still posting to illustrate
that it is hard to do long chain carry propagation without having the
moral equivalent of ADC.

Itanium tried to avoid it by having both ADD and ADD1, which differs
only in the setting of the incoming carry bit to the adder, but requires
you to execute both of them and select the correct result based on the
incoming carry, using eitehr predicates or a pick() operation.

This is effectively the same as a fast HW adder where you duplicate some
effort in order to get the final result fast enough to not impact your
cycle time. Splitting a 64-bit add into 3 32-bit adds gives you 50%
overhead, splitting each of these into 3 16-bit adds increase the
overhead to 125%.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<2021May28.101226@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17235&group=comp.arch#17235

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 08:12:26 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 31
Distribution: world
Message-ID: <2021May28.101226@mips.complang.tuwien.ac.at>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <s8lqsr$aru$1@dont-email.me> <88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me> <s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de> <s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de> <s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de>
Injection-Info: reader02.eternal-september.org; posting-host="24fbea3b8cd41d70d07da302a4c7b344";
logging-data="25278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fkzXxGrTMf5O+8KGbMrow"
Cancel-Lock: sha1:i0hMdIQT1uYnd1ACmxcef+0ZhYs=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Fri, 28 May 2021 08:12 UTC

Thomas Koenig <tkoenig@netcologne.de> writes:
>Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>> Thomas Koenig wrote:
>>> int c_old; c_new;
>>> c_old = 0;
>>> for (i=0; i<n; i++) {
>>> c_new = __builtin_add_overflow (a[i], b[i], res+i);
>>> res[i] += c_old;
>>
>> That does not work:
>>
>> You have to also handle the case where res[i] += c_old causes a new carry!
>
>How?
>
>(Assuming 8-bit to save on some typing)
>
>If a[i] and b[i] are both 0xff, the maximum sum is 0x1fe. Then,
>c_new is 1, res is 0xfe, and adding c_old, which has a maximum of 1,
>can go to 0xff as a maximum.
>
>Or am I missing something?

You found it yourself, but just so that others don't have to search,
the problem is when a[i]+b[i] is 0xff, and c_old is 1. Then c_new is
0, but should be 1.

- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>

Re: Compact representation for common integer constants

<s8r2ln$hrv$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17238&group=comp.arch#17238

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 15:36:23 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8r2ln$hrv$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s80rjn$1ci$2@newsreader4.netcologne.de>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de>
<s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de>
<s8q6n5$1hv5$1@gioia.aioe.org>
Injection-Date: Fri, 28 May 2021 15:36:23 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:501b:0:7285:c2ff:fe6c:992d";
logging-data="18303"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 28 May 2021 15:36 UTC

Terje Mathisen <terje.mathisen@tmsw.no> schrieb:

> I see you already figured this out, but I'm still posting to illustrate
> that it is hard to do long chain carry propagation without having the
> moral equivalent of ADC.

I just browsed around a bit, and I found that, on x86 at least, you
can use _addcarryx_u64.

clang gets this right: https://gcc.godbolt.org/z/b9dTn8aWj
whereas gcc currently does not, as you can see in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79173 .

Re: Compact representation for common integer constants

<2021May28.165948@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17239&group=comp.arch#17239

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 14:59:48 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 88
Distribution: world
Message-ID: <2021May28.165948@mips.complang.tuwien.ac.at>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me> <26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me> <88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me> <2021May27.113439@mips.complang.tuwien.ac.at> <s8ojhh$4b1$2@newsreader4.netcologne.de>
Injection-Info: reader02.eternal-september.org; posting-host="24fbea3b8cd41d70d07da302a4c7b344";
logging-data="22117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QpQz8fxIlDzYPuKIdSge8"
Cancel-Lock: sha1:3OjrTzYiue/2qfV4mkz/6eNiofw=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Fri, 28 May 2021 14:59 UTC

Thomas Koenig <tkoenig@netcologne.de> writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb:
>
>> Gcc has had -freg-struct-return for at least 30 years, but it's
>> incompatible with the way PCC returned structs, so you cannot link
>> code that uses reg-struct-return with code that uses pcc-struct-return
>> if there is such a return between code using different conventions.
>
>The Itanium ABI fixed that.
>
>Rather than quote chapter and verse, here is a short example:
>
>$ cat ret.c
>typedef struct foo
>{
> int a;
> int b;
>} foo;
>
>foo bar()
>{
> return ((foo){.a = 42, .b=21});
>}

produces
....
> movabsq $90194313258, %rax
> ret

Does not look like IA-64 code to me. But I guess that like IA-64, AMD64
profitted from not having had a PCC port. It's interesting that the
struct is returned in a single register and has to be picked apart by
the caller.

For comparison, here's the same code for IA-32:

00000000 <bar>:
0: 8b 44 24 04 mov 0x4(%esp),%eax
4: c7 00 2a 00 00 00 movl $0x2a,(%eax)
a: c7 40 04 15 00 00 00 movl $0x15,0x4(%eax)
11: c2 04 00 ret $0x4

Aarch64:
0 000000000000000 <bar>:
0: d2800540 mov x0, #0x2a // #42
4: f2c002a0 movk x0, #0x15, lsl #32
8: d65f03c0 ret

ARM gnueabi:

....
bar:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
ldr r2, .L3
mov r3, r0
..LPIC0:
add r2, pc, r2
ldm r2, {r0, r1}
stm r3, {r0, r1}
mov r0, r3
bx lr
..L4:
.align 2
..L3:
.word .LANCHOR0-(.LPIC0+8)
.size bar, .-bar
.section .rodata
.align 2
.set .LANCHOR0,. + 0
..LC0:
.word 42
.word 21

Even with the PCC struct-return, this could be made much shorter.
It's also interesting that with all the different ABIs for ARM (and
this one even being called gnueabi), they kept PCC struct-return even
for the newer ones.

Overall, the older architectures use PCC struct-return, the newer ones
return small structs in registers.

- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>

Re: Compact representation for common integer constants

<s8r75a$jj8$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17240&group=comp.arch#17240

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 16:52:58 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8r75a$jj8$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <2021May27.113439@mips.complang.tuwien.ac.at>
<s8ojhh$4b1$2@newsreader4.netcologne.de>
<2021May28.165948@mips.complang.tuwien.ac.at>
Injection-Date: Fri, 28 May 2021 16:52:58 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-501b-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:501b:0:7285:c2ff:fe6c:992d";
logging-data="20072"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 28 May 2021 16:52 UTC

Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb:
> Thomas Koenig <tkoenig@netcologne.de> writes:
>>Anton Ertl <anton@mips.complang.tuwien.ac.at> schrieb:
>>
>>> Gcc has had -freg-struct-return for at least 30 years, but it's
>>> incompatible with the way PCC returned structs, so you cannot link
>>> code that uses reg-struct-return with code that uses pcc-struct-return
>>> if there is such a return between code using different conventions.
>>
>>The Itanium ABI fixed that.
>>
>>Rather than quote chapter and verse, here is a short example:
>>
>>$ cat ret.c
>>typedef struct foo
>>{
>> int a;
>> int b;
>>} foo;
>>
>>foo bar()
>>{
>> return ((foo){.a = 42, .b=21});
>>}
>
> produces
> ...
>> movabsq $90194313258, %rax
>> ret
>
> Does not look like IA-64 code to me.

Sorry for the jargon.

The official document is named the

System V Application Binary Interface
AMD64 Architecture Processor Supplement

which you can google for. The ABI especially for C++
was taken from the Itanium ABI, which you can find at
https://itanium-cxx-abi.github.io/cxx-abi/ , so people refer to the
whole thing as the "Itanium ABI" although that is not 100% correct.

Re: Compact representation for common integer constants

<s8riid$vba$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17241&group=comp.arch#17241

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!/FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 22:07:42 +0200
Organization: Aioe.org NNTP Server
Lines: 24
Message-ID: <s8riid$vba$1@gioia.aioe.org>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May19.124934@mips.complang.tuwien.ac.at>
<d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de>
<s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de>
<s8q6n5$1hv5$1@gioia.aioe.org> <s8r2ln$hrv$1@newsreader4.netcologne.de>
NNTP-Posting-Host: /FKOcGQMirZgkZJCo9x3IA.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Fri, 28 May 2021 20:07 UTC

Thomas Koenig wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>
>> I see you already figured this out, but I'm still posting to illustrate
>> that it is hard to do long chain carry propagation without having the
>> moral equivalent of ADC.
>
> I just browsed around a bit, and I found that, on x86 at least, you
> can use _addcarryx_u64.

Right, this was the intrinsic I used for both of my 128 and 256-bit
examples.
>
> clang gets this right: https://gcc.godbolt.org/z/b9dTn8aWj
> whereas gcc currently does not, as you can see in
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79173 .
>
clang is very swiftly leaving gcc well behind for all new development.

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<fb4441b4-bc4a-4382-a137-92eb2c1b2504n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17242&group=comp.arch#17242

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:6214:2526:: with SMTP id gg6mr4301931qvb.42.1622234933207; Fri, 28 May 2021 13:48:53 -0700 (PDT)
X-Received: by 2002:a05:6820:611:: with SMTP id e17mr8605620oow.0.1622234932972; Fri, 28 May 2021 13:48:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Fri, 28 May 2021 13:48:52 -0700 (PDT)
In-Reply-To: <s8riid$vba$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:e55b:38d5:82c0:8039; posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:e55b:38d5:82c0:8039
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com> <nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me> <igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me> <51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me> <26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me> <88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me> <s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de> <s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de> <s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de> <s8q6n5$1hv5$1@gioia.aioe.org> <s8r2ln$hrv$1@newsreader4.netcologne.de> <s8riid$vba$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fb4441b4-bc4a-4382-a137-92eb2c1b2504n@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Fri, 28 May 2021 20:48:53 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 28
 by: MitchAlsup - Fri, 28 May 2021 20:48 UTC

On Friday, May 28, 2021 at 3:07:47 PM UTC-5, Terje Mathisen wrote:
> Thomas Koenig wrote:
> > Terje Mathisen <terje.m...@tmsw.no> schrieb:
> >
> >> I see you already figured this out, but I'm still posting to illustrate
> >> that it is hard to do long chain carry propagation without having the
> >> moral equivalent of ADC.
> >
> > I just browsed around a bit, and I found that, on x86 at least, you
> > can use _addcarryx_u64.
> Right, this was the intrinsic I used for both of my 128 and 256-bit
> examples.
> >
> > clang gets this right: https://gcc.godbolt.org/z/b9dTn8aWj
> > whereas gcc currently does not, as you can see in
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79173 .
> >
> clang is very swiftly leaving gcc well behind for all new development.
<
Is that because GCC has grown into an impossible monster,
.....that because GCC licensing requirements
or that more people have jumped onto clang
.....that clang is easier to develop ??
<
> Terje
>
> --
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"

Re: Compact representation for common integer constants

<s8rnou$sh5$1@newsreader4.netcologne.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17244&group=comp.arch#17244

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2a0a-a540-1ba0-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Fri, 28 May 2021 21:36:30 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8rnou$sh5$1@newsreader4.netcologne.de>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com>
<s864if$mqg$1@dont-email.me> <q1UpI.60399$DZ5.42895@fx23.iad>
<s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com>
<s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com>
<s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org>
<s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me>
<s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de>
<s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de>
<s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de>
<s8q6n5$1hv5$1@gioia.aioe.org> <s8r2ln$hrv$1@newsreader4.netcologne.de>
<s8riid$vba$1@gioia.aioe.org>
<fb4441b4-bc4a-4382-a137-92eb2c1b2504n@googlegroups.com>
Injection-Date: Fri, 28 May 2021 21:36:30 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2a0a-a540-1ba0-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2a0a:a540:1ba0:0:7285:c2ff:fe6c:992d";
logging-data="29221"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 28 May 2021 21:36 UTC

MitchAlsup <MitchAlsup@aol.com> schrieb:
> On Friday, May 28, 2021 at 3:07:47 PM UTC-5, Terje Mathisen wrote:
>> Thomas Koenig wrote:
>> > Terje Mathisen <terje.m...@tmsw.no> schrieb:
>> >
>> >> I see you already figured this out, but I'm still posting to illustrate
>> >> that it is hard to do long chain carry propagation without having the
>> >> moral equivalent of ADC.
>> >
>> > I just browsed around a bit, and I found that, on x86 at least, you
>> > can use _addcarryx_u64.
>> Right, this was the intrinsic I used for both of my 128 and 256-bit
>> examples.
>> >
>> > clang gets this right: https://gcc.godbolt.org/z/b9dTn8aWj
>> > whereas gcc currently does not, as you can see in
>> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79173 .
>> >
>> clang is very swiftly leaving gcc well behind for all new development.
><
> Is that because GCC has grown into an impossible monster,
> ....that because GCC licensing requirements

Partly. Clang seems to have a lot of big companies behind it,
companies like Google and Apple.

However, don't count out gcc yet. It just so happens that people
take more note when clang outperforms gcc than the other way around.

And I'm still waiting for their version of a working Fortran
compiler, despite the big bucks going into it. Writing a scalarizer
_is_ hard, I have to say that in their defense.

Re: Compact representation for common integer constants

<2021May29.164810@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17247&group=comp.arch#17247

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Sat, 29 May 2021 14:48:10 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 79
Message-ID: <2021May29.164810@mips.complang.tuwien.ac.at>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me> <s8ne5m$g8d$1@dont-email.me> <s8nqlb$160s$1@gioia.aioe.org> <s8nt68$ond$1@newsreader4.netcologne.de> <s8o945$62e$1@gioia.aioe.org> <s8oj0e$4b1$1@newsreader4.netcologne.de> <s8oudj$frs$1@gioia.aioe.org> <s8q19m$1ar$1@newsreader4.netcologne.de> <s8q6n5$1hv5$1@gioia.aioe.org> <s8r2ln$hrv$1@newsreader4.netcologne.de> <s8riid$vba$1@gioia.aioe.org>
Injection-Info: reader02.eternal-september.org; posting-host="ca7182227178d9a3349e5923eb9d036e";
logging-data="32129"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Md1KIksk+T/whyMMH2CDU"
Cancel-Lock: sha1:l6uAlOSxz4GOssSpiPF3Gij5og4=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sat, 29 May 2021 14:48 UTC

Terje Mathisen <terje.mathisen@tmsw.no> writes:
>Thomas Koenig wrote:
>> I just browsed around a bit, and I found that, on x86 at least, you
>> can use _addcarryx_u64.

If you want to be compiler-dependent instead of
architecture-and-compiler-dependent, there is also

https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html

>clang is very swiftly leaving gcc well behind for all new development.

For our not-so-new development, clang is swiftly leaving gcc behind in
compilation slowness. Building the latest Gforth snapshot on a Ryzen
5800X, I see

gcc10 clang11
./configure ./configure CC=clang
real 18.114s 22.961s
user 5.863s 9.329s
sys 1.858s 3.668s

make -j make -j
real 11.930s 33m22.542s
user 53.876s 143m45.884s
sys 3.110s 22.699s

While gcc tends to compile slower over the releases, I think it will
take many releases to catch up with clang in this metric.

The run time of the clang-produced code tends to be long, too:

Time in seconds user time
sieve bubble matrix fib fft
0.056 0.055 0.034 0.047 0.021 Ryzen 5800X gcc-10
1.100 0.933 0.970 1.265 0.560 Ryzen 5800X clang-11

I looked at the generated code, and for a primitive like + which can
be done in 4 instructions and which gcc-10 does in 5 instructions:

563FB2DED3BF: add r13,$08
563FB2DED3C3: add r15,$08
563FB2DED3C7: add r8,$00[r13]
563FB2DED3CB: mov rcx,-$08[r15]
563FB2DED3CF: jmp ecx

clang-11 produces 183 instructions for +. This reminds me of a
problem that gcc had in gcc-3.0 and 3.1, and which they fixed
subsequently.

- anton

>
>Terje
>
>--
>- <Terje.Mathisen at tmsw.no>
>"almost all programming can be viewed as an exercise in caching"

--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>

Re: Compact representation for common integer constants

<2021May29.184428@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17252&group=comp.arch#17252

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Compact representation for common integer constants
Date: Sat, 29 May 2021 16:44:28 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 16
Distribution: world
Message-ID: <2021May29.184428@mips.complang.tuwien.ac.at>
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com> <s89ahe$t4n$1@dont-email.me> <26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me> <88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me> <s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me> <2021May27.113439@mips.complang.tuwien.ac.at> <s8ojhh$4b1$2@newsreader4.netcologne.de> <2021May28.165948@mips.complang.tuwien.ac.at> <s8r75a$jj8$1@newsreader4.netcologne.de>
Injection-Info: reader02.eternal-september.org; posting-host="ca7182227178d9a3349e5923eb9d036e";
logging-data="21833"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OZ4poFdnrpXnegFeIxWMd"
Cancel-Lock: sha1:pS/+edEdAkZV02WrxMjpu+RIeVs=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sat, 29 May 2021 16:44 UTC

Thomas Koenig <tkoenig@netcologne.de> writes:
>The ABI especially for C++
>was taken from the Itanium ABI, which you can find at
>https://itanium-cxx-abi.github.io/cxx-abi/ , so people refer to the
>whole thing as the "Itanium ABI" although that is not 100% correct.

Thanks. I am not into C++, so I have never heard about "Itanium ABI"
before. A quick skim did not reveal anything about struct returns.
It looks to me like this C++ ABI is based on the regular ABI (C and
Fortran features), and defines various C++ things in terms of that,
and that's why it can transcend individual architectures.

- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>

Re: Compact representation for common integer constants

<25fadf1d-bf66-4966-bdf9-b8b39b9abfebn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17253&group=comp.arch#17253

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a37:4484:: with SMTP id r126mr9289946qka.18.1622310763704;
Sat, 29 May 2021 10:52:43 -0700 (PDT)
X-Received: by 2002:aca:1b15:: with SMTP id b21mr13034829oib.155.1622310763425;
Sat, 29 May 2021 10:52:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sat, 29 May 2021 10:52:43 -0700 (PDT)
In-Reply-To: <s8riid$vba$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=87.68.183.172; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 87.68.183.172
References: <44003c05-8b05-4e0e-acb8-bb252be14d26n@googlegroups.com>
<2021May19.124934@mips.complang.tuwien.ac.at> <d5edb86e-0166-4c44-83eb-19e1cd8eb2c4n@googlegroups.com>
<nqapI.385883$2A5.264183@fx45.iad> <s84b5i$mal$1@dont-email.me>
<igmeioFr49pU1@mid.individual.net> <s85u1e$2nb$1@dont-email.me>
<51fddd24-666f-4914-9161-30e010e0ef92n@googlegroups.com> <s864if$mqg$1@dont-email.me>
<q1UpI.60399$DZ5.42895@fx23.iad> <s89ahe$t4n$1@dont-email.me>
<26c0c173-a5b3-4852-8bb9-914ad7252f05n@googlegroups.com> <s8lqsr$aru$1@dont-email.me>
<88b2b9c9-2b2f-4c61-abe7-d11dbfbe6fe2n@googlegroups.com> <s8m1ke$u2m$1@dont-email.me>
<s8nc3e$pi7$1@gioia.aioe.org> <s8nd5j$bas$1@dont-email.me>
<s8ne5m$g8d$1@dont-email.me> <s8nqlb$160s$1@gioia.aioe.org>
<s8nt68$ond$1@newsreader4.netcologne.de> <s8o945$62e$1@gioia.aioe.org>
<s8oj0e$4b1$1@newsreader4.netcologne.de> <s8oudj$frs$1@gioia.aioe.org>
<s8q19m$1ar$1@newsreader4.netcologne.de> <s8q6n5$1hv5$1@gioia.aioe.org>
<s8r2ln$hrv$1@newsreader4.netcologne.de> <s8riid$vba$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <25fadf1d-bf66-4966-bdf9-b8b39b9abfebn@googlegroups.com>
Subject: Re: Compact representation for common integer constants
From: already5...@yahoo.com (Michael S)
Injection-Date: Sat, 29 May 2021 17:52:43 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Michael S - Sat, 29 May 2021 17:52 UTC

On Friday, May 28, 2021 at 11:07:47 PM UTC+3, Terje Mathisen wrote:
> Thomas Koenig wrote:
> > Terje Mathisen <terje.m...@tmsw.no> schrieb:
> >
> >> I see you already figured this out, but I'm still posting to illustrate
> >> that it is hard to do long chain carry propagation without having the
> >> moral equivalent of ADC.
> >
> > I just browsed around a bit, and I found that, on x86 at least, you
> > can use _addcarryx_u64.
> Right, this was the intrinsic I used for both of my 128 and 256-bit
> examples.
> >
> > clang gets this right: https://gcc.godbolt.org/z/b9dTn8aWj
> > whereas gcc currently does not, as you can see in
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79173 .
> >
> clang is very swiftly leaving gcc well behind for all new development.
> Terje
>

That is not what I observed when comparing that state of AVX2 vectorizers in clang10 vs gcc10.
gcc is sometimes o.k., sometimes bad and relatively rarely idiotic. clang is quite often idiotic.
And in gcc, when you see that vectorizer went idiotic, all you need to do is to compile with -O2, which produces solid scalar code.
In clang, to get the same effect, you have to use specialist's flag -fno-vectorize or something like that. I don't think that majority of devs, esp scientists, even heard about its existence.

> --
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"

Pages:123456789101112131415
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor