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. For a version of this page that may be more recent, see BitwiseCowan in WG2's repo for R7RS-large.

Bitwise­Cowan

cowan
2016-07-28 04:25:37
5history
source

Bitwise arithmetic procedures

This proposal is based mainly on SRFI 33, with some changes and additions from Olin's late revisions to SRFI 33 (which were never consummated) and from 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 Common Lisp, SRFI 33, SRFI 60, 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 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 procedures that do not exist in SRFI 33 have their SRFI 60 names, with these exceptions.