Chombo + EB  3.2
CH_System.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _CH_SYSTEM_H_
12 #define _CH_SYSTEM_H_
13 
14 /******************************************************************************/
15 /**
16  * \file
17  *
18  * \brief System dependent functions
19  *
20  *//*+*************************************************************************/
21 
22 #include <cstring>
23 
24 #include "CH_config.H"
25 #include "BaseNamespaceHeader.H"
26 
27 namespace CHSystem
28 {
29  /// Check if a file exists
30  int fileExists(const char *const a_filename);
31 
32  /// Allocate aligned memory
33  int memalign(void **a_memptr, size_t a_alignment, size_t a_size);
34 
35 /*--------------------------------------------------------------------*/
36 // Find the number of bits set to 1 in a 32 bit int
37 /**
38  * \param[in] a_i Integer
39  * \return Number of bits set to 1
40  *//*-----------------------------------------------------------------*/
41 
42  inline int popcnt(unsigned i)
43  {
44 #if CHDEF_SYSTEM_POPCNT_METHOD == 1
45  int ret;
46  __asm__ ("popcnt %1, %0" : "=r" (ret) : "r" (i));
47  return ret;
48 #else
49  // Known as a parallel SWAR algorithm
50  i = i - ((i >> 1) & 0x55555555);
51  i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
52  return (((i + (i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
53 #endif
54  }
55 }
56 
57 // BOOST_PP_STRINGIZE(expr) - Return expr as a string literal.
58 #define BOOST_PP_STRINGIZE_(expr) #expr
59 #define BOOST_PP_STRINGIZE(expr) BOOST_PP_STRINGIZE_(expr)
60 
61 // BOOST_PRAGMA(args) - Emits a pragma.
62 #define BOOST_PRAGMA(args) _Pragma(BOOST_PP_STRINGIZE(args))
63 #if defined(__INTEL_COMPILER)
64  #define BOOST_BUILTIN_ASSUME(expr) \
65  __assume(expr) \
66  /**/
67  #define BOOST_BUILTIN_ASSUME_ALIGNED(ptr, align) \
68  __assume_aligned(ptr, align) \
69  /**/
70 #elif defined(__clang__)
71  #define BOOST_BUILTIN_ASSUME(expr) \
72  __builtin_assume(expr) \
73  /**/
74  #define BOOST_BUILTIN_ASSUME_ALIGNED(ptr, align) \
75  { \
76  ptr = reinterpret_cast<decltype(ptr)>( \
77  __builtin_assume_aligned(ptr, align) \
78  ); \
79  } \
80  /**/
81 #else // GCC
82  #define BOOST_BUILTIN_ASSUME(expr) \
83  do { if (!(expr)) __builtin_unreachable(); } while (0) \
84  /**/
85  #define BOOST_BUILTIN_ASSUME_ALIGNED(ptr, align) \
86  { \
87  ptr = reinterpret_cast<decltype(ptr)>( \
88  __builtin_assume_aligned(ptr, align) \
89  ); \
90  } \
91  /**/
92 #endif
93 #if defined(__INTEL_COMPILER)
94  #define BOOST_DEMAND_VECTORIZATION \
95  BOOST_PRAGMA(simd) \
96  /**/
97 #elif defined(__clang__)
98  #define BOOST_DEMAND_VECTORIZATION \
99  BOOST_PRAGMA(clang loop vectorize(enable) interleave(enable)) \
100  /**/
101 #else
102  #define BOOST_DEMAND_VECTORIZATION \
103  BOOST_PRAGMA(GCC ivdep) \
104  /**/
105 #endif
106 
107 #include "BaseNamespaceFooter.H"
108 #endif
int popcnt(unsigned i)
Definition: CH_System.H:42
int fileExists(const char *const a_filename)
Check if a file exists.
int memalign(void **a_memptr, size_t a_alignment, size_t a_size)
Allocate aligned memory.