blob: b9e64da492bdacfb5e624740549ebc7fc2ca8db0 [file] [log] [blame]
Edward O'Callaghan4856eef2009-08-05 04:02:561/* ===-- clzdi2.c - Implement __clzdi2 -------------------------------------===
2 *
Anton Korobeynikove63da932011-04-19 17:52:093 * The LLVM Compiler Infrastructure
Edward O'Callaghan4856eef2009-08-05 04:02:564 *
Howard Hinnant5b791f62010-11-16 22:13:335 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan4856eef2009-08-05 04:02:567 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __clzdi2 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarfd089992009-06-26 16:47:0314
15#include "int_lib.h"
16
Edward O'Callaghan4856eef2009-08-05 04:02:5617/* Returns: the number of leading 0-bits */
Daniel Dunbarfd089992009-06-26 16:47:0318
Edward O'Callaghan4856eef2009-08-05 04:02:5619/* Precondition: a != 0 */
Daniel Dunbarfd089992009-06-26 16:47:0320
Anton Korobeynikove63da932011-04-19 17:52:0921COMPILER_RT_ABI si_int
Daniel Dunbarfd089992009-06-26 16:47:0322__clzdi2(di_int a)
23{
24 dwords x;
25 x.all = a;
Edward O'Callaghanccf48132009-08-09 18:41:0226 const si_int f = -(x.s.high == 0);
27 return __builtin_clz((x.s.high & ~f) | (x.s.low & f)) +
Daniel Dunbarfd089992009-06-26 16:47:0328 (f & ((si_int)(sizeof(si_int) * CHAR_BIT)));
29}