Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753918AbdLMCoe (ORCPT ); Tue, 12 Dec 2017 21:44:34 -0500 Received: from mx3.wp.pl ([212.77.101.9]:46347 "EHLO mx3.wp.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752661AbdLMCoJ (ORCPT ); Tue, 12 Dec 2017 21:44:09 -0500 Date: Tue, 12 Dec 2017 18:44:00 -0800 From: Jakub Kicinski To: Al Viro Cc: Linus Torvalds , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH] new byteorder primitives - ..._{replace,get}_bits() Message-ID: <20171212184400.13b27cf8@cakuba.netronome.com> In-Reply-To: <20171213015125.GC21978@ZenIV.linux.org.uk> References: <20171211200224.23bc5df4@cakuba.netronome.com> <20171212062002.GY21978@ZenIV.linux.org.uk> <20171212194532.GA7062@ZenIV.linux.org.uk> <20171212120409.64b6362e@cakuba.netronome.com> <20171212234856.GZ21978@ZenIV.linux.org.uk> <20171212155933.03c88eab@cakuba.netronome.com> <20171213003659.GA21978@ZenIV.linux.org.uk> <20171212170437.4b129e50@cakuba.netronome.com> <20171213013056.GB21978@ZenIV.linux.org.uk> <20171212173528.340cd002@cakuba.netronome.com> <20171213015125.GC21978@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-WP-MailID: 7472baebac984ebad2692bfc8a5c23cb X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 000000A [MUPE] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2100 Lines: 70 On Wed, 13 Dec 2017 01:51:25 +0000, Al Viro wrote: > On Tue, Dec 12, 2017 at 05:35:28PM -0800, Jakub Kicinski wrote: > > > It used to be __always_inline, but apparently LLVM/clang doesn't > > propagate constants :( > > > > 4e59532541c8 ("nfp: don't depend on compiler constant propagation") > > Doesn't propagate constants or doesn't have exact same set of > rules for __builtin_constant_p()? IOW, if you dropped that > BUILD_BUG_ON(), what would be left after optimizations? Hm. You're right. It just doesn't recognize the parameter as constant in __builtin_constant_p(). I haven't compiled the actual code, but here is a trivial test: 18:36 ~$ clang --version clang version 4.0.1 (tags/RELEASE_401/final) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/bin 18:36 ~$ cat /tmp/test.c #include static inline int test_thing(unsigned int a) { printf("const: %d\n", __builtin_constant_p(a)); if (a > 10) return a - 1; return a; } int main() { printf("const: %d\n", __builtin_constant_p(0)); return test_thing(0); } 18:36 ~$ clang -g /tmp/test.c -O2 -Wall -W -o /tmp/test 18:36 ~$ /tmp/test const: 1 const: 0 18:36 ~$ objdump -S /tmp/test ... 00000000004004e0
: return a; } int main() { printf("const: %d\n", __builtin_constant_p(0)); 4004e0: 50 push %rax 4004e1: bf a0 05 40 00 mov $0x4005a0,%edi 4004e6: be 01 00 00 00 mov $0x1,%esi 4004eb: 31 c0 xor %eax,%eax 4004ed: e8 fe fe ff ff callq 4003f0 printf("const: %d\n", __builtin_constant_p(a)); 4004f2: bf a0 05 40 00 mov $0x4005a0,%edi 4004f7: 31 f6 xor %esi,%esi 4004f9: 31 c0 xor %eax,%eax 4004fb: e8 f0 fe ff ff callq 4003f0 return test_thing(0); 400500: 31 c0 xor %eax,%eax 400502: 59 pop %rcx 400503: c3 retq 400504: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 40050b: 00 00 00 40050e: 66 90 xchg %ax,%ax ...