Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
#line 2 "../src/kernel/none/mulll.h"1/* Copyright (C) 2000 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_HIREMAINDER16#define LOCAL_HIREMAINDER17extern ulong hiremainder;1819/* Version Peter Montgomery */20/*21* Assume (for presentation) that BITS_IN_LONG = 32.22* Then 0 <= xhi, xlo, yhi, ylo <= 2^16 - 1. Hence23*24* -2^31 + 2^16 <= (xhi-2^15)*(ylo-2^15) + (xlo-2^15)*(yhi-2^15) <= 2^31.25*26* If xhi*ylo + xlo*yhi = 2^32*overflow + xymid, then27*28* -2^32 + 2^16 <= 2^32*overflow + xymid - 2^15*(xhi + ylo + xlo + yhi) <= 0.29*30* 2^16*overflow <= (xhi+xlo+yhi+ylo)/2 - xymid/2^16 <= 2^16*overflow + 2^16-131*32* This inequality was derived using exact (rational) arithmetic;33* it remains valid when we truncate the two middle terms.34*/3536#if !defined(INLINE)37extern long mulll(ulong x, ulong y);38extern long addmul(ulong x, ulong y);39#else4041#if defined(__GNUC__) && !defined(DISABLE_INLINE)42#undef LOCAL_HIREMAINDER43#define LOCAL_HIREMAINDER register ulong hiremainder4445#define mulll(x, y) \46__extension__ ({ \47const ulong __x = (x), __y = (y);\48const ulong __xlo = LOWWORD(__x), __xhi = HIGHWORD(__x); \49const ulong __ylo = LOWWORD(__y), __yhi = HIGHWORD(__y); \50ulong __xylo,__xymid,__xyhi,__xymidhi,__xymidlo; \51ulong __xhl,__yhl; \52\53__xylo = __xlo*__ylo; __xyhi = __xhi*__yhi; \54__xhl = __xhi+__xlo; __yhl = __yhi+__ylo; \55__xymid = __xhl*__yhl - (__xyhi+__xylo); \56\57__xymidhi = HIGHWORD(__xymid); \58__xymidlo = __xymid << BITS_IN_HALFULONG; \59\60__xylo += __xymidlo; \61hiremainder = __xyhi + __xymidhi + (__xylo < __xymidlo) \62+ ((((__xhl + __yhl) >> 1) - __xymidhi) & HIGHMASK); \63\64__xylo; \65})6667#define addmul(x, y) \68__extension__ ({ \69const ulong __x = (x), __y = (y);\70const ulong __xlo = LOWWORD(__x), __xhi = HIGHWORD(__x); \71const ulong __ylo = LOWWORD(__y), __yhi = HIGHWORD(__y); \72ulong __xylo,__xymid,__xyhi,__xymidhi,__xymidlo; \73ulong __xhl,__yhl; \74\75__xylo = __xlo*__ylo; __xyhi = __xhi*__yhi; \76__xhl = __xhi+__xlo; __yhl = __yhi+__ylo; \77__xymid = __xhl*__yhl - (__xyhi+__xylo); \78\79__xylo += hiremainder; __xyhi += (__xylo < hiremainder); \80\81__xymidhi = HIGHWORD(__xymid); \82__xymidlo = __xymid << BITS_IN_HALFULONG; \83\84__xylo += __xymidlo; \85hiremainder = __xyhi + __xymidhi + (__xylo < __xymidlo) \86+ ((((__xhl + __yhl) >> 1) - __xymidhi) & HIGHMASK); \87\88__xylo; \89})9091#else9293INLINE long94mulll(ulong x, ulong y)95{96const ulong xlo = LOWWORD(x), xhi = HIGHWORD(x);97const ulong ylo = LOWWORD(y), yhi = HIGHWORD(y);98ulong xylo,xymid,xyhi,xymidhi,xymidlo;99ulong xhl,yhl;100101xylo = xlo*ylo; xyhi = xhi*yhi;102xhl = xhi+xlo; yhl = yhi+ylo;103xymid = xhl*yhl - (xyhi+xylo);104105xymidhi = HIGHWORD(xymid);106xymidlo = xymid << BITS_IN_HALFULONG;107108xylo += xymidlo;109hiremainder = xyhi + xymidhi + (xylo < xymidlo)110+ ((((xhl + yhl) >> 1) - xymidhi) & HIGHMASK);111112return xylo;113}114115INLINE long116addmul(ulong x, ulong y)117{118const ulong xlo = LOWWORD(x), xhi = HIGHWORD(x);119const ulong ylo = LOWWORD(y), yhi = HIGHWORD(y);120ulong xylo,xymid,xyhi,xymidhi,xymidlo;121ulong xhl,yhl;122123xylo = xlo*ylo; xyhi = xhi*yhi;124xhl = xhi+xlo; yhl = yhi+ylo;125xymid = xhl*yhl - (xyhi+xylo);126127xylo += hiremainder; xyhi += (xylo < hiremainder);128129xymidhi = HIGHWORD(xymid);130xymidlo = xymid << BITS_IN_HALFULONG;131132xylo += xymidlo;133hiremainder = xyhi + xymidhi + (xylo < xymidlo)134+ ((((xhl + yhl) >> 1) - xymidhi) & HIGHMASK);135136return xylo;137}138#endif139140#endif141142143