Don't know whether I can ack this, but after modifiying the conditionals to always compile that part of the code, gcc did in fact compute the strlen result. <br><br>$ gcc -v<br>Using built-in specs.<br>Target: x86_64-linux-gnu<br>
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu<br>
Thread model: posix<br>gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) <br><br>Relevant outputs from processor_enable.c.003t.original after adding -fdump-tree-original to CFLAGS in the Makefile are inlined:<br><br><div class="gmail_quote">
On 30 September 2010 02:41, Carl-Daniel Hailfinger <span dir="ltr"><<a href="mailto:c-d.hailfinger.devel.2006@gmx.net">c-d.hailfinger.devel.2006@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Replace sizeof("string")-1 with strlen("string")<br>
<br>
We want to avoid calls to strlen at runtime if the string is already<br>
known at compile time.<br>
Turns out that gcc and clang will recognize constant strings and compute<br>
the strlen result already at compile time, so trickery with sizeof only<br>
reduces readability but does not improve the code.<br>
<br>
Signed-off-by: Carl-Daniel Hailfinger <<a href="mailto:c-d.hailfinger.devel.2006@gmx.net">c-d.hailfinger.devel.2006@gmx.net</a>><br>
<br>
Index: flashrom-const_strlen/processor_enable.c<br>
===================================================================<br>
--- flashrom-const_strlen/processor_enable.c    (Revision 1183)<br>
+++ flashrom-const_strlen/processor_enable.c    (Arbeitskopie)<br>
@@ -56,13 +56,13 @@<br>
                while (*ptr && isspace(*ptr))<br>
                        ptr++;<br>
                /* "cpu" part appears only with some Linux versions.  */<br>
-               if (strncmp(ptr, "cpu", sizeof("cpu") - 1) == 0)<br>
-                       ptr += sizeof("cpu") - 1;<br>
+               if (strncmp(ptr, "cpu", strlen("cpu")) == 0)<br>
+                       ptr += strlen("cpu");<br></blockquote><div><br>if (strncmp ((const char *) ptr, (const char *) "cpu", 3) == 0)<br>      {<br>        ptr = ptr + 3;<br>      }<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

                while (*ptr && isspace(*ptr))<br>
                        ptr++;<br>
-               if (strncmp(ptr, "model", sizeof("model") - 1) != 0)<br>
+               if (strncmp(ptr, "model", strlen("model")) != 0)<br>
                        continue;<br>
-               ptr += sizeof("model") - 1;<br>
+               ptr += strlen("model");<br></blockquote><div><br> if (strncmp ((const char *) ptr, (const char *) "model", 5) != 0)<br>      {<br>        // predicted unlikely by continue predictor.;<br>
        goto <D.4030>;<br>      }<br>    ptr = ptr + 5;<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
                while (*ptr && isspace(*ptr))<br>
                        ptr++;<br>
                if (*ptr != ':')<br>
@@ -72,9 +72,9 @@<br>
                        ptr++;<br>
                fclose(cpuinfo);<br>
                return (strncmp(ptr, "ICT Loongson-2 V0.3",<br>
-                               sizeof("ICT Loongson-2 V0.3") - 1) == 0)<br>
+                               strlen("ICT Loongson-2 V0.3")) == 0)<br>
                    || (strncmp(ptr, "Godson2 V0.3  FPU V0.1",<br>
-                               sizeof("Godson2 V0.3  FPU V0.1") - 1) == 0);<br>
+                               strlen("Godson2 V0.3  FPU V0.1")) == 0);<br>
        }<br></blockquote><div><br>fclose (cpuinfo);<br>    return strncmp ((const char *) ptr, (const char *) "ICT Loongson-2 V0.3", 19) == 0 || strncmp ((const char *) ptr, (const char *) "Godson2 V0.3  FPU V0.1", 22) == $<br>
  }<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
        fclose(cpuinfo);<br>
        return 0;<br>
<font color="#888888"><br>
<br>
--<br>
<a href="http://www.hailfinger.org/" target="_blank">http://www.hailfinger.org/</a><br>
<br>
<br>
_______________________________________________<br>
flashrom mailing list<br>
<a href="mailto:flashrom@flashrom.org">flashrom@flashrom.org</a><br>
<a href="http://www.flashrom.org/mailman/listinfo/flashrom" target="_blank">http://www.flashrom.org/mailman/listinfo/flashrom</a><br>
</font></blockquote></div>