Skip to content

Instantly share code, notes, and snippets.

View shangsony's full-sized avatar

sonyshang shangsony

View GitHub Profile
@pps83
pps83 / ctz_clz.cpp
Last active March 31, 2025 16:21
__builtin_ctz (ctzl, ctzll) and __builtin_clz (clzl, clzll) for Visual Studio
// Note, bsf/bsr are used by default.
// Enable /arch:AVX2 compilation for better optimizations
#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
#include <limits.h>
#if (defined(__cplusplus) && (__cplusplus >= 202002L)) || \
(defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L))
#include <type_traits>