Sujet : Re: Cray style vectors
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.archDate : 13. Mar 2024, 18:09:37
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2024Mar13.180937@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : xrn 10.11
EricP <
ThatWouldBeTelling@thevillage.com> writes:
Anton Ertl wrote:
DCell mmul (Cell a, Cell b) /* signed multiply, mixed precision */
{
DCell res;
res = UD2D(ummul (a, b));
if (a < 0)
res.hi -= b;
if (b < 0)
res.hi -= a;
return res;
}
I have this technique from Andrew Haley. It relies on twos-complement
representation.
- anton
>
Yeah, that's what Alpha does with UMULH.
I'm still trying to figure out why it works.
Let's consider the case where a>=0 and b<0, and cells are 64 bits. ua
is a interpreted as unsigned cell, and ub is b interpreted as unsigned
cell. The following computations are in Z (the unlimited
integers). For the case under consideration:
ua=a
ub=b+2^64
res = ua*ub = a*(b+2^64)= a*b + a*2^64
So,
a*b = res - a*2^64
The other cases are similar.
- anton
-- 'Anyone trying for "industrial quality" ISA should avoid undefined behavior.' Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>