File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1+ # ビット演算あれこれ
2+
3+ ## 末尾の0個数
4+
5+ c++20以降ならば、[ std::countr_zero] ( https://cpprefjp.github.io/reference/bit/countr_zero.html ) を使うのが良い。
6+
7+ ## 1が立っているビットを全て知りたい
8+
9+ 以下のようなコードが定数倍軽くておススメ。TODO:↑で書き換える。
10+
11+ ``` c++
12+ while (n) {
13+ int i = __ builtin_ctz(n);
14+ n ^= 1 << i;
15+ }
16+ ```
17+
18+ ## __ builtin_clz の高速化について
19+
20+ ` target("lzcnt") ` で速くなるらしい。tzcnt が入ってる命令セットが BMI1 なので、 ` target("bmi") ` を用いる。
21+
22+ ### 参考
23+ - [ https://twitter.com/noshi91/status/1645808228067078144 ] ( https://twitter.com/noshi91/status/1645808228067078144 )
24+ - [ x86 Bit manipulation instruction set - Wikipedeia] ( https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set )
Original file line number Diff line number Diff line change 44
55## Math
66
7- - [ デジタル冪級数 ~ 理論編~ ] ( digital_fps_theory.md )
7+ - [ デジタル冪級数 ~ 理論編~ ] ( digital_fps_theory.md )
8+
9+ ## Bitwise operation
10+
11+ - [ ビット演算あれこれ] ( bitwise_operation.md )
You can’t perform that action at this time.
0 commit comments