News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

CMOVNE strangeness..

Started by Ficko, May 14, 2012, 02:23:19 PM

Previous topic - Next topic

Ficko

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:

clive

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
It could be a random act of randomness. Those happen a lot as well.

qWord

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
FPU in a trice: SmplMath
It's that simple!

dedndave

how to turn a bug into a feature:
describe it in the documentation   :bg

Ficko

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

qWord

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  ::)
FPU in a trice: SmplMath
It's that simple!

jj2007

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
  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