tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] incorrect generated code for == on x86_64


From: Vincent Lefevre
Subject: [Tinycc-devel] incorrect generated code for == on x86_64
Date: Thu, 8 Apr 2010 16:55:25 +0200
User-agent: Mutt/1.5.20-6074-vl-r35499 (2010-04-06)

Hi,

With tcc 0.9.25 on x86_64, x == x is regarded as true, even for NaN.
I've looked at the generated code with "tcc -c" and "objdump -d" for:

int main(void)
{
  volatile double x = 0.0/0.0;
  return x == x ? 1 : 0;
}

It appears:

[...]
  37:   66 0f 2e 45 f8          ucomisd -0x8(%rbp),%xmm0
  3c:   0f 85 05 00 00 00       jne    47 <main+0x47>
  42:   e9 0a 00 00 00          jmpq   51 <main+0x51>
  47:   b8 00 00 00 00          mov    $0x0,%eax
  4c:   e9 05 00 00 00          jmpq   56 <main+0x56>
  51:   b8 01 00 00 00          mov    $0x1,%eax
  56:   e9 00 00 00 00          jmpq   5b <main+0x5b>
  5b:   c9                      leaveq 
  5c:   c3                      retq   

According to

  
http://www.sesp.cse.clrc.ac.uk/html/SoftwareTools/vtune/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc314.htm

(found with Google), one has:

UNORDERED:    ZF,PF,CF <- 111;
GREATER_THAN: ZF,PF,CF <- 000;
LESS_THAN:    ZF,PF,CF <- 001;
EQUAL:        ZF,PF,CF <- 100;

If I understand correctly (I've never worked with x86/x86_64 asm
code), the jne tests the ZF flag, but this flag is set also for
unordered (the case of NaN). Hence the incorrect result.

-- 
Vincent Lefèvre <address@hidden> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]