From: Vincent Fatica on 6 Sep 2009 12:08 (VC9) I am trying to avoid the runtime library in a tiny app (something I do regularly). When I try to zero-fill a STARTUPINFO struct with a for-loop, the compiler turns my for-loop into a call to _memset. ; 13 : STARTUPINFO si; ; 14 : si.cb = sizeof(si); ; 15 : for (BYTE *p = (BYTE*) &si + sizeof(si.cb); p < (BYTE*) &si + sizeof(si); p++) ; 16 : *p=0; push 64 ; 00000040H lea edx, DWORD PTR _si$[esp+104] push 0 push edx add esi, 2 mov DWORD PTR _si$[esp+108], 68 ; 00000044H call _memset add esp, 12 ; 0000000cH How do I avoid that (elegantly)? Is it some kind of optimization I can simply turn off? I can trick the compiler with the likes of ; 16 : *p = p ? 0 : 1; // in the loop That avoids the _memset, but seems particularly kludgy. Thanks. -- - Vince
From: xiaosi on 6 Sep 2009 12:56 You may use intrinsic __stosb to replace memset: #include <intrin.h> STARTUPINFO si; __stosb((unsigned char*)&si, 0, sizeof(si)); si.cb = sizeof(si); "Vincent Fatica" <vince(a)blackholespam.net> wrote: > (VC9) I am trying to avoid the runtime library in a tiny app (something I do > regularly). When I try to zero-fill a STARTUPINFO struct with a for-loop, the > compiler turns my for-loop into a call to _memset. > > ; 13 : STARTUPINFO si; > ; 14 : si.cb = sizeof(si); > ; 15 : for (BYTE *p = (BYTE*) &si + sizeof(si.cb); p < (BYTE*) &si + > sizeof(si); p++) > ; 16 : *p=0; > > push 64 ; 00000040H > lea edx, DWORD PTR _si$[esp+104] > push 0 > push edx > add esi, 2 > mov DWORD PTR _si$[esp+108], 68 ; 00000044H > call _memset > add esp, 12 ; 0000000cH > > How do I avoid that (elegantly)? Is it some kind of optimization I can simply > turn off? I can trick the compiler with the likes of > > ; 16 : *p = p ? 0 : 1; // in the loop > > That avoids the _memset, but seems particularly kludgy. > > Thanks. > -- > - Vince
From: Vincent Fatica on 6 Sep 2009 13:27 On Mon, 7 Sep 2009 00:56:43 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote: |You may use intrinsic __stosb to replace memset: |#include <intrin.h> | STARTUPINFO si; | __stosb((unsigned char*)&si, 0, sizeof(si)); | si.cb = sizeof(si); Thanks. That's interesting. There's something I wonder about. __stosb is listed in the documentation's "x64 Intrinsics"; it is not listed in "x86 Intrinsics". What's up with that? -- - Vince
From: Alexander Grigoriev on 6 Sep 2009 14:16 1. #pragma intrinsic(memset) or: 2. Write your own memset. "Vincent Fatica" <vince(a)blackholespam.net> wrote in message news:4aa3f11d$1(a)news.vefatica.net... > On Mon, 7 Sep 2009 00:56:43 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote: > > |You may use intrinsic __stosb to replace memset: > |#include <intrin.h> > | STARTUPINFO si; > | __stosb((unsigned char*)&si, 0, sizeof(si)); > | si.cb = sizeof(si); > > Thanks. That's interesting. There's something I wonder about. __stosb > is > listed in the documentation's "x64 Intrinsics"; it is not listed in "x86 > Intrinsics". What's up with that? > -- > - Vince
From: Vincent Fatica on 6 Sep 2009 14:47
On Sun, 6 Sep 2009 11:16:51 -0700, "Alexander Grigoriev" <alegr(a)earthlink.net> wrote: |1. #pragma intrinsic(memset) I tried that. With "/MT" I get "warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators". With "/MD" I get R6034 An application has made an attempt to load the C runtime library incorrectly. Please contact the application's support team for more information. -- - Vince |