Module Name: src Committed By: jruoho Date: Wed Dec 22 19:35:42 UTC 2010
Modified Files: src/distrib/sets/lists/comp: mi src/share/man/man3: Makefile Added Files: src/share/man/man3: __builtin_prefetch.3 Log Message: Document the __builtin_prefetch() GNU extension. To generate a diff of this commit: cvs rdiff -u -r1.1560 -r1.1561 src/distrib/sets/lists/comp/mi cvs rdiff -u -r1.68 -r1.69 src/share/man/man3/Makefile cvs rdiff -u -r0 -r1.1 src/share/man/man3/__builtin_prefetch.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/comp/mi diff -u src/distrib/sets/lists/comp/mi:1.1560 src/distrib/sets/lists/comp/mi:1.1561 --- src/distrib/sets/lists/comp/mi:1.1560 Wed Dec 22 17:00:54 2010 +++ src/distrib/sets/lists/comp/mi Wed Dec 22 19:35:41 2010 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1560 2010/12/22 17:00:54 christos Exp $ +# $NetBSD: mi,v 1.1561 2010/12/22 19:35:41 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -4912,6 +4912,7 @@ ./usr/share/man/cat3/__builtin_constant_p.0 comp-c-catman .cat ./usr/share/man/cat3/__builtin_frame_address.0 comp-c-catman .cat ./usr/share/man/cat3/__builtin_object_size.0 comp-c-catman .cat +./usr/share/man/cat3/__builtin_prefetch.0 comp-c-catman .cat ./usr/share/man/cat3/__builtin_return_address.0 comp-c-catman .cat ./usr/share/man/cat3/__builtin_types_compatible_p.0 comp-c-catman .cat ./usr/share/man/cat3/__cacheline_aligned.0 comp-c-catman .cat @@ -11007,6 +11008,7 @@ ./usr/share/man/html3/__builtin_constant_p.html comp-c-htmlman html ./usr/share/man/html3/__builtin_frame_address.html comp-c-htmlman html ./usr/share/man/html3/__builtin_object_size.html comp-c-htmlman html +./usr/share/man/html3/__builtin_prefetch.html comp-c-htmlman html ./usr/share/man/html3/__builtin_return_address.html comp-c-htmlman html ./usr/share/man/html3/__builtin_types_compatible_p.html comp-c-htmlman html ./usr/share/man/html3/__cacheline_aligned.html comp-c-htmlman html @@ -16901,6 +16903,7 @@ ./usr/share/man/man3/__builtin_constant_p.3 comp-c-man .man ./usr/share/man/man3/__builtin_frame_address.3 comp-c-man .man ./usr/share/man/man3/__builtin_object_size.3 comp-c-man .man +./usr/share/man/man3/__builtin_prefetch.3 comp-c-man .man ./usr/share/man/man3/__builtin_return_address.3 comp-c-man .man ./usr/share/man/man3/__builtin_types_compatible_p.3 comp-c-man .man ./usr/share/man/man3/__cacheline_aligned.3 comp-c-man .man Index: src/share/man/man3/Makefile diff -u src/share/man/man3/Makefile:1.68 src/share/man/man3/Makefile:1.69 --- src/share/man/man3/Makefile:1.68 Tue Dec 21 15:05:02 2010 +++ src/share/man/man3/Makefile Wed Dec 22 19:35:42 2010 @@ -1,9 +1,10 @@ -# $NetBSD: Makefile,v 1.68 2010/12/21 15:05:02 jruoho Exp $ +# $NetBSD: Makefile,v 1.69 2010/12/22 19:35:42 jruoho Exp $ # @(#)Makefile 8.2 (Berkeley) 12/13/93 MAN= _DIAGASSERT.3 __CONCAT.3 __UNCONST.3 CMSG_DATA.3 \ __alignof__.3 __arraycount.3 \ - __builtin_constant_p.3 __builtin_return_address.3 \ + __builtin_constant_p.3 __builtin_prefetch.3 \ + __builtin_return_address.3 \ __builtin_types_compatible_p.3 __insn_barrier.3 \ assert.3 attribute.3 bits.3 bitstring.3 \ cdefs.3 dirent.3 dlfcn.3 dl_iterate_phdr.3 end.3 \ Added files: Index: src/share/man/man3/__builtin_prefetch.3 diff -u /dev/null src/share/man/man3/__builtin_prefetch.3:1.1 --- /dev/null Wed Dec 22 19:35:42 2010 +++ src/share/man/man3/__builtin_prefetch.3 Wed Dec 22 19:35:42 2010 @@ -0,0 +1,115 @@ +.\" $NetBSD: __builtin_prefetch.3,v 1.1 2010/12/22 19:35:42 jruoho Exp $ +.\" +.\" Copyright (c) 2010 Jukka Ruohonen <jruoho...@iki.fi> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd December 22, 2010 +.Dt __BUILTIN_PREFETCH 3 +.Os +.Sh NAME +.Nm __builtin_prefetch +.Nd GNU extension to prefetch memory +.Sh SYNOPSIS +.Ft void +.Fn __builtin_prefetch "const void *addr, ..." +.Sh DESCRIPTION +The +.Fn __builtin_prefetch +function prefetches memory from +.Fa addr . +The rationale is to minimize cache-miss latency by +trying to move data into a cache before accessing the data. +Possible use cases include frequently called sections of code +in which it is known that the data in a given address is likely +to be accessed soon. +.Pp +In addition to +.Fa addr , +there are two optional +.Xr stdarg 3 +arguments, +.Fa rw +and +.Fa locality . +The value of the latter should be a compile-time +constant integer between 0 and 3. +The higher the value, the higher the temporal locality in the data. +When +.Fa locality +is 0, it is assumed that there is little or no temporal locality in the data; +after access, it is not necessary to leave the data in the cache. +The default value is 3. +The value of +.Fa rw +is either 0 or 1, corresponding with read and write prefetch, respectively. +The default value of +.Fa rw +is 0. +Also +.Fa rw +must be a compile-time constant integer. +.Pp +The +.Fn __builtin_prefetch +function translates into prefetch instructions +only if the architecture has support for these. +If there is no support, +.Fa addr +is evaluated only if it includes side effects, +although no warnings are issued by +.Xr gcc 1 . +.Sh EXAMPLES +The following optimization appears in the heavily used +.Fn cpu_in_cksum +function that calculates checksums for the +.Xr inet 4 +headers: +.Bd -literal -offset indent +while (mlen >= 32) { + __builtin_prefetch(data + 32); + partial += *(uint16_t *)data; + partial += *(uint16_t *)(data + 2); + partial += *(uint16_t *)(data + 4); + + \&... + + partial += *(uint16_t *)(data + 28); + partial += *(uint16_t *)(data + 30); + + data += 32; + mlen -= 32; + + \&... +.Ed +.Sh SEE ALSO +.Xr gcc 1 , +.Xr attribute 3 +.Rs +.%A Ulrich Drepper +.%T What Every Programmer Should Know About Memory +.%D November 21, 2007 +.%U http://www.akkadia.org/drepper/dsohowto.pdf +.Re +.Sh CAVEATS +This is a non-standard, compiler-specific extension.