Thread: [GD-Windows] VC8.0 and CMOV
Brought to you by:
vexxed72
From: Alen L. <ale...@cr...> - 2007-11-23 10:43:36
|
Hi all, Is there any way to make MSVC8.0 to generate CMOV instructions? I have some performance-critical loops, with a lot of small ifs, where it generates branches, and I'd like it to put cmov/fcmov there instead. Allegedly, it is able to do so, but /O2 doesn't seem to help. I can't even find any intrinsic to do that. Any ideas appreciated. Thanks, Alen |
From: Andrew F. <pb...@gm...> - 2007-11-23 15:13:23
|
Does using "__asm" help? You could hand-code the instructions, then. confer: <http://msdn2.microsoft.com/EN-US/library/45yd4tzz(VS.80).aspx>, which is the VC8.0 specific page about using __asm anywhere a statement could appear. It could be that the scheduler doesn't know that you are guaranteeing that the program will be run on a Pentium Pro or better, system. (Pentium Pro is when that instruction was added.) Of course, now that I go to look for a reference to this on the microsoft web site, this may not be a concern. I'm showing my age. :) --andy On Nov 23, 2007 4:45 AM, Alen Ladavac <ale...@cr...> wrote: > Hi all, > > Is there any way to make MSVC8.0 to generate CMOV instructions? I have > some performance-critical loops, with a lot of small ifs, where it > generates branches, and I'd like it to put cmov/fcmov there instead. > Allegedly, it is able to do so, but /O2 doesn't seem to help. I can't > even find any intrinsic to do that. Any ideas appreciated. > > Thanks, > Alen > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > |
From: Alen L. <ale...@cr...> - 2007-11-23 16:28:21
|
Well, yes I tried that. Creating an inline function with _asm to compare two numbers does work, but it seems to mess up with the compiler's optimizations of the rest of the function, because I can't input and output floats or ALU flags in any other way than through memory. Regarding the architecture, I'm optimizing this with /arch:SSE which, according to MSDN, implies using CMOV as well, but the complier never uses that instruction by itself. (BTw, sorry if this seems a bit off-topic, but google doesn't help, which seems like people usually don't really care. I hoped someone in the gamedev would already have experienced this.) Thanks, Alen Andrew wrote: > Does using "__asm" help? You could hand-code the instructions, then. > confer: > <http://msdn2.microsoft.com/EN-US/library/45yd4tzz(VS.80).aspx>, > which is the VC8.0 specific page about using __asm anywhere a > statement could appear. > It could be that the scheduler doesn't know that you are guaranteeing > that the program will be run on a Pentium Pro or better, system. > (Pentium Pro is when that instruction was added.) Of course, now that > I go to look for a reference to this on the microsoft web site, this > may not be a concern. I'm showing my age. > --andy > On Nov 23, 2007 4:45 AM, Alen Ladavac <ale...@cr...> wrote: >> Hi all, >> >> Is there any way to make MSVC8.0 to generate CMOV instructions? I have >> some performance-critical loops, with a lot of small ifs, where it >> generates branches, and I'd like it to put cmov/fcmov there instead. >> Allegedly, it is able to do so, but /O2 doesn't seem to help. I can't >> even find any intrinsic to do that. Any ideas appreciated. >> >> Thanks, >> Alen >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2005. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Gamedevlists-windows mailing list >> Gam...@li... >> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows >> Archives: >> http://sourceforge.net/mailarchive/forum.php?forum_id=555 >> -- Alen |
From: Jan W. <jan...@gm...> - 2007-11-23 15:59:55
|
Hello, On Fri, 23 Nov 2007 11:45:21 +0100, Alen Ladavac <ale...@cr...> = = wrote: > Is there any way to make MSVC8.0 to generate CMOV instructions? > Allegedly, it is able to do so, Confirmed, I've seen them in VC2005 SP1's output. Not sure whether that = = was due to hand-generated snippets being pasted in by the "optimizer" or= = because the code generator has been improved. Even after quite some experimentation, no reliable way to provoke CMOV w= as = found. One thing that did work (surprisingly enough) is a carry flag-based tric= k: int mask =3D (condition)? ~0 : 0; This actually works out to a SBB, which can be used to select one of two= = values or increment/decrement an index, etc. Whether this is useful = depends on the exact contents of your if() statements. > but /O2 doesn't seem to help Code Generation -> Enhanced Instruction Set will probably be necessary a= s = well. On Fri, 23 Nov 2007 16:13:21 +0100, Andrew Finkenstadt <pb...@gm...= > = wrote: > Does using "__asm" help? You could hand-code the instructions, then. Unfortunately this approach suffers from VC's inability to = peephole-optimize the 'boundaries' of asm code. You'll see back-to-back = = stores and loads of variables you pass to/from asm, which often eats awa= y = any gains attained. CPUs have forwarding hardware for this, but it still= = hurts. HTH+HAND Jan Wassenberg |