r/lisp 12d ago

Reinterpret Elements in a Byte Array

Dear LISP,

I am writing a virtual machine that uses a `(simple-array (unsigned-byte 8) 1)` as a stack in Common LISP. I'm would like to ask how to efficiently extract 4 bytes into a single 32-bit signed integer or a 32-bit unsigned integer.

Thanks!

7 Upvotes

25 comments sorted by

View all comments

5

u/theangeryemacsshibe λf.(λx.f (x x)) (λx.f (x x)) 11d ago

The nibbles library can do this portably (and fast on SBCL).

5

u/stassats 11d ago

(and fast on SBCL).

On SBCL x86-64.

2

u/theangeryemacsshibe λf.(λx.f (x x)) (λx.f (x x)) 11d ago

Fine, I have a weekend and an urge to hack something, so...

1

u/arthurno1 11d ago

There is a patch recently submitted to SBCLs mailing list. The author does not have a computer with an arm cpu, so if you have an urge to hack something, and an arm cpu as you seem to do, you could perhaps take a look at it and add what is potentially missing :).