* RE: [PATCH] include/asm-ARCH/page.h:get_order() Reorganize and op timize
@ 2002-11-13 23:44 Perez-Gonzalez, Inaky
2002-11-14 0:26 ` Falk Hueffner
0 siblings, 1 reply; 3+ messages in thread
From: Perez-Gonzalez, Inaky @ 2002-11-13 23:44 UTC (permalink / raw)
To: 'Falk Hueffner'; +Cc: alan, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1810 bytes --]
> > s = --s >> PAGE_SHIFT;
>
> This code has undefined behaviour.
Do you mean that this:
s = (s-1) >> PAGE_SHIFT
is more deterministic? If so, I agree -- if you mean
something else, I am kind of lost.
> > if (likely (s) < s)
>
> What is that supposed to do?
This is doing the "you are looking at the obvious
and not noticing" [I mean me, not you]. I started with
another algorithm, crappier, that required this in order
to work properly, and I never took it out; not to mention
it is wrong - it should read 'if (likely ((1 << exp) < s))'
... McFly, anybody home?
I also realized I was not calling get_order() -the old version-
statically in the test case, so that slowed it down ... in any
case, it does not seem to affect much [probably because of the
tight loop].
> BTW, I just noticed
>
> #define likely(x) __builtin_expect((x),1)
>
> I think this should rather be
>
> #define likely(x) __builtin_expect((x)!=0,1)
Yep, for NGPT what I did was to cast it to unsigned long,
although your way might be more elegant. Care to submit that?
Okay, so now I got it fixed, I will be submitting a new patch
right now with the whole thing against 2.5.47. The changes versus
the previous one are:
--- page.h 13 Nov 2002 00:49:22 -0000 1.1.2.1
+++ page.h 13 Nov 2002 22:58:51 -0000 1.1.2.2
@@ -10,17 +10,10 @@
static __inline__
int generic_get_order (unsigned long s)
{
- int exp;
-
- s = --s >> PAGE_SHIFT;
+ s = (s - 1) >> PAGE_SHIFT;
if (s == 0)
return 0;
-
- exp = fls (s);
- s = 1 << exp;
- if (likely (s) < s)
- exp++;
- return exp;
+ return fls (s);
}
#endif _GENERIC_PAGE_H
Inaky Perez-Gonzalez -- Not speaking for Intel - opinions are my own [or my
fault]
[-- Attachment #2: tt.txt --]
[-- Type: text/plain, Size: 736 bytes --]
Index: page.h
===================================================================
RCS file: /home/CVS/src/linux/kernel/linux/include/asm-generic/Attic/page.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- page.h 13 Nov 2002 00:49:22 -0000 1.1.2.1
+++ page.h 13 Nov 2002 22:58:51 -0000 1.1.2.2
@@ -10,17 +10,10 @@
static __inline__
int generic_get_order (unsigned long s)
{
- int exp;
-
- s = --s >> PAGE_SHIFT;
+ s = (s - 1) >> PAGE_SHIFT;
if (s == 0)
return 0;
-
- exp = fls (s);
- s = 1 << exp;
- if (likely (s) < s)
- exp++;
- return exp;
+ return fls (s);
}
#endif _GENERIC_PAGE_H
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] include/asm-ARCH/page.h:get_order() Reorganize and op timize
2002-11-13 23:44 [PATCH] include/asm-ARCH/page.h:get_order() Reorganize and op timize Perez-Gonzalez, Inaky
@ 2002-11-14 0:26 ` Falk Hueffner
0 siblings, 0 replies; 3+ messages in thread
From: Falk Hueffner @ 2002-11-14 0:26 UTC (permalink / raw)
To: Perez-Gonzalez, Inaky; +Cc: alan, linux-kernel
"Perez-Gonzalez, Inaky" <inaky.perez-gonzalez@intel.com> writes:
> > > s = --s >> PAGE_SHIFT;
> >
> > This code has undefined behaviour.
>
> Do you mean that this:
>
> s = (s-1) >> PAGE_SHIFT
>
> is more deterministic? If so, I agree -- if you mean something else,
> I am kind of lost.
I mean that this code violates the rule that you may modify a value
only once between two sequence points. Newer gccs have a warning for
this (-Wsequence-point), the info page tells more.
Also, did I understand it right that you want to use fls even on
architectures that don't have it as a builtin? I would guess that will
actually be noticeably slower, since generic_fls is so complicated.
--
Falk
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] include/asm-ARCH/page.h:get_order() Reorganize and op timize
@ 2002-11-14 0:43 Perez-Gonzalez, Inaky
0 siblings, 0 replies; 3+ messages in thread
From: Perez-Gonzalez, Inaky @ 2002-11-14 0:43 UTC (permalink / raw)
To: 'Falk Hueffner'; +Cc: alan, linux-kernel
> > > > s = --s >> PAGE_SHIFT;
> > >
> > > This code has undefined behaviour.
> >
> > Do you mean that this:
> >
> > s = (s-1) >> PAGE_SHIFT
> >
> > is more deterministic? If so, I agree -- if you mean something else,
> > I am kind of lost.
>
> I mean that this code violates the rule that you may modify a value
> only once between two sequence points. Newer gccs have a warning for
> this (-Wsequence-point), the info page tells more.
Agreed, and it was a poor choice from me. (s-1) should be correct,
and gcc-3.2 with -Wsequence-point is happy about it.
> Also, did I understand it right that you want to use fls even on
> architectures that don't have it as a builtin? I would guess that will
> actually be noticeably slower, since generic_fls is so complicated.
Well, it is not that bad, and it is still faster [did a quick test now]
0.144s, 0.241s and 0.358s
[get_order on all numbers from 0 to 90000000 with the optimized version,
the one that uses generic_fls and the old one].
Inaky Perez-Gonzalez -- Not speaking for Intel - opinions are my own [or my
fault]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-11-14 0:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-13 23:44 [PATCH] include/asm-ARCH/page.h:get_order() Reorganize and op timize Perez-Gonzalez, Inaky
2002-11-14 0:26 ` Falk Hueffner
2002-11-14 0:43 Perez-Gonzalez, Inaky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®