18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/sparc64/math-emu/sfp-util.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz) 68c2ecf20Sopenharmony_ci * Copyright (C) 1999 David S. Miller (davem@redhat.com) 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/kernel.h> 118c2ecf20Sopenharmony_ci#include <linux/sched.h> 128c2ecf20Sopenharmony_ci#include <linux/types.h> 138c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ 168c2ecf20Sopenharmony_ci __asm__ ("addcc %4,%5,%1\n\t" \ 178c2ecf20Sopenharmony_ci "add %2,%3,%0\n\t" \ 188c2ecf20Sopenharmony_ci "bcs,a,pn %%xcc, 1f\n\t" \ 198c2ecf20Sopenharmony_ci "add %0, 1, %0\n" \ 208c2ecf20Sopenharmony_ci "1:" \ 218c2ecf20Sopenharmony_ci : "=r" (sh), \ 228c2ecf20Sopenharmony_ci "=&r" (sl) \ 238c2ecf20Sopenharmony_ci : "r" ((UDItype)(ah)), \ 248c2ecf20Sopenharmony_ci "r" ((UDItype)(bh)), \ 258c2ecf20Sopenharmony_ci "r" ((UDItype)(al)), \ 268c2ecf20Sopenharmony_ci "r" ((UDItype)(bl)) \ 278c2ecf20Sopenharmony_ci : "cc") 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ 308c2ecf20Sopenharmony_ci __asm__ ("subcc %4,%5,%1\n\t" \ 318c2ecf20Sopenharmony_ci "sub %2,%3,%0\n\t" \ 328c2ecf20Sopenharmony_ci "bcs,a,pn %%xcc, 1f\n\t" \ 338c2ecf20Sopenharmony_ci "sub %0, 1, %0\n" \ 348c2ecf20Sopenharmony_ci "1:" \ 358c2ecf20Sopenharmony_ci : "=r" (sh), \ 368c2ecf20Sopenharmony_ci "=&r" (sl) \ 378c2ecf20Sopenharmony_ci : "r" ((UDItype)(ah)), \ 388c2ecf20Sopenharmony_ci "r" ((UDItype)(bh)), \ 398c2ecf20Sopenharmony_ci "r" ((UDItype)(al)), \ 408c2ecf20Sopenharmony_ci "r" ((UDItype)(bl)) \ 418c2ecf20Sopenharmony_ci : "cc") 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define umul_ppmm(wh, wl, u, v) \ 448c2ecf20Sopenharmony_ci do { \ 458c2ecf20Sopenharmony_ci UDItype tmp1, tmp2, tmp3, tmp4; \ 468c2ecf20Sopenharmony_ci __asm__ __volatile__ ( \ 478c2ecf20Sopenharmony_ci "srl %7,0,%3\n\t" \ 488c2ecf20Sopenharmony_ci "mulx %3,%6,%1\n\t" \ 498c2ecf20Sopenharmony_ci "srlx %6,32,%2\n\t" \ 508c2ecf20Sopenharmony_ci "mulx %2,%3,%4\n\t" \ 518c2ecf20Sopenharmony_ci "sllx %4,32,%5\n\t" \ 528c2ecf20Sopenharmony_ci "srl %6,0,%3\n\t" \ 538c2ecf20Sopenharmony_ci "sub %1,%5,%5\n\t" \ 548c2ecf20Sopenharmony_ci "srlx %5,32,%5\n\t" \ 558c2ecf20Sopenharmony_ci "addcc %4,%5,%4\n\t" \ 568c2ecf20Sopenharmony_ci "srlx %7,32,%5\n\t" \ 578c2ecf20Sopenharmony_ci "mulx %3,%5,%3\n\t" \ 588c2ecf20Sopenharmony_ci "mulx %2,%5,%5\n\t" \ 598c2ecf20Sopenharmony_ci "sethi %%hi(0x80000000),%2\n\t" \ 608c2ecf20Sopenharmony_ci "addcc %4,%3,%4\n\t" \ 618c2ecf20Sopenharmony_ci "srlx %4,32,%4\n\t" \ 628c2ecf20Sopenharmony_ci "add %2,%2,%2\n\t" \ 638c2ecf20Sopenharmony_ci "movcc %%xcc,%%g0,%2\n\t" \ 648c2ecf20Sopenharmony_ci "addcc %5,%4,%5\n\t" \ 658c2ecf20Sopenharmony_ci "sllx %3,32,%3\n\t" \ 668c2ecf20Sopenharmony_ci "add %1,%3,%1\n\t" \ 678c2ecf20Sopenharmony_ci "add %5,%2,%0" \ 688c2ecf20Sopenharmony_ci : "=r" (wh), \ 698c2ecf20Sopenharmony_ci "=&r" (wl), \ 708c2ecf20Sopenharmony_ci "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \ 718c2ecf20Sopenharmony_ci : "r" ((UDItype)(u)), \ 728c2ecf20Sopenharmony_ci "r" ((UDItype)(v)) \ 738c2ecf20Sopenharmony_ci : "cc"); \ 748c2ecf20Sopenharmony_ci } while (0) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define udiv_qrnnd(q, r, n1, n0, d) \ 778c2ecf20Sopenharmony_ci do { \ 788c2ecf20Sopenharmony_ci UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \ 798c2ecf20Sopenharmony_ci __d1 = (d >> 32); \ 808c2ecf20Sopenharmony_ci __d0 = (USItype)d; \ 818c2ecf20Sopenharmony_ci \ 828c2ecf20Sopenharmony_ci __r1 = (n1) % __d1; \ 838c2ecf20Sopenharmony_ci __q1 = (n1) / __d1; \ 848c2ecf20Sopenharmony_ci __m = (UWtype) __q1 * __d0; \ 858c2ecf20Sopenharmony_ci __r1 = (__r1 << 32) | (n0 >> 32); \ 868c2ecf20Sopenharmony_ci if (__r1 < __m) \ 878c2ecf20Sopenharmony_ci { \ 888c2ecf20Sopenharmony_ci __q1--, __r1 += (d); \ 898c2ecf20Sopenharmony_ci if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */ \ 908c2ecf20Sopenharmony_ci if (__r1 < __m) \ 918c2ecf20Sopenharmony_ci __q1--, __r1 += (d); \ 928c2ecf20Sopenharmony_ci } \ 938c2ecf20Sopenharmony_ci __r1 -= __m; \ 948c2ecf20Sopenharmony_ci \ 958c2ecf20Sopenharmony_ci __r0 = __r1 % __d1; \ 968c2ecf20Sopenharmony_ci __q0 = __r1 / __d1; \ 978c2ecf20Sopenharmony_ci __m = (UWtype) __q0 * __d0; \ 988c2ecf20Sopenharmony_ci __r0 = (__r0 << 32) | ((USItype)n0); \ 998c2ecf20Sopenharmony_ci if (__r0 < __m) \ 1008c2ecf20Sopenharmony_ci { \ 1018c2ecf20Sopenharmony_ci __q0--, __r0 += (d); \ 1028c2ecf20Sopenharmony_ci if (__r0 >= (d)) \ 1038c2ecf20Sopenharmony_ci if (__r0 < __m) \ 1048c2ecf20Sopenharmony_ci __q0--, __r0 += (d); \ 1058c2ecf20Sopenharmony_ci } \ 1068c2ecf20Sopenharmony_ci __r0 -= __m; \ 1078c2ecf20Sopenharmony_ci \ 1088c2ecf20Sopenharmony_ci (q) = (UWtype) (__q1 << 32) | __q0; \ 1098c2ecf20Sopenharmony_ci (r) = __r0; \ 1108c2ecf20Sopenharmony_ci } while (0) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define UDIV_NEEDS_NORMALIZATION 1 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci#define abort() \ 1158c2ecf20Sopenharmony_ci return 0 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 1188c2ecf20Sopenharmony_ci#define __BYTE_ORDER __BIG_ENDIAN 1198c2ecf20Sopenharmony_ci#else 1208c2ecf20Sopenharmony_ci#define __BYTE_ORDER __LITTLE_ENDIAN 1218c2ecf20Sopenharmony_ci#endif 122