File: crc.l

package info (click to toggle)
picolisp 3.1.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,100 kB
  • sloc: ansic: 14,205; lisp: 795; makefile: 290; sh: 13
file content (49 lines) | stat: -rw-r--r-- 960 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 25may11abu
# (c) Software Lab. Alexander Burger

(if (== 64 64) (load "@lib/native.l") (from "/**/"))

(gcc "util" NIL
   (crc (Len Lst) "crc" 'I Len (cons NIL (cons Len) Lst)) )

int crc(int len, char *p) {
   int res, c, i;

   for (res = 0; --len >=0;) {
      c = *p++;
      for (i = 0; i < 8; ++i) {
         if ((c ^ res) & 1)
            res ^= 0x14002;  /* Polynom x**16 + x**15 + x**2 + 1 */
         c >>= 1,  res >>= 1;
      }
   }
   return res;
}

/**/


(ifn (== 64 64) (load "@lib/gcc.l") (from "/**/"))

(gcc "crc" NIL 'crc)

any crc(any ex) {
   any x;
   int len, res, c, i;

   len = evCnt(ex, x = cdr(ex));
   x = cdr(x),  x = EVAL(car(x));
   for (res = 0; --len >=0; x = cdr(x)) {
      c = (int)xCnt(ex,car(x));
      for (i = 0; i < 8; ++i) {
         if ((c ^ res) & 1)
            res ^= 0x14002;  /* Polynom x**16 + x**15 + x**2 + 1 */
         c >>= 1,  res >>= 1;
      }
   }
   return boxCnt(res);
}

/**/

# vi:et:ts=3:sw=3