This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PowerPC: stpcpy optimization for PPC64/POWER7


On 18-09-2013 15:24, Richard Henderson wrote:
> #include <string.h>
> #include <assert.h>
>
> char x[16] __attribute__((aligned(8))) = { "abcd" "efgh" "ij\0l" "mnop" };
> char y[16] __attribute__((aligned(8))) = { "zzzz" "zzzz" "zzzz"  "zzzz" };
>
> int main()
> {
>     long rmask, ralt, rtmp;
>     char *rsrc = x + 8;
>     char *rdst = y + 8;
>
>     asm("ld	%[rtmp], 0(%[rsrc])\n\t"
> 	"cmpb	%[rmask],%[rtmp],%[rzero]\n\t"
>
>         "cntlzd	%[rmask], %[rmask]\n\t"
> 	"srdi	%[rmask], %[rmask],3\n\t"
> 	"addi	%[ralt], %[rmask],-7\n\t"
> 	"ldx	%[rtmp], %[rsrc], %[ralt]\n\t"
> 	"stdx	%[rtmp], %[rdst], %[ralt]\n\t"
> 	"add	%[rdst], %[rdst], %[rmask]"
>
> 	: [rdst] "+b" (rdst),
>           [rtmp] "=r" (rtmp),
>           [ralt] "=r" (ralt),
>           [rmask] "=r" (rmask)
>         : [rzero] "r" (0),
>           [rsrc] "b" (rsrc)
>         : "memory");
>
>     assert(*rdst == '\0');
>     assert(memcmp(y, "zzzd" "efgh" "ij\0z" "zzzz", 16) == 0);
>     ret$ gcc -O0 -g test2.c -o test2urn 0;
> }

Well, your example SIGSEGVed in POWER7 system:

$ gcc -O0 -g test.c -o test && gdb ./test
(gdb) r
Program received signal SIGSEGV, Segmentation fault.
0x00000000100005d8 in main () at test.c:13
13          asm("ld     %[rtmp], 0(%[rsrc])\n\t"
(gdb) disas
[...]
   0x00000000100005cc <+60>:    cntlzd  r9,r9
   0x00000000100005d0 <+64>:    rldicl  r9,r9,61,3
   0x00000000100005d4 <+68>:    addi    r11,r9,-7
=> 0x00000000100005d8 <+72>:    ldx     r10,r11,r11
[...]
(gdb) info r r11
r11            0xfffffffffffffffb       18446744073709551611


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]