[clang] [Headers][X86] Allow MMX/SSE/AVX MOVMSK intrinsics to be used in constexpr (PR #161914)

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 6 01:02:02 PDT 2025


================
@@ -2817,6 +2817,46 @@ static bool interp__builtin_ia32_pshuf(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_ia32_movmsk_op(InterpState &S, CodePtr OpPC,
+                                           const CallExpr *Call) {
+  assert(Call->getNumArgs() == 1);
+
+  const Pointer &Source = S.Stk.pop<Pointer>();
+
+  unsigned SourceLen = Source.getNumElems();
+  const QualType ElemQT = getElemType(Source);
+  const OptPrimType ElemPT = S.getContext().classify(ElemQT);
+  unsigned LaneWidth = S.getASTContext().getTypeSize(ElemQT);
+
+  if (ElemQT->isIntegerType()) {
+    unsigned Byte = 8;
+    unsigned ResultLen = (LaneWidth * SourceLen) / Byte;
+    APInt Result(ResultLen, 0);
+    unsigned ResultIdx = 0;
+    for (unsigned I = 0; I != SourceLen; ++I) {
+      APInt Lane;
+      INT_TYPE_SWITCH_NO_BOOL(*ElemPT,
+                              { Lane = Source.elem<T>(I).toAPSInt(); });
+      for (unsigned J = 0; J != LaneWidth; J += Byte) {
+        Result.setBitVal(ResultIdx++, Lane[J + 7]);
+      }
+    }
+    pushInteger(S, Result.getZExtValue(), Call->getType());
+    return true;
+  }
+  if (ElemQT->isFloatingType()) {
+    APInt Result(SourceLen, 0);
+    using T = PrimConv<PT_Float>::T;
+    for (unsigned I = 0; I != SourceLen; ++I) {
+      APInt Lane = Source.elem<T>(I).getAPFloat().bitcastToAPInt();
+      Result.setBitVal(I, Lane[LaneWidth - 1]);
----------------
RKSimon wrote:

Lane.isNegative()

https://github.com/llvm/llvm-project/pull/161914


More information about the cfe-commits mailing list