This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home.

Source for wiki BitwiseCowan version 5

author

cowan

comment


    

ipnr

127.11.51.1

name

BitwiseCowan

readonly

0

text

= Bitwise arithmetic procedures =

This proposal is based mainly on [http://srfi.schemers.org/srfi-33/srfi-33.html SRFI 33], with some changes and additions from [http://srfi.schemers.org/srfi-33/mail-archive/msg00023.html Olin's late revisions to SRFI 33] (which were never consummated) and from [http://srfi.schemers.org/srfi-60/srfi-60.html SRFI 60].  Until a full spec is written, see the final column of the following table.

== Comparison of proposals ==

The following table compares the names of the bitwise (aka logical) functions of [http://www.lispworks.com/documentation/HyperSpec/Body/c_number.htm Common Lisp], [http://srfi.schemers.org/srfi-33/srfi-33.html SRFI 33], [http://srfi.schemers.org/srfi-60/srfi-60.html SRFI 60], [http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-12.html#node_sec_11.4 R6RS], and BitwiseCowan.  SRFI 33 was never finalized, but is a comprehensive proposal.  SRFI 60 (based on SLIB) is smaller but has a few procedures of its own; some of its procedures have both native (often CL) and SRFI 33 names.  R6RS is a subset of SRFI 60, but all procedure names begin with a `bitwise-` prefix.

||=Function=||=CL=||=SRFI 33=||=SRFI 33 late revs=||=SRFI 60=||=R6RS=||=Cowan=||
||Bitwise NOT||`lognot`||`bitwise-not`||`bitwise-not`||`lognot`, `bitwise-not`||`bitwise-not`||`bitwise-not`||
||Bitwise AND (variadic)||`logand`||`bitwise-and`||`bitwise-and`||`logand`, `bitwise-and`||`bitwise-and`||`bitwise-and`||
||Bitwise IOR (variadic)||`logior`||`bitwise-ior`||`bitwise-ior`||`logior`, `bitwise-ior`||`bitwise-ior`||`bitwise-ior`||
||Bitwise XOR (variadic)||`logxor`||`bitwise-xor`||`bitwise-xor`||`logxor`, `bitwise-xor`||`bitwise-xor`||`bitwise-xor`||
||Bitwise EQV (variadic)||`logeqv`||`bitwise-eqv`||`bitwise-eqv`||---||---||`bitwise-eqv`||
||Bitwise NAND (variadic*)||`lognand`||`bitwise-nand`||`bitwise-nand`||---||---||`bitwise-nand`||
||Bitwise NOR (variadic*)||`lognor`||`bitwise-nor`||`bitwise-nor`||---||---||`bitwise-nor`||
||Bitwise AND with NOT of first arg||`logandc1`||`bitwise-andc1`||`bitwise-andc1`||---||---||`bitwise-andc1`||
||Bitwise AND with NOT of second arg||`logandc2`||`bitwise-andc2`||`bitwise-andc2`||---||---||`bitwise-andc2`||
||Bitwise OR with NOT of first arg||`logorc1`||`bitwise-orc1`||`bitwise-orc1`||---||---||`bitwise-orc1`||
||Bitwise OR with NOT of second arg||`logorc2`||`bitwise-orc2`||`bitwise-orc2`||---||---||`bitwise-orc2`||
||Arithmetic shift||`ash`||`arithmetic-shift`||`arithmetic-shift`||`ash`, `arithmetic-shift`||`bitwise-arithmetic-shift`||`arithmetic-shift`||
||Population count||`logcount`||`bit-count`||`bit-count`||`logcount`, `bit-count`||`bitwise-bit-count`||`bit-count`||
||Integer length||`integer-length`||`integer-length`||`integer-length`||`integer-length`||`bitwise-integer-length`||`integer-length`||
||Mask selects source of bits||---||`bitwise-merge`||`bitwise-merge`||`bitwise-if`, `bitwise-merge`||`bitwise-if`||`bitwise-if`||
||Test single bit||`logbitp`||`bit-set?`||`bit-set?`||`logbit?`, `bit-set?`||`bitwise-bit-set?`||`bit-set?`||
||See if any mask bits set||`logtest`||`any-bits-set?`||`any-bit-set?`||`logtest`, `any-bit-set?`||---||`any-bit-set`||
||See if all mask bits set||---||`all-bits-set?`||`every-bit-set?`||---||---||`every-bit-set?`||
||Replace single bit||---||---||`copy-bit`||`bitwise-copy-bit`||---||`copy-bit`||
||Find first bit set||---||---||`first-set-bit`||`log2-binary-factors`, `first-set-bit`||---||`first-set-bit`||
||Extract bit field†||`ldb`||`extract-bit-field`||`extract-bit-field`||`bit-field`||`bitwise-bit-field`||`bit-field`||
||Test bit field (any)†||`ldb-test`||`test-bit-field?`||`bit-field-any?`||---||---||`bit-field-any?`||
||Test bit field (every)†||---||---||`bit-field-every?`||---||---||`bit-field-every?`||
||Clear bit field†||`mask-field`||`clear-bit-field`||`bit-field-clear`||---||---||`bit-field-clear`||
||Replace bit field†||`dpb`||`replace-bit-field`||`bit-field-replace`||`copy-bit-field`||`bitwise-copy-bit-field`||`copy-bit-field`||
||Replace corresponding bit field†||`deposit-field`||`deposit-field`||`copy-bit-field`||---||---||`bit-field-copy-same`||
||Rotate bit field†||---||---||---||`rotate-bit-field`||`bitwise-rotate-bit-field`||`bit-field-rotate`||
||Reverse bit field†||---||---||---||`reverse-bit-field`||`bitwise-reverse-bit-field`||`bit-field-reverse`||
||Integer to boolean list||---||---||---||`integer->list`||---||`integer->list`||
||Boolean list to integer||---||---||---||`list->integer`||---||`list->integer`||
||Booleans to integer||---||---||---||`booleans->integer`||---||`bits`||

*These procedures were made dyadic in [http://srfi.schemers.org/srfi-33/mail-archive/msg00023.html late revisions to SRFI 33] that were never consummated.  BitwiseCowan adopts this change.

†These procedures take a byte-spec object in Common Lisp (which encodes size and position), leading ''size'' and ''position'' arguments in SRFI-33, and trailing ''start'' and ''end'' arguments in SRFI-60, R6RS, and BitwiseCowan.  Consequently, they are not quite compatible across specifications.  Note that `copy-bit-field` corresponds to different procedures in SRFI 33 and SRFI 60.


== Rationale for name changes in BitwiseCowan ==

BitwiseCowan retains SRFI 33 names for procedures adapted from SRFI 33, with these exceptions:

* The name `bitwise-merge` is replaced by `bitwise-if`, the name used in SRFI 60 and R6RS.

* The name `extract-bit-field` (`bit-field-extract` in Olin's revisions) is replaced by `bit-field`, the name used in SRFI 60 and R6RS.

* The names `any-bits-set?` and `all-bits-set?` are replaced by `any-bit-set?` and `every-bit-set?`, in accordance with Olin's revisions.

* Because  `copy-bit-field` means different things in SRFI 33 and SRFI 60, I have replaced SRFI 33's names `replace-bit-field` and `copy-bit-field` (`bit-field-replace` and `bit-field-copy` in Olin's revisions) with `bit-field-copy` and `bit-field-copy-same`.

The procedures that do not exist in SRFI 33 have their SRFI 60 names, with these exceptions.

* The procedure `booleans->integer` is a convenient way to specify a bitwise integer in the absence of datum syntax: it accepts an arbitrary number of boolean arguments and returns a non-negative integer.  So I gave it the short name `bits`, roughly analogous to `list`, `string`, and `vector`.

* The names `rotate-bit-field` and `reverse-bit-field` are replaced by `bit-field-rotate` and `bit-field-reverse`, in parallel with Olin's revisions.

time

2016-07-28 04:25:37

version

5