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

[RFC] Bit twiddling API #30

Open
Ravenslofty opened this issue Jun 22, 2018 · 1 comment
Open

[RFC] Bit twiddling API #30

Ravenslofty opened this issue Jun 22, 2018 · 1 comment

Comments

@Ravenslofty
Copy link

Ravenslofty commented Jun 22, 2018

(Sorry, I accidentally hit enter)

I'd like to propose some API for things like getting the most/least significant bit index, along with getting the number of set bits in an int.

My main purpose here is to explore how well OCaml works for bitboards, which represent a chessboard as a 64-bit int, with each bit representing the presence/absence of a piece.

This requires a large amount of bit twiddling, for example to serialise given bitboards into moves.

Extracting the MSB/LSB can be done in OCaml purely through your library, but it would benefit heavily from the hardware acceleration of C compiler intrinsics that OCaml doesn't provide.

@Ravenslofty Ravenslofty changed the title [RFC] Bit twiddling [RFC] Bit twiddling API Jun 22, 2018
@mwweissmann
Copy link
Collaborator

I would expect using nativeint for this purpose would yield the best results; unfortunately for you, it is only 63 bit wide. Implementing the bit twiddling in C (on an int64) means, that you have to call a C function, which has a little overhead. I suspect that you CPU caches will equalize the difference between a getLSB FFI call and a Int64.(&&) 0x1L (or whatever).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants