Module Name: src Committed By: jruoho Date: Sun Dec 19 10:07:24 UTC 2010
Modified Files: src/distrib/sets/lists/comp: mi src/share/man/man3: Makefile Added Files: src/share/man/man3: __builtin_constant_p.3 Log Message: Document __builtin_constant_p(). To generate a diff of this commit: cvs rdiff -u -r1.1556 -r1.1557 src/distrib/sets/lists/comp/mi cvs rdiff -u -r1.66 -r1.67 src/share/man/man3/Makefile cvs rdiff -u -r0 -r1.1 src/share/man/man3/__builtin_constant_p.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.1556 src/distrib/sets/lists/comp/mi:1.1557 --- src/distrib/sets/lists/comp/mi:1.1556 Sun Dec 19 09:30:49 2010 +++ src/distrib/sets/lists/comp/mi Sun Dec 19 10:07:23 2010 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1556 2010/12/19 09:30:49 jruoho Exp $ +# $NetBSD: mi,v 1.1557 2010/12/19 10:07:23 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -4908,6 +4908,7 @@ ./usr/share/man/cat3/__aligned.0 comp-c-catman .cat ./usr/share/man/cat3/__alignof__.0 comp-c-catman .cat ./usr/share/man/cat3/__arraycount.0 comp-c-catman .cat +./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_return_address.0 comp-c-catman .cat @@ -10999,6 +11000,7 @@ ./usr/share/man/html3/__aligned.html comp-c-htmlman html ./usr/share/man/html3/__alignof__.html comp-c-htmlman html ./usr/share/man/html3/__arraycount.html comp-c-htmlman html +./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_return_address.html comp-c-htmlman html @@ -16890,6 +16892,7 @@ ./usr/share/man/man3/__aligned.3 comp-c-man .man ./usr/share/man/man3/__alignof__.3 comp-c-man .man ./usr/share/man/man3/__arraycount.3 comp-c-man .man +./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_return_address.3 comp-c-man .man Index: src/share/man/man3/Makefile diff -u src/share/man/man3/Makefile:1.66 src/share/man/man3/Makefile:1.67 --- src/share/man/man3/Makefile:1.66 Sun Dec 19 09:30:50 2010 +++ src/share/man/man3/Makefile Sun Dec 19 10:07:24 2010 @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.66 2010/12/19 09:30:50 jruoho Exp $ +# $NetBSD: Makefile,v 1.67 2010/12/19 10:07:24 jruoho Exp $ # @(#)Makefile 8.2 (Berkeley) 12/13/93 MAN= _DIAGASSERT.3 __CONCAT.3 __UNCONST.3 CMSG_DATA.3 \ __alignof__.3 __arraycount.3 \ - __builtin_return_address.3 __insn_barrier.3 \ + __builtin_constant_p.3 __builtin_return_address.3 __insn_barrier.3 \ assert.3 attribute.3 bits.3 bitstring.3 \ cdefs.3 dirent.3 dlfcn.3 dl_iterate_phdr.3 end.3 \ fast_divide32.3 ffs32.3 gcq.3 \ Added files: Index: src/share/man/man3/__builtin_constant_p.3 diff -u /dev/null src/share/man/man3/__builtin_constant_p.3:1.1 --- /dev/null Sun Dec 19 10:07:24 2010 +++ src/share/man/man3/__builtin_constant_p.3 Sun Dec 19 10:07:24 2010 @@ -0,0 +1,78 @@ +.\" $NetBSD: __builtin_constant_p.3,v 1.1 2010/12/19 10:07:24 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 19, 2010 +.Dt __BUILTIN_CONSTANT_P 3 +.Os +.Sh NAME +.Nm __builtin_constant_p +.Nd GNU extension to determine compile time constants +.Sh SYNOPSIS +.Ft int +.Fn __builtin_constant_p "value" +.Sh DESCRIPTION +The +.Fn __builtin_constant_p +is a +.Tn GNU +extension for determining whether a value +is known to be constant at compile time. +The function is closely related to the concept of +.Dq constant folding +used by modern optimizing compilers. +.Pp +If the +.Fa value +is known to be a compile-time constant, a value 1 is returned. +If +.Fn __builtin_constant_p +returns 0, the +.Fa value +is not a compile-time constant in the sense that +.Xr gcc 1 +was unable to determine whether the value is constant or not. +.Sh EXAMPLES +A typical example of the use of +.Fn __builtin_constant_p +involves a situation where it may be desirable to +fold the computation if it involves a constant, +but a function call is needed otherwise. +For instance, +.Xr bswap 16 +is defined in +.Nx +as: +.Bd -literal -offset indent +#define bswap16(x) \\ + (__builtin_constant_p((x)) ? \\ + __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x)) +.Ed +.Sh SEE ALSO +.Xr gcc 1 , +.Xr __builtin_object_size 3 , +.Xr __builtin_return_address 3 +.Sh CAVEATS +This is a non-standard, compiler-specific extension.