clzti2.c revision 214152
12116Sjkh/* ===-- clzti2.c - Implement __clzti2 -------------------------------------===
22116Sjkh *
32116Sjkh *      	       The LLVM Compiler Infrastructure
42116Sjkh *
52116Sjkh * This file is distributed under the University of Illinois Open Source
62116Sjkh * License. See LICENSE.TXT for details.
72116Sjkh *
82116Sjkh * ===----------------------------------------------------------------------===
92116Sjkh *
102116Sjkh * This file implements __clzti2 for the compiler_rt library.
112116Sjkh *
122116Sjkh * ===----------------------------------------------------------------------===
132116Sjkh */
142116Sjkh
152116Sjkh#if __x86_64
162116Sjkh
172116Sjkh#include "int_lib.h"
182116Sjkh
192116Sjkh/* Returns: the number of leading 0-bits */
202116Sjkh
212116Sjkh/* Precondition: a != 0 */
222116Sjkh
232116Sjkhsi_int
242116Sjkh__clzti2(ti_int a)
252116Sjkh{
262116Sjkh    twords x;
272116Sjkh    x.all = a;
282116Sjkh    const di_int f = -(x.s.high == 0);
292116Sjkh    return __builtin_clzll((x.s.high & ~f) | (x.s.low & f)) +
302116Sjkh           ((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT)));
312116Sjkh}
322116Sjkh
332116Sjkh#endif /* __x86_64 */
342116Sjkh