Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The value of a program is proportional to the weight of its output.


devel / comp.arch / Re: saturating arithmetic, not Signed division by 2^n

SubjectAuthor
* Signed division by 2^nThomas Koenig
+* Re: Signed division by 2^nMarcus
|`- Re: Signed division by 2^nMitchAlsup
+- Re: Signed division by 2^nStephen Fuld
+* Re: Signed division by 2^nAnton Ertl
|+* Re: Signed division by 2^nMitchAlsup
||`* Re: Signed division by 2^nThomas Koenig
|| `* Re: saturating arithmetic, not Signed division by 2^nJohn Levine
||  +- Re: saturating arithmetic, not Signed division by 2^nMitchAlsup
||  +- Re: saturating arithmetic, not Signed division by 2^nBrian G. Lucas
||  `* Re: saturating arithmetic, not Signed division by 2^nJeremy Linton
||   +* Re: saturating arithmetic, not Signed division by 2^nStefan Monnier
||   |+* Re: saturating arithmetic, not Signed division by 2^nThomas Koenig
||   ||+- Re: saturating arithmetic, not Signed division by 2^nMitchAlsup
||   ||+- Re: saturating arithmetic, not Signed division by 2^nStefan Monnier
||   ||+- Re: saturating arithmetic, not Signed division by 2^nDavid Brown
||   ||`- Re: saturating arithmetic, not Signed division by 2^nAnton Ertl
||   |`- Re: saturating arithmetic, not Signed division by 2^nIvan Godard
||   +- Re: saturating arithmetic, not Signed division by 2^nEricP
||   `* Re: saturating arithmetic, not Signed division by 2^nAnton Ertl
||    +- Re: saturating arithmetic, not Signed division by 2^nMitchAlsup
||    `* Re: saturating arithmetic, not Signed division by 2^nGeorge Neuner
||     +* Re: saturating arithmetic, not Signed division by 2^nNiklas Holsti
||     |`- Re: saturating arithmetic, not Signed division by 2^nBill Findlay
||     +* Re: saturating arithmetic, not Signed division by 2^nBill Findlay
||     |`- Re: saturating arithmetic, not Signed division by 2^nTerje Mathisen
||     +* Re: saturating arithmetic, not Signed division by 2^nTerje Mathisen
||     |`* Re: saturating arithmetic, not Signed division by 2^nThomas Koenig
||     | `* Re: saturating arithmetic, not Signed division by 2^nTerje Mathisen
||     |  +- Re: saturating arithmetic, not Signed division by 2^nMitchAlsup
||     |  `* Re: saturating arithmetic, not Signed division by 2^nAndreas Eder
||     |   `* Re: saturating arithmetic, not Signed division by 2^nTerje Mathisen
||     |    `* Re: saturating arithmetic, not Signed division by 2^nThomas Koenig
||     |     `* Re: saturating arithmetic, not Signed division by 2^nTerje Mathisen
||     |      `* Re: saturating arithmetic, not Signed division by 2^nThomas Koenig
||     |       `- Re: saturating arithmetic, not Signed division by 2^nThomas Koenig
||     `- Re: saturating arithmetic, not Signed division by 2^nMitchAlsup
|+* Re: Signed division by 2^nBGB
||+* Re: Signed division by 2^nIvan Godard
|||+- Re: Signed division by 2^nAnton Ertl
|||+- Re: Signed division by 2^nTerje Mathisen
|||+- Re: Signed division by 2^nMitchAlsup
|||`* Re: Signed division by 2^nBGB
||| `* Re: Signed division by 2^nMitchAlsup
|||  `* Re: Signed division by 2^nBGB
|||   `* Re: Signed division by 2^nMitchAlsup
|||    +* More complex instructions to reduce cycle overheadStefan Monnier
|||    |+* Re: More complex instructions to reduce cycle overheadIvan Godard
|||    ||`* Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    || `- Re: More complex instructions to reduce cycle overheadIvan Godard
|||    |+* Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    ||+- Re: More complex instructions to reduce cycle overheadStefan Monnier
|||    ||`* Re: More complex instructions to reduce cycle overheadIvan Godard
|||    || `* Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    ||  `* Re: More complex instructions to reduce cycle overheadIvan Godard
|||    ||   `* Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    ||    `* Re: More complex instructions to reduce cycle overheadIvan Godard
|||    ||     +* Re: More complex instructions to reduce cycle overheadEricP
|||    ||     |+* Re: More complex instructions to reduce cycle overheadThomas Koenig
|||    ||     ||+* Re: More complex instructions to reduce cycle overheadEricP
|||    ||     |||+* Re: More complex instructions to reduce cycle overheadThomas Koenig
|||    ||     ||||`* Re: More complex instructions to reduce cycle overheadBGB
|||    ||     |||| `* Re: More complex instructions to reduce cycle overheadEricP
|||    ||     ||||  +* Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    ||     ||||  |+* Re: More complex instructions to reduce cycle overheadBGB
|||    ||     ||||  ||`* Re: More complex instructions to reduce cycle overheadMarcus
|||    ||     ||||  || `- Re: More complex instructions to reduce cycle overheadBGB
|||    ||     ||||  |`- Re: More complex instructions to reduce cycle overheadJimBrakefield
|||    ||     ||||  `* Re: More complex instructions to reduce cycle overheadBGB
|||    ||     ||||   +* Re: More complex instructions to reduce cycle overheadMarcus
|||    ||     ||||   |`* Re: More complex instructions to reduce cycle overheadBGB
|||    ||     ||||   | `* Re: More complex instructions to reduce cycle overheadEricP
|||    ||     ||||   |  `* Re: More complex instructions to reduce cycle overheadBGB
|||    ||     ||||   |   `- Re: More complex instructions to reduce cycle overheadEricP
|||    ||     ||||   `* Re: More complex instructions to reduce cycle overheadEricP
|||    ||     ||||    `* Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    ||     ||||     `* Re: More complex instructions to reduce cycle overheadBGB
|||    ||     ||||      +* Re: More complex instructions to reduce cycle overheadEricP
|||    ||     ||||      |`* Re: More complex instructions to reduce cycle overheadBGB
|||    ||     ||||      | +- Timing... (Re: More complex instructions to reduce cycle overhead)BGB
|||    ||     ||||      | `* Re: Timing... (Re: More complex instructions to reduce cycle overhead)JimBrakefield
|||    ||     ||||      |  `- Re: Timing... (Re: More complex instructions to reduce cycleBGB
|||    ||     ||||      `* Re: More complex instructions to reduce cycle overheadMarcus
|||    ||     ||||       `- Re: More complex instructions to reduce cycle overheadBGB
|||    ||     |||`* Re: More complex instructions to reduce cycle overheadpaul wallich
|||    ||     ||| `- Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    ||     ||`- Re: More complex instructions to reduce cycle overheadStefan Monnier
|||    ||     |`- Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    ||     +* Re: More complex instructions to reduce cycle overheadPaul A. Clayton
|||    ||     |`- Re: More complex instructions to reduce cycle overheadPaul A. Clayton
|||    ||     `- Re: More complex instructions to reduce cycle overheadMitchAlsup
|||    |`* Re: More complex instructions to reduce cycle overheadAnton Ertl
|||    | `- Re: More complex instructions to reduce cycle overheadTerje Mathisen
|||    `* Re: Signed division by 2^nBGB
|||     `* Re: Signed division by 2^nMitchAlsup
|||      `- Re: Signed division by 2^nBGB
||`- Re: Signed division by 2^nThomas Koenig
|`* Re: Signed division by 2^naph
| `- Re: Signed division by 2^nAnton Ertl
`- Re: Signed division by 2^nIvan Godard

Pages:1234
Re: saturating arithmetic, not Signed division by 2^n

<_RUqI.210217$sd3.37920@fx02.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx02.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: saturating arithmetic, not Signed division by 2^n
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at> <888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
In-Reply-To: <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 38
Message-ID: <_RUqI.210217$sd3.37920@fx02.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Mon, 24 May 2021 21:26:18 UTC
Date: Mon, 24 May 2021 17:26:04 -0400
X-Received-Bytes: 2710
 by: EricP - Mon, 24 May 2021 21:26 UTC

Jeremy Linton wrote:
> On 5/11/2021 3:58 PM, John Levine wrote:
>> It appears that Thomas Koenig <tkoenig@netcologne.de> said:
>>> MitchAlsup <MitchAlsup@aol.com> schrieb:
>>>
>>>> What percentage of integer {signed and unsigned} arithmetic
>>>> uses saturated semantics ?
>>> What programming language supports or demands it? I am
>>> only aware of the "unsigned wraps around, integer overflow
>>> is undefined" variety.
>> Given that many popular chips have dedicated hardware that does saturated
>> arithmetic, there must be something that uses it.
>
> Its also seems to be the cases that few C/etc programmers want overflow,
> and likely would be just as happy with saturating operations by default.
> The advantage beyond it just making more sense, is that it closes a
> whole class of security holes caused by incorrect bounds checking.
>
> This like the alias/restrict mess is something that probably should be
> corrected with something similar to "use strict" in a compilation unit
> that reverses the standard behavior unless the programmer explicitly
> asks for overflow or aliasing.

I had only heard about its use for digital signal processing.
DSP's with saturate arithmetic instructions had a competitive advantage.

The noise generated by clipping a signal is much less than wrapping around.

Apparently GCC internally supports saturate arithmetic in its
Register Transfer Language (RTL) presumably for DSP chips.

https://gcc.gnu.org/onlinedocs/gccint/Arithmetic.html

However given the number of codecs now executed on general processors
saturating arithmetic shows up there too
e.g. ARM Cortex-M4 has saturating arithmetic for 8, 16 and 32 bits.

Re: saturating arithmetic, not Signed division by 2^n

<s8h6qu$3cp$1@newsreader4.netcologne.de>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd6-3221-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Mon, 24 May 2021 21:46:06 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8h6qu$3cp$1@newsreader4.netcologne.de>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<jwvbl8zx5la.fsf-monnier+comp.arch@gnu.org>
Injection-Date: Mon, 24 May 2021 21:46:06 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd6-3221-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd6:3221:0:7285:c2ff:fe6c:992d";
logging-data="3481"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Mon, 24 May 2021 21:46 UTC

Stefan Monnier <monnier@iro.umontreal.ca> schrieb:

> I just happen to (think I) know that I use them in a way which will
> never overflow (e.g. because it's bounded by something like the number
> of heap allocated objects or the number of elements in an array).

I talked to a guy who had a massively parallel simulation going
on one of the university clusters. He burned a few million Euros
doing his simulations, too.

One of the problems he faced was that his model started failing
mysteriously on the very large problems distributed across too
many compute nodes.

The problem? He had more than 2^31 elements in his flow simulation...

So yes, this is a real problem.

> So Ideally I want the compiler to feel free to perform optimizations
> that assume things like associativity (even though those optimizations
> may cause code which previously overflowed to not overflow any more, and
> vice versa).

That, I cannot agree with. Rewriting code into something that does
not work from something that works is usually called a "compiler
bug" :-) unless it is expressively permitted by the language,
or the user was brave enough to set a flag such as -ffast-math
because of its seductive name.

Re: saturating arithmetic, not Signed division by 2^n

<0944bd1d-ff9d-4f90-a306-cca25ce5573fn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:622a:89:: with SMTP id o9mr28064804qtw.339.1621896848034; Mon, 24 May 2021 15:54:08 -0700 (PDT)
X-Received: by 2002:a4a:b3c4:: with SMTP id q4mr20048586ooo.14.1621896847813; Mon, 24 May 2021 15:54:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr2.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: Mon, 24 May 2021 15:54:07 -0700 (PDT)
In-Reply-To: <s8h6qu$3cp$1@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:ed6f:f412:a8c7:989c; posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:ed6f:f412:a8c7:989c
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at> <888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org> <jwvbl8zx5la.fsf-monnier+comp.arch@gnu.org> <s8h6qu$3cp$1@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0944bd1d-ff9d-4f90-a306-cca25ce5573fn@googlegroups.com>
Subject: Re: saturating arithmetic, not Signed division by 2^n
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Mon, 24 May 2021 22:54:08 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 29
 by: MitchAlsup - Mon, 24 May 2021 22:54 UTC

On Monday, May 24, 2021 at 4:46:08 PM UTC-5, Thomas Koenig wrote:
> Stefan Monnier <mon...@iro.umontreal.ca> schrieb:
> > I just happen to (think I) know that I use them in a way which will
> > never overflow (e.g. because it's bounded by something like the number
> > of heap allocated objects or the number of elements in an array).
> I talked to a guy who had a massively parallel simulation going
> on one of the university clusters. He burned a few million Euros
> doing his simulations, too.
>
> One of the problems he faced was that his model started failing
> mysteriously on the very large problems distributed across too
> many compute nodes.
>
> The problem? He had more than 2^31 elements in his flow simulation...
<
Why was he not using 64-bit containers ?
>
> So yes, this is a real problem.
<
For idiots......
<
> > So Ideally I want the compiler to feel free to perform optimizations
> > that assume things like associativity (even though those optimizations
> > may cause code which previously overflowed to not overflow any more, and
> > vice versa).
> That, I cannot agree with. Rewriting code into something that does
> not work from something that works is usually called a "compiler
> bug" :-) unless it is expressively permitted by the language,
> or the user was brave enough to set a flag such as -ffast-math
> because of its seductive name.

Re: saturating arithmetic, not Signed division by 2^n

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

  copy mid

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

  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: saturating arithmetic, not Signed division by 2^n
Date: Mon, 24 May 2021 21:57:53 -0400
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <jwv7djnvb0o.fsf-monnier+comp.arch@gnu.org>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<jwvbl8zx5la.fsf-monnier+comp.arch@gnu.org>
<s8h6qu$3cp$1@newsreader4.netcologne.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0b4c3ff4f4e7019f60bb0b337854c91f";
logging-data="6939"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/rdNBl7S6phVycnWByPt0"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Cancel-Lock: sha1:z6FB9ggitigtUFzpKPK0yU1WDto=
sha1:HgFf+RBmHlYsoDrOf3803CiOUto=
 by: Stefan Monnier - Tue, 25 May 2021 01:57 UTC

Thomas Koenig [2021-05-24 21:46:06] wrote:
>> I just happen to (think I) know that I use them in a way which will
>> never overflow (e.g. because it's bounded by something like the number
>> of heap allocated objects or the number of elements in an array).
[...]
> The problem? He had more than 2^31 elements in his flow simulation...

Indeed, the use of 32bit `int`s to count heap objects is a common bug in
64bit systems. If the system had crashed with an overflow error,
I think he'd have seen the problem much more quickly.

> Stefan Monnier <monnier@iro.umontreal.ca> schrieb:
>> So Ideally I want the compiler to feel free to perform optimizations
>> that assume things like associativity (even though those optimizations
>> may cause code which previously overflowed to not overflow any more, and
>> vice versa).
>
> That, I cannot agree with. Rewriting code into something that does
> not work from something that works is usually called a "compiler
> bug" :-)

FWIW, I tend to agree. Maybe we only need to allow the compiler to
remove overflow situations, and that should give the compiler a free
enough hand (e.g. to simplify `b + x - b` to `x`).

Stefan

Re: saturating arithmetic, not Signed division by 2^n

<s8hre1$d7t$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: iva...@millcomputing.com (Ivan Godard)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Mon, 24 May 2021 20:37:36 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <s8hre1$d7t$1@dont-email.me>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<jwvbl8zx5la.fsf-monnier+comp.arch@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 May 2021 03:37:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c43b97ccc3394a559b844762f996ce42";
logging-data="13565"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zvlCko5pF1oDB5C19EwGc"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.1
Cancel-Lock: sha1:Fzp0aqstdFBy4kCQal9JMCg2Z0Y=
In-Reply-To: <jwvbl8zx5la.fsf-monnier+comp.arch@gnu.org>
Content-Language: en-US
 by: Ivan Godard - Tue, 25 May 2021 03:37 UTC

On 5/24/2021 1:14 PM, Stefan Monnier wrote:
>> Its also seems to be the cases that few C/etc programmers want overflow,
>> and likely would be just as happy with saturating operations by default.
>
> In my case, the vast majority of uses of something like `int` is for
> numbers which should be treated as belonging to mathematical set of
> integers (aka Z).
>
> I just happen to (think I) know that I use them in a way which will
> never overflow (e.g. because it's bounded by something like the number
> of heap allocated objects or the number of elements in an array).
>
> So Ideally I want the compiler to feel free to perform optimizations
> that assume things like associativity (even though those optimizations
> may cause code which previously overflowed to not overflow any more, and
> vice versa). But I'd also like to know if my assumptions were wrong
> (aka when `int` failed to model the set Z), so I'd like the code to
> check for overflows and coredump when it happens. It doesn't have to
> coredump exactly when the operation takes place in the code, but it
> should coredump some time between the moment the offending operation
> took place and the next externally-visible effect.
>
>
> Stefan
>

That's exactly Mill semantics for excepting operations: an exception
sets the NaR bit on the result, whose payload holds debug info to locate
the op that threw. Only later, when the NaR is used in something
visible, do you get a hardware fault and core dump or whatever you have
the OS give you.

This lets you speculatively execute potentially excepting ops without
problems if the speculations was untaken.

Re: saturating arithmetic, not Signed division by 2^n

<s8i03v$1s3$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 06:57:35 +0200
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <s8i03v$1s3$1@dont-email.me>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<jwvbl8zx5la.fsf-monnier+comp.arch@gnu.org>
<s8h6qu$3cp$1@newsreader4.netcologne.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 May 2021 04:57:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3f8f36b7fe84570d50a8a1b32037432f";
logging-data="1923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184Y+vDFekuq4ljwtWcYsCzB1BUIyu/3P4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:L7N5zIxHn0uXZ07da3MuzlohSsU=
In-Reply-To: <s8h6qu$3cp$1@newsreader4.netcologne.de>
Content-Language: en-GB
 by: David Brown - Tue, 25 May 2021 04:57 UTC

On 24/05/2021 23:46, Thomas Koenig wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> schrieb:
>
>> I just happen to (think I) know that I use them in a way which will
>> never overflow (e.g. because it's bounded by something like the number
>> of heap allocated objects or the number of elements in an array).
>
> I talked to a guy who had a massively parallel simulation going
> on one of the university clusters. He burned a few million Euros
> doing his simulations, too.
>
> One of the problems he faced was that his model started failing
> mysteriously on the very large problems distributed across too
> many compute nodes.
>
> The problem? He had more than 2^31 elements in his flow simulation...
>
> So yes, this is a real problem.

The problem isn't the overflow handling - it is that he used a type that
was too small for the values it needed to handle. Any kind of overflow
handling (UB, saturation, wrapping, etc.) would also result in the
program not doing what it was supposed to do. Some kind of trapping on
overflow would still not have let the program work - but it would have
made it faster to find the problem.

>
>> So Ideally I want the compiler to feel free to perform optimizations
>> that assume things like associativity (even though those optimizations
>> may cause code which previously overflowed to not overflow any more, and
>> vice versa).
>
> That, I cannot agree with. Rewriting code into something that does
> not work from something that works is usually called a "compiler
> bug" :-) unless it is expressively permitted by the language,
> or the user was brave enough to set a flag such as -ffast-math
> because of its seductive name.
>

I think it is fine for the compiler to perform optimisations that assume
associativity and which cause code which would overflow in a different
integer model to work without overflow. That's the integer model I like
for normal use. But the "vice versa" part needs more care - it's okay
if the compiler introduces new overflows as long as the results are
correct in the end. (So "z = x - y" can be implemented as "u = 2^n - y;
z = x + u;" as long as the overflow of 2^n does not affect the end result.)

I use "-ffast-math" in my floating point code, but I have checked the
flags it sets and effects it has, and know it is safe for the kind of
floating point I handle. I don't think that counts as "brave". Simply
enabling it because it sounds like it makes your maths go faster is
fool-hardy, rather than brave.

Re: saturating arithmetic, not Signed division by 2^n

<2021May25.083819@mips.complang.tuwien.ac.at>

  copy mid

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

  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: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 06:38:19 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 17
Distribution: world
Message-ID: <2021May25.083819@mips.complang.tuwien.ac.at>
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at> <888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org> <jwvbl8zx5la.fsf-monnier+comp.arch@gnu.org> <s8h6qu$3cp$1@newsreader4.netcologne.de>
Injection-Info: reader02.eternal-september.org; posting-host="7775b0cecc2fbbc421d3f061b8ebcf87";
logging-data="20009"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lIeLGsqZW+1SYMASwn2wa"
Cancel-Lock: sha1:FQazuQkhgWbNdoDrrDB8m3CcjIE=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Tue, 25 May 2021 06:38 UTC

Thomas Koenig <tkoenig@netcologne.de> writes:
>One of the problems he faced was that his model started failing
>mysteriously on the very large problems distributed across too
>many compute nodes.
>
>The problem? He had more than 2^31 elements in his flow simulation...

Sounds like what I predicted in 2001 <9jruht$2nb$1@news.tuwien.ac.at>
about I32LP64:

|And many of these bugs will
|surface in the next years, as arrays grow beyond 2G elements.

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

Re: saturating arithmetic, not Signed division by 2^n

<2021May25.175943@mips.complang.tuwien.ac.at>

  copy mid

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

  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: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 15:59:43 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 34
Message-ID: <2021May25.175943@mips.complang.tuwien.ac.at>
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at> <888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
Injection-Info: reader02.eternal-september.org; posting-host="7775b0cecc2fbbc421d3f061b8ebcf87";
logging-data="2918"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+em5YUtb3qh90MxYrcW1Z0"
Cancel-Lock: sha1:LF6NbvGXvmBN5XFtii9J3hAwUCk=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Tue, 25 May 2021 15:59 UTC

Jeremy Linton <reply-to-list@nospam.org> writes:
>Its also seems to be the cases that few C/etc programmers want overflow,
>and likely would be just as happy with saturating operations by default.

Language like "want overflow" is a sign of muddled thinking. What is
it that you think few programmers want?

* Defined behaviour on overflow? If so, which one?
* Modulo (wraparound) arithmetic
* Trap-on-overflow
* saturating arithmetic
* something else?

* Undefined behaviour on overflow?

* Or do you mean that few c programmers intend overflow to happen?

* Or maybe you think that few C programmers want to think about overflow?

And once you have defined what you mean, on what basis do you make
your claim?

>The advantage beyond it just making more sense, is that it closes a
>whole class of security holes caused by incorrect bounds checking.

Saturation is useful for signal processing, but elsewhere?

If programmers don't want to think about overflow, trapping is usually
more useful for waking them up.

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

Re: saturating arithmetic, not Signed division by 2^n

<8c15cefb-95ba-4cc9-bdfd-c0d707b23708n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:58cc:: with SMTP id u12mr33860421qta.302.1621965049915;
Tue, 25 May 2021 10:50:49 -0700 (PDT)
X-Received: by 2002:aca:ed41:: with SMTP id l62mr3728362oih.175.1621965049663;
Tue, 25 May 2021 10:50:49 -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: Tue, 25 May 2021 10:50:49 -0700 (PDT)
In-Reply-To: <2021May25.175943@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:34d5:dcbf:8bd2:1b38;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:34d5:dcbf:8bd2:1b38
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de>
<s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8c15cefb-95ba-4cc9-bdfd-c0d707b23708n@googlegroups.com>
Subject: Re: saturating arithmetic, not Signed division by 2^n
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Tue, 25 May 2021 17:50:49 +0000
Content-Type: text/plain; charset="UTF-8"
 by: MitchAlsup - Tue, 25 May 2021 17:50 UTC

On Tuesday, May 25, 2021 at 11:40:59 AM UTC-5, Anton Ertl wrote:
> Jeremy Linton <reply-...@nospam.org> writes:
> >Its also seems to be the cases that few C/etc programmers want overflow,
> >and likely would be just as happy with saturating operations by default.
> Language like "want overflow" is a sign of muddled thinking. What is
> it that you think few programmers want?
>
> * Defined behaviour on overflow? If so, which one?
> * Modulo (wraparound) arithmetic
> * Trap-on-overflow
> * saturating arithmetic
> * something else?
>
> * Undefined behaviour on overflow?
>
> * Or do you mean that few c programmers intend overflow to happen?
>
> * Or maybe you think that few C programmers want to think about overflow?
>
> And once you have defined what you mean, on what basis do you make
> your claim?
> >The advantage beyond it just making more sense, is that it closes a
> >whole class of security holes caused by incorrect bounds checking.
> Saturation is useful for signal processing, but elsewhere?
<
Texture access can saturate at the edge of the texture (or wrap around to
the other side, depending...) and I would not call texture access signal
processing.
>
> If programmers don't want to think about overflow, trapping is usually
> more useful for waking them up.
> - anton
> --
> 'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
> Mitch Alsup, <c17fcd89-f024-40e7...@googlegroups.com>

Re: saturating arithmetic, not Signed division by 2^n

<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: gneun...@comcast.net (George Neuner)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 14:09:13 -0400
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at> <888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org> <2021May25.175943@mips.complang.tuwien.ac.at>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="80521af7b9e4340e6a092d3e763ca761";
logging-data="11922"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5UF0zTik8CYR12YE23wuzDt7gAA4UZ7M="
User-Agent: ForteAgent/8.00.32.1272
Cancel-Lock: sha1:Lidfn2AcsSINrOx+o4oFuywLT/g=
 by: George Neuner - Tue, 25 May 2021 18:09 UTC

On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
(Anton Ertl) wrote:

>Saturation is useful for signal processing, but elsewhere?

Also for image processing.

>If programmers don't want to think about overflow, trapping is usually
>more useful for waking them up.

Absolutely.

The real problem is that when programmers really DO want wrap-around
semantics, most often it is for containers whose size is not a
multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.

YMMV,
George

Re: saturating arithmetic, not Signed division by 2^n

<ih4vkmFlrniU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.h...@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 21:57:26 +0300
Organization: Tidorum Ltd
Lines: 29
Message-ID: <ih4vkmFlrniU1@mid.individual.net>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net gy64HtetYunpZL5GB46CxAddPuIfEOOfLv0RZez2TgA5beuiMX
Cancel-Lock: sha1:DAv++cayiVR+Nwi7YWDjV2WUNSI=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0)
Gecko/20100101 Thunderbird/78.7.0
In-Reply-To: <k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
Content-Language: en-US
 by: Niklas Holsti - Tue, 25 May 2021 18:57 UTC

On 2021-05-25 21:09, George Neuner wrote:
> On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
> (Anton Ertl) wrote:
>
>> Saturation is useful for signal processing, but elsewhere?
>
> Also for image processing.
>
>
>> If programmers don't want to think about overflow, trapping is usually
>> more useful for waking them up.
>
> Absolutely.
>
> The real problem is that when programmers really DO want wrap-around
> semantics, most often it is for containers whose size is not a
> multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.

Ada:

type mod_3_bits is mod 8;
-- Wrap-around arithmetic in the range 0 .. 7.

type mod_12_bits is mod 2**12:
-- Wrap-around arithmetic in the range 0 .. 4095.

etc.

Re: saturating arithmetic, not Signed division by 2^n

<0001HW.265D8132001270A4700005E5438F@news.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: findlayb...@blueyonder.co.uk (Bill Findlay)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 20:02:10 +0100
Organization: none
Lines: 24
Message-ID: <0001HW.265D8132001270A4700005E5438F@news.individual.net>
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at> <888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org> <2021May25.175943@mips.complang.tuwien.ac.at> <k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
Reply-To: findlaybill@blueyonder.co.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: individual.net NYdVYWVUhH0rQhacnooeAwWVBtnWxBPn7h9ZI6POpJ+Md5dyhO
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:RbGT1tqNJKIAUp5O57qUF2gzAwk=
User-Agent: Hogwasher/5.24
 by: Bill Findlay - Tue, 25 May 2021 19:02 UTC

On 25 May 2021, George Neuner wrote
(in article<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>):

> On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
> (Anton Ertl) wrote:
>
> > Saturation is useful for signal processing, but elsewhere?
>
> Also for image processing.
>
> > If programmers don't want to think about overflow, trapping is usually
> > more useful for waking them up.
>
> Absolutely.
>
> The real problem is that when programmers really DO want wrap-around
> semantics, most often it is for containers whose size is not a
> multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.

Needless to say (?) this is available in Ada.

--
Bill Findlay

Re: saturating arithmetic, not Signed division by 2^n

<s8jjms$9n5$1@gioia.aioe.org>

  copy mid

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

  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: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 21:38:07 +0200
Organization: Aioe.org NNTP Server
Lines: 35
Message-ID: <s8jjms$9n5$1@gioia.aioe.org>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.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 - Tue, 25 May 2021 19:38 UTC

George Neuner wrote:
> On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
> (Anton Ertl) wrote:
>
>> Saturation is useful for signal processing, but elsewhere?
>
> Also for image processing.
>
>
>> If programmers don't want to think about overflow, trapping is usually
>> more useful for waking them up.
>
> Absolutely.
>
> The real problem is that when programmers really DO want wrap-around
> semantics, most often it is for containers whose size is not a
> multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.

Most old-school programmers learned a long time ago that you should
extend the size of all such arrays/containers/buffers to be a power of
two. :-)

Alternatively you need a way to wrap from a different point, i.e. like
doing BCD math inside a 32 or 64-bit register value you need carries
that jumps from 9 to 16.

The classic method is to add the missing amount and then detect any
carries out from this stage, which you can do with branch-free code but
it is far slower than a simple "n &= 7".

Terje

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

Re: saturating arithmetic, not Signed division by 2^n

<s8jjp9$9n5$2@gioia.aioe.org>

  copy mid

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

  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: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 21:39:24 +0200
Organization: Aioe.org NNTP Server
Lines: 24
Message-ID: <s8jjp9$9n5$2@gioia.aioe.org>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
<0001HW.265D8132001270A4700005E5438F@news.individual.net>
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 - Tue, 25 May 2021 19:39 UTC

Bill Findlay wrote:
> On 25 May 2021, George Neuner wrote
> (in article<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>):
>
>> On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
>> (Anton Ertl) wrote:
>>
>>> Saturation is useful for signal processing, but elsewhere?
>>
>> Also for image processing.

Images are just 2D signals...
>>
>>> If programmers don't want to think about overflow, trapping is usually
>>> more useful for waking them up.

:-)

Terje

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

Re: saturating arithmetic, not Signed division by 2^n

<9254a3b5-0cb9-4f35-8369-6ada90ce004dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ae9:ef55:: with SMTP id d82mr37171672qkg.3.1621972154498;
Tue, 25 May 2021 12:49:14 -0700 (PDT)
X-Received: by 2002:aca:fd10:: with SMTP id b16mr15230097oii.84.1621972154245;
Tue, 25 May 2021 12:49:14 -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: Tue, 25 May 2021 12:49:14 -0700 (PDT)
In-Reply-To: <k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:b502:588c:e274:fb43;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:b502:588c:e274:fb43
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de>
<s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at> <k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9254a3b5-0cb9-4f35-8369-6ada90ce004dn@googlegroups.com>
Subject: Re: saturating arithmetic, not Signed division by 2^n
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Tue, 25 May 2021 19:49:14 +0000
Content-Type: text/plain; charset="UTF-8"
 by: MitchAlsup - Tue, 25 May 2021 19:49 UTC

On Tuesday, May 25, 2021 at 1:09:17 PM UTC-5, George Neuner wrote:
> On Tue, 25 May 2021 15:59:43 GMT, an...@mips.complang.tuwien.ac.at
> (Anton Ertl) wrote:
>
> >Saturation is useful for signal processing, but elsewhere?
> Also for image processing.
> >If programmers don't want to think about overflow, trapping is usually
> >more useful for waking them up.
> Absolutely.
>
> The real problem is that when programmers really DO want wrap-around
> semantics, most often it is for containers whose size is not a
> multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.
<
Which is why the Shift instructions in My 66000 can have an optional length
specifier and one can "smash" any container into the proper signed or unsigned
value. SL Rd,Rc,<length:0>.
This <l:0> is a degenerate subset of the extract instruction (which is an extension
of the SL instruction.)
>
> YMMV,
> George

Re: saturating arithmetic, not Signed division by 2^n

<s8jlrn$epe$1@newsreader4.netcologne.de>

  copy mid

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

  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: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 20:14:47 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <s8jlrn$epe$1@newsreader4.netcologne.de>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
Injection-Date: Tue, 25 May 2021 20:14:47 -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="15150"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Tue, 25 May 2021 20:14 UTC

Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
> George Neuner wrote:
>> On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
>> (Anton Ertl) wrote:
>>
>>> Saturation is useful for signal processing, but elsewhere?
>>
>> Also for image processing.
>>
>>
>>> If programmers don't want to think about overflow, trapping is usually
>>> more useful for waking them up.
>>
>> Absolutely.
>>
>> The real problem is that when programmers really DO want wrap-around
>> semantics, most often it is for containers whose size is not a
>> multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.
>
> Most old-school programmers learned a long time ago that you should
> extend the size of all such arrays/containers/buffers to be a power of
> two. :-)

Something to unlearn... I worked on Siemens/Fujitsu
VP vector computers for a while. These machines got their memory
speed by having many memory banks, arranged to they could feed
their vector registers at one word per cycle, the memory banks
taking turns.

If you had the lowest dimension of your array as a power of two,
that meant waiting for a single memory bank each time you accessed
an array element along the second-lowest dimension.

The loss in efficiency for having an array like

REAL A(1024,...)

vs

REAL A(1025,...)

was astonishing, a factor of 30 or so IIRC.

I haven't run benchmarks, but I would still avoid using powers
of two for the lowest array dimension on a modern system.

Re: saturating arithmetic, not Signed division by 2^n

<0001HW.265DB02D0014846B700005E5438F@news.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: findlayb...@blueyonder.co.uk (Bill Findlay)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Tue, 25 May 2021 23:22:37 +0100
Organization: none
Lines: 46
Message-ID: <0001HW.265DB02D0014846B700005E5438F@news.individual.net>
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at> <888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org> <2021May25.175943@mips.complang.tuwien.ac.at> <k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <ih4vkmFlrniU1@mid.individual.net>
Reply-To: findlaybill@blueyonder.co.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: individual.net tzT2myjiJMQuLQxIp1TvUg6KXDn4vkxqs+2fyTEwaOIvmRptSl
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:kdtWF56ObYmwYcX1unvKn61vt4c=
User-Agent: Hogwasher/5.24
 by: Bill Findlay - Tue, 25 May 2021 22:22 UTC

On 25 May 2021, Niklas Holsti wrote
(in article <ih4vkmFlrniU1@mid.individual.net>):

> On 2021-05-25 21:09, George Neuner wrote:
> > On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
> > (Anton Ertl) wrote:
> >
> > > Saturation is useful for signal processing, but elsewhere?
> >
> > Also for image processing.
> >
> >
> > > If programmers don't want to think about overflow, trapping is usually
> > > more useful for waking them up.
> >
> > Absolutely.
> >
> > The real problem is that when programmers really DO want wrap-around
> > semantics, most often it is for containers whose size is not a
> > multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.
>
> Ada:
>
> type mod_3_bits is mod 8;
> -- Wrap-around arithmetic in the range 0 .. 7.
>
> type mod_12_bits is mod 2**12:
> -- Wrap-around arithmetic in the range 0 .. 4095.
>
> etc.

Where "etc" means, e.g.:

type NEST_depth is mod 19; -- wraps from 18 to 0

type NEST is array (KDF9.NEST_depth) of KDF9.word;

type SJNS_depth is mod 17; -- wraps from 16 to 0

type SJNS is array (KDF9.SJNS_depth) of KDF9.SJNS_link;

These are real examples from my KDF9 emulator.

--
Bill Findlay

Re: saturating arithmetic, not Signed division by 2^n

<s8kodk$17t3$1@gioia.aioe.org>

  copy mid

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

  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: saturating arithmetic, not Signed division by 2^n
Date: Wed, 26 May 2021 08:04:41 +0200
Organization: Aioe.org NNTP Server
Lines: 75
Message-ID: <s8kodk$17t3$1@gioia.aioe.org>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
<s8jlrn$epe$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 - Wed, 26 May 2021 06:04 UTC

Thomas Koenig wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>> George Neuner wrote:
>>> On Tue, 25 May 2021 15:59:43 GMT, anton@mips.complang.tuwien.ac.at
>>> (Anton Ertl) wrote:
>>>
>>>> Saturation is useful for signal processing, but elsewhere?
>>>
>>> Also for image processing.
>>>
>>>
>>>> If programmers don't want to think about overflow, trapping is usually
>>>> more useful for waking them up.
>>>
>>> Absolutely.
>>>
>>> The real problem is that when programmers really DO want wrap-around
>>> semantics, most often it is for containers whose size is not a
>>> multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.
>>
>> Most old-school programmers learned a long time ago that you should
>> extend the size of all such arrays/containers/buffers to be a power of
>> two. :-)
>
> Something to unlearn... I worked on Siemens/Fujitsu
> VP vector computers for a while. These machines got their memory
> speed by having many memory banks, arranged to they could feed
> their vector registers at one word per cycle, the memory banks
> taking turns.
>
> If you had the lowest dimension of your array as a power of two,
> that meant waiting for a single memory bank each time you accessed
> an array element along the second-lowest dimension.
>
> The loss in efficiency for having an array like
>
> REAL A(1024,...)
>
> vs
>
> REAL A(1025,...)
>
> was astonishing, a factor of 30 or so IIRC.
>
> I haven't run benchmarks, but I would still avoid using powers
> of two for the lowest array dimension on a modern system.
>
I have of course hit that exact problem a number of times, as you write
the standard workaround is to extend array dimensions to a close
(relative) prime, with the 17-way memory layout of an early computer the
canonical example of doing the opposite, i.e. creating a memory
subsystem which wasn't susceptible to these kinds of problems.

I'm assuming they got the idea from the 17-year cicadas which I believe
are swarming this year in the US?

Anyway, the only places where I tend to use these powers of two buffer
sizes are one-dimensional and small enough that the entire buffer will
just use a fraction of $L1.

I personally discovered this problem when writing a sliding window comms
protocol around 1983 (Super Kermit), where my solution was to split my
file buffer size (typically 16-32 KB) in such a way that I could easily
determine the relative starting point of any given packet, even when
each of those could have any given size in the 105 to 9000 range.

As a final note, using a relative prime which is of the form 2^n +/- 1
makes it possible to do the DIV/MOD calculations very fast with cheap
hardware, but today you would probably just use a reciprocal MUL.

Terje

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

Re: saturating arithmetic, not Signed division by 2^n

<7a39a825-7c66-40b0-a628-8db51d91b10dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:4756:: with SMTP id k22mr38323039qtp.193.1622039307918;
Wed, 26 May 2021 07:28:27 -0700 (PDT)
X-Received: by 2002:a05:6830:1251:: with SMTP id s17mr2694848otp.81.1622039307689;
Wed, 26 May 2021 07:28:27 -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: Wed, 26 May 2021 07:28:27 -0700 (PDT)
In-Reply-To: <s8kodk$17t3$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:3444:a6bd:58b5:394e;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:3444:a6bd:58b5:394e
References: <s7dn5p$78r$1@newsreader4.netcologne.de> <2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com> <s7en70$n5v$1@newsreader4.netcologne.de>
<s7er6f$2qlr$1@gal.iecc.com> <0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at> <k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com>
<s8jjms$9n5$1@gioia.aioe.org> <s8jlrn$epe$1@newsreader4.netcologne.de> <s8kodk$17t3$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7a39a825-7c66-40b0-a628-8db51d91b10dn@googlegroups.com>
Subject: Re: saturating arithmetic, not Signed division by 2^n
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Wed, 26 May 2021 14:28:27 +0000
Content-Type: text/plain; charset="UTF-8"
 by: MitchAlsup - Wed, 26 May 2021 14:28 UTC

On Wednesday, May 26, 2021 at 1:04:41 AM UTC-5, Terje Mathisen wrote:
> Thomas Koenig wrote:
> > Terje Mathisen <terje.m...@tmsw.no> schrieb:
> >> George Neuner wrote:
> >>> On Tue, 25 May 2021 15:59:43 GMT, an...@mips.complang.tuwien.ac.at
> >>> (Anton Ertl) wrote:
> >>>
> >>>> Saturation is useful for signal processing, but elsewhere?
> >>>
> >>> Also for image processing.
> >>>
> >>>
> >>>> If programmers don't want to think about overflow, trapping is usually
> >>>> more useful for waking them up.
> >>>
> >>> Absolutely.
> >>>
> >>> The real problem is that when programmers really DO want wrap-around
> >>> semantics, most often it is for containers whose size is not a
> >>> multiple of 8-bit bytes: e.g., 3-bit numbers, 12-bit numbers, etc.
> >>
> >> Most old-school programmers learned a long time ago that you should
> >> extend the size of all such arrays/containers/buffers to be a power of
> >> two. :-)
> >
> > Something to unlearn... I worked on Siemens/Fujitsu
> > VP vector computers for a while. These machines got their memory
> > speed by having many memory banks, arranged to they could feed
> > their vector registers at one word per cycle, the memory banks
> > taking turns.
> >
> > If you had the lowest dimension of your array as a power of two,
> > that meant waiting for a single memory bank each time you accessed
> > an array element along the second-lowest dimension.
> >
> > The loss in efficiency for having an array like
> >
> > REAL A(1024,...)
> >
> > vs
> >
> > REAL A(1025,...)
> >
> > was astonishing, a factor of 30 or so IIRC.
> >
> > I haven't run benchmarks, but I would still avoid using powers
> > of two for the lowest array dimension on a modern system.
> >
> I have of course hit that exact problem a number of times, as you write
> the standard workaround is to extend array dimensions to a close
> (relative) prime, with the 17-way memory layout of an early computer the
> canonical example of doing the opposite, i.e. creating a memory
> subsystem which wasn't susceptible to these kinds of problems.
<
Boroughs Scientific Processor BSP.
>
> I'm assuming they got the idea from the 17-year cicadas which I believe
> are swarming this year in the US?
>
> Anyway, the only places where I tend to use these powers of two buffer
> sizes are one-dimensional and small enough that the entire buffer will
> just use a fraction of $L1.
>
> I personally discovered this problem when writing a sliding window comms
> protocol around 1983 (Super Kermit), where my solution was to split my
> file buffer size (typically 16-32 KB) in such a way that I could easily
> determine the relative starting point of any given packet, even when
> each of those could have any given size in the 105 to 9000 range.
>
> As a final note, using a relative prime which is of the form 2^n +/- 1
> makes it possible to do the DIV/MOD calculations very fast with cheap
> hardware, but today you would probably just use a reciprocal MUL.
> Terje
>
> --
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"

Re: saturating arithmetic, not Signed division by 2^n

<877di3so9l.fsf@eder.anydns.info>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: a_eder_...@web.de (Andreas Eder)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Tue, 06 Jul 2021 12:57:42 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <877di3so9l.fsf@eder.anydns.info>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
<s8jlrn$epe$1@newsreader4.netcologne.de> <s8kodk$17t3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b525fe743934c2753a2bf958edb2bb6d";
logging-data="24459"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nvhsXol+X/TfZt3lbbMyC"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Cancel-Lock: sha1:rECHm3etDXBTeDcdwYRMrksq2Vs=
sha1:8B+ky/cpsZ0dtx/6b1Sd3h9V2bE=
 by: Andreas Eder - Tue, 6 Jul 2021 10:57 UTC

On Mi 26 Mai 2021 at 08:04, Terje Mathisen <terje.mathisen@tmsw.no> wrote:

> I have of course hit that exact problem a number of times, as you write
> the standard workaround is to extend array dimensions to a close
> (relative) prime, with the 17-way memory layout of an early computer the
> canonical example of doing the opposite, i.e. creating a memory
> subsystem which wasn't susceptible to these kinds of problems.
>
> I'm assuming they got the idea from the 17-year cicadas which I believe
> are swarming this year in the US?

Well, the only thing that really matters is, that the number is prime.

'Andreas

Re: saturating arithmetic, not Signed division by 2^n

<sc8rgj$372$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!zs51QaFgyCRf+aTPp0mIHw.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Fri, 9 Jul 2021 08:48:52 +0200
Organization: Aioe.org NNTP Server
Lines: 24
Message-ID: <sc8rgj$372$1@gioia.aioe.org>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
<s8jlrn$epe$1@newsreader4.netcologne.de> <s8kodk$17t3$1@gioia.aioe.org>
<877di3so9l.fsf@eder.anydns.info>
NNTP-Posting-Host: zs51QaFgyCRf+aTPp0mIHw.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.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Fri, 9 Jul 2021 06:48 UTC

Andreas Eder wrote:
> On Mi 26 Mai 2021 at 08:04, Terje Mathisen <terje.mathisen@tmsw.no> wrote:
>
>> I have of course hit that exact problem a number of times, as you write
>> the standard workaround is to extend array dimensions to a close
>> (relative) prime, with the 17-way memory layout of an early computer the
>> canonical example of doing the opposite, i.e. creating a memory
>> subsystem which wasn't susceptible to these kinds of problems.
>>
>> I'm assuming they got the idea from the 17-year cicadas which I believe
>> are swarming this year in the US?
>
> Well, the only thing that really matters is, that the number is prime.

Not really: Many of the smaller primes occur far too often in
real/normal code, i.e. 2,3,5 are all unsuitable, 7, 11 or 13 could have
been selected, but 17 have (like 7) fast ways to do the required div/mod
operation, with 17 slightly faster since the base has one more bit.

Terje

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

Re: saturating arithmetic, not Signed division by 2^n

<sc9k3k$q4b$1@newsreader4.netcologne.de>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!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: saturating arithmetic, not Signed division by 2^n
Date: Fri, 9 Jul 2021 13:48:36 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <sc9k3k$q4b$1@newsreader4.netcologne.de>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
<s8jlrn$epe$1@newsreader4.netcologne.de> <s8kodk$17t3$1@gioia.aioe.org>
<877di3so9l.fsf@eder.anydns.info> <sc8rgj$372$1@gioia.aioe.org>
Injection-Date: Fri, 9 Jul 2021 13:48:36 -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="26763"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 9 Jul 2021 13:48 UTC

Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
> Andreas Eder wrote:
>> On Mi 26 Mai 2021 at 08:04, Terje Mathisen <terje.mathisen@tmsw.no> wrote:
>>
>>> I have of course hit that exact problem a number of times, as you write
>>> the standard workaround is to extend array dimensions to a close
>>> (relative) prime, with the 17-way memory layout of an early computer the
>>> canonical example of doing the opposite, i.e. creating a memory
>>> subsystem which wasn't susceptible to these kinds of problems.
>>>
>>> I'm assuming they got the idea from the 17-year cicadas which I believe
>>> are swarming this year in the US?
>>
>> Well, the only thing that really matters is, that the number is prime.
>
> Not really: Many of the smaller primes occur far too often in
> real/normal code, i.e. 2,3,5 are all unsuitable, 7, 11 or 13 could have
> been selected, but 17 have (like 7) fast ways to do the required div/mod
> operation, with 17 slightly faster since the base has one more bit.

In software, dividing and calculating the remainder of 17 would
be done by multiplying with its inverse.

However, having a multiplier on a memory access path seems
excessive. Do you know how they did it? Special case with
shift of signed digits and add?

Re: saturating arithmetic, not Signed division by 2^n

<scac55$jmu$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!zs51QaFgyCRf+aTPp0mIHw.user.gioia.aioe.org.POSTED!not-for-mail
From: terje.ma...@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Fri, 9 Jul 2021 22:39:02 +0200
Organization: Aioe.org NNTP Server
Lines: 46
Message-ID: <scac55$jmu$1@gioia.aioe.org>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
<s8jlrn$epe$1@newsreader4.netcologne.de> <s8kodk$17t3$1@gioia.aioe.org>
<877di3so9l.fsf@eder.anydns.info> <sc8rgj$372$1@gioia.aioe.org>
<sc9k3k$q4b$1@newsreader4.netcologne.de>
NNTP-Posting-Host: zs51QaFgyCRf+aTPp0mIHw.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.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Terje Mathisen - Fri, 9 Jul 2021 20:39 UTC

Thomas Koenig wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>> Andreas Eder wrote:
>>> On Mi 26 Mai 2021 at 08:04, Terje Mathisen <terje.mathisen@tmsw.no> wrote:
>>>
>>>> I have of course hit that exact problem a number of times, as you write
>>>> the standard workaround is to extend array dimensions to a close
>>>> (relative) prime, with the 17-way memory layout of an early computer the
>>>> canonical example of doing the opposite, i.e. creating a memory
>>>> subsystem which wasn't susceptible to these kinds of problems.
>>>>
>>>> I'm assuming they got the idea from the 17-year cicadas which I believe
>>>> are swarming this year in the US?
>>>
>>> Well, the only thing that really matters is, that the number is prime.
>>
>> Not really: Many of the smaller primes occur far too often in
>> real/normal code, i.e. 2,3,5 are all unsuitable, 7, 11 or 13 could have
>> been selected, but 17 have (like 7) fast ways to do the required div/mod
>> operation, with 17 slightly faster since the base has one more bit.
>
> In software, dividing and calculating the remainder of 17 would
> be done by multiplying with its inverse.
>
> However, having a multiplier on a memory access path seems
> excessive. Do you know how they did it? Special case with
> shift of signed digits and add?
>

Take a look at the hex reciprocal for 17, it seems pretty obvious that
this was a fixed shift & add circuit, i.e. a multi-tap access to the
output of the address generator: 255 is 15*17, with something like 16
MWord address space you only need 24 bits, so 4 copies of that 8-bit
pattern should do the trick.

0x1000000 / 0x11 = 0xf0f0f, which is the same as 0x10101010 - 0x1010101
so you start by taking 4 shifted copies, duplicating the result and
shifting one copy 4 more bits up before you subtract. (You probably need
to force the final bit to zero so that the reciprocal mul (which is what
we're doing) ends up with the correct result.

Terje

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

Re: saturating arithmetic, not Signed division by 2^n

<scf4hb$i88$1@newsreader4.netcologne.de>

  copy mid

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

  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-2e47-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Sun, 11 Jul 2021 15:59:39 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <scf4hb$i88$1@newsreader4.netcologne.de>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
<s8jlrn$epe$1@newsreader4.netcologne.de> <s8kodk$17t3$1@gioia.aioe.org>
<877di3so9l.fsf@eder.anydns.info> <sc8rgj$372$1@gioia.aioe.org>
<sc9k3k$q4b$1@newsreader4.netcologne.de> <scac55$jmu$1@gioia.aioe.org>
Injection-Date: Sun, 11 Jul 2021 15:59:39 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-2e47-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:2e47:0:7285:c2ff:fe6c:992d";
logging-data="18696"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Sun, 11 Jul 2021 15:59 UTC

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

>> However, having a multiplier on a memory access path seems
>> excessive. Do you know how they did it? Special case with
>> shift of signed digits and add?
>>
>
> Take a look at the hex reciprocal for 17, it seems pretty obvious that
> this was a fixed shift & add circuit, i.e. a multi-tap access to the
> output of the address generator: 255 is 15*17, with something like 16
> MWord address space you only need 24 bits, so 4 copies of that 8-bit
> pattern should do the trick.
>
> 0x1000000 / 0x11 = 0xf0f0f, which is the same as 0x10101010 - 0x1010101
> so you start by taking 4 shifted copies, duplicating the result and
> shifting one copy 4 more bits up before you subtract. (You probably need
> to force the final bit to zero so that the reciprocal mul (which is what
> we're doing) ends up with the correct result.

I looked at this a little bit more.

There are two ways this could have been sped up: Using the multiply
high method for division by 17, or determining the remainder of
the division first and then doing the multiplication by the inverse.

Looking at the first method: The "magic number" for division by
17 for 24 bits is 0xf0f0f1, with a rightward shift of 28 bits (in
other words, only the fist 20 bits are significant). Converting to
canoncial signed digits, as you did, gets

0xf0f0f1 = 0x1010101 - 0x0101010

which would mean adding four and subtracting three terms. Then,
multiply by 17 again (single shift and add) and subtract from
the original addess to calculate the remainder.

Another possibility would be to calculate the remainder by
summation of digits, for example by splitting a 24-bit-word into
six nibbles. The lower nibbles of each byte would be their own
remainder, and the upper ones could be calculated with a relatively
simple circuit (four to five bits). Then, there would be three
four- and three five-bit quantities to add, with a final calculation
of the remainder. Subtract that from the original address, then
you know that the address is divisible by 17, and you can use the
multiplication by the inverse modulo 2^24, so lower bits only.

Hm... not sure which method would be faster.

Anyway, this still seems to be a _lot_ of logic to put into your
memory subsystem, both in terms of cost and in terms of delay,
just to account for the fact that some people like array sizes
along the lowest dimension which are divisible by 16. I would
assume that this would cost at least a cycle on each memory access.

Re: saturating arithmetic, not Signed division by 2^n

<scp34h$7sa$1@newsreader4.netcologne.de>

  copy mid

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

  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-ffcf-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: saturating arithmetic, not Signed division by 2^n
Date: Thu, 15 Jul 2021 10:37:05 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <scp34h$7sa$1@newsreader4.netcologne.de>
References: <s7dn5p$78r$1@newsreader4.netcologne.de>
<2021May11.193250@mips.complang.tuwien.ac.at>
<888390de-f439-4653-a57c-c0febaa51c8fn@googlegroups.com>
<s7en70$n5v$1@newsreader4.netcologne.de> <s7er6f$2qlr$1@gal.iecc.com>
<0296c592-a553-66a5-4984-2147c5101cd1@nospam.org>
<2021May25.175943@mips.complang.tuwien.ac.at>
<k3eqaghgtdpepj5b2t9irjto5f4puroanl@4ax.com> <s8jjms$9n5$1@gioia.aioe.org>
<s8jlrn$epe$1@newsreader4.netcologne.de> <s8kodk$17t3$1@gioia.aioe.org>
<877di3so9l.fsf@eder.anydns.info> <sc8rgj$372$1@gioia.aioe.org>
<sc9k3k$q4b$1@newsreader4.netcologne.de> <scac55$jmu$1@gioia.aioe.org>
<scf4hb$i88$1@newsreader4.netcologne.de>
Injection-Date: Thu, 15 Jul 2021 10:37:05 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-ffcf-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:ffcf:0:7285:c2ff:fe6c:992d";
logging-data="8074"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Thu, 15 Jul 2021 10:37 UTC

Thomas Koenig <tkoenig@netcologne.de> schrieb:
> Terje Mathisen <terje.mathisen@tmsw.no> schrieb:
>> Thomas Koenig wrote:
>
>>> However, having a multiplier on a memory access path seems
>>> excessive. Do you know how they did it? Special case with
>>> shift of signed digits and add?
>>>
>>
>> Take a look at the hex reciprocal for 17, it seems pretty obvious that
>> this was a fixed shift & add circuit, i.e. a multi-tap access to the
>> output of the address generator: 255 is 15*17, with something like 16
>> MWord address space you only need 24 bits, so 4 copies of that 8-bit
>> pattern should do the trick.
>>
>> 0x1000000 / 0x11 = 0xf0f0f, which is the same as 0x10101010 - 0x1010101
>> so you start by taking 4 shifted copies, duplicating the result and
>> shifting one copy 4 more bits up before you subtract. (You probably need
>> to force the final bit to zero so that the reciprocal mul (which is what
>> we're doing) ends up with the correct result.
>
> I looked at this a little bit more.

.... and a bit more.

I missed one important point: If you don't mind wasting 1/17th of
your memory, you don't need an expensive multiplication.

> Another possibility would be to calculate the remainder by
> summation of digits, for example by splitting a 24-bit-word into
> six nibbles. The lower nibbles of each byte would be their own
> remainder, and the upper ones could be calculated with a relatively
> simple circuit (four to five bits). Then, there would be three
> four- and three five-bit quantities to add, with a final calculation
> of the remainder.

or alternatively by summing up the residual by 17 in chunks of
six bits each (three different functions for each of the bits)
which gives you four five-bit numbers. Reduce to two six-bit
numbers by two layers of half and full adders, put it through the
same circuit six to five bit circuit as before, then you have two
five-bit numbers, which you add and put through the final six to
five bit circuit.

The five-bit adder can be simplified a little bit because you
are only adding values from 0 to 16, so it can be made into a
four-bit adder and a full adder with the carry out and the other
two high bits.

What you do next is to select the memory bank from the 17 values,
and then simply use the high 20 bits for addressing within the
memory bank.

So... does not sound too horrible, but it's still a lot of
effort.

Pages:1234
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor