@@ -2549,7 +2549,7 @@ static bool interp__builtin_elementwise_maxmin(InterpState &S, CodePtr OpPC,
25492549 return true ;
25502550}
25512551
2552- static bool interp__builtin_ia32_pmadd (
2552+ static bool interp__builtin_ia32_pmul (
25532553 InterpState &S, CodePtr OpPC, const CallExpr *Call,
25542554 llvm::function_ref<APInt(const APSInt &, const APSInt &, const APSInt &,
25552555 const APSInt &)>
@@ -2587,54 +2587,6 @@ static bool interp__builtin_ia32_pmadd(
25872587 return true ;
25882588}
25892589
2590- static bool interp__builtin_ia32_pmul (InterpState &S, CodePtr OpPC,
2591- const CallExpr *Call,
2592- unsigned BuiltinID) {
2593- assert (Call->getArg (0 )->getType ()->isVectorType () &&
2594- Call->getArg (1 )->getType ()->isVectorType ());
2595- const Pointer &RHS = S.Stk .pop <Pointer>();
2596- const Pointer &LHS = S.Stk .pop <Pointer>();
2597- const Pointer &Dst = S.Stk .peek <Pointer>();
2598-
2599- const auto *VT = Call->getArg (0 )->getType ()->castAs <VectorType>();
2600- PrimType ElemT = *S.getContext ().classify (VT->getElementType ());
2601- unsigned SourceLen = VT->getNumElements ();
2602-
2603- PrimType DstElemT = *S.getContext ().classify (
2604- Call->getType ()->castAs <VectorType>()->getElementType ());
2605- unsigned DstElem = 0 ;
2606- for (unsigned I = 0 ; I != SourceLen; I += 2 ) {
2607- APSInt Elem1;
2608- APSInt Elem2;
2609- INT_TYPE_SWITCH_NO_BOOL (ElemT, {
2610- Elem1 = LHS.elem <T>(I).toAPSInt ();
2611- Elem2 = RHS.elem <T>(I).toAPSInt ();
2612- });
2613-
2614- APSInt Result;
2615- switch (BuiltinID) {
2616- case clang::X86::BI__builtin_ia32_pmuludq128:
2617- case clang::X86::BI__builtin_ia32_pmuludq256:
2618- case clang::X86::BI__builtin_ia32_pmuludq512:
2619- Result = APSInt (llvm::APIntOps::muluExtended (Elem1, Elem2),
2620- /* IsUnsigned=*/ true );
2621- break ;
2622- case clang::X86::BI__builtin_ia32_pmuldq128:
2623- case clang::X86::BI__builtin_ia32_pmuldq256:
2624- case clang::X86::BI__builtin_ia32_pmuldq512:
2625- Result = APSInt (llvm::APIntOps::mulsExtended (Elem1, Elem2),
2626- /* IsUnsigned=*/ false );
2627- break ;
2628- }
2629- INT_TYPE_SWITCH_NO_BOOL (DstElemT,
2630- { Dst.elem <T>(DstElem) = static_cast <T>(Result); });
2631- ++DstElem;
2632- }
2633-
2634- Dst.initializeAllElements ();
2635- return true ;
2636- }
2637-
26382590static bool interp__builtin_elementwise_triop_fp (
26392591 InterpState &S, CodePtr OpPC, const CallExpr *Call,
26402592 llvm::function_ref<APFloat(const APFloat &, const APFloat &,
@@ -3512,7 +3464,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
35123464 case clang::X86::BI__builtin_ia32_pmaddubsw128:
35133465 case clang::X86::BI__builtin_ia32_pmaddubsw256:
35143466 case clang::X86::BI__builtin_ia32_pmaddubsw512:
3515- return interp__builtin_ia32_pmadd (
3467+ return interp__builtin_ia32_pmul (
35163468 S, OpPC, Call,
35173469 [](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
35183470 const APSInt &HiRHS) {
@@ -3524,7 +3476,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
35243476 case clang::X86::BI__builtin_ia32_pmaddwd128:
35253477 case clang::X86::BI__builtin_ia32_pmaddwd256:
35263478 case clang::X86::BI__builtin_ia32_pmaddwd512:
3527- return interp__builtin_ia32_pmadd (
3479+ return interp__builtin_ia32_pmul (
35283480 S, OpPC, Call,
35293481 [](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
35303482 const APSInt &HiRHS) {
@@ -3677,10 +3629,22 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
36773629 case clang::X86::BI__builtin_ia32_pmuldq128:
36783630 case clang::X86::BI__builtin_ia32_pmuldq256:
36793631 case clang::X86::BI__builtin_ia32_pmuldq512:
3632+ return interp__builtin_ia32_pmul (
3633+ S, OpPC, Call,
3634+ [](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
3635+ const APSInt &HiRHS) {
3636+ return llvm::APIntOps::mulsExtended (LoLHS, LoRHS);
3637+ });
3638+
36803639 case clang::X86::BI__builtin_ia32_pmuludq128:
36813640 case clang::X86::BI__builtin_ia32_pmuludq256:
36823641 case clang::X86::BI__builtin_ia32_pmuludq512:
3683- return interp__builtin_ia32_pmul (S, OpPC, Call, BuiltinID);
3642+ return interp__builtin_ia32_pmul (
3643+ S, OpPC, Call,
3644+ [](const APSInt &LoLHS, const APSInt &HiLHS, const APSInt &LoRHS,
3645+ const APSInt &HiRHS) {
3646+ return llvm::APIntOps::muluExtended (LoLHS, LoRHS);
3647+ });
36843648
36853649 case Builtin::BI__builtin_elementwise_fma:
36863650 return interp__builtin_elementwise_triop_fp (
0 commit comments