Peter-Lawrence . Montgomery on Tue, 10 Nov 1998 07:01:07 +0100 (MET)

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: PARI translated to C

Karim Belabas writes

> [Ilya writes:]
> > Currently PARI uses assembler-like handling of GENs.
> >
> > This patch provides new C-style definition for GEN and the subtypes
> > for GEN.  Minor changes to .h files are done to fix signatures of functions
> > if appropriate.
> >

> We'll see after the "stable" release (if anybody out there uses PARI in
> library mode, please express yourself!)

        Does C9X (draft new C standard) support
extensible arrays at the ends of structs?

        There are too many casts in the existing code.  Loops like

              for (i = 1; i <= lx; i++) p1[i] = (i==j ? un : zero);

(where un and zero are casts from GEN to long) trigger
a bug in the MIPSpro v7.2.1 compiler, using -O3 -IPA
(highest optimization, including inlining of functions across source files).
I have reported this to SGI.

        Why aren't avma, bot, top declared as GENs? For example,

new_chunk(long x)
  const GEN z = ((GEN) avma) - x;
  if ((ulong)x > (ulong)((GEN)avma-(GEN)bot)) err(errpile);
  avma = (long)z; return z;

(in level1.h) could be (with avma and bot changed to GEN):

       if ((ulong)x > (ulong)(avma - bot)) err(errpile);
       avma -= x; return avma;

The generated code should be very similar (one pointer-long subtraction,
one pointer difference, one unsigned compare followed by branch)
but four casts have been eliminated.

       The base type to which GEN points should not be named
long or ulong, although it might be typedef-ed to these.
For example, MIPS (SGI) has three major compilation modes:

         -o32    32-bit instructions.  long and pointers are 32 bits.
         -n32    64-bit instructions.  long and pointers are 32 bits.
         -64     64-bit instructions.  long and pointers are 64 bits.

It might seem we could simply compile with -64, and I have done
so successfully.  The application which we run in library mode
(square root stage of NFS factoring algorithm) can be restricted
to machines which support -64 mode.

        However, we run GP itself on smaller SGI workstations, where the
IRIX operating system can't afford to support both 32-bit and
64-bit pointers even though 64-bit arithmetic is available (using -n32).
In this environment, GEN should be a 32-bit pointer to
a 64-bit data type t (= long long).  The type t should
satisfy sizeof(t) >= sizeof(t*) -- equality is not needed.
PARI lengths would be measured in units of type t.

       I believe that the MSVC configuration on the Alpha
similarly has 32-bit longs.   Can PARI run in LONG_IS_64BIT
mode on the Alpha using Microsoft's compiler under Windows NT?

       Alas, this proposal may be incompatible with Ilya's.
If some code uses

              GEN x;
              x[i] = (t)(expression of type GEN):

to store a pointer into an array of type t, the gap
between the pointers in x[i] and x[i+1] will be sizeof(t).
Ilya's proposal puts a pointer array in some structs,
in which case the gap between successive array elements will
instead be sizeof(valGEN*).  Compatibility mode may
require these sizeof values be identical.

    Peter L. Montgomery