D - DMD optimizer ( -O) bug
When compiling without the -O option, the compiler generates the following
code (correctly)
for the functions HIWORD & LOWORD.
--------------------------------------------
WORD HIWORD(int l)
0040902C enter 4,0
00409030 mov dword ptr [ebp-4],eax
{
return (WORD)((l >> 16) & 0xFFFF);
00409033 mov eax,dword ptr [l]
00409036 sar eax,10h
00409039 mov ecx,0FFFFh
0040903E and eax,ecx
}
00409040 leave
00409041 ret
00409042 int 3
00409043 int 3
WORD LOWORD(int l)
00409044 enter 4,0
00409048 mov dword ptr [ebp-4],eax
{
return (WORD)l;
0040904B mov ax,word ptr [l]
}
With the -O option used, it does some strange stuff
-----------------------------------------------------
WORD HIWORD(int l)
00408F98 ret
00408F99 int 3
00408F9A int 3
00408F9B int 3
{
return (WORD)((l >> 16) & 0xFFFF);
}
WORD LOWORD(int l)
00408F9C ret
00408F9D int 3
00408F9E int 3
00408F9F int 3
{
return (WORD)l;
}
Dec 11 2003
I get, optimized -O -release on std\c\windows\windows.d:
_HIWORD 4 comdat
assume CS:_HIWORD 4
mov AX,6[ESP]
ret 4
_HIWORD 4 ends
_LOWORD 4 comdat
assume CS:_LOWORD 4
mov AX,4[ESP]
ret 4
_LOWORD 4 ends
which looks correct.
Dec 11 2003
It seems relying on extern(xx).
YT
-------------------------------------
//dmd -O test.d
alias int ULONG;
alias ushort WORD;
WORD HIWORD(ULONG l)
{
return (WORD)((l >> 16) & 0xFFFF);
}
extern(Windows) WORD HIWORD_w(ULONG l)
{
return (WORD)((l >> 16) & 0xFFFF);
}
int main()
{
printf("%x\n", HIWORD(0x12345678)); //5678
printf("%x\n", HIWORD_w(0x12345678)); //1234
return 0;
}
--------------------------------
"Walter" <walter digitalmars.com> wrote in message
news:braobo$2t83$1 digitaldaemon.com...
I get, optimized -O -release on std\c\windows\windows.d:
_HIWORD 4 comdat
assume CS:_HIWORD 4
mov AX,6[ESP]
ret 4
_HIWORD 4 ends
_LOWORD 4 comdat
assume CS:_LOWORD 4
mov AX,4[ESP]
ret 4
_LOWORD 4 ends
which looks correct.
Dec 11 2003
I'm not sure what you mean here. Is it working in your tests or not?
"Y.Tomino" <demoonlit inter7.jp> wrote in message
news:brardl$90$1 digitaldaemon.com...
It seems relying on extern(xx).
YT
-------------------------------------
//dmd -O test.d
alias int ULONG;
alias ushort WORD;
WORD HIWORD(ULONG l)
{
return (WORD)((l >> 16) & 0xFFFF);
}
extern(Windows) WORD HIWORD_w(ULONG l)
{
return (WORD)((l >> 16) & 0xFFFF);
}
int main()
{
printf("%x\n", HIWORD(0x12345678)); //5678
printf("%x\n", HIWORD_w(0x12345678)); //1234
return 0;
}
--------------------------------
"Walter" <walter digitalmars.com> wrote in message
news:braobo$2t83$1 digitaldaemon.com...
I get, optimized -O -release on std\c\windows\windows.d:
_HIWORD 4 comdat
assume CS:_HIWORD 4
mov AX,6[ESP]
ret 4
_HIWORD 4 ends
_LOWORD 4 comdat
assume CS:_LOWORD 4
mov AX,4[ESP]
ret 4
_LOWORD 4 ends
which looks correct.
Dec 11 2003
HIWORD of std.c.windows.windows.d is compiled with extern(Windows). Please test HIWORD for every "LinkageAttribute" with -O. HIWORD and HIWORD_w in my test are the same logic. But These return different values.The result is 0x5678. incorrectprintf("%x\n", HIWORD(0x12345678)); //5678The result is 0x1234. correct extern(Windows) HIWORD is correct. extern(D) HIWORD is incorrect. (dickl probably wrote this case) Thanks. YT "Walter" <walter digitalmars.com> wrote in message news:brbcro$opk$1 digitaldaemon.com...printf("%x\n", HIWORD_w(0x12345678)); //1234I'm not sure what you mean here. Is it working in your tests or not? "Y.Tomino" <demoonlit inter7.jp> wrote in message news:brardl$90$1 digitaldaemon.com...It seems relying on extern(xx). YT ------------------------------------- //dmd -O test.d alias int ULONG; alias ushort WORD; WORD HIWORD(ULONG l) { return (WORD)((l >> 16) & 0xFFFF); } extern(Windows) WORD HIWORD_w(ULONG l) { return (WORD)((l >> 16) & 0xFFFF); } int main() { printf("%x\n", HIWORD(0x12345678)); //5678 printf("%x\n", HIWORD_w(0x12345678)); //1234 return 0; } -------------------------------- "Walter" <walter digitalmars.com> wrote in message news:braobo$2t83$1 digitaldaemon.com...I get, optimized -O -release on std\c\windows\windows.d: _HIWORD 4 comdat assume CS:_HIWORD 4 mov AX,6[ESP] ret 4 _HIWORD 4 ends _LOWORD 4 comdat assume CS:_LOWORD 4 mov AX,4[ESP] ret 4 _LOWORD 4 ends which looks correct.
Dec 12 2003
It was compiled as extern(D) ---------------------------------- "Y.Tomino" <demoonlit inter7.jp> wrote in message news:brc86e$2145$1 digitaldaemon.com...HIWORD of std.c.windows.windows.d is compiled with extern(Windows). Please test HIWORD for every "LinkageAttribute" with -O. HIWORD and HIWORD_w in my test are the same logic. But These return different values.The result is 0x5678. incorrectprintf("%x\n", HIWORD(0x12345678)); //5678The result is 0x1234. correct extern(Windows) HIWORD is correct. extern(D) HIWORD is incorrect. (dickl probably wrote this case) Thanks. YT "Walter" <walter digitalmars.com> wrote in message news:brbcro$opk$1 digitaldaemon.com...printf("%x\n", HIWORD_w(0x12345678)); //1234I'm not sure what you mean here. Is it working in your tests or not? "Y.Tomino" <demoonlit inter7.jp> wrote in message news:brardl$90$1 digitaldaemon.com...It seems relying on extern(xx). YT ------------------------------------- //dmd -O test.d alias int ULONG; alias ushort WORD; WORD HIWORD(ULONG l) { return (WORD)((l >> 16) & 0xFFFF); } extern(Windows) WORD HIWORD_w(ULONG l) { return (WORD)((l >> 16) & 0xFFFF); } int main() { printf("%x\n", HIWORD(0x12345678)); //5678 printf("%x\n", HIWORD_w(0x12345678)); //1234 return 0; } -------------------------------- "Walter" <walter digitalmars.com> wrote in message news:braobo$2t83$1 digitaldaemon.com...I get, optimized -O -release on std\c\windows\windows.d: _HIWORD 4 comdat assume CS:_HIWORD 4 mov AX,6[ESP] ret 4 _HIWORD 4 ends _LOWORD 4 comdat assume CS:_LOWORD 4 mov AX,4[ESP] ret 4 _LOWORD 4 ends which looks correct.
Dec 12 2003








"dickl" <dick221z yahoo.com>