Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

__builtin_prefetch(3) [netbsd man page]

__BUILTIN_PREFETCH(3)					   BSD Library Functions Manual 				     __BUILTIN_PREFETCH(3)

NAME
__builtin_prefetch -- GNU extension to prefetch memory SYNOPSIS
void __builtin_prefetch(const void *addr, ...); DESCRIPTION
The __builtin_prefetch() function prefetches memory from 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. In addition to addr, there are two optional stdarg(3) arguments, rw and 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 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 rw is either 0 or 1, corresponding with read and write prefetch, respectively. The default value of rw is 0. Also rw must be a compile-time constant integer. The __builtin_prefetch() function translates into prefetch instructions only if the architecture has support for these. If there is no sup- port, addr is evaluated only if it includes side effects, although no warnings are issued by gcc(1). EXAMPLES
The following optimization appears in the heavily used cpu_in_cksum() function that calculates checksums for the inet(4) headers: 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; ... SEE ALSO
gcc(1), attribute(3) Ulrich Drepper, What Every Programmer Should Know About Memory, http://www.akkadia.org/drepper/cpumemory.pdf, November 21, 2007. CAVEATS
This is a non-standard, compiler-specific extension. BSD
December 22, 2010 BSD

Check Out this Related Man Page

sync_instruction_memory(3C)				   Standard C Library Functions 			       sync_instruction_memory(3C)

NAME
sync_instruction_memory - make modified instructions executable SYNOPSIS
void sync_instruction_memory(caddr_t addr, int len); DESCRIPTION
The sync_instruction_memory() function performs whatever steps are required to make instructions modified by a program executable. Some processor architectures, including some SPARC processors, have separate and independent instruction and data caches which are not kept consistent by hardware. For example, if the instruction cache contains an instruction from some address and the program then stores a new instruction at that address, the new instruction may not be immediately visible to the instruction fetch mechanism. Software must explicitly invalidate the instruction cache entries for new or changed mappings of pages that might contain executable instructions. The sync_instruction_memory() function performs this function, and/or any other functions needed to make modified instructions between addr and addr+len visible. A program should call sync_instruction_memory() after modifying instructions and before executing them. On processors with unified caches (one cache for both instructions and data) and pipelines which are flushed by a branch instruction, such as the x86 architecture, the function may do nothing and just return. The changes are immediately visible to the thread calling sync_instruction_memory() when the call returns, even if the thread should migrate to another processor during or after the call. The changes become visible to other threads in the same manner that stores do; that is, they eventually become visible, but the latency is implementation-dependent. The result of executing sync_instruction_memory() are unpredictable if addr through addr+len-1 are not valid for the address space of the program making the call. RETURN VALUES
No values are returned. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) SunOS 5.11 12 Feb 1997 sync_instruction_memory(3C)
Man Page