spot  2.11.6
clz.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2018, 2021 Laboratoire de Recherche et Développement
3 // de l'Epita (LRDE).
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 #pragma once
21 
22 #include <spot/misc/common.hh>
23 #include <cstddef>
24 #include <climits>
25 
26 namespace spot
27 {
28  template<typename Type,
29  typename = std::enable_if_t<std::is_unsigned<Type>::value>>
30  inline constexpr unsigned clz(Type n) noexcept
31  {
32  unsigned res = CHAR_BIT * sizeof(Type);
33  while (n)
34  {
35  --res;
36  n >>= 1;
37  }
38  return res;
39  }
40 
41 #if __GNUC__
42  template<>
43  inline constexpr unsigned clz(unsigned n) noexcept
44  {
45  return __builtin_clz(n);
46  }
47 
48  template<>
49  inline constexpr unsigned clz(unsigned long n) noexcept
50  {
51  return __builtin_clzl(n);
52  }
53 
54  template<>
55  inline constexpr unsigned clz(unsigned long long n) noexcept
56  {
57  return __builtin_clzll(n);
58  }
59 #endif
60 }
Definition: automata.hh:27

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Feb 27 2015 10:00:07 for spot by doxygen 1.9.1