This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] PowerPC: stpcpy optimization for PPC64/POWER7
- From: Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Wed, 18 Sep 2013 16:00:08 -0300
- Subject: Re: [PATCH] PowerPC: stpcpy optimization for PPC64/POWER7
- Authentication-results: sourceware.org; auth=none
- References: <523715EE dot 9070408 at linux dot vnet dot ibm dot com> <20130917061516 dot GA30130 at bubble dot grove dot modra dot org> <5239B9FE dot 4090506 at linux dot vnet dot ibm dot com> <5239CC7B dot 5010804 at twiddle dot net> <5239E5B2 dot 9050604 at linux dot vnet dot ibm dot com> <5239EFD6 dot 3050701 at twiddle dot net>
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