lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Tue, 16 Jun 2015 15:16:45 -0700
From:	Joe Perches <joe@...ches.com>
To:	Orestes Leal Rodriguez <lukes357@...il.com>
Cc:	linux-kernel@...r.kernel.org, mihai.dontu@...il.com
Subject: Re: [PATCH 1/1] lib: small update for strlen, strnlen, use less cpu
 instructions

On Tue, 2015-06-16 at 13:50 -0500, Orestes Leal Rodriguez wrote:
> Very small update to strlen and strnlen that now use less cpu 
> instructions by using a counter to avoid the memory addresses 
> substraction to find the length of the string.
[]
> @@ -418,12 +422,13 @@ EXPORT_SYMBOL(strlen);
>    */
>   size_t strnlen(const char *s, size_t count)
>   {
> -	const char *sc;
> +	size_t sz = 0;
> 
> -	for (sc = s; count-- && *sc != '\0'; ++sc)
> -		/* nothing */;
> -	return sc - s;
> +	for (; count-- && *s++ != '\0'; sz++)
> +		/* empty */;
> +	return sz;

That's one subtraction at end-of-string vs
a register increment for each non-zero byte.

smaller isn't worth slower.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ