Home | History | Annotate | Download | only in alloc
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*
     18  * Implementation of clz(), which returns the number of leading zero bits,
     19  * starting at the most significant bit position.  If the argument is zero,
     20  * the result is undefined.
     21  *
     22  * On some platforms, gcc provides a __builtin_clz() function that uses
     23  * an optimized implementation (e.g. the CLZ instruction on ARM).
     24  *
     25  * This gets a little tricky for ARM, because it's only available in ARMv5
     26  * and above, and even on ARMv5 it's not available for THUMB code.  So we
     27  * need to tailor this for every source file.
     28  */
     29 #ifndef _DALVIK_CLZ
     30 
     31 #if defined(__arm__) && !defined(__thumb__)
     32 # include <machine/cpu-features.h>
     33 # if defined(__ARM_HAVE_CLZ)
     34 #  define CLZ(x) __builtin_clz(x)
     35 #  define HAVE_BUILTIN_CLZ
     36 # endif
     37 #endif
     38 
     39 #ifndef HAVE_BUILTIN_CLZ
     40 # define CLZ(x) dvmClzImpl(x)
     41 int dvmClzImpl(unsigned int x);
     42 #endif
     43 
     44 #endif // _DALVIK_CLZ
     45