From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by sourceware.org (Postfix) with ESMTPS id 3E4BD3858C56 for ; Thu, 13 Oct 2022 01:43:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E4BD3858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-xb2b.google.com with SMTP id j7so461676ybb.8 for ; Wed, 12 Oct 2022 18:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bOFo5LAivZEQP1VQWrOWt/aTpIRCNSBwZkf6e4PW6Rk=; b=h5MUUmzW9fSxB3qSGue5cUXqglx6ti69DMwazvUk4MI7q/26VAUae8b3RsdZxJpmLO K/G7qNXJ1aMC1jWcvqh6niWr61lWqF6utwdWFzjfYO3oT+ipE++TuTc4VHUJKJbAC+uw xhAJaYkaf3cIqvi7lgY85XXtZ9nL8stLwG7gCHywMynlb5Uu67kLyqALDsYbfHtOFY9H MxruS8kqkbgVmWcYm5g/1N0da0uaqOUaljbYRvBLjlDDlS5jmyvVpcuplj5dpOPQPTXU nC/LMS2EZGrqbS/SanOB5n/BrDM1eLSKA+KMbExSJmRPVHhuDer/J2AL+Fwe4CQ3hrTg vPjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bOFo5LAivZEQP1VQWrOWt/aTpIRCNSBwZkf6e4PW6Rk=; b=z5HrPa1N5bq3uvurX5pWmEsI7mjlx7qZqt8S6xHR4qerMBBUEr9FqiJhqiFicVkF5Q KW+FFEly5EtCw0UW1CZEo4jMSaNAcXErimli9TmxSrISvFDBsfI4sWHhstFzJcrtFCwA lC+szFYUzi14r0Spf/3k9f0NHsC10AcWQ9vYJxpRS/WFBSKMdUOllZHpt5pn+5FpfyqY gAw7TMGcedQEZZ+sCGntI+DvIO09GAbWqb8Q3HSpvtyTfPxcFDW9qWq6CMic+71FjdOH RfqYlSEj+78jqjQBh4JYjXLbqhtK4lOSjIgSbbqwal+aFpRh6JMhIFufuNWTKX8F2r4l ZIkA== X-Gm-Message-State: ACrzQf3MZGEmLcM/b/JwpYP7RUiqRfsJsICJst+eKtHFRJ49fafC/53T o0JN6/mq5ReRNIHChumPJuwgxigaaHr0kW++BUM= X-Google-Smtp-Source: AMsMyM7KEz6bY1J1PPqfRG7OMoUzweGioUE2OL0qeIElgnw/+KjfBiTl6AoRt3hB+13j5lQQ/DbFdIUQfpcjj62eHBo= X-Received: by 2002:a05:6902:1545:b0:6be:a376:6983 with SMTP id r5-20020a056902154500b006bea3766983mr30596816ybu.92.1665625418624; Wed, 12 Oct 2022 18:43:38 -0700 (PDT) MIME-Version: 1.0 References: <3f91174f-598a-6c19-4b73-f19d710b6bd1@gmail.com> In-Reply-To: <3f91174f-598a-6c19-4b73-f19d710b6bd1@gmail.com> From: Hongtao Liu Date: Thu, 13 Oct 2022 09:43:27 +0800 Message-ID: Subject: Re: Ignoring 'target specific option mismatch' on inline To: "J.W. Jagersma" Cc: gcc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Oct 13, 2022 at 5:45 AM J.W. Jagersma via Gcc-help wrote: > > Consider the following (incomplete) code: > > enum simd { mmx = 1, sse = 2 /* , ... */ }; > > template > void simd_func() > { > if constexpr (flags & simd::mmx) > { > // MMX code here > } > else if constexpr (flags & simd::sse) > { > // SSE code here > } > // etc ... > } > > The idea is to instantiate function templates with optimized SIMD routines > multiple times, then I can compile all my code with -march=i386, and select the > best implementation at runtime. It looks like you want to use function multi-versioning. > > However, after already spending a lot of time restructuring my code around this > idea, I discover that gcc refuses to compile this without having the > corresponding target options enabled: > > error: inlining failed in call to 'always_inline' '__m64 _mm_unpacklo_pi8(__m64, __m64)': target specific option mismatch > > That makes no sense to me. I want gcc to emit those SIMD instructions verbatim > in my code, regardless of what compiler options the user specified. What then > is the point of feature-test macros (__SSE__, etc)? I don't get it. > > Is there any option or attribute I can use to make gcc ignore these target > option mismatches when inlining? Or any other way to make this work? maybe you can try #pragma GCC push_options #pragma GCC target("sse2") your codes.. #pragma GCC pop_options https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html#Function-Specific-Option-Pragmas -- BR, Hongtao