# 비트 연산을 벡터화하는 기발한 트릭

Original title: Vectorized CLZ and CTZ

> Hacker News story 50039608 · language: ko · submitted 2026-10-11
> Web version: https://zeli.app/ko/story/50039608
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 65 · by [zX41ZdbW](<https://news.ycombinator.com/user?id=zX41ZdbW>) · 💬 5
[original](<https://purplesyringa.moe/blog/vectorized-clz-and-ctz/>) · [HN discussion](<https://news.ycombinator.com/item?id=50039608>)

## Summary

이 글은 CLZ(선행 0 개수)와 CTZ(후행 0 개수)를 벡터화하는 영리한 방법을 소개한다. 부동소수점 트릭을 사용해 스칼라 버전보다 빠르게 동작하며, Haswell과 Alder Lake에서 측정한 결과를 제시한다. 또한 de Bruijn 수열을 이용한 대안과 64비트 최적화 알고리즘도 다룬다.

## Key quote

> 이 함수는 Haswell에서 반복당 0.49나노초, 지연 시간에 구속될 때 2.3나노초에 실행된다. Alder Lake에서는 반복당 0.35나노초, 지연 시간에 구속될 때 1.3나노초이다.

## HN discussion (5 comments)

### [wahern](<https://news.ycombinator.com/item?id=50051342>)

> 스스로 아이디어를 떠올린 것 같다는 게 꽤 멋지긴 한데, 그들이 확실히 최초는 아니다: https://graphics.stanford.edu/~seander/bithacks.html#ZerosOn...

### [jandrewrogers](<https://news.ycombinator.com/item?id=50050518>)

> 이건 유능한 SIMD 코드에 무엇이 필요한지 잘 보여주는 예시다.

### [saagarjha](<https://news.ycombinator.com/item?id=50050527>)

> GPU 같은 데서 유용할지도 모르겠네?

---

## Cite

- Page: https://zeli.app/ko/story/50039608
- Date: 2026-10-11
- Source: purplesyringa.moe (https://purplesyringa.moe/blog/vectorized-clz-and-ctz/)
- Hacker News: https://news.ycombinator.com/item?id=50039608

## Other languages

- en: https://zeli.app/story/50039608 · markdown: https://zeli.app/story/50039608.md
- zh: https://zeli.app/zh/story/50039608 · markdown: https://zeli.app/zh/story/50039608.md
- ja: https://zeli.app/ja/story/50039608 · markdown: https://zeli.app/ja/story/50039608.md
- de: https://zeli.app/de/story/50039608 · markdown: https://zeli.app/de/story/50039608.md
- es: https://zeli.app/es/story/50039608 · markdown: https://zeli.app/es/story/50039608.md
- ru: https://zeli.app/ru/story/50039608 · markdown: https://zeli.app/ru/story/50039608.md
