Changeset 8559


Ignore:
Timestamp:
02/13/05 04:13:33 (16 years ago)
Author:
piso
Message:

BIT-NOT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/bit-array-ops.lisp

    r8556 r8559  
    22;;;
    33;;; Copyright (C) 2003-2005 Peter Graves
    4 ;;; $Id: bit-array-ops.lisp,v 1.4 2005-02-13 04:02:56 piso Exp $
     4;;; $Id: bit-array-ops.lisp,v 1.5 2005-02-13 04:13:33 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    4646     (require-same-dimensions bit-array-1 result-bit-array)
    4747     result-bit-array)))
    48 
    49 (defmacro def-bit-array-op (name function)
    50   `(defun ,name (bit-array-1 bit-array-2 &optional result-bit-array)
    51      ,(format nil
    52         "Perform a bit-wise ~A on the elements of BIT-ARRAY-1 and ~
    53                BIT-ARRAY-2,~%  putting the results in RESULT-BIT-ARRAY.  ~
    54                If RESULT-BIT-ARRAY is T,~%  BIT-ARRAY-1 is used.  If ~
    55                RESULT-BIT-ARRAY is NIL or omitted, a new array is~%  created.  ~
    56                All the arrays must have the same rank and dimensions."
    57         (symbol-name function))
    58      (require-same-dimensions bit-array-1 bit-array-2)
    59      (let ((result-bit-array (pick-result-array result-bit-array bit-array-1)))
    60        (dotimes (i (array-total-size result-bit-array) result-bit-array)
    61          (setf (row-major-aref result-bit-array i)
    62                (logand (,function (row-major-aref bit-array-1 i)
    63                                   (row-major-aref bit-array-2 i))
    64                        1))))))
    65 
    66 ;; (def-bit-array-op bit-and   logand)
    67 ;; (def-bit-array-op bit-ior   logior)
    68 ;; (def-bit-array-op bit-xor   logxor)
    69 ;; (def-bit-array-op bit-eqv   logeqv)
    70 ;; (def-bit-array-op bit-nand  lognand)
    71 ;; (def-bit-array-op bit-nor   lognor)
    72 ;; (def-bit-array-op bit-andc1 logandc1)
    73 ;; (def-bit-array-op bit-andc2 logandc2)
    74 ;; (def-bit-array-op bit-orc1  logorc1)
    75 ;; (def-bit-array-op bit-orc2  logorc2)
    7648
    7749(defun bit-and (bit-array-1 bit-array-2 &optional result-bit-array)
     
    203175
    204176(defun bit-not (bit-array &optional result-bit-array)
    205   "Performs a bit-wise logical NOT on the elements of BIT-ARRAY,
    206    putting the results in RESULT-BIT-ARRAY.  If RESULT-BIT-ARRAY is T,
    207    BIT-ARRAY is used.  If RESULT-BIT-ARRAY is NIL or omitted, a new array is
    208    created.  Both arrays must have the same rank and dimensions."
    209177  (let ((result-bit-array (pick-result-array result-bit-array bit-array)))
     178    (if (and (simple-bit-vector-p bit-array)
     179             (simple-bit-vector-p result-bit-array))
     180        (%simple-bit-vector-bit-not bit-array result-bit-array)
    210181    (dotimes (i (array-total-size result-bit-array) result-bit-array)
    211182      (setf (row-major-aref result-bit-array i)
    212             (logxor (row-major-aref bit-array i) 1)))))
     183            (logxor (row-major-aref bit-array i) 1))))))
Note: See TracChangeset for help on using the changeset viewer.