OpenCores
URL https://opencores.org/ocsvn/core_arm/core_arm/trunk

Subversion Repositories core_arm

[/] [core_arm/] [trunk/] [soft/] [cdef/] [cdef_lib_b1.el] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tarookumic
; Konrad Eisele <eiselekd@web.de>
2
; cdef_lib_b1.el: Some Bitvector functions
3
;-----------------------------------------------------------------------
4
 
5
(defun mapcar* (function &rest args)
6
  "Apply FUNCTION to successive cars of all ARGS. Return the list of results."
7
  ;; If no list is exhausted,
8
  (if (not (memq 'nil args))
9
      ;; apply function to CARs.
10
      (cons (apply function (mapcar 'car args))
11
            (apply 'mapcar* function
12
                   ;; Recurse for rest of elements.
13
                   (mapcar 'cdr args)))))
14
 
15
 
16
(defun isundef-p (e)
17
  (not (or (eq e 0) (eq e 1))))
18
 
19
(defun and-bit (l)
20
  "And bit using undef values"
21
  (if (and (eq (nth 0 l) '1) (eq (nth 1 l) '1))
22
    '1
23
    (if (or (isundef-p (nth 0 l)) (isundef-p (nth 1 l)))
24
      'U
25
      '0
26
    )
27
  )
28
)
29
 
30
(defun or-bit (l)
31
  "And bit using undef values"
32
  (if (and (eq (nth 0 l) '0) (eq (nth 1 l) '0))
33
    '0
34
    (if (or (isundef-p (nth 0 l)) (isundef-p (nth 1 l)))
35
      'U
36
      '1
37
    )
38
  )
39
)
40
 
41
(defun make-undef-bit (l)
42
  "Undef values on l[1] == 0"
43
  (if (eq (nth 1 l) '1)
44
    (nth 0 l)
45
    'U
46
  )
47
)
48
 
49
(defun make-isundef-bit (b)
50
  "1 if not undef"
51
  (if (isundef-p b)
52
    '0
53
    '1
54
  )
55
)
56
 
57
 
58
(defun and-bitstring (a b)
59
  "And bitstring"
60
  (mapcar 'and-bit (mapcar* 'list a b))
61
)
62
 
63
(defun or-bitstring (a b)
64
  "Or bitstring"
65
  (mapcar 'or-bit (mapcar* 'list a b))
66
)
67
 
68
(defun make-undef-bitstring (a u)
69
  "Set undefined value where u == 0"
70
  (mapcar 'make-undef-bit (mapcar* 'list a u))
71
)
72
 
73
(defun make-set-bitstring (a)
74
  "Make maskestring where not undefined"
75
  (mapcar 'make-isundef-bit a)
76
)
77
 
78
(defun count-bits (a)
79
  "Count n equal bits from start"
80
  (let ((e (pop a))
81
        (n 1))
82
    (if (eq e '())
83
      (setq n 0)
84
      (while (eq e (nth 0 a))
85
         (pop a)
86
         (setq n (+ n 1))
87
      )
88
    )
89
    `,n
90
  )
91
)
92
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.