Date: Thu, 25 Jul 2013 12:43:49 +0100 From: David Chisnall <theraven@FreeBSD.org> To: Hans Petter Selasky <hps@bitfrost.no> Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, Tim Kientzle <kientzle@FreeBSD.org>, src-committers@FreeBSD.org, Bruce Evans <brde@optusnet.com.au> Subject: Re: svn commit: r253636 - head/sys/vm Message-ID: <73FCA347-5EB9-445F-A25C-D06CA137CBEE@FreeBSD.org> In-Reply-To: <51F0DDB0.7080102@bitfrost.no> References: <201307250348.r6P3mbsG049595@svn.freebsd.org> <20130725171038.O841@besplex.bde.org> <51F0DDB0.7080102@bitfrost.no>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On 25 Jul 2013, at 09:11, Hans Petter Selasky <hps@bitfrost.no> wrote:
> The structure looks like some size, so bzero() might run faster than memset() depending on the compiler settings. Should be profiled before changed!
They will generate identical code for small structures with known sizes. Both clang and gcc have a simplify libcalls pass that recognises both functions and will elide the call in preference to a small set of inline stores.
However(), memset is to be preferred in this idiom because the compiler provides better diagnostics in the case of error:
bzero.c:9:22: warning: 'memset' call operates on objects of type 'struct foo'
while the size is based on a different type 'struct foo *'
[-Wsizeof-pointer-memaccess]
memset(f, 0, sizeof(f));
~ ^
bzero.c:9:22: note: did you mean to dereference the argument to 'sizeof' (and
multiply it by the number of elements)?
memset(f, 0, sizeof(f));
^
The same line with bzero(f, sizeof(f)) generates no error.
David
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
iQIcBAEBAgAGBQJR8Q92AAoJEKx65DEEsqId+bEP/Rm3oxEzblD4n+MTtd3dwjvt
RV5eSDHKFV5GyRMtvggrQy10NPulZDjiRLCzIivbpM9ybDOg+sxTUrRJn+2FOp9i
GBuvX543BO4TTtxkpBdk69HCwe5iiAfNdO7Ls/FfDFYDJodVyPQf8GG8/pvyTNJ+
9s3mjdoUc3Wv+nTkWY5QJQvV0Mibn5+NeO1oLDEznbhihcIVDOovTMN2iY0NfcLb
aAKdTQt41PwIE3Jml67HIEgbSRIo79Eind8kDUfkK/nqx8+Yw2tbECZsDZPDkUIX
dMcyoSen+GKjpq45NHfIYU3TP4vUdbIxCbopbK9gBddHYWdHOKCGqW7DTmZZXoHU
odnSoCldpMy7q2nmeqIea22KX0DVNbUGPpy95WNCLf0BAE2afHiJYaKD0AEkEkx8
bpy27cBgYWidUifzbrwOxD3t9GJTFY0wkRXdg+j7JHP8mrlEGOalEflrlmj27NJ3
P+xflWSOk2nFWyg91Kw6XlsLD+pLmZeMEX2ILZbdv9f1T/EfhTgpjzQ8ug2WsFsq
TCVWCLnMN8itFphngLmLwUyHaY+8k66XLfr4LLSzH+yh4CmWtOJtLz/07eJEhiV7
DBZmmeyoqf2quYdNXWrXrzBk1smpI0Lvm8/yFAeICZPkOzxGI7u9+XxpJPJ9XI2h
bmB9v3wloqdzhSUKNm79
=9SVh
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?73FCA347-5EB9-445F-A25C-D06CA137CBEE>
