Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752960AbbDFHVy (ORCPT ); Mon, 6 Apr 2015 03:21:54 -0400 Received: from hofr.at ([212.69.189.236]:48862 "EHLO mail.hofr.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750961AbbDFHVw (ORCPT ); Mon, 6 Apr 2015 03:21:52 -0400 Date: Mon, 6 Apr 2015 09:21:50 +0200 From: Nicholas Mc Guire To: Joe Perches Cc: Nicholas Mc Guire , Michal Marek , Masahiro Yamada , Sam Ravnborg , Thomas Gleixner , "H. Peter Alvin" , John Stultz , Andrew Hunter , Paul Turner , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] time: allow gcc to fold constants when using msecs_to_jiffies Message-ID: <20150406072150.GA14317@opentech.at> References: <1428218636-3780-1-git-send-email-hofrat@osadl.org> <1428218636-3780-3-git-send-email-hofrat@osadl.org> <1428278627.2775.75.camel@perches.com> <20150406010025.GA5956@opentech.at> <1428286502.2775.92.camel@perches.com> <20150406042654.GA28155@opentech.at> <1428294823.2775.94.camel@perches.com> <20150406064005.GA32350@opentech.at> <1428304366.2775.98.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1428304366.2775.98.camel@perches.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2444 Lines: 102 On Mon, 06 Apr 2015, Joe Perches wrote: > On Mon, 2015-04-06 at 08:40 +0200, Nicholas Mc Guire wrote: > > #define msecs_to_jiffies(m) \ > > (__builtin_constant_p (m) \ > > ? ((m) * HZ / MSECS_PER_SEC ) : __msecs_to_jiffies(m)) > [] > > main: > > .LFB12: > > .cfi_startproc > > subq $8, %rsp #, > > .cfi_def_cfa_offset 16 > > movl $10, %esi #, > > movl $.LC0, %edi #, > > xorl %eax, %eax # > > call printf # > > vs: > > > static inline unsigned long msecs_to_jiffies(int m) > > { > > return __builtin_constant_p (m) ? > > (m) * HZ / MSECS_PER_SEC : __msecs_to_jiffies(m); > > } > [] > > main: > > .LFB13: > > .cfi_startproc > > subq $8, %rsp #, > > .cfi_def_cfa_offset 16 > > xorl %esi, %esi # > > movl $.LC0, %edi #, > > xorl %eax, %eax # > > call printf # > > > > giving it another run from scratch somewhere I simply screwed up or > > overlooked some detail. > > If the optimizer was doing it's job properly, wouldn't > the macro and inline output object code be the same? > yes - and they are - that was my mistake I grabed the wrong asm snippet - here is the complete test case also made a mess of the code while trimming down the mail - so here is the single test case showing, I think, that inline works as well and as expected. testi.h: #define HZ 100 #define MSECS_PER_SEC 1000 #define TIMEOUT 100 extern inline unsigned long __msecs_to_jiffies(int m); unsigned long msecs_to_jiffies(int m) { return __builtin_constant_p(m) ? ((m) * HZ / MSECS_PER_SEC ) : __msecs_to_jiffies(m); } test.c: #include #include "testi.h" unsigned long __msecs_to_jiffies(int m) { return (m * HZ / MSECS_PER_SEC); } int main(int argc, char **argv) { //int m = atoi(argv[1]); int m = TIMEOUT; printf("%lu\n",msecs_to_jiffies(m)); return 0; } compiled with: gcc -O2 -S --verbose-asm test.c main: .LFB13: .cfi_startproc subq $8, %rsp #, .cfi_def_cfa_offset 16 movl $10, %esi #, movl $.LC0, %edi #, xorl %eax, %eax # call printf # need to cleanup here :) thx! hofrat -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/