On Sat, 6 Nov 2010 03:36:27 +0900 Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> wrote: > Andrew Morton wrote: > > > > #define roundup(x, y) ( \ > > > > { \ > > > > typeof(y) __y = y; \ > > > > (((x) + (__y - 1)) / __y) * __y; \ > > > > } \ > > > > ) > > > > > > > > for roundup((long long), (const)) case. > > > > > > I guess this is my fault (I'm not completely convinced) since my testing > > > was done with gcc 4. I just retested to make sure that > > > gcc-4.5.1-4.fc14.x86_64 is able to optimize both (and it does). Is the > > > fact that it requires compiler optimizations for the code to build a > > > good thing? > > > > It does make us pretty fragile against future compiler versions, but we > > do rely quite a lot on such compiler things. And things do break, such > > as the several-month outbreak of calls to > > you_cannot_kmalloc_that_much() a while back. > > > > I wonder if there's some way of tricking gcc back into doing the right > > thing here. Make __y const or something? > > Nice suggestion. > > -typeof(y) __y = y; > +const typeof(y) __y = y; > > solved __divdi3 problem with GCC 3.3.5. > OK, thanks. Pending any better ideas, I typed this in: From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> gcc-3.3.5 (at least) is failing to optimise away the divide when `y' is a constant 64-bit power-of-two value - it emits a call to __divdi3(). It turns out that defining `y' as const prevents this. Reported-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Tested-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Cc: Randy Dunlap <randy.dunlap@xxxxxxxxxx> Cc: Eric Paris <eparis@xxxxxxxxxx> Cc: James Morris <jmorris@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/kernel.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff -puN include/linux/kernel.h~include-linux-kernelh-roundup-work-around-a-gcc-33-miscompile include/linux/kernel.h --- a/include/linux/kernel.h~include-linux-kernelh-roundup-work-around-a-gcc-33-miscompile +++ a/include/linux/kernel.h @@ -58,9 +58,11 @@ extern const char linux_proc_banner[]; #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) + +/* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ #define roundup(x, y) ( \ { \ - typeof(y) __y = y; \ + const typeof(y) __y = y; \ (((x) + (__y - 1)) / __y) * __y; \ } \ ) _ -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html