source: trunk/j/src/org/armedbear/lisp/ldb.lisp @ 6041

Last change on this file since 6041 was 6041, checked in by piso, 19 years ago

%LDB

File size: 1.6 KB
Line 
1;;; ldb.lisp
2;;;
3;;; Copyright (C) 2003-2004 Peter Graves
4;;; $Id: ldb.lisp,v 1.3 2004-02-28 18:40:08 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package "SYSTEM")
21
22(defun byte (size position)
23  (cons size position))
24
25(defun byte-size (bytespec)
26  (car bytespec))
27
28(defun byte-position (bytespec)
29  (cdr bytespec))
30
31;; For the LDB compiler macro.
32(defun %ldb (size position integer)
33  (logand (ash integer (- position))
34    (1- (ash 1 size))))
35
36(defun ldb (bytespec integer)
37  (logand (ash integer (- (byte-position bytespec)))
38          (1- (ash 1 (byte-size bytespec)))))
39
40(defun ldb-test (bytespec integer)
41  (not (zerop (ldb bytespec integer))))
42
43(defun dpb (newbyte bytespec integer)
44  (let* ((size (byte-size bytespec))
45         (position (byte-position bytespec))
46         (mask (1- (ash 1 size))))
47    (logior (logand integer (lognot (ash mask position)))
48      (ash (logand newbyte mask) position))))
Note: See TracBrowser for help on using the repository browser.