Skip to content

migrate from bit-manipulation builtins in fbcode/torchrec - #4787

Closed
yfeldblum wants to merge 1 commit into
mainfrom
export-D121529288
Closed

yfeldblum wants to merge 1 commit into
mainfrom
export-D121529288

Conversation

@yfeldblum

@yfeldblum yfeldblum commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary:
Migrates the TorchRec dynamic-embedding bit operations to the C++20 <bit> APIs.

  • Replaces __builtin_clz, __builtin_clzl, and __builtin_clzll, along with the fallback get_bit loop and ClzImpl specializations, with one Clz<T> implementation that calls std::countl_zero.
  • Replaces __builtin_ctz, __builtin_ctzl, and __builtin_ctzll, along with the fallback loop and CtzImpl specializations, with one Ctz<T> implementation that calls std::countr_zero.
  • Both implementations preserve the existing signed-to-unsigned behavior by converting through std::make_unsigned_t<T> before counting.

Differential Revision: D121529288

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2026
@meta-codesync

meta-codesync Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

@yfeldblum has exported this pull request. If you are a Meta employee, you can view the originating Diff in D121529288.

@yfeldblum yfeldblum changed the title migrate from bit-manipulation builtins in fbcode/torchrec migrate from bit-manipulation builtins Sep 24, 2026
@meta-codesync meta-codesync Bot changed the title migrate from bit-manipulation builtins migrate from bit-manipulation builtins in fbcode/torchrec (#4787) Sep 25, 2026
meta-codesync Bot pushed a commit that referenced this pull request Sep 25, 2026
Summary:

Replaces `__builtin_clz`/`__builtin_clzl`/`__builtin_clzll` and `__builtin_ctz`/`__builtin_ctzl`/`__builtin_ctzll` with `std::countl_zero`/`std::countr_zero` in the `ClzImpl`/`CtzImpl` template specializations in `clz_impl.cpp` and `ctz_impl.cpp`, keeping the existing casts to the unsigned counterpart of each signed specialization.

Differential Revision: D121529288
meta-codesync Bot pushed a commit that referenced this pull request Sep 25, 2026
Summary:
Pull Request resolved: #4787

Replaces `__builtin_clz`/`__builtin_clzl`/`__builtin_clzll` and `__builtin_ctz`/`__builtin_ctzl`/`__builtin_ctzll` with `std::countl_zero`/`std::countr_zero` in the `ClzImpl`/`CtzImpl` template specializations in `clz_impl.cpp` and `ctz_impl.cpp`, keeping the existing casts to the unsigned counterpart of each signed specialization.

Differential Revision: D121529288
meta-codesync Bot pushed a commit that referenced this pull request Sep 29, 2026
Summary:

Replaces `__builtin_clz`/`__builtin_clzl`/`__builtin_clzll` and `__builtin_ctz`/`__builtin_ctzl`/`__builtin_ctzll` with `std::countl_zero`/`std::countr_zero` in the `ClzImpl`/`CtzImpl` template specializations in `clz_impl.cpp` and `ctz_impl.cpp`, keeping the existing casts to the unsigned counterpart of each signed specialization.

Differential Revision: D121529288
meta-codesync Bot pushed a commit that referenced this pull request Sep 29, 2026
Summary:
Pull Request resolved: #4787

Replaces `__builtin_clz`/`__builtin_clzl`/`__builtin_clzll` and `__builtin_ctz`/`__builtin_ctzl`/`__builtin_ctzll` with `std::countl_zero`/`std::countr_zero` in the `ClzImpl`/`CtzImpl` template specializations in `clz_impl.cpp` and `ctz_impl.cpp`, keeping the existing casts to the unsigned counterpart of each signed specialization.

Differential Revision: D121529288
meta-codesync Bot pushed a commit that referenced this pull request Oct 1, 2026
Summary:

Replaces `__builtin_clz`/`__builtin_clzl`/`__builtin_clzll` and `__builtin_ctz`/`__builtin_ctzl`/`__builtin_ctzll` with `std::countl_zero`/`std::countr_zero` in the `ClzImpl`/`CtzImpl` template specializations in `clz_impl.cpp` and `ctz_impl.cpp`, keeping the existing casts to the unsigned counterpart of each signed specialization.

Differential Revision: D121529288
@meta-codesync
meta-codesync Bot force-pushed the export-D121529288 branch from e073ad6 to 6c2bafb Compare October 1, 2026 14:12
meta-codesync Bot pushed a commit that referenced this pull request Oct 1, 2026
Summary:
Pull Request resolved: #4787

Replaces `__builtin_clz`/`__builtin_clzl`/`__builtin_clzll` and `__builtin_ctz`/`__builtin_ctzl`/`__builtin_ctzll` with `std::countl_zero`/`std::countr_zero` in the `ClzImpl`/`CtzImpl` template specializations in `clz_impl.cpp` and `ctz_impl.cpp`, keeping the existing casts to the unsigned counterpart of each signed specialization.

Differential Revision: D121529288
@meta-codesync
meta-codesync Bot force-pushed the export-D121529288 branch from 6c2bafb to 99e35b7 Compare October 1, 2026 14:15
Summary:
Migrates the TorchRec dynamic-embedding bit operations to the C++20 `<bit>` APIs.

- Replaces `__builtin_clz`, `__builtin_clzl`, and `__builtin_clzll`, along with the fallback `get_bit` loop and `ClzImpl` specializations, with one `Clz<T>` implementation that calls `std::countl_zero`.
- Replaces `__builtin_ctz`, `__builtin_ctzl`, and `__builtin_ctzll`, along with the fallback loop and `CtzImpl` specializations, with one `Ctz<T>` implementation that calls `std::countr_zero`.
- Both implementations preserve the existing signed-to-unsigned behavior by converting through `std::make_unsigned_t<T>` before counting.

Differential Revision: D121529288
@meta-codesync meta-codesync Bot changed the title migrate from bit-manipulation builtins in fbcode/torchrec (#4787) migrate from bit-manipulation builtins in fbcode/torchrec Oct 4, 2026
@meta-codesync
meta-codesync Bot force-pushed the export-D121529288 branch from 99e35b7 to bba7dea Compare October 4, 2026 14:24
@meta-codesync meta-codesync Bot closed this in d1b6c0f Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant