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

#ifndef _X86INTRIN_H_INCLUDED
# error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead."
#endif

#ifndef __TBM__
# error "TBM instruction set not enabled"
#endif /* __TBM__ */

#ifndef _TBMINTRIN_H_INCLUDED
#define _TBMINTRIN_H_INCLUDED

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

#define __bextri_u32(X, I)                                              \
  ((unsigned int)__builtin_ia32_bextri_u32 ((unsigned int)(X),          \
                                            (unsigned int)(I)))

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blcfill_u32 (unsigned int __X)
{
  return __X & (__X + 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blci_u32 (unsigned int __X)
{
  return __X | ~(__X + 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blcic_u32 (unsigned int __X)
{
  return ~__X & (__X + 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blcmsk_u32 (unsigned int __X)
{
  return __X ^ (__X + 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blcs_u32 (unsigned int __X)
{
  return __X | (__X + 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blsfill_u32 (unsigned int __X)
{
  return __X | (__X - 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__blsic_u32 (unsigned int __X)
{
  return ~__X | (__X - 1);
}

__E2K_INLINE unsigned int __DEFAULT_FUNCS_ATTRS
__t1mskc_u32 (unsigned int __X)
{
  return ~__X | (__X + 1);
}

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

#define __bextri_u64(X, I)                                                 \
  ((unsigned long long)__builtin_ia32_bextri_u64 ((unsigned long long)(X), \
                                                  (unsigned long long)(I)))

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blcfill_u64 (unsigned long long __X)
{
  return __X & (__X + 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blci_u64 (unsigned long long __X)
{
  return __X | ~(__X + 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blcic_u64 (unsigned long long __X)
{
  return ~__X & (__X + 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blcmsk_u64 (unsigned long long __X)
{
  return __X ^ (__X + 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blcs_u64 (unsigned long long __X)
{
  return __X | (__X + 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blsfill_u64 (unsigned long long __X)
{
  return __X | (__X - 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__blsic_u64 (unsigned long long __X)
{
  return ~__X | (__X - 1);
}

__E2K_INLINE unsigned long long __DEFAULT_FUNCS_ATTRS
__t1mskc_u64 (unsigned long long __X)
{
  return ~__X | (__X + 1);
}

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

#undef __DEFAULT_FUNCS_ATTRS

#endif /* _TBMINTRIN_H_INCLUDED */
