[M3devel] thoughts on NT386/LONGINT?

Jay K jay.krell at cornell.edu
Fri Jan 29 11:09:46 CET 2010


So I looked again -- how is floating point dealt with?
Well, it has its own stack. That helps here (even if it is otherwise lame).

 

 

The "easy" way would be to have M3x86.m3 

do stuff "directly", but each function would have

a little local array of __int64 that push/pop/add/sub/mult

used. It would be very inefficient but would work.

Passing parameters would pop from the local array

and push onto the machine stack. 

 

 

You can see this approach if you watch the

talk on the "XMLVM" where they implement Java for iPhone.

They disassemble .class files into a direct xml representation,

then use XSL style sheets to translate to Objective-C,

or JavaScript, or almost anything.

They give each function a little array to model the Java VM stack.

 

 

I'm still spinning on an efficient approach.

I can actually generate a *little* bit of correct reasonable

code, but not much yet.

Just 64bit moves of constants into variables.

 

 

 - Jay

 


From: jay.krell at cornell.edu
To: hosking at cs.purdue.edu
CC: m3devel at elegosoft.com
Subject: RE: [M3devel] thoughts on NT386/LONGINT?
Date: Mon, 25 Jan 2010 11:14:57 +0000



 >> I think what I see now -- just use the machine stack.

I'm not sure this works so easily if you consider function calls.
  Taking a mix of LONGINT and non-LONGINT parameters.
 
There'd be a series of load_integer and pop_param calls.
Normally all the machine stack pushes are in pop_param.
Now they'd be in a mix of load_integer and pop_param.
If pop_param is called as each parameter is computed, ok.
If they are all computed and then all popped, not ok.
 
 
 - Jay
 


From: jay.krell at cornell.edu
To: hosking at cs.purdue.edu
CC: m3devel at elegosoft.com
Subject: RE: [M3devel] thoughts on NT386/LONGINT?
Date: Sat, 23 Jan 2010 15:31:38 +0000



 > You might easily just push/pop operands and return values on the stack

I don't think I understood you.
My "worst case" was to store everything in temporaries.
But I think I see now.
Some sort of stack is required.
There is the "virtual stack" already in use. (I assume "v" = "virtual").
   It should already handle constant folding, but its register manipulation isn't right for 64bit values.
I think what I see now -- just use the machine stack.
Even to push immediate values.
And, to be really lame, most/all operations can be function calls.
 And not even in the "normal" way, but like:


#ifdef _WIN32


void __stdcall m3_add64(__int64 a)
{
    (&a)[1] += a;
}


void __cdecl m3_neg64(__int64 a)
{
    a = -a;
}


where we convince the C compiler to do the right stack maintenance.
We'd just generate parameter-less calls.
For actually passing longint parameters to real Modula-3 functions,
I'd have to look, but, like, pop_param would do nothing.


 - Jay




From: jay.krell at cornell.edu
To: hosking at cs.purdue.edu
CC: m3devel at elegosoft.com
Subject: RE: [M3devel] thoughts on NT386/LONGINT?
Date: Fri, 22 Jan 2010 22:53:41 +0000



I'll see what I can figure out. 




I considered pushings pairs of operands in m3x86.m3 but I think
that won't work.




Noticing how integer vs. floating point is handled
is perhaps useful, as this is another way in which m3cg
is "homogenous" but backends have to act differently
based on type.




 - Jay





From: hosking at cs.purdue.edu
Date: Fri, 22 Jan 2010 09:49:28 -0500
To: jay.krell at cornell.edu
CC: m3devel at elegosoft.com
Subject: Re: [M3devel] thoughts on NT386/LONGINT?


That's a very good question.  I suspect allocating register pairs as needed would make for a fairly difficult implementation.  I would err on the side of simplicity for LONGINT code generation rather than complexity.  You might easily just push/pop operands and return values on the stack, on the grounds that modern x86 hardware will do a good job renaming stack locations to registers.  i.e., worry about correctness first and performance later.



On 22 Jan 2010, at 07:39, Jay K wrote:

Anyone have any thoughts on how to implement LONGINT on NT386?
 

The code is setup to do pretty good constant folding and enregistration.
 

I did the work so that constant folding should work for LONGINT.
 

However I think doing good enregistration is maybe still
too much work. In particular, I think every LONGINT
operation will do a load, operation, store.
Typical of unoptimized code, but not typical
of the Modula-3/NT386 quality.


 
In particular, there is still this notion of an "operand"
that might be held in one register.

 
I'd have to make it a register pair, or array of registers,
or invent "psuedo registers" that are register pairs.
An array of registers is the obvious best choice, but
none of these are a small change.
 

96 occurences of "reg" in Stackx86.m3, 58 in M3x86.m3,
would probably all have to change.
63 in Codex86.m3 unsure.
 It is the lowest level and might need to only deal with single
  registers.

 
Returning LONGINT from a function also needs separate attention.
Maybe I really should go ahead and use an array of registers?
 

 - Jay


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100129/1c964751/attachment-0002.html>


More information about the M3devel mailing list