================
@@ -797,6 +797,175 @@ def StdcRotateRight : Builtin {
   let Prototype = "void(...)";
 }
 
+def StdcLeadingZeros: Builtin {
+  let Spellings = ["__builtin_stdc_leading_zeros"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcLeadingOnes: Builtin {
+  let Spellings = ["__builtin_stdc_leading_ones"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcTrailingZeros: Builtin {
+  let Spellings = ["__builtin_stdc_trailing_zeros"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcTrailingOnes: Builtin {
+  let Spellings = ["__builtin_stdc_trailing_ones"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcFirstLeadingZero: Builtin {
+  let Spellings = ["__builtin_stdc_first_leading_zero"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcFirstLeadingOne: Builtin {
+  let Spellings = ["__builtin_stdc_first_leading_one"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcFirstTrailingZero: Builtin {
+  let Spellings = ["__builtin_stdc_first_trailing_zero"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcFirstTrailingOne: Builtin {
+  let Spellings = ["__builtin_stdc_first_trailing_one"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcCountZeros: Builtin {
+  let Spellings = ["__builtin_stdc_count_zeros"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcCountOnes: Builtin {
+  let Spellings = ["__builtin_stdc_count_ones"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcHasSingleBit: Builtin {
+  let Spellings = ["__builtin_stdc_has_single_bit"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "bool(...)";
+}
+
+def StdcBitWidth: Builtin {
+  let Spellings = ["__builtin_stdc_bit_width"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcBitFloor: Builtin {
+  let Spellings = ["__builtin_stdc_bit_floor"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcBitCeil: Builtin {
+  let Spellings = ["__builtin_stdc_bit_ceil"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcLeadingZerosLib: LibBuiltin<"stdbit.h", "C23_LANG"> {
+  let Spellings = ["stdc_leading_zeros"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
+def StdcLeadingOnesLib: LibBuiltin<"stdbit.h", "C23_LANG"> {
+  let Spellings = ["stdc_leading_ones"];
----------------
AaronBallman wrote:

It seems the way we usually handle this for other math functions is via 
templates. e.g., 
```
def SqrtF16F128 : Builtin, F16F128MathTemplate {
  let Spellings = ["__builtin_sqrt"];
  let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
                    ConstIgnoringErrnoAndExceptions];
  let Prototype = "T(T)";
}

def Sqrt : FPMathTemplate, LibBuiltin<"math.h"> {
  let Spellings = ["sqrt"];
  let Attributes = [NoThrow, ConstIgnoringErrnoAndExceptions];
  let Prototype = "T(T)";
  let AddBuiltinPrefixedAlias = 1;
}
```
where the template spits out the various spellings. I think we want similar 
here, don't we @efriedma-quic?

Basically, I think we ultimately want a new kind of template along the lines of:
```
class IntBitUtilTemplate : Template<["unsigned char", "unsigned short", 
"unsigned int", "unsigned long", "unsigned long long"],
                                   ["_uc", "_us", "_ui", "_ul", "_ull"], 
/*AsPrefix=*/1>;

```
That should get used by at least the library function form. But do we want it 
to be used in the builtin form same as we do for things like `__builtin_sqrt` 
where we'd get `__builtin_stdc_leading_ones_ull` generated for us? Then most of 
the builtins don't require any custom checking and can have a specific 
signature listed for them. I think we would still need the generic builtin to 
have the custom type checking to handle `_BitInt` properly.

https://github.com/llvm/llvm-project/pull/185978
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to