11.4Schristos/* $NetBSD: gmisc.c,v 1.4 2012/03/13 21:13:34 christos Exp $ */ 21.1Skleink 31.1Skleink/**************************************************************** 41.1Skleink 51.1SkleinkThe author of this software is David M. Gay. 61.1Skleink 71.1SkleinkCopyright (C) 1998 by Lucent Technologies 81.1SkleinkAll Rights Reserved 91.1Skleink 101.1SkleinkPermission to use, copy, modify, and distribute this software and 111.1Skleinkits documentation for any purpose and without fee is hereby 121.1Skleinkgranted, provided that the above copyright notice appear in all 131.1Skleinkcopies and that both that the copyright notice and this 141.1Skleinkpermission notice and warranty disclaimer appear in supporting 151.1Skleinkdocumentation, and that the name of Lucent or any of its entities 161.1Skleinknot be used in advertising or publicity pertaining to 171.1Skleinkdistribution of the software without specific, written prior 181.1Skleinkpermission. 191.1Skleink 201.1SkleinkLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 211.1SkleinkINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 221.1SkleinkIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 231.1SkleinkSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 241.1SkleinkWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 251.1SkleinkIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 261.1SkleinkARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 271.1SkleinkTHIS SOFTWARE. 281.1Skleink 291.1Skleink****************************************************************/ 301.1Skleink 311.1Skleink/* Please send bug reports to David M. Gay (dmg at acm dot org, 321.1Skleink * with " at " changed at "@" and " dot " changed to "."). */ 331.1Skleink 341.1Skleink#include "gdtoaimp.h" 351.1Skleink 361.1Skleink void 371.1Skleink#ifdef KR_headers 381.1Skleinkrshift(b, k) Bigint *b; int k; 391.1Skleink#else 401.1Skleinkrshift(Bigint *b, int k) 411.1Skleink#endif 421.1Skleink{ 431.1Skleink ULong *x, *x1, *xe, y; 441.1Skleink int n; 451.1Skleink 461.1Skleink x = x1 = b->x; 471.2Skleink n = (unsigned int)k >> kshift; 481.1Skleink if (n < b->wds) { 491.1Skleink xe = x + b->wds; 501.1Skleink x += n; 511.1Skleink if (k &= kmask) { 521.1Skleink n = ULbits - k; 531.1Skleink y = *x++ >> k; 541.1Skleink while(x < xe) { 551.1Skleink *x1++ = (y | (*x << n)) & ALL_ON; 561.1Skleink y = *x++ >> k; 571.1Skleink } 581.1Skleink if ((*x1 = y) !=0) 591.1Skleink x1++; 601.1Skleink } 611.1Skleink else 621.1Skleink while(x < xe) 631.1Skleink *x1++ = *x++; 641.1Skleink } 651.4Schristos 661.4Schristos ptrdiff_t td = x1 - b->x; 671.4Schristos _DIAGASSERT(__type_fit(int, td)); 681.4Schristos if ((b->wds = (int)td) == 0) 691.1Skleink b->x[0] = 0; 701.1Skleink } 711.1Skleink 721.1Skleink int 731.1Skleink#ifdef KR_headers 741.3Skleinktrailz(b) CONST Bigint *b; 751.1Skleink#else 761.3Skleinktrailz(CONST Bigint *b) 771.1Skleink#endif 781.1Skleink{ 791.3Skleink ULong L; 801.3Skleink CONST ULong *x, *xe; 811.1Skleink int n = 0; 821.1Skleink 831.1Skleink x = b->x; 841.1Skleink xe = x + b->wds; 851.1Skleink for(n = 0; x < xe && !*x; x++) 861.1Skleink n += ULbits; 871.1Skleink if (x < xe) { 881.1Skleink L = *x; 891.1Skleink n += lo0bits(&L); 901.1Skleink } 911.1Skleink return n; 921.1Skleink } 93