xref: /aosp_15_r20/external/libwebm/webm_parser/src/bit_utils.cc (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "src/bit_utils.h"
9 
10 #include <cstdint>
11 
12 namespace webm {
13 
CountLeadingZeros(std::uint8_t value)14 std::uint8_t CountLeadingZeros(std::uint8_t value) {
15   // Special case for 0 since we can't shift by sizeof(T) * 8 bytes.
16   if (value == 0)
17     return 8;
18 
19   std::uint8_t count = 0;
20   while (!(value & (0x80 >> count))) {
21     ++count;
22   }
23   return count;
24 }
25 
26 }  // namespace webm
27