Mail Archives: djgpp/2003/01/29/11:45:44
Jan Engelhardt wrote:
> Martin Dickop wrote:
> > CBFalconer <cbfalconer AT yahoo DOT com> writes:
> >
> >> It seems to me that a lot of time is spent executing strlen. I
> >> had expected gcc for the x86 to generate some fast string scan
> >> instructions inline, but every time I look I find calls to the
> >> library.
>
> Aside from what is shown in earlier reply, try adding the
> -finline-functions flag to GCC. (I use gcc 2.95.3 and I see
> repnz scasb in the GDB and HT disassembler often.)
>
> > What version of gcc are you using, and what flags? With gcc 3.2
> > on a x86 GNU/Linux system and -O2 optimization, this code
> >
> > #include <string.h>
> > size_t foo (const char *s) { return strlen (s); }
> >
> > generates `repnz scasb' as the loop to scan for the '\0'
> > character.
Not here. Under DJGPP, gcc 3.2.1 with:
gcc -W -Wall -ansi -pedantic -gstabs+ -O2 -Wa,-alhn=strlgh.s
strlgh.c
gives the following listing with the stabs lines deleted (long
lines, thus pasted as quote):
-minline-all-stringops doesn't bring in any scasb sequences
either. (All this may have more to do with the library than gcc)
> 1 .file "strlgh.c"
> 4 .section .text
> 5 Ltext0:
> 46 .globl _s
> 47 LC0:
> 48 0000 54686973 .ascii "This is a string\0"
> 48 20697320
> 48 61207374
> 48 72696E67
> 48 00
> 49 .section .data
> 50 .p2align 2
> 51 _s:
> 52 0000 00000000 .long LC0
> 53 0004 00000000 .section .text
> 53 00000000
> 53 00000000
> 54 LC1:
> 55 0011 25642025 .ascii "%d %s\12\0"
> 55 730A00
> 56 0018 908DB426 .p2align 4,,15
> 56 00000000
> 60 .globl _main
> 61 _main:
> 1:strlgh.c **** /* Compile with -Wa,-alhn=strlgh.s to show code generated */
> 2:strlgh.c **** /* also try -minline-all-stringops */
> 3:strlgh.c ****
> 4:strlgh.c **** #include <stdio.h>
> 5:strlgh.c **** #include <string.h>
> 6:strlgh.c ****
> 7:strlgh.c **** char *s = "This is a string";
> 8:strlgh.c ****
> 9:strlgh.c **** int main(int argc, char *argv[])
> 10:strlgh.c **** {
> 62 .stabn 68,0,10,LM1-_main
> 63 LM1:
> 64 0020 55 pushl %ebp
> 11:strlgh.c **** int lgh;
> 12:strlgh.c ****
> 13:strlgh.c **** lgh = strlen(s);
> 66 LM2:
> 67 LBB2:
> 68 0021 8B0D9000 movl _s, %ecx
> 68 0000
> 70 LM3:
> 71 0027 89E5 movl %esp, %ebp
> 72 0029 56 pushl %esi
> 73 002a 53 pushl %ebx
> 74 002b 83E4F0 andl $-16, %esp
> 75 002e 8B750C movl 12(%ebp), %esi
> 77 LM4:
> 78 0031 83EC0C subl $12, %esp
> 80 LM5:
> 81 0034 8B5D08 movl 8(%ebp), %ebx
> 83 LM6:
> 84 0037 51 pushl %ecx
> 85 0038 E8C3FFFF call _strlen
> 85 FF
> 14:strlgh.c **** printf("%d %s\n", lgh, s);
> 87 LM7:
> 88 003d 8B159000 movl _s, %edx
> 88 0000
> 89 0043 83C40C addl $12, %esp
> 90 0046 52 pushl %edx
> 91 0047 50 pushl %eax
> 92 0048 68110000 pushl $LC1
> 92 00
> 93 004d E8AEFFFF call _printf
> 93 FF
> 15:strlgh.c **** if (argc)
> 95 LM8:
> 96 0052 83C410 addl $16, %esp
> 97 0055 85DB testl %ebx, %ebx
> 98 0057 7403 je L2
> 16:strlgh.c **** while (--argc) {
> 100 LM9:
> 101 0059 4B decl %ebx
> 102 005a 7509 jne L6
> 103 L2:
> 17:strlgh.c **** lgh = strlen(argv[argc]);
> 18:strlgh.c **** printf("%d %s\n", lgh, argv[argc]);
> 19:strlgh.c **** }
> 20:strlgh.c **** return 0;
> 21:strlgh.c **** }
> 105 LM10:
> 106 LBE2:
> 107 005c 8D65F8 leal -8(%ebp), %esp
> 108 005f 31C0 xorl %eax, %eax
> 109 0061 5B popl %ebx
> 110 0062 5E popl %esi
> 111 0063 5D popl %ebp
> 112 0064 C3 ret
> 113 .p2align 4,,7
> 114 L6:
> 116 LM11:
> 117 LBB3:
> 118 0065 83EC0C subl $12, %esp
> 119 0068 8B0C9E movl (%esi,%ebx,4), %ecx
> 120 006b 51 pushl %ecx
> 121 006c E88FFFFF call _strlen
> 121 FF
> 123 LM12:
> 124 0071 8B149E movl (%esi,%ebx,4), %edx
> 125 0074 83C40C addl $12, %esp
> 126 0077 52 pushl %edx
> 127 0078 50 pushl %eax
> 128 0079 68110000 pushl $LC1
> 128 00
> 129 007e E87DFFFF call _printf
> 129 FF
> 130 0083 83C410 addl $16, %esp
> 131 0086 4B decl %ebx
> 132 0087 75DC jne L6
> 133 0089 EBD1 jmp L2
> 134 LBE3:
> 143 Lscope0:
> 146 .text
> 148 Letext:
> 149 008b 90909090 .ident "GCC: (GNU) 3.2.1"
> 149 90
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
- Raw text -