gen, bitset: use clz() to simplify
Fixes #448. * spot/gen/automata.cc (ulog2): Here. * spot/misc/bitset.hh: And there.
This commit is contained in:
parent
d1cc45f223
commit
8e8f77756d
2 changed files with 7 additions and 25 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2017-2019 Laboratoire de Recherche et Developpement
|
||||
// de l'EPITA (LRDE).
|
||||
// Copyright (C) 2017-2019, 2021 Laboratoire de Recherche et
|
||||
// Developpement de l'EPITA (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
#include <spot/twa/twagraph.hh>
|
||||
#include <spot/gen/automata.hh>
|
||||
#include <spot/tl/parse.hh>
|
||||
#include <spot/misc/clz.hh>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
|
@ -177,17 +178,7 @@ namespace spot
|
|||
{
|
||||
assert(n>0);
|
||||
--n;
|
||||
#ifdef __GNUC__
|
||||
return 8*sizeof(unsigned) - __builtin_clz(n);
|
||||
#else
|
||||
unsigned res = 0;
|
||||
while (n)
|
||||
{
|
||||
++res;
|
||||
n >>= 1;
|
||||
}
|
||||
return res;
|
||||
#endif
|
||||
return CHAR_BIT*sizeof(unsigned) - clz(n);
|
||||
}
|
||||
|
||||
static twa_graph_ptr
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2018 Laboratoire de Recherche et Développement
|
||||
// Copyright (C) 2018, 2021 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -359,19 +359,10 @@ namespace spot
|
|||
auto v = data[i];
|
||||
if (v == 0)
|
||||
{
|
||||
res -= 8*sizeof(word_t);
|
||||
res -= CHAR_BIT*sizeof(word_t);
|
||||
continue;
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
res += 8*sizeof(word_t) - clz(v);
|
||||
#else
|
||||
while (v)
|
||||
{
|
||||
++res;
|
||||
v >>= 1;
|
||||
}
|
||||
#endif
|
||||
return res-1;
|
||||
return res + CHAR_BIT*sizeof(word_t) - clz(v) - 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue