Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can confirm the same behaviour of your non-VM code, but since I don't have a VM I haven't tested the VM part.</p> <p>However, the compiler, both Clang and GCC will evaluate the constant expression at compile time. See the assembly output below (using <code>gcc -O0 test.cpp -S</code>) :</p> <pre><code> .file "test.cpp" .section .rodata .LC0: .string "equal" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $.LC0, %edi call puts movl $0, %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1" .section .note.GNU-stack,"",@progbits </code></pre> <p>It looks like you understand assembly, but it's clear that there is only the "equal" string, there is no "not equal". So the comparison is not even done at run time, it just prints "equal".</p> <p>I would try to code the calculation and comparison using assembly and see if you have the same behavior. If you have different behavior on the VM, then it's the way the VM does the calculation.</p> <p><strong>UPDATE 1:</strong> (Based on the "UPDATE 2" in the original question). Below is the <code>gcc -O0 -S test.cpp</code> output assembly (for 64 bit architecture). In it you can see the <code>movabsq $4607182418800017408, %rax</code> line twice. This will be for the two comparison flags, I haven't verified, but I presume the $4607182418800017408 value is 1.1 in floating point terms. It would be interesting to compile this on the VM, if you get the same result (two similar lines) then the VM will be doing something funny at run-time, otherwise it's a combination of VM and compiler.</p> <pre><code>main: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movabsq $4607182418800017408, %rax movq %rax, -16(%rbp) movabsq $4607182418800017408, %rax movq %rax, -8(%rbp) movsd -16(%rbp), %xmm1 movsd .LC1(%rip), %xmm0 addsd %xmm1, %xmm0 movsd -8(%rbp), %xmm2 movsd .LC1(%rip), %xmm1 addsd %xmm2, %xmm1 ucomisd %xmm1, %xmm0 jp .L6 ucomisd %xmm1, %xmm0 je .L7 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload