1
1

* As promised to George and per #93, add macros for hinting to the compiler

whether an if statement is likely to be taken and for prefetching memory.
  Current macros:

    OPAL_LIKELY(expression)
    OPAL_UNLIKELY(expression)
    OPAL_PREFETC(address)

This commit was SVN r10278.
Этот коммит содержится в:
Brian Barrett 2006-06-09 19:50:51 +00:00
родитель a4030ad2d9
Коммит 4c80624fb3
3 изменённых файлов: 128 добавлений и 2 удалений

Просмотреть файл

@ -8,7 +8,7 @@ dnl of Tennessee Research Foundation. All rights
dnl reserved.
dnl Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl Copyright (c) 2004-2006 The Regents of the University of California.
dnl All rights reserved.
dnl $COPYRIGHT$
dnl
@ -153,6 +153,38 @@ AC_DEFUN([OMPI_SETUP_CC],[
unset add
fi
# see if the C compiler supports __builtin_expect
AC_CACHE_CHECK([if $CC supports __builtin_expect],
[ompi_cv_cc_supports___builtin_expect],
[AC_TRY_COMPILE([],
[void *ptr = (void*) 0;
if (__builtin_expect (ptr != NULL, 1)) return 0;],
[ompi_cv_cc_supports___builtin_expect="yes"],
[ompi_cv_cc_supports___builtin_expect="no"])])
if test "$ompi_cv_cc_supports___builtin_expect" = "yes" ; then
have_builtin_expect=1
else
have_builtin_expect=0
fi
AC_DEFINE_UNQUOTED([OMPI_C_HAVE_BUILTIN_EXPECT], [$have_builtin_expect],
[Whether C compiler supports __builtin_expect])
# see if the C compiler supports __builtin_prefetch
AC_CACHE_CHECK([if $CC supports __builtin_prefetch],
[ompi_cv_cc_supports___builtin_prefetch],
[AC_TRY_COMPILE([],
[int ptr;
__builtin_prefetch(&ptr);],
[ompi_cv_cc_supports___builtin_prefetch="yes"],
[ompi_cv_cc_supports___builtin_prefetch="no"])])
if test "$ompi_cv_cc_supports___builtin_prefetch" = "yes" ; then
have_builtin_prefetch=1
else
have_builtin_prefetch=0
fi
AC_DEFINE_UNQUOTED([OMPI_C_HAVE_BUILTIN_PREFETCH], [$have_builtin_prefetch],
[Whether C compiler supports __builtin_prefetch])
# Preload the optflags for the case where the user didn't specify
# any. If we're using GNU compilers, use -O3 (since it GNU
# doesn't require all compilation units to be compiled with the

Просмотреть файл

@ -8,7 +8,7 @@ dnl of Tennessee Research Foundation. All rights
dnl reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl Copyright (c) 2004-2006 The Regents of the University of California.
dnl All rights reserved.
dnl $COPYRIGHT$
dnl
@ -135,6 +135,42 @@ AC_DEFUN([OMPI_SETUP_CXX],[
# config/cxx_find_template_parameters.m4
OMPI_CXX_FIND_TEMPLATE_PARAMETERS
# see if the C++ compiler supports __builtin_expect
AC_LANG_PUSH(C++)
AC_CACHE_CHECK([if $CXX supports __builtin_expect],
[ompi_cv_cxx_supports___builtin_expect],
[AC_TRY_COMPILE([],
[void *ptr = (void*) 0;
if (__builtin_expect (ptr != NULL, 1)) return 0;],
[ompi_cv_cxx_supports___builtin_expect="yes"],
[ompi_cv_cxx_supports___builtin_expect="no"])])
if test "$ompi_cv_cxx_supports___builtin_expect" = "yes" ; then
have_builtin_expect=1
else
have_builtin_expect=0
fi
AC_DEFINE_UNQUOTED([OMPI_CXX_HAVE_BUILTIN_EXPECT], [$have_builtin_expect],
[Whether C++ compiler supports __builtin_expect])
AC_LANG_POP(C++)
# see if the C compiler supports __builtin_prefetch
AC_LANG_PUSH(C++)
AC_CACHE_CHECK([if $CXX supports __builtin_prefetch],
[ompi_cv_cxx_supports___builtin_prefetch],
[AC_TRY_COMPILE([],
[int ptr;
__builtin_prefetch(&ptr);],
[ompi_cv_cxx_supports___builtin_prefetch="yes"],
[ompi_cv_cxx_supports___builtin_prefetch="no"])])
if test "$ompi_cv_cxx_supports___builtin_prefetch" = "yes" ; then
have_builtin_prefetch=1
else
have_builtin_prefetch=0
fi
AC_DEFINE_UNQUOTED([OMPI_CXX_HAVE_BUILTIN_PREFETCH], [$have_builtin_prefetch],
[Whether C++ compiler supports __builtin_prefetch])
AC_LANG_POP(C++)
# If we are on HP-UX, ensure that we're using aCC
case "$host" in
*hpux*)

58
opal/include/opal/prefetch.h Обычный файл
Просмотреть файл

@ -0,0 +1,58 @@
/*
* Copyright (c) 2004-2006 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file
*
* Compiler-specific prefetch functions
*
* A small set of prefetch / prediction interfaces for using compiler
* directives to improve memory prefetching and branch prediction
*/
#ifndef OPAL_PREFETCH_H
#define OPAL_PREFETCH_H
#if defined(c_plusplus) || defined(__cplusplus)
/* C++ code */
#if OMPI_CXX_HAVE_BUILTIN_EXPECT
#define OPAL_LIKELY(expression) __builtin_expect(!!(expression), 1)
#define OPAL_UNLIKELY(expression) __builtin_expect(!!(expression), 0)
#else
#define OPAL_LIKELY(expression) (expression)
#define OPAL_UNLIKELY(expression) (expression)
#endif
#if OMPI_CXX_HAVE_BUILTIN_PREFETCH
#define OPAL_PREFETCH(address) __builtin_prefetch(address)
#else
#define OPAL_PREFETCH(address)
#endif
#else
/* C code */
#if OMPI_C_HAVE_BUILTIN_EXPECT
#define OPAL_LIKELY(expression) __builtin_expect(!!(expression), 1)
#define OPAL_UNLIKELY(expression) __builtin_expect(!!(expression), 0)
#else
#define OPAL_LIKELY(expression) (expression)
#define OPAL_UNLIKELY(expression) (expression)
#endif
#if OMPI_C_HAVE_BUILTIN_PREFETCH
#define OPAL_PREFETCH(address) __builtin_prefetch(address)
#else
#define OPAL_PREFETCH(address)
#endif
#endif
#endif