crc32: remove useless __pure modifier from functions
PATCH 1/1 crc32: remove useless __pure modifier from functions
From: Pekka Enberg <[email protected]>
The pure attribute has absolutely no effect with GCC 4.2:
text data bss dec hex filename 2456 0 0 2456 998 lib/crc32.o.old 2456 0 0 2456 998 lib/crc32.o.new
--- lib/crc32.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
lib/crc32.c +6 -6
@@ -49,7 +49,7 @@ MODULE_LICENSE("GPL");* @p: pointer to buffer over which CRC is run * @len: length of buffer @p */ -u32 __pure crc32_le (u32 crc,unsigned char const *p,size_t len); +u32 crc32_le (u32 crc,unsigned char const *p,size_t len);#if CRC_LE_BITS ==1 /*
@@ -57,7 +57,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len);* simplified by inlining the table in ?: form. */ -u32 __pure crc32_le (u32 crc,unsigned char const *p,size_t len) +u32 crc32_le (u32 crc,unsigned char const *p,size_t len) {int i;while (len--) {
@@ -69,7 +69,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) }#else /* Table-based approach */ -u32 __pure crc32_le (u32 crc,unsigned char const *p,size_t len) +u32 crc32_le (u32 crc,unsigned char const *p,size_t len) {# if CRC_LE_BITS ==8 const u32 *b =(u32 *)p;
@@ -145,7 +145,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)* @p: pointer to buffer over which CRC is run * @len: length of buffer @p */ -u32 __pure crc32_be (u32 crc,unsigned char const *p,size_t len); +u32 crc32_be (u32 crc,unsigned char const *p,size_t len);#if CRC_BE_BITS ==1 /*
@@ -153,7 +153,7 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len);* simplified by inlining the table in ?: form. */ -u32 __pure crc32_be (u32 crc,unsigned char const *p,size_t len) +u32 crc32_be (u32 crc,unsigned char const *p,size_t len) {int i;while (len--) {
@@ -167,7 +167,7 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) }#else /* Table-based approach */ -u32 __pure crc32_be (u32 crc,unsigned char const *p,size_t len) +u32 crc32_be (u32 crc,unsigned char const *p,size_t len) {# if CRC_BE_BITS ==8 const u32 *b =(u32 *)p;
Signature · 1 line
1.5.4.3
Actually, the effects of most keywords (like const, etc) affect things outside of the module (the callers)
http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Function-Attributes.html
has a good explanation.
Briefly, a _pure function only depends on its parameters and the only return is via the function return, so the compiler can optimize some of its calls away.
Signature · 2 lines
- Thiago Galesi
Quoted 82 lines · Pekka Enberg
From: Pekka Enberg <[email protected]>
The pure attribute has absolutely no effect with GCC 4.2:
text data bss dec hex filename 2456 0 0 2456 998
lib/crc32.o.old2456 0 0 2456 998lib/crc32.o.newSigned-off-by Pekka Enberg <[email protected]>---
lib/crc32.c | 12 ++++++------1 files changed, 6 insertions(+), 6 deletions(-)lib/crc32.c +6
-7@@ -49,7 +49,7 @@ MODULE_LICENSE("GPL");* @p: pointer to buffer over which CRC is run * @len: length of buffer @p */ -u32 __pure crc32_le (u32 crc,unsigned char const *p,size_t len); +u32 crc32_le (u32 crc,unsigned char const *p,size_t len); #if CRC_LE_BITS == 1 /*@@ -57,7 +57,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len);* simplified by inlining the table in ?: form. */ -u32 __pure crc32_le (u32 crc,unsigned char const *p,size_t len) +u32 crc32_le (u32 crc,unsigned char const *p,size_t len) { int i; while (len--) {@@ -69,7 +69,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len) } #else /* Table-based approach */ -u32 __pure crc32_le (u32 crc,unsigned char const *p,size_t len) +u32 crc32_le (u32 crc,unsigned char const *p,size_t len) { # if CRC_LE_BITS == 8 const u32 *b =(u32 *)p;@@ -145,7 +145,7 @@ u32 __pure crc32_le(u32 crc, unsigned char const *p, size_t len)* @p: pointer to buffer over which CRC is run * @len: length of buffer @p */ -u32 __pure crc32_be (u32 crc,unsigned char const *p,size_t len); +u32 crc32_be (u32 crc,unsigned char const *p,size_t len); #if CRC_BE_BITS == 1 /*@@ -153,7 +153,7 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len);* simplified by inlining the table in ?: form. */ -u32 __pure crc32_be (u32 crc,unsigned char const *p,size_t len) +u32 crc32_be (u32 crc,unsigned char const *p,size_t len) { int i; while (len--) {@@ -167,7 +167,7 @@ u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len) } #else /* Table-based approach */ -u32 __pure crc32_be (u32 crc,unsigned char const *p,size_t len) +u32 crc32_be (u32 crc,unsigned char const *p,size_t len) { # if CRC_BE_BITS == 8 const u32 *b =(u32 *)p; --1.5.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 9 lines · Thiago Galesi
Actually, the effects of most keywords (like const, etc) affect things outside of the module (the callers)
http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Function-Attributes.html
has a good explanation.Briefly, a
_purefunction only depends on its parameters and the only return is via the function return, so the compiler can optimize some of its calls away.
Hmm. They're not marked as pure in the header files. Does GCC look it up from the object file or something for this...?
Pekka
Quoted 3 lines
Hmm. They're not marked as pure in the header files. Does GCC look it up from the object file or something for this...?
I just tested this, the answer is No :(
It only works if it's marked in the header. But when it's marked, it works, and redundant calls are optimized.
Signature · 2 lines
- Thiago Galesi
Quoted 8 lines · Thiago Galesi
Quoted 3 lines
Hmm. They're not marked as pure in the header files. Does GCC look it up from the object file or something for this...?
I just tested this, the answer is No :(
It only works if it's marked in the header. But when it's marked, it works, and redundant calls are optimized.
Did you see any change in size of your kernel with this annotation? It didn't seem to have any effect as far as I could tell.
There are a number of functions in lib/ code that could be marked __pure or __attribute_const__ but I'm not sure if it's worth the effort, for my compiler (gcc 4.2) at least.
Quoted 3 lines
Did you see any change in size of your kernel with this annotation? It didn't seem to have any effect as far as I could tell.
No, because I didn't test it with the kernel. Anyway, probably size won't change a lot.
What the compiler does is: if (you're saying) it's a pure function, and it has been called previously with the same parameters, the return value is identical, hence, the compiler doesn't need to call the function again.
Here's the test I did http://duskblue.org/pure_test.tar.gz Pretty straighforward, but you have to 'make CFLAGS=-O1' to make the optimization work.
Quoted 5 lines
There are a number of functions in
lib/code that could be marked__pureor__attribute_const__but I'm not sure if it's worth the effort, for my compiler (gcc 4.2) at least.
What const does is similar: it indicates that the function will not change parameters marked with __const, so it will not need to reload them after the function is called.
Signature · 2 lines
- Thiago Galesi