From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 03E633858C55 for ; Thu, 13 Oct 2022 13:23:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 03E633858C55 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-ej1-x629.google.com with SMTP id 13so3907903ejn.3 for ; Thu, 13 Oct 2022 06:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=aH5ZQ5aLtot9mndONl/SEjbaCINBSAL3+VO3F9KMuuo=; b=Sk2KvVpoF/azOWP1QDv9Cfw9msEsxfcEvsBQnZBS8mPnqh6lRpTQzDl/SbgbIpzud8 ukZ4H78DoXKdtz4JWdNEntm0UZ3CuPnMvwbqp03MTbbB4z5GF0cdVWG4AZaAzedoRESe lJeDjGSLmJhNmLfaKHF/KHZ/4xHeqi54fLodxcJM9QGKvdnydBTMaQCXR0Xe+epSa2Ci my6YAFvPLxU+IBeaLUDzCGtCgzgUkSay22OfJPS9OdH/Ia8RU1hNLKqN9yICu1vAbP4w X40dxQxHZLl/JSrARF/+9zzbTmh+QRpVgFk16aX/Z+DEl6qP+sRi0+GiLGHCId6YwbCt gnow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aH5ZQ5aLtot9mndONl/SEjbaCINBSAL3+VO3F9KMuuo=; b=Xk0BecAFrVRl88fxOkpmcW5zOWfpBpkG+qzYeFV9lZU5CpgwO2oQLzpV4EJOzlC9NI mGTr5Tro5qIWroZe1IOCd8Rwc/37mBi0ym85ig0tomDf5R41X9THDxgH463tUKRpPZBG CtD0Ah6UEuEyGlgsuYZKru5Jru8oyqVow7ZZQQwRY7beJen4EytEQ05zJpirGvzPz3yc Vn5hZX+pjz8+vocxzXbC+wvIA0fQ2DLG0iH2Nb4Ok5aksjcIVPGnXHdEgH0cxEmsKDTA QD933w9DqwLqOLDzm77RX5asYn0YXufaJQzvQlH7mBhOH3wNBwjYNI2hO/4mjumZAAjp fUsg== X-Gm-Message-State: ACrzQf2X1sGxZiJB+PlQVz9SO71bFTtaTbsRSB6eQxI9lD7Qaf8VKoW5 I1t4f2Imc7MV7ezN+iJCqAQ= X-Google-Smtp-Source: AMsMyM4A0OTI0Nll055Et3cjsGsfa5oe6LE4hUg0Nx1RVybpbGnimdMGCQTrhT1CFExEI7dwzKLeAA== X-Received: by 2002:a17:907:2d1f:b0:78e:174d:2ce0 with SMTP id gs31-20020a1709072d1f00b0078e174d2ce0mr1541726ejc.638.1665667399743; Thu, 13 Oct 2022 06:23:19 -0700 (PDT) Received: from [10.0.0.1] (138.sub226.ddfr.nl. [217.27.226.138]) by smtp.gmail.com with ESMTPSA id k2-20020aa7c042000000b0045c010d0584sm9141795edo.47.2022.10.13.06.23.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Oct 2022 06:23:19 -0700 (PDT) Message-ID: <6952f945-8980-3ddc-73c4-7646988b2a33@gmail.com> Date: Thu, 13 Oct 2022 15:23:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: Ignoring 'target specific option mismatch' on inline To: Hongtao Liu Cc: gcc-help References: <3f91174f-598a-6c19-4b73-f19d710b6bd1@gmail.com> Content-Language: en-US From: "J.W. Jagersma" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,NICE_REPLY_A,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 2022-10-13 03:43, Hongtao Liu wrote: > 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 Hi, and thanks, While that would work, it would also give the compiler free reign to auto- vectorize any code (__builtin_memcpy, etc) using those target options, right? My goal though is to only generate SIMD code for those targets specified in the template parameter. Another idea I had: template consteval const char* simd_target_options() { // compile-time string wizardry goes here ... return "mmx,sse,sse2"; // just to test } template [[gnu::target(simd_target_options())]] void simd_func() { /* ... */ } Which also doesn't work: error: attribute 'target' argument is not a string To be expected I suppose, although I know some attributes do take arbitrary expressions. What I'm really looking for is an option to automatically propagate target options from inlined functions, but that just doesn't seem to exist.