Files
Aaru/Aaru.Images/QED/Helpers.cs

82 lines
2.2 KiB
C#
Raw Permalink Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Helpers.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
2018-12-31 13:17:27 +00:00
// Contains helpers for QEMU Enhanced Disk images.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-12-19 10:45:18 +00:00
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
2018-12-31 13:17:27 +00:00
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
public sealed partial class Qed
{
2022-03-06 13:29:38 +00:00
static bool IsPowerOfTwo(uint x)
{
2024-05-01 04:05:22 +01:00
while((x & 1) == 0 && x > 1) x >>= 1;
2018-12-31 13:17:27 +00:00
2022-03-06 13:29:38 +00:00
return x == 1;
}
2018-12-31 13:17:27 +00:00
2022-03-06 13:29:38 +00:00
static int Ctz32(uint val)
{
2023-10-03 23:34:59 +01:00
var cnt = 0;
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
if((val & 0xFFFF) == 0)
{
cnt += 16;
val >>= 16;
}
2018-12-31 13:17:27 +00:00
2022-03-06 13:29:38 +00:00
if((val & 0xFF) == 0)
{
cnt += 8;
val >>= 8;
}
2018-12-31 13:17:27 +00:00
2022-03-06 13:29:38 +00:00
if((val & 0xF) == 0)
{
cnt += 4;
val >>= 4;
}
2018-12-31 13:17:27 +00:00
2022-03-06 13:29:38 +00:00
if((val & 0x3) == 0)
{
cnt += 2;
val >>= 2;
}
2018-12-31 13:17:27 +00:00
2022-03-06 13:29:38 +00:00
if((val & 0x1) == 0)
{
cnt++;
val >>= 1;
}
2018-12-31 13:17:27 +00:00
2024-05-01 04:05:22 +01:00
if((val & 0x1) == 0) cnt++;
2018-12-29 17:34:38 +00:00
2022-03-06 13:29:38 +00:00
return cnt;
}
}