Pristine Ack-5.5
[Ack-5.5.git] / mach / proto / fp / shifter.c
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
6 /* $Id: shifter.c,v 1.7 1994/06/24 13:32:49 ceriel Exp $ */
7
8 # include "FP_types.h"
9
10 void
11 b64_sft(e1,n)
12 B64     *e1;
13 int     n;
14 {
15         if (n > 0) {
16                 if (n > 63) {
17                         e1->l_32 = 0;
18                         e1->h_32 = 0;
19                         return;
20                 }
21                 if (n >= 32) {
22                         e1->l_32 = e1->h_32;
23                         e1->h_32 = 0;
24                         n -= 32;
25                 }
26                 if (n > 0) {
27                         e1->l_32 >>= n;
28                         if (e1->h_32 != 0) {
29                                 e1->l_32 |= (e1->h_32 << (32 - n));
30                                 e1->h_32 >>= n;
31                         }
32                 }
33                 return;
34         }
35         n = -n;
36         if (n > 0) {
37                 if (n > 63) {
38                         e1->l_32 = 0;
39                         e1->h_32 = 0;
40                         return;
41                 }
42                 if (n >= 32) {
43                         e1->h_32 = e1->l_32;
44                         e1->l_32 = 0;
45                         n -= 32;
46                 }
47                 if (n > 0) {
48                         e1->h_32 <<= n;
49                         if (e1->l_32 != 0) {
50                                 e1->h_32 |= (e1->l_32 >> (32 - n));
51                                 e1->l_32 <<= n;
52                         }
53                 }
54         }
55 }
56
57 void
58 b64_lsft(e1)
59 B64     *e1;
60 {
61         /*      shift left 1 bit */
62         e1->h_32 <<= 1;
63         if (e1->l_32 & 0x80000000L) e1->h_32 |= 1;
64         e1->l_32 <<= 1;
65 }
66
67 void
68 b64_rsft(e1)
69 B64     *e1;
70 {
71         /*      shift right 1 bit */
72         e1->l_32 >>= 1;
73         if (e1->h_32 & 1) e1->l_32 |= 0x80000000L;
74         e1->h_32 >>= 1;
75 }