Re: Is it just me, or …
Verfasst: 21.05.2010, 14:55
Habe die beiden nicht mehr installiert … probier es aus und poste hier :)
Die deutsche Spieleentwickler-Community (seit 1999).
https://zfx.info/
Code: Alles auswählen
// Compile with /Ox /Ob2, link with /LTCG
#include <iostream>
struct Vector {
float A, B, C, D;
Vector(float A, float B, float C, float D)
: A(A), B(B), C(C), D(D) { }
Vector operator + (Vector const & Summand) {
return Vector(A + Summand.A, B + Summand.B, C + Summand.C, D + Summand.D);
}
~Vector() { }
};
int main() {
float A, B, C, D;
::std::cin >> A >> B >> C >> D;
Vector const Result = Vector(A, B, C, D) + Vector(0.0f, 1.0f, 2.0f, 3.0f);
::std::cout << Result.A << Result.B << Result.C << Result.D;
return 0;
}Code: Alles auswählen
int main() {
00401030 push ebp
00401031 mov ebp,esp
00401033 and esp,0FFFFFFF8h
00401036 sub esp,40h
float A, B, C, D;
::std::cin >> A >> B >> C >> D;
00401039 lea eax,[esp+0Ch]
0040103D push eax
0040103E lea ecx,[esp+0Ch]
00401042 push ecx
00401043 mov ecx,dword ptr [__imp_std::cin (402040h)]
00401049 lea edx,[esp+0Ch]
0040104D push edx
0040104E lea eax,[esp+0Ch]
00401052 push eax
00401053 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
00401059 mov ecx,eax
0040105B call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
00401061 mov ecx,eax
00401063 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
00401069 mov ecx,eax
0040106B call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
Vector const Result = Vector(A, B, C, D) + Vector(0.0f, 1.0f, 2.0f, 3.0f);
00401071 fldz
00401073 fstp dword ptr [esp+10h]
00401077 lea ecx,[esp+10h]
0040107B fld1
0040107D lea eax,[esp+30h]
00401081 fstp dword ptr [esp+14h]
00401085 lea edx,[esp+20h]
00401089 fld dword ptr [__real@40000000 (402118h)]
0040108F fstp dword ptr [esp+18h]
00401093 fld dword ptr [__real@40400000 (402114h)]
00401099 fstp dword ptr [esp+1Ch]
0040109D fld dword ptr [esp]
004010A0 fstp dword ptr [esp+20h]
004010A4 fld dword ptr [esp+4]
004010A8 fstp dword ptr [esp+24h]
004010AC fld dword ptr [esp+8]
004010B0 fstp dword ptr [esp+28h]
004010B4 fld dword ptr [esp+0Ch]
004010B8 fstp dword ptr [esp+2Ch]
004010BC call Vector::operator+ (401000h)
::std::cout << Result.A << Result.B << Result.C << Result.D;
004010C1 fld dword ptr [esp+3Ch]
004010C5 mov ecx,dword ptr [__imp_std::cout (40203Ch)]
004010CB sub esp,10h
004010CE fstp dword ptr [esp+0Ch]
004010D2 fld dword ptr [esp+48h]
004010D6 fstp dword ptr [esp+8]
004010DA fld dword ptr [esp+44h]
004010DE fstp dword ptr [esp+4]
004010E2 fld dword ptr [esp+40h]
004010E6 fstp dword ptr [esp]
004010E9 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
004010EF mov ecx,eax
004010F1 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
004010F7 mov ecx,eax
004010F9 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
004010FF mov ecx,eax
00401101 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
return 0;
00401107 xor eax,eax
}
Code: Alles auswählen
int main() {
01131030 push ebp
01131031 mov ebp,esp
01131033 and esp,0FFFFFFF8h
01131036 sub esp,40h
float A, B, C, D;
::std::cin >> A >> B >> C >> D;
01131039 lea eax,[esp+0Ch]
0113103D push eax
0113103E lea ecx,[esp+0Ch]
01131042 push ecx
01131043 mov ecx,dword ptr [__imp_std::cin (1132040h)]
01131049 lea edx,[esp+0Ch]
0113104D push edx
0113104E lea eax,[esp+0Ch]
01131052 push eax
01131053 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (1132038h)]
01131059 mov ecx,eax
0113105B call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (1132038h)]
01131061 mov ecx,eax
01131063 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (1132038h)]
01131069 mov ecx,eax
0113106B call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (1132038h)]
Vector const Result = Vector(A, B, C, D) + Vector(0.0f, 1.0f, 2.0f, 3.0f);
01131071 fldz
01131073 fstp dword ptr [esp+10h]
01131077 lea ecx,[esp+10h]
0113107B fld1
0113107D lea eax,[esp+30h]
01131081 fstp dword ptr [esp+14h]
01131085 lea edx,[esp+20h]
01131089 fld dword ptr [__real@40000000 (1132118h)]
0113108F fstp dword ptr [esp+18h]
01131093 fld dword ptr [__real@40400000 (1132114h)]
01131099 fstp dword ptr [esp+1Ch]
0113109D fld dword ptr [esp]
011310A0 fstp dword ptr [esp+20h]
011310A4 fld dword ptr [esp+4]
011310A8 fstp dword ptr [esp+24h]
011310AC fld dword ptr [esp+8]
011310B0 fstp dword ptr [esp+28h]
011310B4 fld dword ptr [esp+0Ch]
011310B8 fstp dword ptr [esp+2Ch]
011310BC call Vector::operator+ (1131000h)
::std::cout << Result.A << Result.B << Result.C << Result.D;
011310C1 fld dword ptr [esp+3Ch]
011310C5 mov ecx,dword ptr [__imp_std::cout (1132044h)]
011310CB sub esp,10h
011310CE fstp dword ptr [esp+0Ch]
011310D2 fld dword ptr [esp+48h]
011310D6 fstp dword ptr [esp+8]
011310DA fld dword ptr [esp+44h]
011310DE fstp dword ptr [esp+4]
011310E2 fld dword ptr [esp+40h]
011310E6 fstp dword ptr [esp]
011310E9 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (113203Ch)]
011310EF mov ecx,eax
011310F1 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (113203Ch)]
011310F7 mov ecx,eax
011310F9 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (113203Ch)]
011310FF mov ecx,eax
01131101 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (113203Ch)]
return 0;
01131107 xor eax,eax
}
Code: Alles auswählen
int main() {
00401000 sub esp,20h
float A, B, C, D;
::std::cin >> A >> B >> C >> D;
00401003 lea eax,[esp+0Ch]
00401007 push eax
00401008 lea ecx,[esp+0Ch]
0040100C push ecx
0040100D mov ecx,dword ptr [__imp_std::cin (402040h)]
00401013 lea edx,[esp+0Ch]
00401017 push edx
00401018 lea eax,[esp+0Ch]
0040101C push eax
0040101D call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
00401023 mov ecx,eax
00401025 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
0040102B mov ecx,eax
0040102D call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
00401033 mov ecx,eax
00401035 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (402044h)]
Vector const Result = Vector(A, B, C, D) + Vector(0.0f, 1.0f, 2.0f, 3.0f);
0040103B fld dword ptr [esp]
0040103E fadd qword ptr [__real@0000000000000000 (402130h)]
::std::cout << Result.A << Result.B << Result.C << Result.D;
00401044 mov ecx,dword ptr [__imp_std::cout (40203Ch)]
0040104A sub esp,10h
0040104D fstp dword ptr [esp+20h]
00401051 fld dword ptr [esp+14h]
00401055 fadd qword ptr [__real@3ff0000000000000 (402128h)]
0040105B fstp dword ptr [esp+24h]
0040105F fld dword ptr [esp+18h]
00401063 fadd qword ptr [__real@4000000000000000 (402120h)]
00401069 fstp dword ptr [esp+28h]
0040106D fld dword ptr [esp+1Ch]
00401071 fadd qword ptr [__real@4008000000000000 (402118h)]
00401077 fstp dword ptr [esp+2Ch]
0040107B fld dword ptr [esp+2Ch]
0040107F fstp dword ptr [esp+0Ch]
00401083 fld dword ptr [esp+28h]
00401087 fstp dword ptr [esp+8]
0040108B fld dword ptr [esp+24h]
0040108F fstp dword ptr [esp+4]
00401093 fld dword ptr [esp+20h]
00401097 fstp dword ptr [esp]
0040109A call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
004010A0 mov ecx,eax
004010A2 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
004010A8 mov ecx,eax
004010AA call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
004010B0 mov ecx,eax
004010B2 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (402038h)]
return 0;
004010B8 xor eax,eax
}
Code: Alles auswählen
int main() {
00181000 sub esp,20h
float A, B, C, D;
::std::cin >> A >> B >> C >> D;
00181003 lea eax,[esp+0Ch]
00181007 push eax
00181008 lea ecx,[esp+0Ch]
0018100C push ecx
0018100D mov ecx,dword ptr [__imp_std::cin (182040h)]
00181013 lea edx,[esp+0Ch]
00181017 push edx
00181018 lea eax,[esp+0Ch]
0018101C push eax
0018101D call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (182038h)]
00181023 mov ecx,eax
00181025 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (182038h)]
0018102B mov ecx,eax
0018102D call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (182038h)]
00181033 mov ecx,eax
00181035 call dword ptr [__imp_std::basic_istream<char,std::char_traits<char> >::operator>> (182038h)]
Vector const Result = Vector(A, B, C, D) + Vector(0.0f, 1.0f, 2.0f, 3.0f);
0018103B fld dword ptr [esp]
0018103E fadd qword ptr [__real@0000000000000000 (182130h)]
::std::cout << Result.A << Result.B << Result.C << Result.D;
00181044 mov ecx,dword ptr [__imp_std::cout (182044h)]
0018104A sub esp,10h
0018104D fstp dword ptr [esp+20h]
00181051 fld dword ptr [esp+14h]
00181055 fadd qword ptr [__real@3ff0000000000000 (182128h)]
0018105B fstp dword ptr [esp+24h]
0018105F fld dword ptr [esp+18h]
00181063 fadd qword ptr [__real@4000000000000000 (182120h)]
00181069 fstp dword ptr [esp+28h]
0018106D fld dword ptr [esp+1Ch]
00181071 fadd qword ptr [__real@4008000000000000 (182118h)]
00181077 fstp dword ptr [esp+2Ch]
0018107B fld dword ptr [esp+2Ch]
0018107F fstp dword ptr [esp+0Ch]
00181083 fld dword ptr [esp+28h]
00181087 fstp dword ptr [esp+8]
0018108B fld dword ptr [esp+24h]
0018108F fstp dword ptr [esp+4]
00181093 fld dword ptr [esp+20h]
00181097 fstp dword ptr [esp]
0018109A call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (18203Ch)]
001810A0 mov ecx,eax
001810A2 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (18203Ch)]
001810A8 mov ecx,eax
001810AA call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (18203Ch)]
001810B0 mov ecx,eax
001810B2 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (18203Ch)]
return 0;
001810B8 xor eax,eax
}
Code: Alles auswählen
bool CheckCharacter(char x) { // default char signed
return (48 <= x) && (127 >= x);
}Nein, der zweite Vergleich ist nicht immer wahr, sondern nur wenn x >= 127 ist. f'`8kKrishty hat geschrieben:Hmmm, der Compiler scheint auch nicht daraufhin zu optimieren, dass durch Datentypgrenzen bestimmte Vergleiche konstant sind:Hier wird der Compiler beide Vergleiche durchführen, obwohl der zweite Vergleich durch das char-Intervall von [-128, 127] immer true liefert.Code: Alles auswählen
bool CheckCharacter(char x) { // default char signed return (48 <= x) && (127 >= x); }
Immer, wenn eine Bereichsgrenze auf 0, 127, 32767 oder 2^31-1 liegt, kann man durch den richtigen Datentypen einen Vergleich sparen. Leider muss man das scheinbar manuell machen. Oder gibt es einen guten Grund, warum der Compiler das nicht optimiert?
In dem Augenblick, in dem ich 128 hinschriebe, würden beide Operanden als signed short behandelt, weil 128 zu groß für char ist.Alexander Kornrumpf hat geschrieben:P.P.S. Was soll überhaupt das dämliche = dort? 128 > x hätte es doch auch getan. Vielleicht kapiert der compiler das sogar besser.
Ich habe vor ein paar Monaten mal versucht, auf GCC umzusteigen … und so viel besser als VC ist der auch nicht. Den ersten Bug hatte ich – kein Witz – in der ersten Programmzeile: GCC #defined __cplusplus einfach zu 1 statt zum Datum des Sprachstandards. Von da an ging es dann weiter mit __builtins, die nicht existieren obwohl das komplette Internet das Gegenteil behauptet, einer Standardbibliothek wo die Hälfte (so ziemlich alles mit wchar_t) noch nicht implementiert ist und endet dann mit dem herrlichen online-Support, der schlicht und einfach nicht existiert (darüber, ob sie __cplusplus nun endlich standardkonform machen, flamen sie seit sieben Jahren). Irgendwie ist es da bequemer, von Zeit zu Zeit das VC-Kompilat gegenzutesten und hier und da von Hand zu optimieren. Und was Schrompf sagt kommt auch noch dazu.Jörg hat geschrieben:Vielleicht sollte man aufhoeren, MS VC als DEN Compiler zu sehen ;) Selbst der betagte gcc 4.3.3 bekommt es gebacken.
Code: Alles auswählen
new (&Array[Index]) int(::std::move(Array[Index-1]));
xor ebx, ebx
lea eax,[edx+ecx*4]
cmp eax,ebx
je 0F21260h
mov edi,dword ptr [eax-4]
mov dword ptr [eax],edi
dec ecx // 0F21260h
Was mich ehrlich gesagt in der These bestätigt, dass das ein bekloppter(das wäre zu zeigen) Randfall(das ist nun per Definition unstrittig) ist.In dem Augenblick, in dem ich 128 hinschriebe, würden beide Operanden als signed short behandelt, weil 128 zu groß für char ist.
Code: Alles auswählen
bool IsNonControlASCII(char x) {
return (0x20 <= x) && (0x7F >= x);
}Bevor sie den Zeichensatz reformieren, sollten sie sich endlich mal auf vernünftige Line-Endings einigen ;)Alexander Kornrumpf hat geschrieben:Allerdings hoffe ich auf den Tag wo ASCII an sich ein "bekloppter Randfall" wird. Es ist eine Zumutung wie oft man auch heute noch Encodingproblemen begegnet.
Code: Alles auswählen
struct NonTrivialType {
int x;
NonTrivialType() : x(0) { }
NonTrivialType(NonTrivialType const & Ref) : x(Ref.x) { }
};
…
NonTrivialType * Array = new NonTrivialType[2];
new (&Array[0]) NonTrivialType(Array[1]);Code: Alles auswählen
13F6E12DF test r11,r11
13F6E12E2 je 13F6E12EBh
13F6E12E4 mov eax,dword ptr [r11+4]
13F6E12E8 mov dword ptr [r11],eax
13F6E12EB …Code: Alles auswählen
13F6E12E4 mov eax,dword ptr [r11+4]
13F6E12E8 mov dword ptr [r11],eax