This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: MS/CW-style inline assembly for GCC

On Mon, May 10, 2004 at 12:43:43PM -0400, Ian Lance Taylor wrote:
> Jack Lloyd <> writes:
> > Actually pretty much all MPI math can be implemented efficiently in plain
> > C.
> Is this really true?  What about the simple case of unlimited-
> precision addition on a processor which has a carry flag?  Do we
> expect the compiler to be smart enough to turn a loop like
>   c = 0;
>   for (i = 0; i < len; i++)
>     {
>       r[i] = a[i] + b[i] + c;
>       c = (int) (((long long) a[i] + (long long) b[i]) >> 32);
>     }
> into code which uses the "add with carry" instruction?

Actually, usually one uses compares, GNU MP's add loop looks like this:

      ul = *up++;
      vl = *vp++;
      sl = ul + vl;
      cy1 = sl < ul;
      rl = sl + cy;
      cy2 = rl < sl;
      cy = cy1 | cy2;
      *rp++ = rl;
  while (--n != 0);

The code you posted doesn't exactly work if you're using 64 bit words, which is
kind of a must.

And yes, I expect the compiler to figure it out. :) I actually didn't even
think about CPUs with a cc, most of my asm programming has been on Alpha. My
fault on that.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]