Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the bit-ops Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 03:16:51 2022 GMT+0.
Next: Systems, Previous: The bit-ops Reference Manual, Up: The bit-ops Reference Manual [Contents][Index]
In the modern Common Lisp implementations, bit-vector operation functions such as bit-and
are compiled into word-size iterations where 32 or 64 bits are processed at once. However, it requires a careful handling when multiple operations are combined, e.g. for avoiding the generation of intermediate vectors by destructively modifying the existing vectors. For example,
(bit-and a (bit-and b c))
causes consing since the intermediate value (bit-and b c)
is generated on the heap. This library addresses this problem as well as the scarsity of useful bit-vector functions in ANSI CL.
This section provides a review of related libraries, which I believe is important for alleviating choise paralysis.
BIT-SMASHER provides functions for converting bit-vector to/from integers, octets and hex strings. BIT-OPS does not have such conversion functions. BIT-SMASHER also provides functions for arithmetic, such as addition, subtraction, shifting. However, note that those operations are not always optimized and runs bitvec->integer->bitvec conversion each time, with possibly consing.
BITFIELD-SCHEMA provides several functions analogous to DPB and LPB for integers (GET/PUT-INTEGER). It also provides a DSL for writing accessors to bit-vectors (ala union type in C).
Example from the doc:
(defbitfield-schema tree-node (:offset offt)
(disabled-p :width 1)
(values :width 16 :count 10)
(left-child :width 24)
(right-child :width 7))
BINARY-TYPES provides DEFINE-BITFIELD
and
DEFINE-BINARY-CLASS
whose role is similar to BITFIELD-SCHEMA
, but is for
parsing machine integers, not bit-vectors.
TRIVIAL-BIT-STREAMS
provides a buffered stream of bits. NIBBLES
provides optimized access to octet vectors, especially on SBCL by defining
several SSE VOP operations.
Compute bitwise operations using bit vector arithmetic.
BODY
accepts a single form.
Within BODY
, one can use variables holding bit-vectors as arguments to
bitwise operations, as well as constants 0 and 1, which maps to the bit vector filled with
0 or 1, respectively.
All bit-vectors that are involved in bitwise operations should be of the same length.
Primitive operators corresponds to ANSI CL functions: For example, (not subform)
is compiled
into (bit-not subform <temporary storage>)
. Following primitive operators are available:
not and andc1 andc2 eqv ior nand nor orc1 orc2 xor
Additionally, (SUBSEQ FORM OFFSET)
operator evaluates FORM and
extracts its window starting from OFFSET and of the length equal to the other variables.
FORM is a regular lisp expression, not a bitwise operation, and the result may be different
from the other bit-vectors.
The final computation result is stored in a newly allocated vector, or in RESULT
if specified,
in spirit similar to the optional argument of Common Lisp bit-vector functions.
The entire form returns the bit-vector which contains the result.
The compiler does various optimizations:
DEFINE-BITWISE-OPERATION
.
(as-bitwise-operations ()
(and a b c))
->
(LET* ((#:LEN835 (LENGTH C)) (#:G833 (MAKE-BIT-VECTOR #:LEN835)))
(LET* ((+ZERO+ (MAKE-ZERO #:LEN835))
(+ONE+ (MAKE-ONE #:LEN835)))
(DECLARE (DYNAMIC-EXTENT +ZERO+ +ONE+))
(DECLARE (IGNORABLE +ZERO+ +ONE+))
(BIT-AND B C #:G833)
(BIT-AND A #:G833 #:G833)
#:G833))
(define-bitwise-operation if (condition then else)
`(ior (and ,condition ,then)
(andc1 ,condition ,else)))
(as-bitwise-operations (:result r)
(if a b c))
->
(LET* ((#:LEN839 (LENGTH C)) (#:G836 R))
(LET* ((+ZERO+ (MAKE-ZERO #:LEN839))
(+ONE+ (MAKE-ONE #:LEN839))
(#:G837 (MAKE-BIT-VECTOR #:LEN839)))
(DECLARE (DYNAMIC-EXTENT +ZERO+ +ONE+ #:G837))
(DECLARE (IGNORABLE +ZERO+ +ONE+))
(BIT-AND A B #:G836)
(BIT-ANDC1 A C #:G837)
(BIT-IOR #:G836 #:G837 #:G836)
#:G836))
This library is at least tested on implementation listed below:
Also, it depends on the following libraries:
Copyright (c) 2017 Masataro Asai (guicho2.71828@gmail.com)
Licensed under the LLGPL License.
Next: Modules, Previous: Introduction, Up: The bit-ops Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
Optimized bit-vector operations
Masataro Asai
(GIT https://github.com/guicho271828/bit-ops.git)
LLGPL
0.1
src (module).
Next: Files, Previous: Systems, Up: The bit-ops Reference Manual [Contents][Index]
Modules are listed depth-first from the system components tree.
bit-ops (system).
Next: Packages, Previous: Modules, Up: The bit-ops Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: bit-ops/src/package.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
bit-ops (system).
Next: bit-ops/src/macros.lisp, Previous: bit-ops/bit-ops.asd, Up: Lisp [Contents][Index]
src (module).
Next: bit-ops/src/functions.lisp, Previous: bit-ops/src/package.lisp, Up: Lisp [Contents][Index]
src (module).
Previous: bit-ops/src/macros.lisp, Up: Lisp [Contents][Index]
src (module).
Next: Definitions, Previous: Files, Up: The bit-ops Reference Manual [Contents][Index]
Packages are listed by definition order.
Next: bit-ops-asd, Previous: Packages, Up: Packages [Contents][Index]
Next: Indexes, Previous: Packages, Up: The bit-ops Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Public Interface, Up: Public Interface [Contents][Index]
Compute bitwise operations using bit vector arithmetic.
BODY accepts a single form. Within BODY, one can use variables holding bit-vectors as arguments to
bitwise operations, as well as constants 0 and 1, which maps to the bit vector filled with
0 or 1, respectively.
All bit-vectors that are involved in bitwise operations should be of the same length.
Primitive operators corresponds to ANSI CL functions: For example, (not subform) is compiled
into (bit-not subform <temporary storage>) . Following primitive operators are available:
not and andc1 andc2 eqv ior nand nor orc1 orc2 xor
Additionally, (SUBSEQ FORM OFFSET) operator evaluates FORM and
extracts its window starting from OFFSET and of the length equal to the other variables.
FORM is a regular lisp expression, not a bitwise operation, and the result may be different
from the other bit-vectors.
The final computation result is stored in a newly allocated vector, or in RESULT if specified,
in spirit similar to the optional argument of Common Lisp bit-vector functions.
The entire form returns the bit-vector which contains the result.
The compiler does various optimizations:
* Nested expressions store the results into dynamic-extent temporary vectors.
* Common subexpressions are eliminated.
* The number of temporary vectors are minimized/shared in spirit similar to register allocation.
* Macros for bitwise operations can be defined with DEFINE-BITWISE-OPERATION.
Defines a bitwise operation that is available within AS-BITWISE-OPERATIONS macro.
Primitive operators corresponds to ANSI CL functions: For example, (not subform) is compiled
into (bit-not subform <temporary storage>) .
not and andc1 andc2 eqv ior nand nor orc1 orc2 xor
Previous: Macros, Up: Public Interface [Contents][Index]
if A_i=1 then B_i else C_i
a => b :- not a or b
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Internals, Up: Internals [Contents][Index]
Next: Conditions, Previous: Special variables, Up: Internals [Contents][Index]
Wrapper for REPLACE which follows the syntax of bit-* (The last arg is the destination).
Automatically defined boolean function.
Automatically defined getter function. When DEFAULT is supplied, the value is set automatically.
Automatically defined setter function.
Next: Structures, Previous: Ordinary functions, Up: Internals [Contents][Index]
unbound-variable.
Next: Types, Previous: Conditions, Up: Internals [Contents][Index]
Previous: Structures, Up: Internals [Contents][Index]
Previous: Definitions, Up: The bit-ops Reference Manual [Contents][Index]
Jump to: | (
A B C D F M O P R S |
---|
Jump to: | (
A B C D F M O P R S |
---|
Next: Data types, Previous: Functions, Up: Indexes [Contents][Index]
Jump to: | *
I N O S |
---|
Jump to: | *
I N O S |
---|
Jump to: | B C F M O P S T U |
---|
Jump to: | B C F M O P S T U |
---|