4 // #include "basics.h" included later to avoid macro recursion for malloc
14 if (n == 0) return NULL;
15 p = (void*) malloc (n);
17 { fprintf (stderr,"Could not allocate %i bytes\n",n);
28 void *Realloc (void *p, int n)
30 { if (p == NULL) return Malloc (n);
31 if (n == 0) { Free(p); return NULL; }
32 p = (void*) realloc (p,n);
34 { fprintf (stderr,"Could not allocate %i bytes\n",n);
42 // bits needed to represent a number between 0 and n
52 // returns e[p..p+len-1], assuming len <= W
54 uint bitread (uint *e, uint p, uint len)
60 { if (p) answ |= (*(e+1)) << (W-p);
62 else { if (p+len > W) answ |= (*(e+1)) << (W-p);
69 // writes e[p..p+len-1] = s, len <= W
71 void bitwrite (register uint *e, register uint p,
72 register uint len, register uint s)
76 { *e |= (*e & ((1<<p)-1)) | (s << p);
79 *e = (*e & ~((1<<p)-1)) | (s >> (W-p));
81 else { if (p+len <= W)
82 { *e = (*e & ~(((1<<len)-1)<<p)) | (s << p);
85 *e = (*e & ((1<<p)-1)) | (s << p);
87 *e = (*e & ~((1<<len)-1)) | (s >> (W-p));
90 // writes e[p..p+len-1] = 0
92 void bitzero2 (register uint *e, register uint p,
106 *e &= ~(((1<<len)-1)<<p);