freebsd_amp_hwpstate/contrib/compiler-rt/lib/clzdi2.c

31 lines
843 B
C
Raw Normal View History

2010-10-21 19:02:02 +00:00
/* ===-- clzdi2.c - Implement __clzdi2 -------------------------------------===
*
2011-06-02 20:02:42 +00:00
* The LLVM Compiler Infrastructure
2010-10-21 19:02:02 +00:00
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
2010-10-21 19:02:02 +00:00
*
* ===----------------------------------------------------------------------===
*
* This file implements __clzdi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
2011-06-02 20:02:42 +00:00
#include "abi.h"
2010-10-21 19:02:02 +00:00
#include "int_lib.h"
/* Returns: the number of leading 0-bits */
/* Precondition: a != 0 */
2011-06-02 20:02:42 +00:00
COMPILER_RT_ABI si_int
2010-10-21 19:02:02 +00:00
__clzdi2(di_int a)
{
dwords x;
x.all = a;
const si_int f = -(x.s.high == 0);
return __builtin_clz((x.s.high & ~f) | (x.s.low & f)) +
(f & ((si_int)(sizeof(si_int) * CHAR_BIT)));
}