From 8e8f77756db0c70668fe29ce48c65c71d7b0a439 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sun, 17 Jan 2021 16:09:14 +0100 Subject: [PATCH] gen, bitset: use clz() to simplify Fixes #448. * spot/gen/automata.cc (ulog2): Here. * spot/misc/bitset.hh: And there. --- spot/gen/automata.cc | 17 ++++------------- spot/misc/bitset.hh | 15 +++------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/spot/gen/automata.cc b/spot/gen/automata.cc index 00b7a5268..165ab8c98 100644 --- a/spot/gen/automata.cc +++ b/spot/gen/automata.cc @@ -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 #include #include +#include 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 diff --git a/spot/misc/bitset.hh b/spot/misc/bitset.hh index 0ab26763a..f66c6007d 100644 --- a/spot/misc/bitset.hh +++ b/spot/misc/bitset.hh @@ -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; }