I thought share a new experience - too me at least :lol - about this little bustard.
xor esi, esi
xor edx, edx
cmp esi, edx
cmovne edx, dword ptr [esi]
Will generate an exception despite that the mov should not take place. :dazzled:
It's probably doing the test late in the pipeline. What CPUs have you tested this on?
It's mentioned here on page 16 as a hazard
http://www.cs.cmu.edu/~fp/courses/15213-s07/misc/asm64-handout.pdf
AMD64 Architecture Programmer's Manual Volume 3, General Purpose and System Instructions:
QuoteFor the memory-based forms of CMOVcc, memory-related exceptions may be reported even if the condition is false
how to turn a bug into a feature:
describe it in the documentation :bg
QuoteWhat CPUs have you tested this on?
I3-2100
QuoteFor the memory-based forms of CMOVcc, memory-related exceptions may be reported even if the condition is false
That's what I guessed but the word "may" suggest it is a random behavior most more likelly a design bug than a "feature" like Dave have hinted it. :wink
Of course, both, Intel and AMD, doesn't though about this problem before introducing these pipline-friendly instructions - they should also work with invalid pointers ::)
Quote from: qWord on May 14, 2012, 07:14:38 PM
Of course, both, Intel and AMD, doesn't though about this problem before introducing these pipline-friendly instructions - they should also work with invalid pointers ::)
Make them work with invalid pointers :bg
Quoteinclude \masm32\MasmBasic\MasmBasic.inc ; download (http://www.masm32.com/board/index.php?topic=12460)
Init tc con ; initialise with try/catch handling, output to console
ErrLines ; use error lines
Try
mov esi, 400010h
.Repeat
mov edx, -1163005939 ; set a magic value
mov ecx, esi ; make sure they
sub esi, 4 ; are not equal
SetErrLine "cmovne failed"
cmp esi, ecx ; never equal, so this
cmove edx, dword ptr [esi] ; will never be triggered
PrintLine "edx=", Hex$(edx), " at ", Hex$(esi)
SetErrLine "before until"
.Until LastEx(code) ; repeat until we get an exception
SetErrLine "after until"
Catch
Print CrLf$, "Last exception info = '", LastEx(info), "', triggered at ", Hex$(LastEx(addr))
Exit
TryCatchEnd
end start
Last exception info = 'cmovne failed', triggered at 00401059