Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
#line 2 "../src/kernel/none/divll_pre.h"1/* Copyright (C) 2014 The PARI group.23This file is part of the PARI/GP package.45PARI/GP is free software; you can redistribute it and/or modify it under the6terms of the GNU General Public License as published by the Free Software7Foundation; either version 2 of the License, or (at your option) any later8version. It is distributed in the hope that it will be useful, but WITHOUT9ANY WARRANTY WHATSOEVER.1011Check the License for details. You should have received a copy of it, along12with the package; see the file 'COPYING'. If not, write to the Free Software13Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */1415#undef LOCAL_HIREMAINDER16extern ulong hiremainder;17#if defined(INLINE) && defined(__GNUC__) && !defined(DISABLE_INLINE)18#define LOCAL_HIREMAINDER register ulong hiremainder19#else20#define LOCAL_HIREMAINDER21#endif2223#if defined(INLINE) && defined(__GNUC__) && !defined(DISABLE_INLINE)24INLINE ulong /* precompute inverse of n */25get_Fl_red(ulong n)26{27LOCAL_HIREMAINDER;28n <<= bfffo(n);29hiremainder = ~n;30return divll(~0UL, n);31}32#else33INLINE ulong /* precompute inverse of n */34get_Fl_red(ulong n)35{36ulong q, oldhi = hiremainder;37n <<= bfffo(n);38hiremainder = ~n;39q = divll(~0UL, n);40hiremainder = oldhi;41return q;42}43#endif4445INLINE ulong /* requires u1 <= n, n normalised */46divll_pre_normalized(ulong u1, ulong u0, ulong n, ulong ninv, ulong *pt_r)47{48ulong q0, q1, r;49LOCAL_HIREMAINDER;50LOCAL_OVERFLOW;51q0 = mulll(ninv, u1); q1 = hiremainder;52q0 = addll(q0, u0);53q1 = addllx(q1+1, u1);54r = u0 - q1 * n;55if (r > q0)56{57r += n; q1--;58}59if (r >= n)60{61r -= n; q1++;62}63*pt_r = r; return q1;64}6566INLINE ulong /* requires u1 <= n, n normalised */67remll_pre_normalized(ulong u1, ulong u0, ulong n, ulong ninv)68{69ulong q0, q1, r;70LOCAL_HIREMAINDER;71LOCAL_OVERFLOW;72q0 = mulll(ninv, u1); q1 = hiremainder;73q0 = addll(q0, u0);74q1 = addllx(q1, u1);75r = u0 - (q1 + 1) * n;76if (r >= q0)77r += n;78return r < n ? r : r - n;79}8081INLINE ulong /* reduce <a_hi, a_lo> mod n */82remll_pre(ulong a_hi, ulong a_lo, ulong n, ulong ninv)83{84int norm = bfffo(n);85int bits = BITS_IN_LONG - norm;86ulong sn = n << norm;87if (a_hi >= n) /* reduce a_hi first */88{89const ulong u1 = norm ? a_hi >> bits : 0;90const ulong u0 = a_hi << norm;91a_hi = remll_pre_normalized(u1, u0, sn, ninv) >> norm;92}93/* now reduce <a_hi, a_lo> */94{95const ulong u1 = ((a_hi << norm) | (norm ? a_lo >> bits: 0));96const ulong u0 = a_lo << norm;97return remll_pre_normalized(u1, u0, sn, ninv) >> norm;98}99}100101#if !defined(INLINE)102extern ulong divll_pre(ulong a_lo, ulong n, ulong ninv);103#else104105#if defined(__GNUC__) && !defined(DISABLE_INLINE)106#define divll_pre(a, n, ninv) \107__extension__ ({ \108ulong __a = (a); \109ulong __n = (n); \110int norm = bfffo(__n); \111int bits = BITS_IN_LONG - norm; \112ulong r, sn = __n << norm; \113const ulong u1 = ((hiremainder << norm) | (norm ? __a >> bits: 0)); \114const ulong u0 = __a << norm; \115const ulong q = divll_pre_normalized(u1, u0, sn, ninv, &r); \116hiremainder = r>>norm; q; \117})118119#else /* __GNUC__ */120INLINE ulong121divll_pre(ulong a_lo, ulong n, ulong ninv)122{123int norm = bfffo(n);124int bits = BITS_IN_LONG - norm;125ulong r, sn = n << norm;126const ulong u1 = ((hiremainder << norm) | (norm ? a_lo >> bits: 0));127const ulong u0 = a_lo << norm;128const ulong q = divll_pre_normalized(u1, u0, sn, ninv, &r);129hiremainder = r>>norm; return q;130}131#endif /* __GNUC__ */132133#endif134135136