| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Find a word |
-= Pete Replied to David Nugent about: Find a word =-
G'day David
> Good point, QC supports _fastcall and register in as much as it
> won't choke on them but i don't know if the compiler will optimize
> for them.
DN> Hmm, it will have to do it if it understands the keywords.
DN> _fastcall isn't simply an optimisation - it is a completey
DN> different calling convention, and if it ignored them, then the
DN> code would crash.
Thats a point, i just did a test compile on the source below with
optimisations set to full, _fastcall works on the call setup but falls
down in the function itself, see the CV screen captures.
********* test.c ***************************************
#pragma check_stack (off)
int _fastcall test1(int arg1, int arg2);
int test2(int arg1, int arg2);
int main(void) {
test1(2, 2);
test2(2, 2);
return 0;
}
int _fastcall test1(int arg1, int arg2) {
return arg1 + arg2;
}
int test2(int arg1, int arg2) {
register int retval;
retval = arg1 + arg2;
return retval;
}
*******************************************************
************ screen captures from CV ******************
main:
6: int main(void) {
[setup code deleted]
7:
8: test1(2, 2);
49E3:0019 B80200 MOV AX,0002
49E3:001C BA0200 MOV DX,0002
49E3:001F E81A00 CALL test1 (003C)
using the AX:DX regs to pass the arguments so far so good :-)
9: test2(2, 2);
49E3:0022 B80200 MOV AX,0002
49E3:0025 50 PUSH AX
49E3:0026 B80200 MOV AX,0002
49E3:0029 50 PUSH AX
49E3:002A E83700 CALL test2 (0064)
49E3:002D 83C404 ADD SP,+04
using the stack for the 2nd function as expected though i could have
been tighter.
10:
11: return 0;
[exit code for main() deleted]
test1:
14: int _fastcall test1(int arg1, int arg2) {
49E3:003C 55 PUSH BP
49E3:003D 8BEC MOV BP,SP
49E3:003F 81EC0400 SUB SP,0004
49E3:0043 56 PUSH SI
49E3:0044 57 PUSH DI
49E3:0045 8946FC MOV Word Ptr [BP-04],AX
49E3:0048 8956FE MOV Word Ptr [BP-02],DX
49E3:004B 8B76FC MOV SI,Word Ptr [arg1]
49E3:004E 8B7EFE MOV DI,Word Ptr [arg2]
a lot of waste here, 2 stack variables are being created AX & DX are
being assigned to them then those values are moved back out to SI DI.
15:
16: return arg1 + arg2;
49E3:0051 8BC6 MOV AX,SI
49E3:0053 03C7 ADD AX,DI
49E3:0055 E90600 JMP test1+22 (005E)
all this could have been cut down to 'ADD AX, DX' :-(
49E3:0058 8976FC MOV Word Ptr [arg1],SI
49E3:005B 897EFE MOV Word Ptr [arg2],DI
why these two lines are here i've no idea as the code is never run.
17:
18: }
49E3:005E 5F POP DI
49E3:005F 5E POP SI
49E3:0060 8BE5 MOV SP,BP
49E3:0062 5D POP BP
49E3:0063 C3 RET
19:
test2:
20: int test2(int arg1, int arg2) {
49E3:0064 55 PUSH BP
49E3:0065 8BEC MOV BP,SP
49E3:0067 81EC0200 SUB SP,0002
49E3:006B 56 PUSH SI
49E3:006C 57 PUSH DI
49E3:006D 8B7E06 MOV DI,Word Ptr [arg2]
although the local variable 'retval' is suppose to be a register
variable the compiler is making local stack space for it anyway but
never using it.
21:
22: register int retval;
23:
24: retval = arg1 + arg2;
49E3:0070 8B4604 MOV AX,Word Ptr [arg1]
49E3:0073 03C7 ADD AX,DI
49E3:0075 8BF0 MOV retval,AX
25: return retval;
49E3:0077 8BC6 MOV AX,retval
49E3:0079 E90300 JMP test2+1b (007F)
49E3:007C 897E06 MOV Word Ptr [arg2],DI
why DI is being assigned back to the passed argument i can't say, as
it's being preceded by a non conditional jump that bit of code would
never be run.
26: }
49E3:007F 5F POP DI
49E3:0080 5E POP SI
49E3:0081 8BE5 MOV SP,BP
49E3:0083 5D POP BP
49E3:0084 C3 RET
27:
************************************************************
SI reg int retval = 0x0004
CV's locals window shows the local variable 'retval' to be the SI reg
so the 'register' command does work.
> BTW if i keep talking like this Dave i might have you going back
> and using MSC :-)
DN> Not much chance of that, no. :) I did hobble together the os/2
DN> hosted version of MSC 7 to compile and link OS/2 code, but
DN> debugging support was poor (the os/2 hosted msc7 had no
DN> codeview, and CV from MSC6 for OS/2 did not support the new
DN> 32-bit debugging records that MSC7 output).
I can only hope that MSC6 optimises better than QC25 does. I get the
impression the entry and exit code for functions in QC are preset and
added regardless.
DN> In any case, it is well past the time where 16-bit compilers are
DN> useful for applications work. Intel users have had 32-bit CPUs
DN> for 7 years, and it is about time we used them as they were
DN> designed. :)
So true intel CPU'S that run 32bit optcode have been around since
the 386.
BTW sorry about the long message it's just that this stuff interests
me.
Pete.
Email:pcollis{at}ozemail.com.au
--- OMX/Blue Wave v2.12
* Origin: Gates of Hell (3:713/914.16)SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 430 808 809 932 934 SEEN-BY: 712/508 515 713/111 317 601 611 615 618 700 826 888 914 714/906 SEEN-BY: 800/1 @PATH: 713/914 615 888 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.