This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/79173] New: add-with-carry and subtract-with-borrow support (x86_64 and others)
- From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 21 Jan 2017 00:51:53 +0000
- Subject: [Bug target/79173] New: add-with-carry and subtract-with-borrow support (x86_64 and others)
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79173
Bug ID: 79173
Summary: add-with-carry and subtract-with-borrow support
(x86_64 and others)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent-gcc at vinc17 dot net
Target Milestone: ---
There should be a way to support full add-with-carry and subtract-with-borrow
by generating adc / sbb instructions on x86_64 (and similar instructions on
other targets).
GCC could add builtins, such as __builtin_addc* and __builtin_subc* (two
arguments, carry in, carry out, and the result), similar to Clang:
http://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins
as suggested in PR 60206 comment 3.
Detection of special constructs in standard C/... code would be useful too.
Here are some examples from
https://gcc.gnu.org/ml/gcc-help/2017-01/msg00067.html for subtraction:
typedef unsigned long T;
void sub1 (T *p, T u0, T u1, T u2, T v0, T v1, T v2)
{
T t1;
int b0, b1;
p[0] = u0 - v0;
b0 = u0 < v0;
t1 = u1 - v1;
b1 = u1 < v1;
p[1] = t1 - b0;
b1 |= p[1] > t1;
p[2] = u2 - v2 - b1;
}
void sub2 (T *p, T u0, T u1, T u2, T v0, T v1, T v2)
{
int b0, b1;
p[0] = u0 - v0;
b0 = u0 < v0;
p[1] = u1 - v1 - b0;
b1 = u1 < v1 || (u1 == v1 && b0 != 0);
p[2] = u2 - v2 - b1;
}
In the second example, the b1 line could also be replaced by:
b1 = u1 < v1 + b0 || v1 + b0 < v1;
For the subtractions, optimal code would contain 1 sub and 2 sbb's.