Pristine Ack-5.5
[Ack-5.5.git] / modules / src / em_opt / aux.c
1 #ifndef NORCSID
2 static char rcsid4[] = "$Id: aux.c,v 2.6 1994/06/24 11:14:01 ceriel Exp $";
3 #endif
4
5 #include "nopt.h"
6
7 arith
8 OO_rotate(w,amount)
9         arith w, amount;
10 {
11         long highmask, lowmask;
12         highmask = (long)(-1) << amount;
13         lowmask = ~highmask;
14         if(OO_WSIZE!=4)
15                 highmask &= (OO_WSIZE==2)?0xFFFF:0xFF;
16         return(((w<<amount)&highmask) | ((w >> (8*OO_WSIZE-amount))&lowmask));
17 }
18
19 int
20 OO_signsame(a,b)
21         arith a, b;
22 {
23         return( (a ^ b) >= 0);
24 }
25
26 int
27 OO_sfit(val,nbits)
28         arith val, nbits;
29 {
30         register long mask = ~((1L << (nbits - 1)) - 1);
31         return(((val&mask) == 0) | (val&mask)==mask);
32 }
33
34 int
35 OO_ufit(val, nbits)
36         arith val, nbits;
37 {
38         return((val&(~((1L << (nbits - 1)) - 1))) == 0);
39 }
40
41 int
42 OO_extsame(a1,a2)
43         register p_instr a1, a2;
44 {
45         if (a1->em_argtype != a2->em_argtype)
46                 return(0);
47         switch(a1->em_argtype) {
48         case cst_ptyp:
49                 return (a1->em_cst == a2->em_cst);
50         case sof_ptyp:
51                 if(a1->em_off != a2->em_off)
52                         return(0);
53                 return (strcmp(a1->em_dnam,a2->em_dnam)==0);
54         case nof_ptyp:
55                 if (a1->em_off != a2->em_off)
56                         return(0);
57                 return (a1->em_dlb == a2->em_dlb);
58         default:
59                 fatal("illegal type (%d) to sameext!",a1->em_argtype);
60                 /*NOTREACHED*/
61         }
62 }
63
64 int
65 OO_namsame(a1,a2)
66         register p_instr a1, a2;
67 {
68         if (a1->em_argtype != a2->em_argtype)
69                 return(0);
70         switch(a1->em_argtype) {
71         case cst_ptyp:
72                 return 1;
73         case sof_ptyp:
74                 return (strcmp(a1->em_dnam,a2->em_dnam)==0);
75         case nof_ptyp:
76                 return (a1->em_dlb == a2->em_dlb);
77         default:
78                 fatal("illegal type (%d) to samenam!",a1->em_argtype);
79                 /*NOTREACHED*/
80         }
81 }
82
83 arith
84 OO_offset(a)
85         register p_instr a;
86 {
87         switch(a->em_argtype) {
88         case cst_ptyp:
89                 return a->em_cst;
90         case sof_ptyp:
91                 return a->em_off;
92         case nof_ptyp:
93                 return a->em_off;
94         default:
95                 fatal("illegal type (%d) to offset!",a->em_argtype);
96                 /*NOTREACHED*/
97         }
98 }