Patch to add builtin strncmp and builtin strncpy
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Sun Nov 26 18:31:00 GMT 2000
> From: Jakub Jelinek <jakub@redhat.com>
> >
> > Why not also
> >
> > strncpy(s1, "string", n) -> memcpy (s1, "string", sizeof ("string")+1)
> > (where strlen("string")+1 < n)
>
> Because they do different thing, strncpy has to pad it with '\0' up to
> length n.
Exactly.
> The transformation could be really
> -> slen = strlen ("string") + 1;
> memcpy (s1, "string", slen);
> memset (s1 + slen, 0, n - slen);
>
> but then the question is if it is really an optimization (it could be if
> both memcpy and memset are inlined.
Is there a way to tell if memset is going to be inlined by gcc ahead
of time? E.g. if (n-slen) < some-threshold? I could then have the
builtin transform these cases too. (The clear_storage() function is
gobbledygook to me.)
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions
More information about the Gcc-patches
mailing list