r218118 - [x86] Add _addcarry_u{32|64} and _subborrow_u{32|64}.

Pasi Parviainen pasi.parviainen at iki.fi
Fri Sep 19 11:51:53 PDT 2014


On 19.9.2014 13:29, Robert Khasanov wrote:
> Author: rkhasanov
> Date: Fri Sep 19 05:29:22 2014
> New Revision: 218118
>
> URL: http://llvm.org/viewvc/llvm-project?rev=218118&view=rev
> Log:
> [x86] Add _addcarry_u{32|64} and _subborrow_u{32|64}.
> They are added to adxintrin.h but outside __ADX__ block.
> These intrinics generates adc and sbb correspondingly that were available before ADX
>
>
> Added:
>      cfe/trunk/test/CodeGen/adc-builtins.c
> Modified:
>      cfe/trunk/include/clang/Basic/BuiltinsX86.def
>      cfe/trunk/lib/Headers/adxintrin.h
>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=218118&r1=218117&r2=218118&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Sep 19 05:29:22 2014
> @@ -628,6 +628,10 @@ BUILTIN(__builtin_ia32_rdrand64_step, "U
>   // ADX
>   BUILTIN(__builtin_ia32_addcarryx_u32, "UcUcUiUiUi*", "")
>   BUILTIN(__builtin_ia32_addcarryx_u64, "UcUcULLiULLiULLi*", "")
> +BUILTIN(__builtin_ia32_addcarry_u32, "UcUcUiUiUi*", "")
> +BUILTIN(__builtin_ia32_addcarry_u64, "UcUcULLiULLiULLi*", "")
> +BUILTIN(__builtin_ia32_subborrow_u32, "UcUcUiUiUi*", "")
> +BUILTIN(__builtin_ia32_subborrow_u64, "UcUcULLiULLiULLi*", "")
>
>   // RDSEED
>   BUILTIN(__builtin_ia32_rdseed16_step, "UiUs*", "")
>
> Modified: cfe/trunk/lib/Headers/adxintrin.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/adxintrin.h?rev=218118&r1=218117&r2=218118&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Headers/adxintrin.h (original)
> +++ cfe/trunk/lib/Headers/adxintrin.h Fri Sep 19 05:29:22 2014
> @@ -28,6 +28,7 @@
>   #ifndef __ADXINTRIN_H
>   #define __ADXINTRIN_H
>
> +/* Intrinsics that are available only if __ADX__ defined */
>   #ifdef __ADX__
>   static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
>   _addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
> @@ -46,4 +47,37 @@ _addcarryx_u64(unsigned char __cf, unsig
>   #endif
>   #endif
>
> +/* Intrinsics that are also available if __ADX__ undefined */
> +static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
> +_addcarry_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
> +              unsigned int *__p)
> +{
> +  return __builtin_ia32_addcarry_u32(__cf, __x, __y, __p);
> +}
> +
> +#ifdef __x86_64__
> +static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
> +_addcarry_u64(unsigned char __cf, unsigned long __x, unsigned long __y,
> +              unsigned long long  *__p)
> +{
> +  return __builtin_ia32_addcarry_u64(__cf, __x, __y, __p);
> +}

Shouldn't the __x and __y arguments have type of unsigned long long 
instead of unsigned long? Otherwise this doesn't make sense with LLP64 
model, and builtin is defined to take ULLi . Also same goes for 
_subborrow_u64 and for _addcarryx_u64 from r218117.

Pasi.

> +#endif
> +
> +static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
> +_subborrow_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
> +              unsigned int *__p)
> +{
> +  return __builtin_ia32_subborrow_u32(__cf, __x, __y, __p);
> +}
> +
> +#ifdef __x86_64__
> +static __inline unsigned char __attribute__((__always_inline__, __nodebug__))
> +_subborrow_u64(unsigned char __cf, unsigned long __x, unsigned long __y,
> +              unsigned long long  *__p)
> +{
> +  return __builtin_ia32_subborrow_u64(__cf, __x, __y, __p);
> +}
> +#endif
> +
>   #endif /* __ADXINTRIN_H */
>
> Added: cfe/trunk/test/CodeGen/adc-builtins.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/adc-builtins.c?rev=218118&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/adc-builtins.c (added)
> +++ cfe/trunk/test/CodeGen/adc-builtins.c Fri Sep 19 05:29:22 2014
> @@ -0,0 +1,31 @@
> +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffreestanding -emit-llvm -o - %s | FileCheck %s
> +
> +#include <x86intrin.h>
> +
> +unsigned char test_addcarry_u32(unsigned char __cf, unsigned int __x,
> +                                unsigned int __y, unsigned int *__p) {
> +// CHECK-LABEL: test_addcarry_u32
> +// CHECK: call i8 @llvm.x86.addcarry.u32
> +  return _addcarry_u32(__cf, __x, __y, __p);
> +}
> +
> +unsigned char test_addcarry_u64(unsigned char __cf, unsigned long __x,
> +                                unsigned long __y, unsigned long long *__p) {
> +// CHECK-LABEL: test_addcarry_u64
> +// CHECK: call i8 @llvm.x86.addcarry.u64
> +  return _addcarry_u64(__cf, __x, __y, __p);
> +}
> +
> +unsigned char test_subborrow_u32(unsigned char __cf, unsigned int __x,
> +                                unsigned int __y, unsigned int *__p) {
> +// CHECK-LABEL: test_subborrow_u32
> +// CHECK: call i8 @llvm.x86.subborrow.u32
> +  return _subborrow_u32(__cf, __x, __y, __p);
> +}
> +
> +unsigned char test_subborrow_u64(unsigned char __cf, unsigned long __x,
> +                                unsigned long __y, unsigned long long *__p) {
> +// CHECK-LABEL: test_subborrow_u64
> +// CHECK: call i8 @llvm.x86.subborrow.u64
> +  return _subborrow_u64(__cf, __x, __y, __p);
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list