<commit_before>// -*- C++ -*-

#ifndef HL_ILOG2_H
#define HL_ILOG2_H

#if defined(_WIN32)
#include <intrn.h>
#endif

namespace HL {

  /// Quickly calculate the CEILING of the log (base 2) of the argument.
#if defined(_WIN32)
  static inline int ilog2 (size_t sz)
  {
    int retval;
    sz = (sz << 1) - 1;
    _BitScanForward (&retval, sz);
    return retval;
  }
#elif defined(__GNUC__) && defined(__i386__)
  static inline int ilog2 (size_t sz)
  {
    sz = (sz << 1) - 1;
    asm ("bsrl %0, %0" : "=r" (sz) : "0" (sz));
    return (int) sz;
  }
#elif 0 // defined(__GNUC__) && defined(__x86_64__)
  static inline int ilog2 (size_t sz)
  {
    sz = (sz << 1) - 1;
    asm ("bsrq %0, %0" : "=r" (sz) : "0" (sz));
    return (int) sz;<commit_msg>Fixed.<commit_after>// -*- C++ -*-

#ifndef HL_ILOG2_H
#define HL_ILOG2_H

#if defined(_WIN32)
#include <windows.h>
#endif

namespace HL {

  /// Quickly calculate the CEILING of the log (base 2) of the argument.
#if defined(_WIN32)
  static inline int ilog2 (size_t sz)
  {
    DWORD index;
    _BitScanReverse (&index, sz);
    if (!(sz & (sz-1))) {
      return index;
    } else {
      return index+1;
    }
  }
#elif defined(__GNUC__) && defined(__i386__)
  static inline int ilog2 (size_t sz)
  {
    sz = (sz << 1) - 1;
    asm ("bsrl %0, %0" : "=r" (sz) : "0" (sz));
    return (int) sz;
  }
#elif 0 // defined(__GNUC__) && defined(__x86_64__)
  static inline int ilog2 (size_t sz)
  {
    sz = (sz << 1) - 1;
    asm ("bsrq %0, %0" : "=r" (sz) : "0" (sz));
    return (int) sz;
{'fraction_non_alphanumeric': 0.1778501628664495, 'fraction_numerical': 0.03908794788273615, 'mean_word_length': 2.7281553398058254, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2682140', 'n_tokens_mistral': 670, 'n_tokens_neox': 627, 'n_words': 187}