public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft•net>
To: rdreier@cisco•com
Cc: randy.dunlap@oracle•com, linux-next@vger•kernel.org,
	general@lists•openfabrics.org, linux-kernel@vger•kernel.org
Subject: Re: [ofa-general] [PATCH 2.6.30] RDMA/cxgb3: Remove modulo math.
Date: Wed, 11 Feb 2009 00:00:49 -0800 (PST)	[thread overview]
Message-ID: <20090211.000049.193727089.davem@davemloft.net> (raw)
In-Reply-To: <ada4oz1a188.fsf@cisco.com>

From: Roland Dreier <rdreier@cisco•com>
Date: Tue, 10 Feb 2009 23:20:39 -0800

>  > unsigned long page_size[4];
>  > 
>  > int main(int argc)
>  > {
>  >         unsigned long long x = argc;
>  > 
>  >         return x % (1UL << (12 + page_size[argc]));
>  > }
>  > 
>  > I get a call to __umoddi3:
> 
> You're not testing the same thing.  The original code was:
> 
> 		wqe->recv.sgl[i].to = cpu_to_be64(((u32) wr->sg_list[i].addr) %
> 				(1UL << (12 + page_size[i])));
> 
> and it's not that easy to see with all the parentheses, but the
> expression being done is (u32) % (unsigned long).  So rather than
> unsigned long long in your program, you should have just done unsigned
> (u32 is unsigned int on all Linux architectures).  In that case gcc does
> not generate a call to any library function in all the versions I have
> handy, although gcc 4.1 does do a div instead of an and.  (And I don't
> think any 32-bit architectures require a library function for (unsigned)
> % (unsigned), so the code should be OK)
> 
> Your example shows that gcc is missing a strength reduction opportunity
> in not handling (u64) % (unsigned long) on 32 bit architectures, but I
> guess it is a more difficult optimization to do, since gcc has to know
> that it can simply zero the top 32 bits.

Indeed, I get the divide if I use "unsigned int" for "x".

I still think you should make this change, as many systems out
there are getting the expensive divide.

main:
	sethi	%hi(page_size), %g1
	or	%g1, %lo(page_size), %g1
	mov	%o0, %g3
	sll	%o0, 2, %g4
	ld	[%g1+%g4], %g2
	mov	1, %g1
	add	%g2, 12, %g2
	sll	%g1, %g2, %g1
	wr	%g0, %g0, %y
	nop
	nop
	nop
	udiv	%o0, %g1, %o0
	smul	%o0, %g1, %o0
	jmp	%o7+8
	 sub	%g3, %o0, %o0

  reply	other threads:[~2009-02-11  8:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-10 18:44 [ofa-general] [PATCH 2.6.30] RDMA/cxgb3: Remove modulo math Steve Wise
2009-02-10 19:04 ` [ofa-general] " Randy Dunlap
2009-02-10 19:10   ` Steve Wise
2009-02-10 19:12     ` Randy Dunlap
2009-02-11  0:38 ` [ofa-general] " Roland Dreier
2009-02-11  1:03   ` Steve Wise
     [not found]   ` <499223F8.1010204@opengridcomputing.com>
2009-02-11  1:07     ` David Miller
2009-02-11  1:18       ` Roland Dreier
2009-02-11  1:23         ` David Miller
2009-02-11  7:20           ` Roland Dreier
2009-02-11  8:00             ` David Miller [this message]
2009-02-11 15:44   ` Steve Wise
2009-02-11 18:12     ` Roland Dreier
2009-02-11 18:32       ` Steve Wise
2009-02-11 18:36         ` Roland Dreier
2009-02-11 18:44           ` Steve Wise

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=20090211.000049.193727089.davem@davemloft.net \
    --to=davem@davemloft$(echo .)net \
    --cc=general@lists$(echo .)openfabrics.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=randy.dunlap@oracle$(echo .)com \
    --cc=rdreier@cisco$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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