@@ -1229,6 +1229,49 @@ LIBC_INLINE constexpr cpp::enable_if_t<is_big_int_v<T>, T> mask_leading_ones() {
1229
1229
return out;
1230
1230
}
1231
1231
1232
+ // Specialization of count_zeros ('math_extras.h') for BigInt.
1233
+ template <typename T>
1234
+ [[nodiscard]]
1235
+ LIBC_INLINE constexpr cpp::enable_if_t <is_big_int_v<T>, int >
1236
+ count_zeros (T value) {
1237
+ return cpp::popcount (~value);
1238
+ }
1239
+
1240
+ // Specialization of first_leading_zero ('math_extras.h') for BigInt.
1241
+ template <typename T>
1242
+ [[nodiscard]]
1243
+ LIBC_INLINE constexpr cpp::enable_if_t <is_big_int_v<T>, int >
1244
+ first_leading_zero (T value) {
1245
+ return value == cpp::numeric_limits<T>::max () ? 0
1246
+ : cpp::countl_one (value) + 1 ;
1247
+ }
1248
+
1249
+ // Specialization of first_leading_one ('math_extras.h') for BigInt.
1250
+ template <typename T>
1251
+ [[nodiscard]]
1252
+ LIBC_INLINE constexpr cpp::enable_if_t <is_big_int_v<T>, int >
1253
+ first_leading_one (T value) {
1254
+ return first_leading_zero (~value);
1255
+ }
1256
+
1257
+ // Specialization of first_trailing_zero ('math_extras.h') for BigInt.
1258
+ template <typename T>
1259
+ [[nodiscard]]
1260
+ LIBC_INLINE constexpr cpp::enable_if_t <is_big_int_v<T>, int >
1261
+ first_trailing_zero (T value) {
1262
+ return value == cpp::numeric_limits<T>::max () ? 0
1263
+ : cpp::countr_zero (~value) + 1 ;
1264
+ }
1265
+
1266
+ // Specialization of first_trailing_one ('math_extras.h') for BigInt.
1267
+ template <typename T>
1268
+ [[nodiscard]]
1269
+ LIBC_INLINE constexpr cpp::enable_if_t <is_big_int_v<T>, int >
1270
+ first_trailing_one (T value) {
1271
+ return value == cpp::numeric_limits<T>::max () ? 0
1272
+ : cpp::countr_zero (value) + 1 ;
1273
+ }
1274
+
1232
1275
} // namespace LIBC_NAMESPACE
1233
1276
1234
1277
#endif // LLVM_LIBC_SRC___SUPPORT_UINT_H
0 commit comments