[docs] Update HowToReleaseLLVM documentation.
[llvm-project.git] / compiler-rt / lib / builtins / ppc / gcc_qmul.c
blob75f519aad6f082222d5f5c95d5ee7498dba80c6c
1 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 // See https://llvm.org/LICENSE.txt for license information.
3 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 // long double __gcc_qmul(long double x, long double y);
6 // This file implements the PowerPC 128-bit double-double multiply operation.
7 // This implementation is shamelessly cribbed from Apple's DDRT, circa 1993(!)
9 #include "DD.h"
11 long double __gcc_qmul(long double x, long double y) {
12 static const uint32_t infinityHi = UINT32_C(0x7ff00000);
13 DD dst = {.ld = x}, src = {.ld = y};
15 register double A = dst.s.hi, a = dst.s.lo, B = src.s.hi, b = src.s.lo;
17 double aHi, aLo, bHi, bLo;
18 double ab, tmp, tau;
20 ab = A * B;
22 // Detect special cases
23 if (ab == 0.0) {
24 dst.s.hi = ab;
25 dst.s.lo = 0.0;
26 return dst.ld;
29 const doublebits abBits = {.d = ab};
30 if (((uint32_t)(abBits.x >> 32) & infinityHi) == infinityHi) {
31 dst.s.hi = ab;
32 dst.s.lo = 0.0;
33 return dst.ld;
36 // Generic cases handled here.
37 aHi = high26bits(A);
38 bHi = high26bits(B);
39 aLo = A - aHi;
40 bLo = B - bHi;
42 tmp = LOWORDER(ab, aHi, aLo, bHi, bLo);
43 tmp += (A * b + a * B);
44 tau = ab + tmp;
46 dst.s.lo = (ab - tau) + tmp;
47 dst.s.hi = tau;
49 return dst.ld;