/* Copyright (c) 2018 ZAO "MCST". All rights reserved. */

#if !defined _X86INTRIN_H_INCLUDED && !defined _IMMINTRIN_H_INCLUDED
# error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead."
#endif

#ifndef __BMI__
# error "BMI instruction set not enabled"
#endif /* __BMI__ */

#ifndef _BMIINTRIN_H_INCLUDED
#define _BMIINTRIN_H_INCLUDED

/* Define the default attributes for the functions in this file */
#define __DEFAULT_FUNCS_ATTRS __attribute__((/*__gnu_inline__,*/ __always_inline__, __artificial__))

__E2K_INLINE unsigned short __DEFAULT_FUNCS_ATTRS
__tzcnt_u16 (unsigned short __X)
{
  return __builtin_ctzs (__X);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__andn_u32 (unsigned int __X, unsigned int __Y)
{
  return ~__X & __Y;
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__bextr_u32 (unsigned int __X, unsigned int __Y)
{
  return __builtin_ia32_bextr_u32 (__X, __Y);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
_bextr_u32 (unsigned int __X, unsigned int __Y, unsigned __Z)
{
  return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blsi_u32 (unsigned int __X)
{
  return __X & -__X;
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
_blsi_u32 (unsigned int __X)
{
  return __blsi_u32 (__X);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blsmsk_u32 (unsigned int __X)
{
  return __X ^ (__X - 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
_blsmsk_u32 (unsigned int __X)
{
  return __blsmsk_u32 (__X);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blsr_u32 (unsigned int __X)
{
  return __X & (__X - 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
_blsr_u32 (unsigned int __X)
{
  return __blsr_u32 (__X);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__tzcnt_u32 (unsigned int __X)
{
  return __builtin_ctz (__X);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
_tzcnt_u32 (unsigned int __X)
{
  return __tzcnt_u32 (__X);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__andn_u64 (unsigned long long __X, unsigned long long __Y)
{
  return ~__X & __Y;
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__bextr_u64 (unsigned long long __X, unsigned long long __Y)
{
  return __builtin_ia32_bextr_u64 (__X, __Y);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
_bextr_u64 (unsigned long long __X, unsigned int __Y, unsigned int __Z)
{
  return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blsi_u64 (unsigned long long __X)
{
  return __X & -__X;
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
_blsi_u64 (unsigned long long __X)
{
  return __blsi_u64 (__X);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blsmsk_u64 (unsigned long long __X)
{
  return __X ^ (__X - 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
_blsmsk_u64 (unsigned long long __X)
{
  return __blsmsk_u64 (__X);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blsr_u64 (unsigned long long __X)
{
  return __X & (__X - 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
_blsr_u64 (unsigned long long __X)
{
  return __blsr_u64 (__X);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__tzcnt_u64 (unsigned long long __X)
{
  return __builtin_ctzll (__X);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
_tzcnt_u64 (unsigned long long __X)
{
  return __tzcnt_u64 (__X);
}

#undef __DEFAULT_FUNCS_ATTRS

#endif /* _BMIINTRIN_H_INCLUDED */
