Chombo + EB  3.0
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 /**
17  * \file
18  *
19  * \brief System dependent functions
20  *
21  *//*+*************************************************************************/
22
23 #include <cstring>
24
25 #include "CH_config.H"
27
28 namespace CHSystem
29 {
30  /// Allocate aligned memory
31  int memalign(void **a_memptr, size_t a_alignment, size_t a_size);
32
33 /*--------------------------------------------------------------------*/
34 // Find the number of bits set to 1 in a 32 bit int
35 /**
36  * \param[in] a_i Integer
37  * \return Number of bits set to 1
38 /*//*-----------------------------------------------------------------*/
39
40  inline int popcnt(unsigned i)
41  {
42 #if CHDEF_SYSTEM_POPCNT_METHOD == 1
43  int ret;
44  __asm__ ("popcnt %1, %0" : "=r" (ret) : "r" (i));
45  return ret;
46 #else
47  // Known as a parallel SWAR algorithm
48  i = i - ((i >> 1) & 0x55555555);
49  i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
50  return (((i + (i >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
51 #endif
52  }
53 }
54
55 #include "BaseNamespaceFooter.H"
56 #endif
int popcnt(unsigned i)
Definition: CH_System.H:40
Definition: CH_System.H:28
int memalign(void **a_memptr, size_t a_alignment, size_t a_size)
Allocate aligned memory.