public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Mc Guire <der.herr@hofr.at>
To: Joe Perches <joe@perches.com>
Cc: Nicholas Mc Guire <hofrat@osadl.org>,
	Michal Marek <mmarek@suse.cz>,
	Masahiro Yamada <yamada.m@jp.panasonic.com>,
	Sam Ravnborg <sam@ravnborg.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Alvin" <hpa@zytor.com>,
	John Stultz <john.stultz@linaro.org>,
	Andrew Hunter <ahh@google.com>, Paul Turner <pjt@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] time: allow gcc to fold constants when using msecs_to_jiffies
Date: Mon, 6 Apr 2015 09:21:50 +0200	[thread overview]
Message-ID: <20150406072150.GA14317@opentech.at> (raw)
In-Reply-To: <1428304366.2775.98.camel@perches.com>

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 <stdio.h>
#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
<snip>
main:
.LFB13:
        .cfi_startproc
        subq    $8, %rsp        #,
        .cfi_def_cfa_offset 16
        movl    $10, %esi       #,
        movl    $.LC0, %edi     #,
        xorl    %eax, %eax      #
        call    printf  #
<snip>


need to cleanup here :)

thx!
hofrat

  reply	other threads:[~2015-04-06  7:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-05  7:23 [PATCH 0/3] time: use __builtin_constant_p() in msecs_to_jiffies Nicholas Mc Guire
2015-04-05  7:23 ` [PATCH 1/3] time: move timeconst.h into include/generated Nicholas Mc Guire
2015-04-05  7:23 ` [PATCH 2/3] time: allow gcc to fold constants when using msecs_to_jiffies Nicholas Mc Guire
2015-04-06  0:03   ` Joe Perches
2015-04-06  1:00     ` Nicholas Mc Guire
2015-04-06  2:15       ` Joe Perches
2015-04-06  4:26         ` Nicholas Mc Guire
2015-04-06  4:33           ` Joe Perches
2015-04-06  6:40             ` Nicholas Mc Guire
2015-04-06  7:12               ` Joe Perches
2015-04-06  7:21                 ` Nicholas Mc Guire [this message]
2015-04-12  8:36         ` Nicholas Mc Guire
2015-04-05  7:23 ` [PATCH 3/3] time: update msecs_to_jiffies doc and move to kernel-doc format Nicholas Mc Guire
2015-04-05  9:33 ` [PATCH 0/3] time: use __builtin_constant_p() in msecs_to_jiffies Joe Perches

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=20150406072150.GA14317@opentech.at \
    --to=der.herr@hofr.at \
    --cc=ahh@google.com \
    --cc=hofrat@osadl.org \
    --cc=hpa@zytor.com \
    --cc=joe@perches.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=pjt@google.com \
    --cc=sam@ravnborg.org \
    --cc=tglx@linutronix.de \
    --cc=yamada.m@jp.panasonic.com \
    /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