Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bits functions #1319

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions library/bits.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#:or
#:xor
#:not
#:shift))
#:shift
#:dpb
#:ldb))

(in-package #:coalton-library/bits)

Expand All @@ -36,7 +38,19 @@
(not "The bitwise logical `not` of two integers"
(:int -> :int))
(shift "The arithmetic left-shift of an integer by an integer number of bits"
(Integer -> :int -> :int))))
(Integer -> :int -> :int)))

(declare dpb (Bits :a => :a -> UFix -> UFix -> :a -> :a))
(define (dpb newbyte size position bitstring)
"Deposits a byte `newbyte` of size `size` into a bitstring `bitstring` at a position `position`."
(lisp :a (newbyte bitstring size position)
(cl:dpb newbyte (cl:byte size position) bitstring)))

(declare ldb (Bits :a => UFix -> UFix -> :a -> :a))
(define (ldb size position bitstring)
"Deposits a byte of size `size` into a bitstring at a position `position`."
(lisp :a (bitstring size position)
(cl:ldb (cl:byte size position) bitstring))))

#+sb-package-locks
(sb-ext:lock-package "COALTON-LIBRARY/BITS")
Expand Down
Loading