9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] vlong double-spill botch
@ 2011-01-03 14:44 Fernan Bolando
  2011-01-03 14:56 ` erik quanstrom
  0 siblings, 1 reply; 3+ messages in thread
From: Fernan Bolando @ 2011-01-03 14:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

what does vlong double-spill botch mean in
r = (a * b) + (((a * u) + (b * t)) << 18);          /* low is only 35b */

a larger section of the code is shown below


t_uint64 a = ABS (s1);
t_uint64 b = ABS (s2);
t_uint64 t, u, r;

if ((a == 0) || (b == 0)) {                             /* operand = 0? */
    rs[0] = rs[1] = 0;                                  /* result 0 */
    return;
    }
if ((a & FIT32) || (b & FIT32)) {                       /* fit in 64b? */
    t = a >> 18;                                        /* no, split in half */
    a = a & RMASK;                                      /* "dp" multiply */
    u = b >> 18;
    b = b & RMASK;
    r = (a * b) + (((a * u) + (b * t)) << 18);          /* low is only 35b */
    rs[0] = ((t * u) << 1) + (r >> 35);                 /* so lsh hi 1 */
    rs[1] = r & MMASK;
    }



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] vlong double-spill botch
  2011-01-03 14:44 [9fans] vlong double-spill botch Fernan Bolando
@ 2011-01-03 14:56 ` erik quanstrom
  2011-01-04 13:31   ` Fernan Bolando
  0 siblings, 1 reply; 3+ messages in thread
From: erik quanstrom @ 2011-01-03 14:56 UTC (permalink / raw)
  To: fernanbolando, 9fans

> what does vlong double-spill botch mean in
> r = (a * b) + (((a * u) + (b * t)) << 18);          /* low is only 35b */
>

this is a workaround that i put in the compiler;
it's not in the distribution.  the distribution
compiler happily miscompiles.

if both the left and rhs side of an expression
need to allocate more registers, then 8c often
miscompiles.  you may be able to fix this by
changing 18 to 18ull, but you might as well
do it this way:

	r = a*u + b*t;
	r <<= 18ull;
	r += a*b;

http://9fans.net/archive/2009/09/436
http://9fans.net/archive/2009/08/1044
http://9fans.net/archive/2009/08/1042

- erik



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] vlong double-spill botch
  2011-01-03 14:56 ` erik quanstrom
@ 2011-01-04 13:31   ` Fernan Bolando
  0 siblings, 0 replies; 3+ messages in thread
From: Fernan Bolando @ 2011-01-04 13:31 UTC (permalink / raw)
  To: erik quanstrom; +Cc: 9fans

On Mon, Jan 3, 2011 at 10:56 PM, erik quanstrom
<quanstro@labs.coraid.com> wrote:
>> what does vlong double-spill botch mean in
>> r = (a * b) + (((a * u) + (b * t)) << 18);          /* low is only 35b */
>>
>
> this is a workaround that i put in the compiler;
> it's not in the distribution.  the distribution
> compiler happily miscompiles.
>
> if both the left and rhs side of an expression
> need to allocate more registers, then 8c often
> miscompiles.  you may be able to fix this by
> changing 18 to 18ull, but you might as well
> do it this way:
>
>        r = a*u + b*t;
>        r <<= 18ull;
>        r += a*b;
>
This did not work, but this did
ra = a * b;
rb = a * u;
rc = b * t;
r = ra + ((rb + rc) << 18);



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-04 13:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-03 14:44 [9fans] vlong double-spill botch Fernan Bolando
2011-01-03 14:56 ` erik quanstrom
2011-01-04 13:31   ` Fernan Bolando

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).