trancexx Posted July 18, 2011 Author Share Posted July 18, 2011 JohnOne, we (as people knowing about the rule) have unwritten rule that anyone saying something like that must, and this a must must, tell a joke aferward or one angel falls. In the meantime it's said that one whale dies too, or two, I'm not sure. Save the whales JohnOne. Save the poor whales and the angel, I beg you. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted July 18, 2011 Share Posted July 18, 2011 Whats the difference between jam and marmelade? You cant marmelade your cock in a car door. [toned down for tastefullness] AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
trancexx Posted July 18, 2011 Author Share Posted July 18, 2011 LOL thanks. ...you just waited to use spoiler tags on something, admit it. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
jaberwacky Posted July 19, 2011 Share Posted July 19, 2011 (edited) 8B5508 mov edx, dword[ebp+08] ; first parameter is copied to edx ; sString "first parameter is copied to edx." If sString is passed as a reference then wouldn't that line go away? Edited July 19, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Mat Posted July 19, 2011 Share Posted July 19, 2011 On that line *the pointer sString* is copied to edx. You've got to remember that LPCWSTR is defined as WCHAR* so you are only passing a pointer. AutoIt Project Listing Link to comment Share on other sites More sharing options...
Greenhorn Posted August 18, 2011 Share Posted August 18, 2011 (edited) Hi, maybe this will shrink the code at 3 bytes ... INT WINAPI ChrInStr (LPCWSTR szString, WCHAR chFind) { if (szString) { for(INT i = 0; szString[i]; i++) { if (szString[i] == chFind) return i ; } } return 0 ; } Regards Greenhorn Edited August 18, 2011 by Greenhorn Link to comment Share on other sites More sharing options...
trancexx Posted August 19, 2011 Author Share Posted August 19, 2011 Hi, maybe this will shrink the code at 3 bytes ... INT WINAPI ChrInStr (LPCWSTR szString, WCHAR chFind) { if (szString) { for(INT i = 0; szString[i]; i++) { if (szString[i] == chFind) return i ; } } return 0 ; } Regards Greenhorn I don't see how. What's the logic? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Greenhorn Posted August 19, 2011 Share Posted August 19, 2011 I don't see how. What's the logic?You save at least two bytes: "xor eax, eax" at "if (szStrig == 0) return 0 ;".If you take a look at the generated listing file or the disassembly in the debugger, you'll see. Regards Greenhorn Link to comment Share on other sites More sharing options...
trancexx Posted August 19, 2011 Author Share Posted August 19, 2011 You save at least two bytes: "xor eax, eax" at "if (szStrig == 0) return 0 ;".If you take a look at the generated listing file or the disassembly in the debugger, you'll see. Regards GreenhornCould you show me?I'm kinda noobish. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Valik Posted August 19, 2011 Share Posted August 19, 2011 I'm also rather skeptical that will produce a smaller size. I sincerely hope the compiler is smart enough to realize the following two blocks of code are functionally equivalent and produce the same (optimized) disassembly:if (!value) return 0; // code return 0;And:if (value) // code return 0; Link to comment Share on other sites More sharing options...
jaberwacky Posted August 20, 2011 Share Posted August 20, 2011 (edited) I think I got it. (lol, probably not) If the function parameters are pushed on the stack then is it necessary to mov the arguments into variables? In other words is this necessary: mov edx, dword[ebp+08] ; first parameter is copied to edx ; sString? Edited August 20, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Valik Posted August 20, 2011 Share Posted August 20, 2011 Remember, this is COMPILER output. To remove that means to remove the non-null test which I believe we already established is part of the function. Link to comment Share on other sites More sharing options...
Greenhorn Posted August 20, 2011 Share Posted August 20, 2011 I'm also rather skeptical that will produce a smaller size. I sincerely hope the compiler is smart enough to realize the following two blocks of code are functionally equivalent and produce the same (optimized) disassembly: if (!value) return 0; // code return 0;And: if (value) // code return 0;Yes, I think with the optimization switches on, the compiler should do it in this way ... I've just tested the function in 64 bit Debug configuration and I had a lot more bytes than 39. EDIT: Your right Valik, I've tested it in Release configuration and the generated listing file shows the same ... Here is trancexx's function... expandcollapse popup?ChrInStr@@YAHPEB_W_W@Z PROC ; ChrInStr, COMDAT ; 225 : if (sString == NULL) return 0; ; 226 : ; 227 : for(INT i = 0; sString[i]; ++i) 00000 0f b7 05 00 00 00 00 movzx eax, WORD PTR ?szTitle@@3PA_WA 00007 33 c9 xor ecx, ecx 00009 8b d1 mov edx, ecx 0000b 66 85 c0 test ax, ax 0000e 74 1d je SHORT $LN2@ChrInStr 00010 4c 8d 05 00 00 00 00 lea r8, OFFSET FLAT:?szTitle@@3PA_WA ; szTitle $LL4@ChrInStr: ; 228 : { ; 229 : if (sString[i] == sFind) return i; 00017 66 83 f8 69 cmp ax, 105 ; 00000069H 0001b 74 13 je SHORT $LN9@ChrInStr ; 225 : if (sString == NULL) return 0; ; 226 : ; 227 : for(INT i = 0; sString[i]; ++i) 0001d 41 0f b7 44 50 02 movzx eax, WORD PTR [r8+rdx*2+2] 00023 48 ff c2 inc rdx 00026 ff c1 inc ecx 00028 66 85 c0 test ax, ax 0002b 75 ea jne SHORT $LL4@ChrInStr $LN2@ChrInStr: ; 230 : } ; 231 : ; 232 : return 0; 0002d 33 c0 xor eax, eax ; 233 : } 0002f c3 ret 0 $LN9@ChrInStr: ; 228 : { ; 229 : if (sString[i] == sFind) return i; 00030 8b c1 mov eax, ecx ; 233 : } 00032 c3 ret 0 ?ChrInStr@@YAHPEB_W_W@Z ENDP ; ChrInStr ...and here is mine... expandcollapse popup?ChrInStr_@@YAHPEB_W_W@Z PROC ; ChrInStr_, COMDAT ; 237 : if (szString) ; 238 : { ; 239 : for(INT i = 0; szString[i]; i++) 00000 0f b7 05 00 00 00 00 movzx eax, WORD PTR ?szTitle@@3PA_WA 00007 33 c9 xor ecx, ecx 00009 8b d1 mov edx, ecx 0000b 66 85 c0 test ax, ax 0000e 74 1d je SHORT $LN2@ChrInStr_ 00010 4c 8d 05 00 00 00 00 lea r8, OFFSET FLAT:?szTitle@@3PA_WA ; szTitle $LL4@ChrInStr_: ; 240 : { ; 241 : if (szString[i] == chFind) 00017 66 83 f8 6e cmp ax, 110 ; 0000006eH 0001b 74 13 je SHORT $LN9@ChrInStr_ ; 237 : if (szString) ; 238 : { ; 239 : for(INT i = 0; szString[i]; i++) 0001d 41 0f b7 44 50 02 movzx eax, WORD PTR [r8+rdx*2+2] 00023 48 ff c2 inc rdx 00026 ff c1 inc ecx 00028 66 85 c0 test ax, ax 0002b 75 ea jne SHORT $LL4@ChrInStr_ $LN2@ChrInStr_: ; 243 : } ; 244 : } ; 245 : return 0 ; 0002d 33 c0 xor eax, eax ; 246 : } 0002f c3 ret 0 $LN9@ChrInStr_: ; 242 : return i ; 00030 8b c1 mov eax, ecx ; 246 : } 00032 c3 ret 0 ?ChrInStr_@@YAHPEB_W_W@Z ENDP ; ChrInStr_ If you want to get it smaller in size (and maybe a few clocks faster), then you should write your own proc in assembly, as Valik already pointed to ... Regards Greenhorn Link to comment Share on other sites More sharing options...
trancexx Posted August 20, 2011 Author Share Posted August 20, 2011 You can't compare 64 and 32 bit code. Calling convention is different, stack handling, instruction set, ten other things... Anyway, as pointed already, your function can't be and isn't shorter. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now