On Mon, 24 Jun 2024 15:28:58 +0200 =?UTF-8?Q?Bernhard_=C3=9Cbelacker?= 
<bernha...@mailbox.org> wrote:

At the bottom is also a minimal reproducer which showed the difference
with and without valgrind to me.


Sorry, I copied a slightly wrong version of the minimal reproducer
in the attachement of my first message,
which unfortunately uses not a fcvtas instruction.
(It is sensitive to the optimization level.)

The intended minimal reproducer is below.

Kind regards,
Bernhard





benutzer@chroot-13-trixie-unstable:~$ cat fp-valgrind-test.c
/*
cat fp-valgrind-test.c
gcc -g -O2 fp-valgrind-test.c -o fp-valgrind-test -lm
./fp-valgrind-test
valgrind ./fp-valgrind-test
gdb -q --args ./fp-valgrind-test
disassemble main
q
*/

#include <stdio.h>
#include <math.h>

double __attribute__((optimize("O0"))) value()
{
  return 322.5;
}

int main()
{
  double a = value();
  int b = (int)round(a);
  printf("a=%f a=0x%llx b=%d\n", a, *(long long unsigned int*)&a, b);
}
benutzer@chroot-13-trixie-unstable:~$ gcc -g -O2 fp-valgrind-test.c -o 
fp-valgrind-test -lm
benutzer@chroot-13-trixie-unstable:~$ ./fp-valgrind-test
a=322.500000 a=0x4074280000000000 b=323
benutzer@chroot-13-trixie-unstable:~$ valgrind ./fp-valgrind-test
==26860== Memcheck, a memory error detector
==26860== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==26860== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==26860== Command: ./fp-valgrind-test
==26860==
a=322.500000 a=0x4074280000000000 b=322
==26860==
==26860== HEAP SUMMARY:
==26860==     in use at exit: 0 bytes in 0 blocks
==26860==   total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==26860==
==26860== All heap blocks were freed -- no leaks are possible
==26860==
==26860== For lists of detected and suppressed errors, rerun with: -s
==26860== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
benutzer@chroot-13-trixie-unstable:~$ gdb -q --args ./fp-valgrind-test
Reading symbols from ./fp-valgrind-test...
(gdb) disassemble main
Dump of assembler code for function main:
   0x0000000000000640 <+0>:     stp     x29, x30, [sp, #-16]!
   0x0000000000000644 <+4>:     mov     x29, sp
   0x0000000000000648 <+8>:     bl      0x7a0 <value>
   0x000000000000064c <+12>:    fcvtas  w2, d0                                 
<<<<<<< in valgrind $w0 is 322, without valgrind $w0 is 323
   0x0000000000000650 <+16>:    fmov    x1, d0
   0x0000000000000654 <+20>:    adrp    x0, 0x0
   0x0000000000000658 <+24>:    add     x0, x0, #0x7d0
   0x000000000000065c <+28>:    bl      0x630 <printf@plt>
   0x0000000000000660 <+32>:    mov     w0, #0x0                        // #0
   0x0000000000000664 <+36>:    ldp     x29, x30, [sp], #16
   0x0000000000000668 <+40>:    ret
End of assembler dump.
(gdb) q
benutzer@chroot-13-trixie-unstable:~$

Reply via email to