forked from OSchip/llvm-project
[X86] Add __popcntd and __popcntq to ia32intrin.h to match gcc and icc. Remove popcnt feature flag from _popcnt32/_popcnt64 and move to ia32intrin.h to match gcc
gcc and icc both implement popcntd and popcntq which we did not. gcc doesn't seem to require a feature flag for the _popcnt32/_popcnt64 spelling and will use a libcall if its not supported. Differential Revision: https://reviews.llvm.org/D59567 llvm-svn: 356689
This commit is contained in:
parent
c14f3e4222
commit
1383340422
|
@ -28,6 +28,48 @@
|
|||
#ifndef __IA32INTRIN_H
|
||||
#define __IA32INTRIN_H
|
||||
|
||||
/** Counts the number of bits in the source operand having a value of 1.
|
||||
*
|
||||
* \headerfile <x86intrin.h>
|
||||
*
|
||||
* This intrinsic corresponds to the <c> POPCNT </c> instruction or a
|
||||
* a sequence of arithmetic and logic ops to calculate it.
|
||||
*
|
||||
* \param __A
|
||||
* An unsigned 32-bit integer operand.
|
||||
* \returns A 32-bit integer containing the number of bits with value 1 in the
|
||||
* source operand.
|
||||
*/
|
||||
static __inline__ int __attribute__((__always_inline__, __nodebug__))
|
||||
__popcntd(unsigned int __A)
|
||||
{
|
||||
return __builtin_popcount(__A);
|
||||
}
|
||||
|
||||
#define _popcnt32(A) __popcntd((A))
|
||||
|
||||
#ifdef __x86_64__
|
||||
/** Counts the number of bits in the source operand having a value of 1.
|
||||
*
|
||||
* \headerfile <x86intrin.h>
|
||||
*
|
||||
* This intrinsic corresponds to the <c> POPCNT </c> instruction or a
|
||||
* a sequence of arithmetic and logic ops to calculate it.
|
||||
*
|
||||
* \param __A
|
||||
* An unsigned 64-bit integer operand.
|
||||
* \returns A 64-bit integer containing the number of bits with value 1 in the
|
||||
* source operand.
|
||||
*/
|
||||
static __inline__ long long __attribute__((__always_inline__, __nodebug__))
|
||||
__popcntq(unsigned long long __A)
|
||||
{
|
||||
return __builtin_popcountll(__A);
|
||||
}
|
||||
|
||||
#define _popcnt64(A) __popcntq((A))
|
||||
#endif /* __x86_64__ */
|
||||
|
||||
#ifdef __x86_64__
|
||||
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
|
||||
__readeflags(void)
|
||||
|
|
|
@ -43,22 +43,6 @@ _mm_popcnt_u32(unsigned int __A)
|
|||
return __builtin_popcount(__A);
|
||||
}
|
||||
|
||||
/// Counts the number of bits in the source operand having a value of 1.
|
||||
///
|
||||
/// \headerfile <x86intrin.h>
|
||||
///
|
||||
/// This intrinsic corresponds to the <c> POPCNT </c> instruction.
|
||||
///
|
||||
/// \param __A
|
||||
/// A signed 32-bit integer operand.
|
||||
/// \returns A 32-bit integer containing the number of bits with value 1 in the
|
||||
/// source operand.
|
||||
static __inline__ int __DEFAULT_FN_ATTRS
|
||||
_popcnt32(int __A)
|
||||
{
|
||||
return __builtin_popcount(__A);
|
||||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
/// Counts the number of bits in the source operand having a value of 1.
|
||||
///
|
||||
|
@ -75,22 +59,6 @@ _mm_popcnt_u64(unsigned long long __A)
|
|||
{
|
||||
return __builtin_popcountll(__A);
|
||||
}
|
||||
|
||||
/// Counts the number of bits in the source operand having a value of 1.
|
||||
///
|
||||
/// \headerfile <x86intrin.h>
|
||||
///
|
||||
/// This intrinsic corresponds to the <c> POPCNT </c> instruction.
|
||||
///
|
||||
/// \param __A
|
||||
/// A signed 64-bit integer operand.
|
||||
/// \returns A 64-bit integer containing the number of bits with value 1 in the
|
||||
/// source operand.
|
||||
static __inline__ long long __DEFAULT_FN_ATTRS
|
||||
_popcnt64(long long __A)
|
||||
{
|
||||
return __builtin_popcountll(__A);
|
||||
}
|
||||
#endif /* __x86_64__ */
|
||||
|
||||
#undef __DEFAULT_FN_ATTRS
|
||||
|
|
|
@ -1,24 +1,39 @@
|
|||
// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s
|
||||
// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
|
||||
// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
|
||||
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <x86intrin.h>
|
||||
|
||||
unsigned int test_mm_popcnt_u32(unsigned int __X) {
|
||||
//CHECK: call i32 @llvm.ctpop.i32
|
||||
#ifdef __POPCNT__
|
||||
int test_mm_popcnt_u32(unsigned int __X) {
|
||||
//CHECK-POPCNT: call i32 @llvm.ctpop.i32
|
||||
return _mm_popcnt_u32(__X);
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int test_popcnt_32(int __X) {
|
||||
int test_popcnt32(unsigned int __X) {
|
||||
//CHECK: call i32 @llvm.ctpop.i32
|
||||
return _popcnt32(__X);
|
||||
}
|
||||
|
||||
unsigned long long test_mm_popcnt_u64(unsigned long long __X) {
|
||||
//CHECK: call i64 @llvm.ctpop.i64
|
||||
return _mm_popcnt_u64(__X);
|
||||
int test__popcntd(unsigned int __X) {
|
||||
//CHECK: call i32 @llvm.ctpop.i32
|
||||
return __popcntd(__X);
|
||||
}
|
||||
|
||||
unsigned long long test_popcnt_64(long long __X) {
|
||||
#ifdef __POPCNT__
|
||||
long long test_mm_popcnt_u64(unsigned long long __X) {
|
||||
//CHECK-POPCNT: call i64 @llvm.ctpop.i64
|
||||
return _mm_popcnt_u64(__X);
|
||||
}
|
||||
#endif
|
||||
|
||||
long long test_popcnt64(unsigned long long __X) {
|
||||
//CHECK: call i64 @llvm.ctpop.i64
|
||||
return _popcnt64(__X);
|
||||
}
|
||||
|
||||
long long test__popcntq(unsigned long long __X) {
|
||||
//CHECK: call i64 @llvm.ctpop.i64
|
||||
return __popcntq(__X);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue