/* Copyright 2005 Castle Technology Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *  AsmUtils (clz.h)
 *
 * Copyright (C) 2004 Castle Technology Ltd
 *
 * Author: Ben Avison
 *
 */

#ifndef asmuntils_clz_h_included
#define asmuntils_clz_h_included

#ifdef __cplusplus
extern "C" {
#endif

/* These functions adapt to be optimal for CPUs with or without the CLZ instruction */

extern unsigned int clz(unsigned int);
  /* Returns the number of leading zero bits in the argument, 0 ... 32 */

extern unsigned int ctz(unsigned int);
  /* Returns the number of trailing zero bits in the argument, 0 ... 32 */

extern unsigned int clo(unsigned int);
  /* Returns the number of leading one bits in the argument, 0 ... 32 */

extern unsigned int cto(unsigned int);
  /* Returns the number of trailing one bits in the argument, 0 ... 32 */

extern unsigned int clz64(unsigned long long);
  /* Returns the number of leading zero bits in the argument, 0 ... 64 */

extern unsigned int ctz64(unsigned long long);
  /* Returns the number of trailing zero bits in the argument, 0 ... 64 */

extern unsigned int clo64(unsigned long long);
  /* Returns the number of leading one bits in the argument, 0 ... 64 */

extern unsigned int cto64(unsigned long long);
  /* Returns the number of trailing one bits in the argument, 0 ... 64 */

#ifdef __cplusplus
}
#endif

#endif
