public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "J.W. Jagersma" <jwjagersma@gmail.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: Ignoring 'target specific option mismatch' on inline
Date: Wed, 12 Oct 2022 23:44:14 +0200	[thread overview]
Message-ID: <3f91174f-598a-6c19-4b73-f19d710b6bd1@gmail.com> (raw)

Consider the following (incomplete) code:

    enum simd { mmx = 1, sse = 2 /* , ... */ };

    template<simd flags>
    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.

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?

             reply	other threads:[~2022-10-12 21:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12 21:44 J.W. Jagersma [this message]
2022-10-13  1:43 ` Hongtao Liu
2022-10-13 13:23   ` J.W. Jagersma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f91174f-598a-6c19-4b73-f19d710b6bd1@gmail.com \
    --to=jwjagersma@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).