gnzlbg / bitwise Goto Github PK
View Code? Open in Web Editor NEWPortable high-level bitwise manipulation algorithms
Home Page: https://gnzlbg.github.io/bitwise
License: MIT License
Portable high-level bitwise manipulation algorithms
Home Page: https://gnzlbg.github.io/bitwise
License: MIT License
Implement:
find_first_bit_set
, find first one, bit scan forward. Instructions: FFS, BSF.find_first_bit_unset
, find first zero. Instructions: FFZ.Right now the feature flag bmi2
must be explicitly passed to the library to enable the BMI2.0 instruction set. It would be better to enable this depending on the architecture.
Blocked on rust-lang/rust#30462 .
Current Morton index encoding/decoding algorithms use parallel_bit_deposit
/parallel_bit_extract
which are very fast (4cycles) if the architecture supports the BMI2.0 instruction set.
However, if the architecture doesn't support BMI2.0 we are falling back to a software emulation for the parallel_bit_deposit/extract
algorithms. For computing morton codes there are faster methods available:
All the algorithms have been given readable names that clearly state what they do. Some of the algorithms map to hardware intrinsics and other names that are also commonly in use. It should be easy to find any algorithm using any of its common names.
i128
and u128
should implement Word
as well. I need this in an application of morton encoding where I need more than 21 bits of precision on each axis. In the meantime I will use two u64, but it would be nice if we could have support for general bitwise operations on the 128-bit types as well. Is there any interest in this?
Hey, any chance you could publish the latest state to crates.io? Thank you
The command llc -mattr=help
can be used to list all target features! The following features are relevant for bitwise manipulation:
These tooling issues should be fixed before 1.0:
cargo-fuzz
asm.py
to test the generated assembly of some algorithms on some platforms (as long as we rely on bitintr
we should be fine though).The following benchmarks are important:
State and assert pre-conditions on library functions using debug_assert!
.
Problem:
error: unrecognized platform-specific intrinsic function: x86_bmi_bextr_32
src/x86/intrinsics/bmi/bextr.rs:11:9
|
11 | fn x86_bmi_bextr_32(x: u32, y: u32) -> u32;
Solution: update Cargo.toml to
[dependencies]
bitintr = "0.3"
Implement morton index algorithms to interleave/de-interleave morton coordinates in integers.
This is a mind dump of what I'd like to see in for 1.0, API wise, functionality wise, and algorithmic wise.
i128/u128
support.parallel_bits_deposit/extract
-right and extract_bits_right
(see compress and expand.x
a contiguous sequence of 1 bits ?count_ones
/count_zeros
/ leading ones/ leading zeros / trailing ones / trailing zeros in subword iUse intrinsics from the llvmint package.
parallel_bits_deposit
/extract
=> bmi_pdep_32/64
and bmi_pext_32/64
(BMI 2.0),leading_zeros
=> LLVM's __lzcnt16/32/u32/64/u64
(blocked on huonw/llvmint#3) (BMI 1.0, ABM),count_ones
=> LLVM's _popcnt_32/u32/64/u64
(blocked on huonw/llvmint#4) (SSE4.2, ABM),trailing_zeros
=> tzcnt
(BMI 1.0), (blocked on huonw/llvmint#5 and rust-lang/rust#34382)reset_bits_geq(starting bit)
=> bmi_bzhi_32/64
(BMI 1.0)reset_least_significant_one
=> BLSR
(BMI 1.0)~x & y
(BMI 1.0) (TODO: implement algorithm)(src >> start) & ((1 << len)-1)
=> bmi_bextr_32/64
(BMI 1.0)isolate_least_significant_one
: Extract lowest set isolated bit: x & -x
(blocked on "not available in llvmint) (BMI 1.0)mask_trailing_zeros_and_least_significant_one
: Get mask up to lowest set bit: x ^ (x - 1)
(blocked on "not available in llvmint") (BMI 1.0)A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.