clzti2.c revision 239138
1214152Sed/* ===-- clzti2.c - Implement __clzti2 -------------------------------------=== 2214152Sed * 3214152Sed * The LLVM Compiler Infrastructure 4214152Sed * 5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open 6222656Sed * Source Licenses. See LICENSE.TXT for details. 7214152Sed * 8214152Sed * ===----------------------------------------------------------------------=== 9214152Sed * 10214152Sed * This file implements __clzti2 for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13214152Sed */ 14214152Sed 15239138Sandrew#include "int_lib.h" 16239138Sandrew 17214152Sed#if __x86_64 18214152Sed 19214152Sed/* Returns: the number of leading 0-bits */ 20214152Sed 21214152Sed/* Precondition: a != 0 */ 22214152Sed 23214152Sedsi_int 24214152Sed__clzti2(ti_int a) 25214152Sed{ 26214152Sed twords x; 27214152Sed x.all = a; 28214152Sed const di_int f = -(x.s.high == 0); 29214152Sed return __builtin_clzll((x.s.high & ~f) | (x.s.low & f)) + 30214152Sed ((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT))); 31214152Sed} 32214152Sed 33214152Sed#endif /* __x86_64 */ 34