Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/math-emu: Update macros from GCC

The add_ssaaaa, sub_ddmmss, umul_ppmm and udiv_qrnnd macros originate
from GCC's longlong.h which in turn was copied from GMP's longlong.h a
few decades ago.

This was found when compiling with clang:

arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
inline asm context requiring an l-value: remove the cast or build with
-fheinous-gnu-extensions
FP_ADD_D(R, T, B);
^~~~~~~~~~~~~~~~~
...

./arch/powerpc/include/asm/sfp-machine.h:283:27: note: expanded from
macro 'sub_ddmmss'
: "=r" ((USItype)(sh)), \
~~~~~~~~~~^~~

Segher points out: this was fixed in GCC over 16 years ago
( https://gcc.gnu.org/r56600 ), and in GMP (where it comes from)
presumably before that.

Update the add_ssaaaa, sub_ddmmss, umul_ppmm and udiv_qrnnd macros to
the latest GCC version in order to git rid of the invalid casts. These
were taken as-is from GCC's longlong in order to make future syncs
obvious. Other parts of sfp-machine.h were left as-is as the file
contains more features than present in longlong.h.

Link: https://github.com/ClangBuiltLinux/linux/issues/260
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Segher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Joel Stanley and committed by
Michael Ellerman
b682c869 afa202b6

+29 -63
+29 -63
arch/powerpc/include/asm/sfp-machine.h
··· 213 213 * respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow 214 214 * (i.e. carry out) is not stored anywhere, and is lost. 215 215 */ 216 - #define add_ssaaaa(sh, sl, ah, al, bh, bl) \ 216 + #define add_ssaaaa(sh, sl, ah, al, bh, bl) \ 217 217 do { \ 218 218 if (__builtin_constant_p (bh) && (bh) == 0) \ 219 - __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \ 220 - : "=r" ((USItype)(sh)), \ 221 - "=&r" ((USItype)(sl)) \ 222 - : "%r" ((USItype)(ah)), \ 223 - "%r" ((USItype)(al)), \ 224 - "rI" ((USItype)(bl))); \ 225 - else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \ 226 - __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \ 227 - : "=r" ((USItype)(sh)), \ 228 - "=&r" ((USItype)(sl)) \ 229 - : "%r" ((USItype)(ah)), \ 230 - "%r" ((USItype)(al)), \ 231 - "rI" ((USItype)(bl))); \ 219 + __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2" \ 220 + : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\ 221 + else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ 222 + __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2" \ 223 + : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\ 232 224 else \ 233 - __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \ 234 - : "=r" ((USItype)(sh)), \ 235 - "=&r" ((USItype)(sl)) \ 236 - : "%r" ((USItype)(ah)), \ 237 - "r" ((USItype)(bh)), \ 238 - "%r" ((USItype)(al)), \ 239 - "rI" ((USItype)(bl))); \ 225 + __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3" \ 226 + : "=r" (sh), "=&r" (sl) \ 227 + : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \ 240 228 } while (0) 241 229 242 230 /* sub_ddmmss is used in op-2.h and udivmodti4.c and should be equivalent to ··· 236 248 * and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere, 237 249 * and is lost. 238 250 */ 239 - #define sub_ddmmss(sh, sl, ah, al, bh, bl) \ 251 + #define sub_ddmmss(sh, sl, ah, al, bh, bl) \ 240 252 do { \ 241 253 if (__builtin_constant_p (ah) && (ah) == 0) \ 242 - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \ 243 - : "=r" ((USItype)(sh)), \ 244 - "=&r" ((USItype)(sl)) \ 245 - : "r" ((USItype)(bh)), \ 246 - "rI" ((USItype)(al)), \ 247 - "r" ((USItype)(bl))); \ 248 - else if (__builtin_constant_p (ah) && (ah) ==~(USItype) 0) \ 249 - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \ 250 - : "=r" ((USItype)(sh)), \ 251 - "=&r" ((USItype)(sl)) \ 252 - : "r" ((USItype)(bh)), \ 253 - "rI" ((USItype)(al)), \ 254 - "r" ((USItype)(bl))); \ 254 + __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2" \ 255 + : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ 256 + else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \ 257 + __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2" \ 258 + : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ 255 259 else if (__builtin_constant_p (bh) && (bh) == 0) \ 256 - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \ 257 - : "=r" ((USItype)(sh)), \ 258 - "=&r" ((USItype)(sl)) \ 259 - : "r" ((USItype)(ah)), \ 260 - "rI" ((USItype)(al)), \ 261 - "r" ((USItype)(bl))); \ 262 - else if (__builtin_constant_p (bh) && (bh) ==~(USItype) 0) \ 263 - __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \ 264 - : "=r" ((USItype)(sh)), \ 265 - "=&r" ((USItype)(sl)) \ 266 - : "r" ((USItype)(ah)), \ 267 - "rI" ((USItype)(al)), \ 268 - "r" ((USItype)(bl))); \ 260 + __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2" \ 261 + : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ 262 + else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ 263 + __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2" \ 264 + : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ 269 265 else \ 270 - __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \ 271 - : "=r" ((USItype)(sh)), \ 272 - "=&r" ((USItype)(sl)) \ 273 - : "r" ((USItype)(ah)), \ 274 - "r" ((USItype)(bh)), \ 275 - "rI" ((USItype)(al)), \ 276 - "r" ((USItype)(bl))); \ 266 + __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2" \ 267 + : "=r" (sh), "=&r" (sl) \ 268 + : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \ 277 269 } while (0) 278 270 279 271 /* asm fragments for mul and div */ ··· 262 294 * UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype 263 295 * word product in HIGH_PROD and LOW_PROD. 264 296 */ 265 - #define umul_ppmm(ph, pl, m0, m1) \ 297 + #define umul_ppmm(ph, pl, m0, m1) \ 266 298 do { \ 267 299 USItype __m0 = (m0), __m1 = (m1); \ 268 - __asm__ ("mulhwu %0,%1,%2" \ 269 - : "=r" ((USItype)(ph)) \ 270 - : "%r" (__m0), \ 271 - "r" (__m1)); \ 300 + __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ 272 301 (pl) = __m0 * __m1; \ 273 302 } while (0) 274 303 ··· 277 312 * significant bit of DENOMINATOR must be 1, then the pre-processor symbol 278 313 * UDIV_NEEDS_NORMALIZATION is defined to 1. 279 314 */ 280 - #define udiv_qrnnd(q, r, n1, n0, d) \ 315 + #define udiv_qrnnd(q, r, n1, n0, d) \ 281 316 do { \ 282 - UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \ 317 + UWtype __d1, __d0, __q1, __q0; \ 318 + UWtype __r1, __r0, __m; \ 283 319 __d1 = __ll_highpart (d); \ 284 320 __d0 = __ll_lowpart (d); \ 285 321 \ ··· 291 325 if (__r1 < __m) \ 292 326 { \ 293 327 __q1--, __r1 += (d); \ 294 - if (__r1 >= (d)) /* we didn't get carry when adding to __r1 */ \ 328 + if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\ 295 329 if (__r1 < __m) \ 296 330 __q1--, __r1 += (d); \ 297 331 } \