================
@@ -717,6 +717,52 @@ static bool interp__builtin_popcount(InterpState &S,
CodePtr OpPC,
return true;
}
+static bool interp__builtin_ia32_crc32(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const CallExpr *Call,
+ unsigned BuiltinID) {
+ APSInt Data = popToAPSInt(S, Call->getArg(1));
+ APSInt CRC = popToAPSInt(S, Call->getArg(0));
+
+ uint64_t CRCVal = CRC.getZExtValue();
+ uint64_t DataVal = Data.getZExtValue();
+
+ // Determine the data width based on the builtin
+ unsigned DataBytes;
+ switch (BuiltinID) {
+ case clang::X86::BI__builtin_ia32_crc32qi:
+ DataBytes = 1;
+ break;
+ case clang::X86::BI__builtin_ia32_crc32hi:
+ DataBytes = 2;
+ break;
+ case clang::X86::BI__builtin_ia32_crc32si:
+ DataBytes = 4;
+ break;
+ case clang::X86::BI__builtin_ia32_crc32di:
+ DataBytes = 8;
+ break;
+ default:
+ llvm_unreachable("Unknown CRC32 builtin");
+ }
+
+ // CRC32C polynomial (iSCSI polynomial, bit-reversed)
+ static const uint32_t CRC32C_POLY = 0x82F63B78;
+
+ // Process each byte
+ uint32_t Result = static_cast<uint32_t>(CRCVal);
+ for (unsigned i = 0; i < DataBytes; ++i) {
----------------
tbaederr wrote:
```suggestion
for (unsigned I = 0; i != DataBytes; ++i) {
```
Same with `j` below.
https://github.com/llvm/llvm-project/pull/173908
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits