4 ms·
One of the big problems here is that the C calling convention, which a lot of other languages use as well, requires a lot of that brain damage. Calls are suppos
by Sanddancer 12y ago
One of the big problems here is that the C calling convention, which a lot of other languages use as well, requires a lot of that brain damage. Calls are supposed to put just the first argument in the A register, and everything else on the stack, save any potential register that an operation the function may use, and generally be painfully slow.
One of the things optimization does is figure out what rules it can break in order to make the program go faster -- when it can put more arguments in registers, because only the code being compiled will see that function, etc. So, in order to make compilers smarter and more intuitive, we have to agree to break binary compatibility, which is something people are rather gun shy about. But, I think it's time to have that conversation.
- asveikau 12y agoThere is no such thing as a C calling convention. It isn't in the language spec. Also I am not sure which one in common use behaves exactly as you say. On ia32 it's usually all stack. (Though I think Microsoft uses ECX for the c++ this pointer.) On amd64 it's common to use registers for the first few integers. (Say, 4 of them.) Further, within a non-exported function it's fair game to break ABIs/calling conventions.
- Retra 12y agoA convention is a convention. It doesn't need a spec.
- asveikau 12y agoC is a language with a spec. When you say "c calling convention" this implies that it is C, and not something else. There are various ABIs, some with specs and some with unwritten rules, but two C programs can run on the same platform conforming to differing ABIs and still be both C. If this sounds far fetched, consider for example that it's common to experience a lot of pain trying to link code compiled with GCC against code compiled with the ms compiler or vice-versa. Same language, CPU, OS. Differing abi.
- asuffield 12y agoThe C language spec alone is not sufficient to build a useful system. You're also going to need some kind of operating system interface (defined in POSIX), binary format (ELF), and so on. The specification that you're both trying to find is called the "System V Application Binary Interface, AMD64 Architecture Processor Supplement" and is found here: http://www.x86-64.org/documentation/abi.pdf http://www.x86-64.org/documentation/abi.pdf There are similar variations for other architectures. Microsoft does something different, I don't know where their spec lives.
- asveikau 12y agoThat is the sysv abi, popular with unixy platforms. It's one abi. You have already mentioned there are others. So how is it "what I was trying to find"? My point is there is not one that is called "C".