From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Jelinek To: Ulrich Drepper Cc: libc-hacker@sourceware.cygnus.com Subject: Re: [PATCH] shut up warnings in bits/string2.h Date: Wed, 08 Dec 1999 00:22:00 -0000 Message-id: <19991208092350.A545@mff.cuni.cz> References: <19991207220811.M515@mff.cuni.cz> X-SW-Source: 1999-12/msg00019.html On Tue, Dec 07, 1999 at 11:38:43PM -0800, Ulrich Drepper wrote: > Jakub Jelinek writes: > > > This patch shuts up gcc 2.96 warnings about long switch expressions not > > converted to int. > > Well, rth commented that this might fail for long strings. But those > strings must be string constants, not actual strings. And gcc (nor > any other compiler) will have support for strings of more than 2^32 > character in length. So it should be possible to apply the patch. All the inlines where I changed this are invoked from macros which guard it by something like this: __builtin_constant_p (n) && (n) <= 16 where the length limit is 16 or 8 as far as I could see, so I don't see how that could be a problem (the only problematic thing could be say memcpy(p, "string", -4) because then n is builtin constant and is <= 16, but that should be guarded by __builtin_constant_p (n) && (n) <= 16U ). > > > How does it work on other architectures? > > Which functions? The generic functions should perform quite good. > The copying of constant strings work by moving immedate values which > is much faster. E.g. #include void foo(char *p) { strcpy(p, "strn"); } gets compiled with -O2 -m32 by gcc 2.96 (but similarly by egcs 1.1.2) into: foo: save %sp, -224, %sp sethi %hi(.LLC0+1), %o0 or %o0, %lo(.LLC0+1), %o0 add %o0, -1, %o5 sub %o0, %o5, %o0 cmp %o0, 1 bne .LL145 mov %i0, %o0 mov 115, %o1 mov 116, %o2 mov 114, %o3 mov 110, %o4 stb %o1, [%fp-32] stb %g0, [%fp-31] stb %o1, [%fp-24] stb %g0, [%fp-23] stb %o1, [%fp-48] stb %o2, [%fp-47] stb %g0, [%fp-46] stb %o1, [%fp-40] stb %o2, [%fp-39] stb %g0, [%fp-38] stb %o1, [%fp-64] stb %o2, [%fp-63] stb %o3, [%fp-62] stb %g0, [%fp-61] stb %o1, [%fp-56] stb %o2, [%fp-55] stb %o3, [%fp-54] stb %g0, [%fp-53] stb %o1, [%fp-80] stb %o2, [%fp-79] stb %o3, [%fp-78] stb %o4, [%fp-77] stb %g0, [%fp-76] stb %o1, [%fp-72] stb %o2, [%fp-71] stb %o3, [%fp-70] stb %o4, [%fp-69] stb %g0, [%fp-68] ldub [%o5+5], %o7 mov %o1, %l0 stb %o1, [%fp-96] stb %o2, [%fp-95] stb %o3, [%fp-94] stb %o4, [%fp-93] stb %g0, [%fp-92] stb %g0, [%fp-91] stb %o1, [%fp-88] stb %o2, [%fp-87] stb %o3, [%fp-86] stb %o4, [%fp-85] stb %g0, [%fp-84] stb %g0, [%fp-83] stb %o1, [%fp-112] stb %o2, [%fp-111] stb %o3, [%fp-110] stb %o4, [%fp-109] stb %g0, [%fp-108] stb %o7, [%fp-107] stb %g0, [%fp-106] stb %o1, [%fp-104] stb %o2, [%fp-103] stb %o3, [%fp-102] stb %o4, [%fp-101] stb %g0, [%fp-100] stb %o7, [%fp-99] stb %g0, [%fp-98] ldub [%o5+6], %l1 mov %o2, %g3 ldub [%fp-68], %o0 stb %o1, [%fp-120] stb %o2, [%fp-119] stb %o3, [%fp-118] stb %o4, [%fp-117] stb %o7, [%fp-115] stb %l1, [%fp-114] mov %o3, %g2 mov %o4, %o5 stb %o0, [%i0+4] stb %l0, [%i0] stb %g3, [%i0+1] stb %g2, [%i0+2] stb %o5, [%i0+3] stb %o1, [%fp-128] stb %o2, [%fp-127] stb %o3, [%fp-126] stb %o4, [%fp-125] stb %g0, [%fp-124] stb %o7, [%fp-123] stb %l1, [%fp-122] stb %g0, [%fp-121] stb %g0, [%fp-116] b .LL144 stb %g0, [%fp-113] .LL145: mov %o5, %o1 call memcpy, 0 mov 5, %o2 .LL144: ret restore while compiling it with the same compiler with -O2 -D__NO_STRING_INLINES turns into (and similarly with egcs 1.1.2): foo: sethi %hi(.LLC0), %g2 ldub [%g2+%lo(.LLC0)], %g3 or %g2, %lo(.LLC0), %g2 stb %g3, [%o0] ldub [%g2+1], %g3 stb %g3, [%o0+1] ldub [%g2+2], %o1 stb %o1, [%o0+2] ldub [%g2+3], %g3 stb %g3, [%o0+3] ldub [%g2+4], %o1 retl stb %o1, [%o0+4] I haven't yet investigated what's the problem, but some string2.h inlines work as expected (e.g. memset). Cheers, Jakub ___________________________________________________________________ Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj Linux version 2.3.18 on a sparc64 machine (1343.49 BogoMips) ___________________________________________________________________