Skip to content

Commit 7cf9adc

Browse files
committed
記事追加
1 parent 9187baf commit 7cf9adc

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docsrc/note/bitwise_operation.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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)

docsrc/note/note.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44

55
## Math
66

7-
- [デジタル冪級数 ~理論編~](digital_fps_theory.md)
7+
- [デジタル冪級数 ~理論編~](digital_fps_theory.md)
8+
9+
## Bitwise operation
10+
11+
- [ビット演算あれこれ](bitwise_operation.md)

0 commit comments

Comments
 (0)