[M3devel] calling conventions (small proposal)

Jay K jay.krell at cornell.edu
Mon Feb 22 22:10:08 CET 2010



 >> But why would you have platform-dependent pragmas in code that is not platform-dependent?

 

 

example of mostly portable + pragma:

 

 

hand.c:

 

#if !defined(_MSC_VER) && !defined(__stdcall)

#define __stdcall /* nothing */

#endif

 

void __stdcall set_singleton

ANSI(( ulong a, ulong* s))

KR((a, s) ulong a; ulong* s;)

{

ulong a_word = a / SET_GRAIN;

ulong a_bit = a % SET_GRAIN;

s[a_word] |= (1UL << a_bit);

}

 

 

(gcc on Windows #defines __stdcall to __attribute__(something))

 

 

Not the best example -- this function doesn't seem well motivated.

We probably need a CG.i3 function to do div and mod in one go, since

the processors usually expose that. 

Though this case is with a constant power of two, so..

And m3front would be a little pressed to notice the opportunity?

 

 

- Jay

 


From: hosking at cs.purdue.edu
Date: Mon, 22 Feb 2010 11:01:57 -0500
To: jay.krell at cornell.edu
CC: m3devel at elegosoft.com; darko at darko.org
Subject: Re: [M3devel] calling conventions (small proposal)

Pragmas should never give errors.
If you are proposing that all platforms recognise the pragmas, but most do nothing with them, then I guess OK.  But why would you have platform-dependent pragmas in code that is not platform-dependent?




Antony Hosking | Associate Professor | Computer Science | Purdue University
305 N. University Street | West Lafayette | IN 47907 | USA
Office +1 765 494 6001 | Mobile +1 765 427 5484



On 22 Feb 2010, at 04:52, Jay K wrote:

I wouldn't mind
 - an error 
 - or a way to mark a pragma as needing an error vs. being ok with a warning 
   Though perhaps that shouldn't be a pragma but some other syntax not in <* *>.
   In fact, maybe this stuff doesn't belong in <* *>. I don't care much what
   the syntax is, but there is a legitimate need to note calling conventions,
   a syntax is already in use. I'd rather not invent a new syntax.
 
 
The word "ignore" isn't relevant.
Sorry if I was confusing.
The proposal is that all targets recognize the pragmas __stdcall, __cdecl, etc.
but that most platforms interpret them as doing nothing.
The pragmas already exist.
"Recognize and do nothing" is much different than "ignore stuff that isn't recognized".
 
 
 - Jay
 


Subject: Re: [M3devel] calling conventions (small proposal)
From: hosking at cs.purdue.edu
Date: Sun, 21 Feb 2010 16:52:20 -0500
CC: jay.krell at cornell.edu; m3devel at elegosoft.com
To: darko at darko.org

The compiler does continue to compile having warned that the pragma has no meaning.


So, yes, they are ignored, but I want a warning.


I even want a warning if I write <**>.




On 21 Feb 2010, at 16:47, Darko wrote:


I thought that was the point of pragmas, that the compiler could freely ignore them and that they did not involve the correctness of the program.




On 22/02/2010, at 8:42 AM, Tony Hosking wrote:



Yes, but my point is that a pragma that has no meaning *should* give a warning.  Otherwise, why did I write it.


On 21 Feb 2010, at 16:16, Jay K wrote:

To be clear, I don't propose ignoring all unrecognized pragmas.
Just calling conventions.
You could interpret it as: 
  The pragmas *are* recognized, on all targets, but they have no meaning on most.
  The meaning is "do nothing".
 
 
Look at the situation in C for AMD64_NT. Calling conventions are accepted for compatibility
with I386_NT source. And they all mean nothing. This lets people maintain
one portable code base, and they *don't* even need to do so much as:
#ifndef _X86_
#define __stdcall /* nothing */
#define __cdecl /* nothing */
#define __fastcall /* nothing */
#endif
 
 
I'd be willing to prune the "big" list of calling conventions down to just two: __stdcall, __cdecl.
The rest are a pointless proliferation of synonyms.
Though that'd probably gratuitously break stuff (of course I can fix the entire cm3 tree in
a few minutes, that's not the issue).
 
 
Separate file would work, but I'd really rather stuff be all together.
Once you separate things, one version goes stale.
 
 
 - Jay
 


Subject: Re: [M3devel] calling conventions (small proposal)
From: hosking at cs.purdue.edu
Date: Sun, 21 Feb 2010 15:54:13 -0500
CC: jay.krell at cornell.edu; m3devel at elegosoft.com
To: darko at darko.org


Accepting and silently ignoring sounds very dangerous!


I want my compiler to warn me when I use a pragma that is unrecognised for my particular target.


Silence is deadly!


On 21 Feb 2010, at 15:09, Darko wrote:



This is a good idea. An alternate proposal would be to put the calling conventions in an external file, but this change would seem to be the simplest and in line with the stated definition of pragamas.






On 21/02/2010, at 10:52 PM, Jay K wrote:
1) All platforms should accept, but silently ignore, the NT386/I386_CYGWIN/etc. calling conventions:
at least __stdcall, and __cdecl
Probably all the synonyms: C, WINAPI, CALLBACK, WINAPIV, APIENTRY, APIPRIVATE, PASCAL,
 
This is a very small change.
 
 
This is will allow:
  a) possibly merging the two nearly identical OpenGL.i3 files
  b) implementing functions in Modula-3 that are portable, but use __stdcall, possibly for perf
  I intend to that for hand.c's replacement, soon.
  
 
Maybe experiment as to the perf.
__stdcall is supposed to be faster, because the code is smaller.
But __cdecl might be able to compete by using stores to the stack instead of pushes?
  I'd have to see how that compares in size, and it does increase stack usage some.
 
 
Probably not worth large scale experimenting/changing, but maybe nice to mark
new functions/interfaces as __stdcall (see next point).
 
 
I was actually thinking of trying flat out changing the default, but I think that is too difficult,
what with all the C<=>Modula-3 transitions. And not worth it given other
more valuable work to do.
 
 
2) The calling convention pragmas should be allowed on an interface, to set
the default for an interface.
 
2b) and I guess as well on a module, for unexported functions
 
I assert that other than __stdcall and __cdecl on NT386, nothing else is
particularly interesting here. There is __fastcall, maybe interesting.
It has different meanings to different compilers.
I'd rather keep this all fairly constrained.
 
No other platform has more than one calling convention, so this doesn't
have be to further generalized. Besides, as long as no platform uses
the same name to mean multiple things, ok.
 Mac68K Classic?
 Mac68K CFM? 
 Win16?
 MS-DOS?
 
 
(I did recently acquire a working Mac68K, as well it is easily
 run on a modern PPC Mac; far down the list, but...)
 
 
 - Jay






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


More information about the M3devel mailing list