[PATCH 08/27] S390: Optimize strnlen and wcsnlen.

Ondřej Bílka neleai@seznam.cz
Fri Jun 26 19:45:00 GMT 2015


On Fri, Jun 26, 2015 at 01:51:33PM +0200, Stefan Liebler wrote:
> This patch provides optimized versions of strnlen and wcsnlen with the z13
> vector instructions.
snip

> +	/* Find zero in 16 byte aligned loop.  */
> +.Lloop1:
> +	vl	%v16,0(%r5,%r2) /* Load s.  */
> +	aghi	%r5,16
> +	vfenezbs %v16,%v16,%v16	/* Find element not equal with zero search.  */
> +	je	.Lfound	/* Jump away if zero was found.  */
> +	clgrjhe	%r5,%r3,.Lfound /* current_len >= maxlen -> end.  */
> +	vl	%v16,0(%r5,%r2)
> +	aghi	%r5,16
> +	vfenezbs %v16,%v16,%v16
> +	je	.Lfound
> +	clgrjhe	%r5,%r3,.Lfound
> +	vl	%v16,0(%r5,%r2)
> +	aghi	%r5,16
> +	vfenezbs %v16,%v16,%v16
> +	je	.Lfound
> +	clgrjhe	%r5,%r3,.Lfound
> +	vl	%v16,0(%r5,%r2)
> +	aghi	%r5,16
> +	vfenezbs %v16,%v16,%v16
> +	je	.Lfound
> +	clgrjl	%r5,%r3,.Lloop1 /* maxlen not reached -> loop.  */

While I couldn't find any program that calls strnlen and one could argue
to optimize this for size this also looks bit suboptimal.

Here you could expand prologue with four checks to be make loop 64-byte
aligned. Then you could check maxlen only once per 64 bytes.




More information about the Libc-alpha mailing list