[PATCH v2] Add __pure2 to __locale_ctype_ptr(_l)

Wilco Dijkstra Wilco.Dijkstra@arm.com
Tue Nov 7 15:02:00 GMT 2017

Corinna Vinschen wrote: 
On Nov  6 18:40, Wilco Dijkstra wrote:

> I tried again on an x86_64 system running gcc 6.4.0, with -O2, -O3, with
> the original while as well as a for loop, with and without __pure2, and
> I don't see any difference whatsoever.

Did you check the call to __locale_ctype_ptr is lifted out of the loop in the
optimized case? It seems you might just be benchmarking the original version.
Even GCC4.8 optimizes a slightly modified version of your loop with -O3:

    for (p = &arr[0]; c = *p++; )
      a = ispunct (c);
      if (a)
        printf ("holla\n");

And it works with -O2 if you split off the p++ in the increment part of the for.

> So it seems this is very much architecture dependent.  We can surely add
> __pure2 if it makes a difference on some platforms.

No this is certainly not architecture dependent. The ctype implementation used to
be fast, but it is slow now - changes made to ctype last year caused it.


More information about the Newlib mailing list