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

Subversion Repositories core_arm

[/] [core_arm/] [trunk/] [soft/] [cdef/] [cdef_lib_g1.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_g1.el: Some bit grouping functions
3
;-----------------------------------------------------------------------
4
 
5
 
6
(defun make-setbit-groups-rec (a)
7
   (if (> (length a) 0)
8
      (let ((n (count-bits a))
9
            (e (nth 0 a)))
10
        (append (make-setbit-groups-rec (nthcdr n a)) `(,(make-list n e)))
11
      )
12
      '()
13
   )
14
)
15
 
16
;a:      (1 1 1 0 0 1 1 0 0)
17
;result: ((1 1 1) (0 0) (1 1) (0 0))
18
;(make-setbit-groups-rec '(1 1 1 0 0 1 1 0 0))
19
(defun make-setbit-groups (a)
20
   "Raise the consecutive 1s"
21
   (reverse (make-setbit-groups-rec a)))
22
 
23
 
24
;-----------------------------------------------------------------------
25
 
26
;l:        (0  0  0  0  0)
27
;p1:     1     x
28
;p2:     3         |<x
29
;result:  ((0)(1  1)( 0 0))
30
;(or-split-setbit-copy-list '(0  0  0  0  0) 1 3)
31
 
32
(defun or-split-setbit-copy-list (l p1 p2 )
33
  "Splits list between [p1,p2]  and fill [p1,p2] with ones"
34
  (let
35
      ((r l)
36
       (size (length l)))
37
    (if (and (in-bound-p 1 size p1)(in-bound-p 1 size p2))  ; split into 3
38
        (
39
          `( ( ,(cut-copy-list l 0 p1) ) ( ,(make-list (- p2 p1) 1) ) ( ,(cut-copy-list l p2 size)))
40
         )
41
        (if (in-bound-p 1 size p1)                          ; split into 2
42
           (
43
            `( ( ,(cut-copy-list l 0 p1) ) ( ,(make-list (- size p1) 1) ) )
44
            )
45
           (if (in-bound-p 1 size p2)                       ; split into 2
46
               (
47
                `( ( ,(make-list p2 1) ) (  ,(cut-copy-list l p2 size) ) )
48
               )
49
               (if (and (<= p1 0) (>= p2 size))
50
                   `( ,(make-list size 1) )
51
                   `( ,l);                                       ; do not split
52
               )
53
           )
54
        )
55
    )
56
    ))
57
 
58
 
59
;l:      ((1  1  1)(0  0)(1  1))
60
;off:  2         x
61
;elt: (x x)
62
;result: ((1  1)(1)(1)(0)(1  1))
63
;(or-setbit-groups-into '((1  1  1)(0  0)(1  1)) 2 '(0 0))
64
 
65
(defun or-setbit-groups-into (l off elt)
66
  "Insert splitting range element <elt> into list <l> at offset <off>"
67
  (let ((cur 0)
68
        (start off)
69
        (end (+ off (length elt)))
70
        (v '())
71
        )
72
    (dolist (e (mapcar (function (lambda (x)
73
      (let ((curstart cur)
74
            (curend (+ cur (length x))))
75
        (setq cur curend)
76
        (or-split-setbit-copy-list x (- start curstart) (- end curstart)
77
            )))) l )
78
     v)
79
      (setq v (append v e))
80
      )
81
))
82
 
83
 
84
;a:      ((1  1  1)(0  0)(1  1))
85
;b:      ((0)(1  1  1)(0  0)(1))
86
;result: ((1)(1  1)(1)(0)(1)(1))
87
;(or-setbit-groups '((1  1  1)(0  0)(1  1)) '((0)(1  1  1)(0  0)(1)))
88
 
89
(defun or-setbit-groups (a b)
90
  "Split and or 2 raised setbit groups using '1"
91
  (let ((value a)
92
        (off 0)
93
        )
94
    (dolist (elt b value)
95
      (if (eq (nth 0 elt) 1)
96
          (setq value (or-setbit-groups-into value off elt))
97
      )
98
      (setq off (+ off (length elt)))
99
      )))
100
 
101
;-----------------------------------------------------------------------
102
 
103
;l:      ((1  1  1)(0  0)(1  1))
104
;off:  2         x
105
;elt: (x x)
106
;result: ((1  1)(1)(1)(0)(1  1))
107
;(and-setbit-groups-into '((1  1  1)(0  0)(1  1)) 2 '(0 0))
108
 
109
(defun and-setbit-groups-into (l off elt)
110
  "Insert splitting range element <elt> into list <l> at offset <off>"
111
  (let ((cur 0)
112
        (start off)
113
        (end (+ off (length elt)))
114
        (v '())
115
        )
116
    (dolist (e (mapcar (function (lambda (x)
117
      (let ((curstart cur)
118
            (curend (+ cur (length x))))
119
        (setq cur curend)
120
        (and-split-setbit-copy-list x (- start curstart) (- end curstart)
121
            )))) l )
122
     v)
123
      (setq v (append v e))
124
      )
125
))
126
 
127
;l:        (1  1  1  1  1)
128
;p1:     1     x
129
;p2:     3         |<x
130
;result:  ((1)(0  0)( 1 1))
131
;(and-split-setbit-copy-list '(1 1 1 1 1) 1 3)
132
 
133
(defun and-split-setbit-copy-list (l p1 p2 )
134
  "Splits list between [p1,p2]  and fill [p1,p2] with ones"
135
  (let
136
      ((r l)
137
       (size (length l)))
138
    (if (and (in-bound-p 1 size p1)(in-bound-p 1 size p2))  ; split into 3
139
        (
140
          `( ( ,(cut-copy-list l 0 p1) ) ( ,(make-list (- p2 p1) 0) ) ( ,(cut-copy-list l p2 size)))
141
         )
142
        (if (in-bound-p 1 size p1)                          ; split into 2
143
           (
144
            `( ( ,(cut-copy-list l 0 p1) ) ( ,(make-list (- size p1) 0) ) )
145
            )
146
           (if (in-bound-p 1 size p2)                       ; split into 2
147
               (
148
                `( ( ,(make-list p2 0) ) (  ,(cut-copy-list l p2 size) ) )
149
               )
150
               (if (and (<= p1 0) (>= p2 size))
151
                   `( ,(make-list size 0) )
152
                   `( ,l);                                       ; do not split
153
               )
154
           )
155
        )
156
    )
157
    ))
158
 
159
;a:      ((1  1  1)(0  0)(1  1))
160
;b:      ((0)(1  1  1)(0  0)(1))
161
;result: ((0)(1  1)(0)(0)(0)(1))
162
;(and-setbit-groups '((1  1  1)(1  0)(1  1)) '((0  0 0)( 0 0 0)(0)))
163
 
164
(defun and-setbit-groups (a b)
165
  "Split and or 2 raised setbit groups using '0"
166
  (let ((value a)
167
        (off 0)
168
        )
169
    (dolist (elt b value)
170
      (if (eq (nth 0 elt) 0)
171
          (setq value (and-setbit-groups-into value off elt))
172
      )
173
      (setq off (+ off (length elt)))
174
      )))
175
 
176
;-----------------------------------------------------------------------
177
 
178
; l:             ((1)(1  1)(1)(0 0 0))
179
; (f start end): (f 0 1) (f 1 3) (f 3 4)
180
;(defun func1 (start end)
181
;   `(,start ,end)
182
;)
183
;(mapcar-setbit 'func1 '((1)(1  1)(1)(0 0 0)))
184
 
185
(defun mapcar-setbit (f finest i)
186
  ;call func <(f start end i)> for every setbit part
187
  (if (not (memq 'nil finest))
188
      (let ((off 0))
189
        ( mapcar (function (lambda (x)
190
             (let ((cur off))
191
               (setq off (+ off (length x)))
192
               (if (eq (nth 0 x) 1)
193
                   (funcall f cur (+ cur (length x)) i))))) finest ))))

powered by: WebSVN 2.1.0

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