[M3devel] INTEGER

Jay K jay.krell at cornell.edu
Thu Apr 22 21:38:03 CEST 2010


I have to add something. There is another use of LONGINT.

Kind of an annoying practical one, and a minor side affect. Not really a nice abstract one.

And in fact, it implies a sort of use of "INT128".

 

 

To declare opaque data with a particular alignment.

 

 

To match an external definition.

Specifically, jmpbuf.

Many systems want a 64bit aligned jmpbuf.

   Even some 32bit ones. e.g. ALPHA32_VMS. But it isn't the only one.

 

There are systems that prefer as high as 128 bit aligned jmpbuf, but I think are ok with less aligned (PPC_LINUX), or not (PA64_HPUX?).

  I'm not able to declare these today.

 

 

And C doesn't do this necessarily with larger types, but with other syntax.

I think 32bit Linux/ppc says something like:

 

 

typedef struct __attribute___(align(128)) { /* 32 is ok, but 128 is ideal */
   ...

} jmpbuf;

 

Ok, details:

 

Oh. Maybe I should use "double" for this purpose? I did sometimes. I forgot.

That solves part of the problem, as much as LONGINT solves.

 

 

http://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-libs/m3core/src/C/PA32_HPUX/Csetjmp.i3?rev=1.3;content-type=text%2Fplain

(* 200 bytes with 8 byte alignment *)
TYPE jmp_buf = ARRAY [0..24] OF double;


 

 

http://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-libs/m3core/src/C/PPC_LINUX/Csetjmp.i3?rev=1.10;content-type=text%2Fplain

(* ideal alignment is 16 bytes but 4 is ok; 8 here *)
TYPE jmp_buf = ARRAY [0..73] OF LONGINT;

 

 

 

http://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-libs/m3core/src/C/PA64_HPUX/Csetjmp.i3?rev=1.3;content-type=text%2Fplain

(* 640 bytes with 16 byte alignment if we can get it, else 8 byte alignment,
 which is the best we can ask for (front end internally uses 16 byte alignment) *)
TYPE jmp_buf = ARRAY [0..79] OF double;


 

I should use double? Or we should have another way to say this?

Or, for that matter, as I've suggested, we shouldn't duplicate the information both in Csetjmp.i3 and Target.m3? Target.m3 has available to it arbitrary alignment.

 

 

Ok, PPC_LINUX and PA32/64_HPUX were the only ones I could find that want >4 alignment on 32bit, or >8 on 64bit. And 8 on 32 you can get with double. I had forgotten about that technique.

 

 

I think this is at least another good argument for removing the type declaration from Csetjmp.i3, maybe the function too, and putting it only in Target.m3 (Target.m3 currently only declares setjmp, not longjmp).

 

 

If not a way to declare alignment in the language.

The thing is, you know, the only need for this is to match external/C definitions, and those definitions are now tremendously more under our control than they used to be, so the need to describe "anything" is reduced.

 

 

Tony is that at all difficult? Injecting the jmpbuf and longjmp information from Target.m3 instead of in Csetjmp.i3? I'll try to get to it. I'd like to further reduce the volume and "wide distribution" of target-specific data. There's still a lot of duplication and non-centralization.

 

 

 - Jay

 
> Date: Thu, 22 Apr 2010 10:55:23 -0400
> From: hendrik at topoi.pooq.com
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] INTEGER
> 
> On Thu, Apr 22, 2010 at 02:36:17PM -0400, Tony Hosking wrote:
> > Let me see.
> > 
> > The green book definition says the base type of a subrange of INTEGER literals is INTEGER.
> > You say that the base type of a subrange of LONGINT literals is LONGINT.
> > But you say that LONGINT is not a defined type. So, what is the type 
> > of a LONGINT literal?
> 
> (a) 3849587394875493920398438483929293484L could very well be of type 
> 3849587394875493920398438483929293484L..3849587394875493920398438483929293484L
> which is a one-element subtype of LONGINT.
> 
> LONGINY is a type. It's just one that's not available directly to the 
> programmer. It would not need to have a defined size, if the language 
> allowed LONGINT values to occur *only* where an upper bound on 
> their size is known, such as by being elements of a subrange.
> 
> -- hendrik
> 
> > 
> > [I think I misunderstood you previously. I had interpreted that you meant LONGINT subranges to have base type INTEGER.]
> > 
> > On 22 Apr 2010, at 08:38, hendrik at topoi.pooq.com wrote:
> > 
> > > On Thu, Apr 22, 2010 at 11:57:16AM -0400, Tony Hosking wrote:
> > >> But this is bizarre. What type does an element of a subrange of 
> > >> LONGINT have if not LONGINT?
> > > 
> > > It has LONGINT as a type.
> > > 
> > >> If the subrange has a base type of INTEGER then we need a mapping 
> > >> between the elements of the subrange and the base INTEGER values.
> > > 
> > > Yes. And INTEGER is different from the notion mathematicians have of 
> > > integers in that there is a limit on the size of integers. It's a 
> > > machine or implementation-dependent limit, and it's imposed for 
> > > efficiency reasons, but it's a specific limit just the same.
> > > This limit is precisely what we're up against.
> > > 
> > >> But then, values of the LONGINT subrange don't have the same 
> > >> representation as their INTEGER counterpart.
> > > 
> > > Of course not. If they did have the same representation, there would be 
> > > in-range for INTEGERs, and there would be no need to have LONGINT at 
> > > all.
> > > 
> > > LONGINT is there precisely for the integers that *don't* fit in INTEGER.
> > > 
> > >> 
> > >> All very odd.
> > > 
> > > But dictated by the intended use -- that of having integral ranges
> > > whose bounds are dictated by the problem, not the hardware.
> > > 
> > > -- hendrik
> > 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100422/58fb97bd/attachment-0002.html>


More information about the M3devel mailing list