shifter.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. # include "FP_types.h"
  7. void
  8. b64_sft(e1,n)
  9. B64 *e1;
  10. int n;
  11. {
  12. if (n > 0) {
  13. if (n > 63) {
  14. e1->l_32 = 0;
  15. e1->h_32 = 0;
  16. return;
  17. }
  18. if (n >= 32) {
  19. e1->l_32 = e1->h_32;
  20. e1->h_32 = 0;
  21. n -= 32;
  22. }
  23. if (n > 0) {
  24. e1->l_32 >>= n;
  25. if (e1->h_32 != 0) {
  26. e1->l_32 |= (e1->h_32 << (32 - n));
  27. e1->h_32 >>= n;
  28. }
  29. }
  30. return;
  31. }
  32. n = -n;
  33. if (n > 0) {
  34. if (n > 63) {
  35. e1->l_32 = 0;
  36. e1->h_32 = 0;
  37. return;
  38. }
  39. if (n >= 32) {
  40. e1->h_32 = e1->l_32;
  41. e1->l_32 = 0;
  42. n -= 32;
  43. }
  44. if (n > 0) {
  45. e1->h_32 <<= n;
  46. if (e1->l_32 != 0) {
  47. e1->h_32 |= (e1->l_32 >> (32 - n));
  48. e1->l_32 <<= n;
  49. }
  50. }
  51. }
  52. }
  53. void
  54. b64_lsft(e1)
  55. B64 *e1;
  56. {
  57. /* shift left 1 bit */
  58. e1->h_32 <<= 1;
  59. if (e1->l_32 & 0x80000000L) e1->h_32 |= 1;
  60. e1->l_32 <<= 1;
  61. }
  62. void
  63. b64_rsft(e1)
  64. B64 *e1;
  65. {
  66. /* shift right 1 bit */
  67. e1->l_32 >>= 1;
  68. if (e1->h_32 & 1) e1->l_32 |= 0x80000000L;
  69. e1->h_32 >>= 1;
  70. }