RE: Possible VC7.1 C++ Optimizer Error with intrinsic _byteswap_uint64 when compiler enters register contention (0/1)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Ivan,

I have already downloaded your sample project to our local machine, and
perform some tests(using "b=_strtoui64(av[2],&ptr,0");). The problem is the
oupput of the release version app(optimized) will always be invalid--zero,
meanwhile the debug version app works well. Please let me know if my test
results is different from yours.

>Unfortunatelly, it seems that when a certain number of complex
>operations are performed before the _byteswap_uint64() function is
>evaluated (leading to a possible contention in register usage), the
>intrinsic generation of the _byteswap_uint64 gets confused as to what
>register is actually holding the results.

I agree with you that the problem is caused by the incorrect optimization
to the program: in the release version the _byteswap_uint64 operation code
will be inlined to the caller program's code, and just as your sample
assembly code illustrated, the inline code has the error.

Based on my repeated test, I found the root cause of the misoptimization
appears to be av[1]/av[2], which the program arguments you used directly in
the _strtoui64 function call. If use a const integer or a character buffer
instead, then the release version program would work as well as the debug
version one, such as:

char bufA[8], bufB[8];
memcpy(bufA, av[1], 8);
memcpy(bufB, av[2], 8);

a=_strtoui64(bufA,&ptr,0);
b=_strtoui64(bufB,&ptr,0);
//res1 = a & b;
res = _byteswap_uint64(a & b);
...

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • Re: CString oversteps bounds in Release compile
    ... and I am using the "Debug Multithreaded" option for the run ... correlation between source and object code in release mode. ... my resource header) for my resource variable, nIDResource, moved to ... into the eax register the data stored at location _afxPchNil, ...
    (microsoft.public.vc.mfc)
  • Re: H-Series Photos
    ... The H-Series emulator has been completed ... - Q register inoperative (replaced by debug monitor) ... - Interrupt inactive for one instruction on certain instructions ...
    (comp.sys.harris)
  • Re: Difference ARM7-TDMI and ARM7-TDMI-S in debugging
    ... CPU forced into debug mode by setting DBGRQ in debug control ... Wait until debug status register indicates DBGACK set ... Write NOP with bit 33 clear ...
    (comp.sys.arm)
  • Re: how long is double
    ... > FP arithmetic is very sensitive to such things as rounding mode and ... > that in debug mode more intermediate results are being written back and ... > lower precision than register values). ... Unfortunately enabling this option slows down floating point ...
    (comp.lang.cpp)