Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
#line 2 "../src/kernel/none/divll.h"1/* Copyright (C) 2003 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/* This file originally adapted from gmp-3.1.1 (from T. Granlund), files16* longlong.h and gmp-impl.h1718Copyright (C) 2000 Free Software Foundation, Inc. */1920#undef LOCAL_HIREMAINDER21#define LOCAL_HIREMAINDER22extern ulong hiremainder;2324#if !defined(INLINE)25extern long divll(ulong x, ulong y);26#else2728#define __GLUE(hi, lo) (((hi) << BITS_IN_HALFULONG) | (lo))29#define __SPLIT(a, b, c) b = HIGHWORD(a); c = LOWWORD(a)30#define __LDIV(a, b, q, r) q = a / b; r = a - q*b31extern ulong hiremainder;3233/* divide (hiremainder * 2^BITS_IN_LONG + n0) by d; assume hiremainder < d.34* Return quotient, set hiremainder to remainder */3536#if defined(__GNUC__) && !defined(DISABLE_INLINE)37#undef LOCAL_HIREMAINDER38#define LOCAL_HIREMAINDER register ulong hiremainder3940#define divll(n0, d) \41__extension__ ({ \42ulong __d1, __d0, __q1, __q0, __r1, __r0, __m, __n1, __n0; \43ulong __k, __d; \44\45__n1 = hiremainder; __n0 = n0; __d = d; \46if (__n1 == 0) \47{ /* Only one division needed */ \48__LDIV(__n0, __d, __q1, hiremainder); \49} \50else if (__d < LOWMASK) \51{ /* Two half-word divisions */ \52__n1 = __GLUE(__n1, HIGHWORD(__n0)); \53__LDIV(__n1, __d, __q1, __r1); \54__n1 = __GLUE(__r1, LOWWORD(__n0)); \55__LDIV(__n1, __d, __q0, hiremainder); \56__q1 = __GLUE(__q1, __q0); \57} \58else \59{ /* General case */ \60if (__d & HIGHBIT) \61{ \62__k = 0; __SPLIT(__d, __d1, __d0); \63} \64else \65{ \66__k = bfffo(__d); \67__n1 = (__n1 << __k) | (__n0 >> (BITS_IN_LONG - __k)); \68__n0 <<= __k; \69__d = __d << __k; __SPLIT(__d, __d1, __d0); \70} \71__LDIV(__n1, __d1, __q1, __r1); \72__m = __q1 * __d0; \73__r1 = __GLUE(__r1, HIGHWORD(__n0)); \74if (__r1 < __m) \75{ \76__q1--, __r1 += __d; \77if (__r1 >= __d) /* we didn't get carry when adding to __r1 */ \78if (__r1 < __m) __q1--, __r1 += __d; \79} \80__r1 -= __m; \81__LDIV(__r1, __d1, __q0, __r0); \82__m = __q0 * __d0; \83__r0 = __GLUE(__r0, LOWWORD(__n0)); \84if (__r0 < __m) \85{ \86__q0--, __r0 += __d; \87if (__r0 >= __d) \88if (__r0 < __m) __q0--, __r0 += __d; \89} \90hiremainder = (__r0 - __m) >> __k; \91__q1 = __GLUE(__q1, __q0); \92} \93__q1; \94})9596#else /* __GNUC__ */9798INLINE long99divll(ulong n0, ulong d)100{101ulong __d1, __d0, __q1, __q0, __r1, __r0, __m, __n1, __n0;102ulong __k, __d;103104__n1 = hiremainder; __n0 = n0; __d = d;105106if (__n1 == 0)107{ /* Only one division needed */108__LDIV(__n0, __d, __q1, hiremainder);109}110else if (__d < LOWMASK)111{ /* Two half-word divisions */112__n1 = __GLUE(__n1, HIGHWORD(__n0));113__LDIV(__n1, __d, __q1, __r1);114__n1 = __GLUE(__r1, LOWWORD(__n0));115__LDIV(__n1, __d, __q0, hiremainder);116__q1 = __GLUE(__q1, __q0);117}118else119{ /* General case */120if (__d & HIGHBIT)121{122__k = 0; __SPLIT(__d, __d1, __d0);123}124else125{126__k = bfffo(__d);127__n1 = (__n1 << __k) | (__n0 >> (BITS_IN_LONG - __k));128__n0 = __n0 << __k;129__d = __d << __k; __SPLIT(__d, __d1, __d0);130}131__LDIV(__n1, __d1, __q1, __r1);132__m = __q1 * __d0;133__r1 = __GLUE(__r1, HIGHWORD(__n0));134if (__r1 < __m)135{136__q1--, __r1 += __d;137if (__r1 >= __d) /* we didn't get carry when adding to __r1 */138if (__r1 < __m) __q1--, __r1 += __d;139}140__r1 -= __m;141__LDIV(__r1, __d1, __q0, __r0);142__m = __q0 * __d0;143__r0 = __GLUE(__r0, LOWWORD(__n0));144if (__r0 < __m)145{146__q0--, __r0 += __d;147if (__r0 >= __d)148if (__r0 < __m) __q0--, __r0 += __d;149}150hiremainder = (__r0 - __m) >> __k;151__q1 = __GLUE(__q1, __q0);152}153return __q1;154}155156#endif /* __GNUC__ */157158#endif159160161