Andy Glew’s CMOVcc Mea Culpa

Compiler writers and assembly coders have long bemoaned the fact that x86 has no CMOVcc store. Additionally, many are shocked to learn that a CMOVcc load always reads memory. Consider the following situation:


   int x = (p == NULL) ? 0 : p->v;

You’d like to generate this code, but it will crash when p is null:


   cmp rax, 0
   cmovne rcx, [rax+foo_offset]

I just discovered this comp.arch posting, where Andy Glew explains how this all came to be.

Advertisements


%d bloggers like this: