Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Document the __builtin_prefetch() GNU extension.



details:   https://anonhg.NetBSD.org/src/rev/a18284cbddde
branches:  trunk
changeset: 759981:a18284cbddde
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Dec 22 19:35:41 2010 +0000

description:
Document the __builtin_prefetch() GNU extension.

diffstat:

 distrib/sets/lists/comp/mi          |    5 +-
 share/man/man3/Makefile             |    5 +-
 share/man/man3/__builtin_prefetch.3 |  115 ++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+), 3 deletions(-)

diffs (168 lines):

diff -r c3f186f66859 -r a18284cbddde distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Wed Dec 22 17:06:03 2010 +0000
+++ b/distrib/sets/lists/comp/mi        Wed Dec 22 19:35:41 2010 +0000
@@ -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
diff -r c3f186f66859 -r a18284cbddde share/man/man3/Makefile
--- a/share/man/man3/Makefile   Wed Dec 22 17:06:03 2010 +0000
+++ b/share/man/man3/Makefile   Wed Dec 22 19:35:41 2010 +0000
@@ -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 \
diff -r c3f186f66859 -r a18284cbddde share/man/man3/__builtin_prefetch.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man3/__builtin_prefetch.3       Wed Dec 22 19:35:41 2010 +0000
@@ -0,0 +1,115 @@
+.\" $NetBSD: __builtin_prefetch.3,v 1.1 2010/12/22 19:35:42 jruoho Exp $
+.\"
+.\" Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
+.\" 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.



Home | Main Index | Thread Index | Old Index