Skip to content

Commit 0b974db

Browse files
committed
Add configure infrastructure to detect support for C99's restrict.
Will be used in later commits improving performance for a few key routines where information about aliasing allows for significantly better code generation. This allows to use the C99 'restrict' keyword without breaking C89, or for that matter C++, compilers. If not supported it's defined to be empty. Author: Andres Freund Discussion: https://postgr.es/m/20170914063418.sckdzgjfrsbekae4@alap3.anarazel.de
1 parent 5fa6b0d commit 0b974db

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

configure

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11545,6 +11545,52 @@ _ACEOF
1154511545
;;
1154611546
esac
1154711547

11548+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
11549+
$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
11550+
if ${ac_cv_c_restrict+:} false; then :
11551+
$as_echo_n "(cached) " >&6
11552+
else
11553+
ac_cv_c_restrict=no
11554+
# The order here caters to the fact that C++ does not require restrict.
11555+
for ac_kw in __restrict __restrict__ _Restrict restrict; do
11556+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
11557+
/* end confdefs.h. */
11558+
typedef int * int_ptr;
11559+
int foo (int_ptr $ac_kw ip) {
11560+
return ip[0];
11561+
}
11562+
int
11563+
main ()
11564+
{
11565+
int s[1];
11566+
int * $ac_kw t = s;
11567+
t[0] = 0;
11568+
return foo(t)
11569+
;
11570+
return 0;
11571+
}
11572+
_ACEOF
11573+
if ac_fn_c_try_compile "$LINENO"; then :
11574+
ac_cv_c_restrict=$ac_kw
11575+
fi
11576+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
11577+
test "$ac_cv_c_restrict" != no && break
11578+
done
11579+
11580+
fi
11581+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_restrict" >&5
11582+
$as_echo "$ac_cv_c_restrict" >&6; }
11583+
11584+
case $ac_cv_c_restrict in
11585+
restrict) ;;
11586+
no) $as_echo "#define restrict /**/" >>confdefs.h
11587+
;;
11588+
*) cat >>confdefs.h <<_ACEOF
11589+
#define restrict $ac_cv_c_restrict
11590+
_ACEOF
11591+
;;
11592+
esac
11593+
1154811594
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for printf format archetype" >&5
1154911595
$as_echo_n "checking for printf format archetype... " >&6; }
1155011596
if ${pgac_cv_printf_archetype+:} false; then :

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,7 @@ fi
12991299
m4_defun([AC_PROG_CC_STDC], []) dnl We don't want that.
13001300
AC_C_BIGENDIAN
13011301
AC_C_INLINE
1302+
AC_C_RESTRICT
13021303
PGAC_PRINTF_ARCHETYPE
13031304
AC_C_FLEXIBLE_ARRAY_MEMBER
13041305
PGAC_C_SIGNED

src/include/pg_config.h.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,20 @@
923923
if such a type exists, and if the system does not define it. */
924924
#undef intptr_t
925925

926+
/* Define to the equivalent of the C99 'restrict' keyword, or to
927+
nothing if this is not supported. Do not define if restrict is
928+
supported directly. */
929+
#undef restrict
930+
/* Work around a bug in Sun C++: it does not support _Restrict or
931+
__restrict__, even though the corresponding Sun C compiler ends up with
932+
"#define restrict _Restrict" or "#define restrict __restrict__" in the
933+
previous line. Perhaps some future version of Sun C++ will work with
934+
restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
935+
#if defined __SUNPRO_CC && !defined __RESTRICT
936+
# define _Restrict
937+
# define __restrict__
938+
#endif
939+
926940
/* Define to empty if the C compiler does not understand signed types. */
927941
#undef signed
928942

src/include/pg_config.h.win32

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,17 @@
681681
#define inline __inline
682682
#endif
683683

684+
/* Define to the equivalent of the C99 'restrict' keyword, or to
685+
nothing if this is not supported. Do not define if restrict is
686+
supported directly. */
687+
/* Visual Studio 2008 and upwards */
688+
#if (_MSC_VER >= 1500)
689+
/* works for C and C++ in msvc */
690+
#define restrict __restrict
691+
#else
692+
#define restrict
693+
#endif
694+
684695
/* Define to empty if the C compiler does not understand signed types. */
685696
/* #undef signed */
686697

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy