1112158Sdas/**************************************************************** 2112158Sdas 3112158SdasThe author of this software is David M. Gay. 4112158Sdas 5112158SdasCopyright (C) 1998 by Lucent Technologies 6112158SdasAll Rights Reserved 7112158Sdas 8112158SdasPermission to use, copy, modify, and distribute this software and 9112158Sdasits documentation for any purpose and without fee is hereby 10112158Sdasgranted, provided that the above copyright notice appear in all 11112158Sdascopies and that both that the copyright notice and this 12112158Sdaspermission notice and warranty disclaimer appear in supporting 13112158Sdasdocumentation, and that the name of Lucent or any of its entities 14112158Sdasnot be used in advertising or publicity pertaining to 15112158Sdasdistribution of the software without specific, written prior 16112158Sdaspermission. 17112158Sdas 18112158SdasLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 19112158SdasINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 20112158SdasIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 21112158SdasSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22112158SdasWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 23112158SdasIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 24112158SdasARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 25112158SdasTHIS SOFTWARE. 26112158Sdas 27112158Sdas****************************************************************/ 28112158Sdas 29165743Sdas/* Please send bug reports to David M. Gay (dmg at acm dot org, 30165743Sdas * with " at " changed at "@" and " dot " changed to "."). */ 31112158Sdas 32112158Sdas#include "gdtoaimp.h" 33112158Sdas 34112158Sdas void 35112158Sdas#ifdef KR_headers 36112158Sdasrshift(b, k) Bigint *b; int k; 37112158Sdas#else 38112158Sdasrshift(Bigint *b, int k) 39112158Sdas#endif 40112158Sdas{ 41112158Sdas ULong *x, *x1, *xe, y; 42112158Sdas int n; 43112158Sdas 44112158Sdas x = x1 = b->x; 45112158Sdas n = k >> kshift; 46112158Sdas if (n < b->wds) { 47112158Sdas xe = x + b->wds; 48112158Sdas x += n; 49112158Sdas if (k &= kmask) { 50112158Sdas n = ULbits - k; 51112158Sdas y = *x++ >> k; 52112158Sdas while(x < xe) { 53112158Sdas *x1++ = (y | (*x << n)) & ALL_ON; 54112158Sdas y = *x++ >> k; 55112158Sdas } 56112158Sdas if ((*x1 = y) !=0) 57112158Sdas x1++; 58112158Sdas } 59112158Sdas else 60112158Sdas while(x < xe) 61112158Sdas *x1++ = *x++; 62112158Sdas } 63112158Sdas if ((b->wds = x1 - b->x) == 0) 64112158Sdas b->x[0] = 0; 65112158Sdas } 66112158Sdas 67112158Sdas int 68112158Sdas#ifdef KR_headers 69112158Sdastrailz(b) Bigint *b; 70112158Sdas#else 71112158Sdastrailz(Bigint *b) 72112158Sdas#endif 73112158Sdas{ 74112158Sdas ULong L, *x, *xe; 75112158Sdas int n = 0; 76112158Sdas 77112158Sdas x = b->x; 78112158Sdas xe = x + b->wds; 79112158Sdas for(n = 0; x < xe && !*x; x++) 80112158Sdas n += ULbits; 81112158Sdas if (x < xe) { 82112158Sdas L = *x; 83112158Sdas n += lo0bits(&L); 84112158Sdas } 85112158Sdas return n; 86112158Sdas } 87