1
#include <iostream>
#include <stdint.h>
using namespace std;
typedef __int128_t int128_t;
int main() {
  int128_t y = 0;
  cout<<__builtin_clzll(static_cast<unsigned long long>(y>>64)) <<endl;
  cout<<__builtin_clzll(static_cast<unsigned long long>(0)) <<endl;
}

the output: 63 64

gcc version 5.3.0 20151204

why the results is wrong? is there any other way to count leading zeros of int128_t.

Zuo Wang
  • 43
  • 2
  • 2
    I find the answer myself: GCC leaves __builtin_clz undefined for zero. It wasted my much time, hope it can save your time. – Zuo Wang Jan 10 '16 at 14:14

0 Answers0