Re: Cray style vectors

Liste des GroupesRevenir à c arch 
Sujet : Re: Cray style vectors
De : mitchalsup (at) *nospam* aol.com (MitchAlsup1)
Groupes : comp.arch
Date : 12. Mar 2024, 20:07:01
Autres entêtes
Organisation : Rocksolid Light
Message-ID : <aac798f6f6b611c624b1bb0ad1f7d30a@www.novabbs.org>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Rocksolid Light
Tim Rentsch wrote:

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

Tim Rentsch wrote:
>
Terje Mathisen <terje.mathisen@tmsw.no> writes:
>
If I really had to write a 64x64->128 MUL, with no widening MUL or
MULH which returns the high half, then I would punt and do it using
32-bit parts (all variables are u64):  [...]
>
I wrote some code along the same lines.  A difference is you
are considering unsigned multiplication, and I am considering
signed multiplication.
>
Signed mul is just a special case of unsigned mul, right?
>
I.e. in case of a signed widening mul, you'd first extract the signs,
convert the inputs to unsigned, then do the unsigned widening mul,
before finally resotirng the sign as the XOR of the input signs?
>
There is a small gotcha if either of the inputs are of the 0x80000000
form, i.e. MININT, but the naive iabs() conversion will do the right
thing by leaving the input unchanged.
>
At the other end there cannot be any issues since restoring a negative
output sign cannot overflow/fail.

It isn't quite that simple.  Some of what you describe has a risk
of running afoul of implementation-defined behavior or undefined
behavior (as for example abs( INT_MIN )).  I'm pretty sure it's
possible to avoid those pitfalls, but it requires a fair amount
of care and careful thinking.
It would be supremely nice if we could go back in time before computers and reserve an integer encoding that represents the
value of "there is no value here" and mandate if upon integer arithmetic.

Note that my goal is only to avoid the possibility of undefined
behavior that comes from signed overflow.  My approach is to safely
determine whether the signed multiplication would overflow, and if
it wouldn't then simply use signed arithmetic to get the result.
Double width multiplication cannot overflow. 2n = n×n then, ignoring
the top n bits gives you your non-overflowing multiply.

I use unsigned types to determine the safety, and if it's safe then
using signed types to get a result.  For the current problem I don't
care about widening, except as it might help to determine safety.

Date Sujet#  Auteur
11 Mar 24 * Re: Cray style vectors11Tim Rentsch
12 Mar 24 `* Re: Cray style vectors10Terje Mathisen
12 Mar 24  +- Re: Cray style vectors1MitchAlsup1
12 Mar 24  +* Re: Cray style vectors3Tim Rentsch
12 Mar 24  i`* Re: Cray style vectors2MitchAlsup1
13 Mar 24  i `- Re: Cray style vectors1Tim Rentsch
13 Mar 24  `* Re: Cray style vectors5Anton Ertl
13 Mar 24   +- Re: Cray style vectors1Tim Rentsch
13 Mar 24   +- Re: Cray style vectors1Anton Ertl
15 Mar 24   `* Re: Cray style vectors2Terje Mathisen
15 Mar 24    `- Re: Cray style vectors1Anton Ertl

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal