flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2, 3 |
Author |
|
vivik 29 Apr 2018, 05:49
Yet they have the concept of calling conventions, which is the same thing, just more limited.
|
|||
![]() |
|
vivik 29 Apr 2018, 07:49
crossplatform complicates things.
|
|||
![]() |
|
DimonSoft 29 Apr 2018, 16:36
vivik wrote: Custom calling convention is needed for connecting assembly language and hll language properly. Just the need to push variables to stack (when you could just pass them in registers) kind of defeats the point of writing some function in assembly. A-a-and this is not custom calling convention. The example shows what is known as fastcall and is implemented like everywhere. I’m pretty sure Delphi uses it for internal subroutines by default, MSVC might do this as well. Like you said, register allocation is quite complex. But compiler is just a program which is not wise by any means, only plain algorithms. Even if you got the means to specify custom registers to use it would most likely be compiled to additional mov’s at the beginning of a function to copy the values to the registers this particular compiler’s code generator prefers. No luck trying to win anything. |
|||
![]() |
|
rugxulo 02 May 2018, 02:00
This probably won't help much, but a guy on YouTube (Bisqwit) is a genius regarding things like this. His latest video is on a similar topic, if you're ultra curious.
|
|||
![]() |
|
vivik 10 May 2018, 17:01
I'm a bit bitter that nobody donates anything. Why pay somebody to do something that he will do anyway.
@DimonSoft In fastcall you can use only 3 registers, while you potentially can use all 7 for passing data (esp still used for stack). @rugxulo That's cool, I don't have to read gcc and clang sources now. |
|||
![]() |
|
vivik 14 May 2018, 06:36
hm...
Code: GLOBAL(boolean) jpeg_fill_bit_buffer (bitread_working_state *state, register bit_buf_type get_buffer, register int bits_left, int nbits) Look at "register" keyword. This does what I hope this does? |
|||
![]() |
|
DimonSoft 14 May 2018, 10:54
vivik wrote: @DimonSoft In fastcall you can use only 3 registers, while you potentially can use all 7 for passing data (esp still used for stack). You wouldn’t be happy with that in general: the caller also needs to store its data somewhere between the calls. If it has to spit data from registers into memory to make use of your custom calling convention with 7 GPRs involved, you lose everything you might have won by using register-based calling convention. |
|||
![]() |
|
vivik 14 May 2018, 13:41
What if function returns 7 different values? This way, they will already be in registers ready to use, without any stack operations.
|
|||
![]() |
|
rugxulo 15 May 2018, 01:01
vivik wrote: Look at "register" keyword. This does what I hope this does? Certainly you're aware of C's long-standing use of it. But modern compilers ignore the hint, figuring they know better. So it's mostly a no-op these days. |
|||
![]() |
|
vivik 15 May 2018, 15:32
Code: #include <stdio.h> void test_reg(register int i) { i = 2; } int main() { int i = 1; printf("%i\n", i); test_reg(i); printf("%i\n", i); getchar(); } //output: //1 //1 nevermind then, just brainfart |
|||
![]() |
|
Furs 16 May 2018, 20:14
BTW fastcall passes only 2 parameters in registers: ecx and edx. eax is not used and neither preserved.
The 3 parameters (eax, ecx, edx) is a GCC-specific custom calling convention (by custom I mean that it doesn't even have a name, you have to use regparm(3) attribute AFAIK, or it does it automatically if it determines all callers of the function (LTO or if it's with static linkage)). But in respect to the topic, I don't think this is good idea for C. It's a language made to be compiled, not interpreted. ![]() |
|||
![]() |
|
vivik 16 May 2018, 20:56
edit and continue != interpreted. It merely redirects functions to newer versions of functions.
|
|||
![]() |
|
DimonSoft 18 May 2018, 09:22
Furs wrote: BTW fastcall passes only 2 parameters in registers: ecx and edx. eax is not used and neither preserved. fastcall is not a calling convention but a set of calling conventions that use registers for parameter passing, so it’s not really valid to talk about The Right Fastcall. Maybe the most common… But Delphi uses 3 registers for fastcall, so I’d say it’s not obvious which one is more common. It depends… |
|||
![]() |
|
Goto page Previous 1, 2, 3 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.