<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word" xmlns:m =
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.6001.18023" name=GENERATOR>
<STYLE>@font-face {
font-family: Cambria Math;
}
@font-face {
font-family: Calibri;
}
@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 72.0pt 72.0pt 72.0pt; }
P.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
LI.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
DIV.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-compose
}
.MsoChpDefault {
mso-style-type: export-only
}
DIV.Section1 {
page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV><SPAN class=318130412-27052008><FONT face=Arial color=#0000ff size=2>Both
ZF and PF will be set if unordered, so the code below is IEEE correct...you want
to generate 'fcmp ueq' instead of 'fcmp oqe'</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=Section1>
<P class=MsoNormal>This is the resulting x86 assembly code:<o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">movss
xmm0,dword ptr [ecx+4] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN lang=NL-BE
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">ucomiss
xmm0,dword ptr [ecx+8] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN lang=NL-BE
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">sete
al <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">setnp
dl <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">test
dl,al <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">mov
edx,edi <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne
edx,ecx <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne
ecx,esi <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne
esi,edi</SPAN><o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal>While I’m pleasantly surprised that my branch does get
turned into several select operations as intended (cmov - conditional move –
in x86), I’m confused why it uses the ucomiss instruction (unordered compare
and set flags). I only used IRBuilder::CreateFCmpOEQ. It also appears to
invert the conditional, for no clear reason. I think it could be rewritten as
follows:<o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">movss
xmm0,dword ptr [ecx+4] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">comiss
xmm0,dword ptr [ecx+8] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">mov
edx,edi <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove
edx,ecx <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove
ecx,esi <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove
esi,edi</SPAN><o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal>Compared to the original C syntax code this looks pretty
straightforward. Curiously, when I replace the compare-for-equality with
something like a less-than, it does generate such compact code (using <SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">comiss</SPAN>
and <SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmova</SPAN>).
And the not-equal case looks like this:<o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">movss
xmm0,dword ptr [ecx+4] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">ucomiss
xmm0,dword ptr [ecx+8] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">mov
esi,ecx <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove
esi,edx <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne
ecx,eax <o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove
edx,eax</SPAN><o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal>So this generates compact code but with an unordered
compare.<o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal>Anyway, it looks like the compare-for-equality case in
particular is missing an optimization opportunity. It’s no big deal to me but
I thought someone here might be interested…<o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal>Cheers,<o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal>Nicolas
Capens<o:p></o:p></P></DIV></BLOCKQUOTE></BODY></HTML>