18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#include <linux/kernel.h> 38c2ecf20Sopenharmony_ci#include <linux/sched.h> 48c2ecf20Sopenharmony_ci#include <linux/types.h> 58c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ 88c2ecf20Sopenharmony_ci __asm__ ("addcc %r4,%5,%1\n\t" \ 98c2ecf20Sopenharmony_ci "addx %r2,%3,%0\n" \ 108c2ecf20Sopenharmony_ci : "=r" (sh), \ 118c2ecf20Sopenharmony_ci "=&r" (sl) \ 128c2ecf20Sopenharmony_ci : "%rJ" ((USItype)(ah)), \ 138c2ecf20Sopenharmony_ci "rI" ((USItype)(bh)), \ 148c2ecf20Sopenharmony_ci "%rJ" ((USItype)(al)), \ 158c2ecf20Sopenharmony_ci "rI" ((USItype)(bl)) \ 168c2ecf20Sopenharmony_ci : "cc") 178c2ecf20Sopenharmony_ci#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ 188c2ecf20Sopenharmony_ci __asm__ ("subcc %r4,%5,%1\n\t" \ 198c2ecf20Sopenharmony_ci "subx %r2,%3,%0\n" \ 208c2ecf20Sopenharmony_ci : "=r" (sh), \ 218c2ecf20Sopenharmony_ci "=&r" (sl) \ 228c2ecf20Sopenharmony_ci : "rJ" ((USItype)(ah)), \ 238c2ecf20Sopenharmony_ci "rI" ((USItype)(bh)), \ 248c2ecf20Sopenharmony_ci "rJ" ((USItype)(al)), \ 258c2ecf20Sopenharmony_ci "rI" ((USItype)(bl)) \ 268c2ecf20Sopenharmony_ci : "cc") 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define umul_ppmm(w1, w0, u, v) \ 298c2ecf20Sopenharmony_ci __asm__ ("! Inlined umul_ppmm\n\t" \ 308c2ecf20Sopenharmony_ci "wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n\t" \ 318c2ecf20Sopenharmony_ci "sra %3,31,%%g2 ! Don't move this insn\n\t" \ 328c2ecf20Sopenharmony_ci "and %2,%%g2,%%g2 ! Don't move this insn\n\t" \ 338c2ecf20Sopenharmony_ci "andcc %%g0,0,%%g1 ! Don't move this insn\n\t" \ 348c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 358c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 368c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 378c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 388c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 398c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 408c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 418c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 428c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 438c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 448c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 458c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 468c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 478c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 488c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 498c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 508c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 518c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 528c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 538c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 548c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 558c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 568c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 578c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 588c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 598c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 608c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 618c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 628c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 638c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 648c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 658c2ecf20Sopenharmony_ci "mulscc %%g1,%3,%%g1\n\t" \ 668c2ecf20Sopenharmony_ci "mulscc %%g1,0,%%g1\n\t" \ 678c2ecf20Sopenharmony_ci "add %%g1,%%g2,%0\n\t" \ 688c2ecf20Sopenharmony_ci "rd %%y,%1\n" \ 698c2ecf20Sopenharmony_ci : "=r" (w1), \ 708c2ecf20Sopenharmony_ci "=r" (w0) \ 718c2ecf20Sopenharmony_ci : "%rI" ((USItype)(u)), \ 728c2ecf20Sopenharmony_ci "r" ((USItype)(v)) \ 738c2ecf20Sopenharmony_ci : "%g1", "%g2", "cc") 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* It's quite necessary to add this much assembler for the sparc. 768c2ecf20Sopenharmony_ci The default udiv_qrnnd (in C) is more than 10 times slower! */ 778c2ecf20Sopenharmony_ci#define udiv_qrnnd(q, r, n1, n0, d) \ 788c2ecf20Sopenharmony_ci __asm__ ("! Inlined udiv_qrnnd\n\t" \ 798c2ecf20Sopenharmony_ci "mov 32,%%g1\n\t" \ 808c2ecf20Sopenharmony_ci "subcc %1,%2,%%g0\n\t" \ 818c2ecf20Sopenharmony_ci "1: bcs 5f\n\t" \ 828c2ecf20Sopenharmony_ci "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \ 838c2ecf20Sopenharmony_ci "sub %1,%2,%1 ! this kills msb of n\n\t" \ 848c2ecf20Sopenharmony_ci "addx %1,%1,%1 ! so this can't give carry\n\t" \ 858c2ecf20Sopenharmony_ci "subcc %%g1,1,%%g1\n\t" \ 868c2ecf20Sopenharmony_ci "2: bne 1b\n\t" \ 878c2ecf20Sopenharmony_ci "subcc %1,%2,%%g0\n\t" \ 888c2ecf20Sopenharmony_ci "bcs 3f\n\t" \ 898c2ecf20Sopenharmony_ci "addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n\t" \ 908c2ecf20Sopenharmony_ci "b 3f\n\t" \ 918c2ecf20Sopenharmony_ci "sub %1,%2,%1 ! this kills msb of n\n\t" \ 928c2ecf20Sopenharmony_ci "4: sub %1,%2,%1\n\t" \ 938c2ecf20Sopenharmony_ci "5: addxcc %1,%1,%1\n\t" \ 948c2ecf20Sopenharmony_ci "bcc 2b\n\t" \ 958c2ecf20Sopenharmony_ci "subcc %%g1,1,%%g1\n\t" \ 968c2ecf20Sopenharmony_ci "! Got carry from n. Subtract next step to cancel this carry.\n\t" \ 978c2ecf20Sopenharmony_ci "bne 4b\n\t" \ 988c2ecf20Sopenharmony_ci "addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n\t" \ 998c2ecf20Sopenharmony_ci "sub %1,%2,%1\n\t" \ 1008c2ecf20Sopenharmony_ci "3: xnor %0,0,%0\n\t" \ 1018c2ecf20Sopenharmony_ci "! End of inline udiv_qrnnd\n" \ 1028c2ecf20Sopenharmony_ci : "=&r" (q), \ 1038c2ecf20Sopenharmony_ci "=&r" (r) \ 1048c2ecf20Sopenharmony_ci : "r" ((USItype)(d)), \ 1058c2ecf20Sopenharmony_ci "1" ((USItype)(n1)), \ 1068c2ecf20Sopenharmony_ci "0" ((USItype)(n0)) : "%g1", "cc") 1078c2ecf20Sopenharmony_ci#define UDIV_NEEDS_NORMALIZATION 0 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#define abort() \ 1108c2ecf20Sopenharmony_ci return 0 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 1138c2ecf20Sopenharmony_ci#define __BYTE_ORDER __BIG_ENDIAN 1148c2ecf20Sopenharmony_ci#else 1158c2ecf20Sopenharmony_ci#define __BYTE_ORDER __LITTLE_ENDIAN 1168c2ecf20Sopenharmony_ci#endif 117