[Bug target/110104] gcc produces sub-optimal code for _addcarry_u64 chain

2023-07-07 Thread slash.tmp at free dot fr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110104

--- Comment #5 from Mason  ---
FWIW, trunk (gcc14) translates testcase3 to the same code as the other
testcases, while remaining portable across all architectures:

$ gcc-trunk -O3 -march=bdver3 testcase3.c

typedef unsigned long long u64;
typedef unsigned __int128 u128;
void testcase3(u64 *acc, u64 a, u64 b)
{
  int c1, c2;
  u128 res = (u128)a * b;
  u64 lo = res, hi = res >> 64;
  c1 = __builtin_add_overflow(lo, acc[0], [0]);
  c2 = __builtin_add_overflow(hi, acc[1], [1])
 | __builtin_add_overflow(c1, acc[1], [1]);
   __builtin_add_overflow(c2, acc[2], [2]);
}

testcase3:
movq%rsi, %rax
mulq%rdx
addq%rax, (%rdi)
adcq%rdx, 8(%rdi)
adcq$0, 16(%rdi)
ret

Thanks again, Jakub.

[Bug target/110104] gcc produces sub-optimal code for _addcarry_u64 chain

2023-06-16 Thread slash.tmp at free dot fr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110104

--- Comment #4 from Mason  ---
I confirm that trunk now emits the same code for testcase1 and testcase2.
Thanks Jakub and Roger, great work!

[Bug target/110104] gcc produces sub-optimal code for _addcarry_u64 chain

2023-06-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110104

Jakub Jelinek  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #3 from Jakub Jelinek  ---
GCC trunk now emits
movq%rsi, %rax
mulq%rdx
addq%rax, (%rdi)
adcq%rdx, 8(%rdi)
adcq$0, 16(%rdi)
ret

[Bug target/110104] gcc produces sub-optimal code for _addcarry_u64 chain

2023-06-14 Thread slash.tmp at free dot fr via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110104

--- Comment #2 from Mason  ---
You meant PR79173 ;)

Latest update:
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621554.html

I didn't see my testcase specifically in Jakub's patch,
but I'll test trunk on godbolt when/if the patch lands.

[Bug target/110104] gcc produces sub-optimal code for _addcarry_u64 chain

2023-06-08 Thread roger at nextmovesoftware dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110104

Roger Sayle  changed:

   What|Removed |Added

 Status|ASSIGNED|NEW
   Assignee|roger at nextmovesoftware dot com  |unassigned at gcc dot 
gnu.org

--- Comment #1 from Roger Sayle  ---
I proposed a fix at
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/620823.html
but this was obsoleted by a much more comprehensive patch (for PR79193)
proposed by Jakub just an hour earlier:
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/620821.html

[Bug target/110104] gcc produces sub-optimal code for _addcarry_u64 chain

2023-06-04 Thread roger at nextmovesoftware dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110104

Roger Sayle  changed:

   What|Removed |Added

 CC||roger at nextmovesoftware dot 
com
 Status|UNCONFIRMED |ASSIGNED
 Ever confirmed|0   |1
   Assignee|unassigned at gcc dot gnu.org  |roger at 
nextmovesoftware dot com
   Last reconfirmed||2023-06-04