According to Peter:
Function InPortW ( port: Integer ) result: ShortWord; begin (* InPortW *) asm ( 'inw %%dx, %%ax' : '=a' ( result ) : 'd' ( port ) ); end (* InPortW *); Function InPortB ( port: Integer ) result: Byte; begin (* InPortB *) asm ( 'inw %%dx, %%al' : '=a' ( result ) : 'd' ( port ) ); end (* InPortB *);
(NOT TESTED, sorry!) PredatorZeta, are you sure that it's `inw' in the second case, not `inb'?
Thanks Peter for your bugfixes to my procedures! I know, I'm very absent-minded in these days..."inw" it's because I cute and paste in Rhide the first proc!!! BTW, here it's occasion to explain two things (heheheh):
1)_The reserved word "result" ISN'T explained properly in the info documentation. (at least in my version!!???). It work, but with this stupid warning:
Warning: return value of function not assigned
I think because GPC can't consider the Asm assignment as a real assignment....
2)_The code outputted from your proc with -O2 switch activated is:
1 pushl %ebp 2 movl %esp,%ebp 3 subl $12,%esp 4 movl %ecx,-4(%ebp) 5 movl 8(%ebp),%edx /APP 6 inb %dx, %al /NOAPP 7 movb %al,-5(%ebp) 8 movb -5(%ebp),%al | 9 leave 10 ret
=8-||||| AAAAAAAARRRRGGGHHH!!!8-)) Whatta the lines 7 and 8 do?????? NOTHING!!! If I cutout these lines the code works IDeNtIcAL!! Also this cost >3< clock cycles on Pentium, for the AGI stall...
PredatorZeta, are you sure that it's `inw' in the second case, not `inb'?
Uhhmmmm....OKK, This is my fault:))))))))))))
BTW, you can even use these as procedures in your program without loss
of
speed: With full optimization `-O3', GPC will automatically inline the above.
Trust me, with these macro: {$DEFINE Inportw(port,myvar) Asm("inw %%dx, %%ax" : "=a" (myvar) : "d" (port))} {$DEFINE Inportb(port,myvar) Asm("inb %%dx, %%al" : "=a" (myvar) : "d" (port))}
the code works without useless MOVs, and it's inlined with or without -O3.8-))))))
Cya...
On Fri, 2 May 1997, PredatorZeta wrote:
1)_The reserved word "result" ISN'T explained properly in the info documentation. (at least in my version!!???). It work, but with this stupid warning:
'result' is not a reserved word. In extended pascal, you may declare a return variable, which in this case happens to be called 'result'.
Warning: return value of function not assigned
I think because GPC can't consider the Asm assignment as a real assignment....
Right, gpc does not handle this properly. But I had the impression the compiler flow analysis would recognize this, if the output section of the asm() uses the result variable...
2)_The code outputted from your proc with -O2 switch activated is:
1 pushl %ebp 2 movl %esp,%ebp 3 subl $12,%esp 4 movl %ecx,-4(%ebp) 5 movl 8(%ebp),%edx /APP 6 inb %dx, %al /NOAPP 7 movb %al,-5(%ebp) 8 movb -5(%ebp),%al | 9 leave 10 ret
=8-||||| AAAAAAAARRRRGGGHHH!!!8-)) Whatta the lines 7 and 8 do?????? NOTHING!!! If I cutout these lines the code works IDeNtIcAL!! Also this cost >3< clock cycles on Pentium, for the AGI stall...
I think this is because the return value of the function is declared volatile to prevent optimization screwing it up. I remember having problems with this, so please don't remove the volatile stuff until the real problem is tracked. In this case (when the return variable exists) the code is of course quite stupid. (but I don't remember the intel assembler well enough to be sure about the problem)
Juki jtv@hut.fi
ps. Thanks for the asm manual! Although quite PC specific ":-)" it is a lot simpler to understand than the GCC documentation. Please keep working with it.