2016-04-28 14:10:21 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-04-28 14:10:21 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-04-28 14:10:21 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_internal_Assume_h
|
|
|
|
#define vtk_m_internal_Assume_h
|
|
|
|
|
|
|
|
#include <vtkm/Assert.h>
|
|
|
|
|
|
|
|
// Description:
|
|
|
|
// VTKM_ASSUME instructs the compiler that a certain non-obvious condition will
|
|
|
|
// *always* be true. Beware that if cond is false at runtime, the results are
|
|
|
|
// unpredictable (and likely catastrophic). A runtime assertion is added so
|
|
|
|
// that debugging builds may easily catch violations of the condition.
|
|
|
|
//
|
|
|
|
// A useful application of this macro is when a method is passed in a
|
|
|
|
// vtkm::Vec that is uninitialized and conditional fills the vtkm::Vec
|
|
|
|
// based on other runtime information such as cell type. This allows you to
|
|
|
|
// assert that only valid cell types will be used, producing more efficient
|
|
|
|
// code.
|
|
|
|
//
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_ASSUME(cond) \
|
|
|
|
VTKM_SWALLOW_SEMICOLON_PRE_BLOCK \
|
|
|
|
{ \
|
|
|
|
const bool c = cond; \
|
|
|
|
VTKM_ASSERT("Bad assumption in VTKM_ASSUME: " #cond&& c); \
|
|
|
|
VTKM_ASSUME_IMPL(c); \
|
|
|
|
(void)c; /* Prevents unused var warnings */ \
|
|
|
|
} \
|
2017-01-10 17:40:17 +00:00
|
|
|
VTKM_SWALLOW_SEMICOLON_POST_BLOCK
|
2016-04-28 14:10:21 +00:00
|
|
|
|
|
|
|
// VTKM_ASSUME_IMPL is compiler-specific:
|
2016-06-29 15:56:24 +00:00
|
|
|
#if defined(__CUDA_ARCH__)
|
2017-05-18 14:29:41 +00:00
|
|
|
//For all versions of CUDA this is a no-op while we look
|
|
|
|
//for a CUDA asm snippet that replicates this kind of behavior
|
|
|
|
#define VTKM_ASSUME_IMPL(cond) (void)0 /* no-op */
|
2016-06-29 15:56:24 +00:00
|
|
|
#else
|
2016-06-09 17:29:14 +00:00
|
|
|
|
2016-06-29 15:56:24 +00:00
|
|
|
#if defined(VTKM_MSVC)
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_ASSUME_IMPL(cond) __assume(cond)
|
2016-06-09 17:29:14 +00:00
|
|
|
#elif defined(VTKM_ICC)
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_ASSUME_IMPL(cond) __assume(cond)
|
|
|
|
#elif defined(VTKM_GCC) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
|
2016-04-28 14:10:21 +00:00
|
|
|
// Added in 4.5.0:
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_ASSUME_IMPL(cond) \
|
|
|
|
if (!(cond)) \
|
|
|
|
__builtin_unreachable()
|
2016-04-28 14:10:21 +00:00
|
|
|
#elif defined(VTKM_CLANG)
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_ASSUME_IMPL(cond) \
|
|
|
|
if (!(cond)) \
|
|
|
|
__builtin_unreachable()
|
2016-04-28 14:10:21 +00:00
|
|
|
#else
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_ASSUME_IMPL(cond) (void)0 /* no-op */
|
2016-04-28 14:10:21 +00:00
|
|
|
#endif
|
|
|
|
|
2016-06-29 15:56:24 +00:00
|
|
|
#endif
|
|
|
|
|
2016-04-28 14:10:21 +00:00
|
|
|
#endif // vtk_m_internal_Assume_h
|