2014-12-04 07:52:26 +08:00
|
|
|
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
|
|
|
// RUN: -triple i686--windows -Oz -emit-llvm %s -o - \
|
|
|
|
// RUN: | FileCheck %s -check-prefix CHECK -check-prefix CHECK-I386
|
|
|
|
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
|
|
|
// RUN: -triple thumbv7--windows -Oz -emit-llvm %s -o - \
|
|
|
|
// RUN: | FileCheck %s
|
|
|
|
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
|
|
|
|
// RUN: -triple x86_64--windows -Oz -emit-llvm %s -o - \
|
|
|
|
// RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64
|
|
|
|
|
|
|
|
// Intrin.h needs size_t, but -ffreestanding prevents us from getting it from
|
|
|
|
// stddef.h. Work around it with this typedef.
|
|
|
|
typedef __SIZE_TYPE__ size_t;
|
|
|
|
|
|
|
|
#include <Intrin.h>
|
2014-06-19 04:51:10 +08:00
|
|
|
|
|
|
|
void *test_InterlockedExchangePointer(void * volatile *Target, void *Value) {
|
|
|
|
return _InterlockedExchangePointer(Target, Value);
|
|
|
|
}
|
|
|
|
|
2016-02-19 04:02:03 +08:00
|
|
|
// CHECK: define{{.*}}i8* @test_InterlockedExchangePointer(i8** {{[a-z_ ]*}}%Target, i8* %Value){{.*}}{
|
2014-12-04 07:52:26 +08:00
|
|
|
// CHECK: %[[TARGET:[0-9]+]] = bitcast i8** %Target to [[iPTR:i[0-9]+]]*
|
|
|
|
// CHECK: %[[VALUE:[0-9]+]] = ptrtoint i8* %Value to [[iPTR]]
|
|
|
|
// CHECK: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg [[iPTR]]* %[[TARGET]], [[iPTR]] %[[VALUE]] seq_cst
|
|
|
|
// CHECK: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXCHANGE]] to i8*
|
2014-06-19 05:48:44 +08:00
|
|
|
// CHECK: ret i8* %[[RESULT]]
|
2014-06-19 04:51:10 +08:00
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
void *test_InterlockedCompareExchangePointer(void * volatile *Destination,
|
|
|
|
void *Exchange, void *Comparand) {
|
|
|
|
return _InterlockedCompareExchangePointer(Destination, Exchange, Comparand);
|
|
|
|
}
|
|
|
|
|
2016-02-19 04:02:03 +08:00
|
|
|
// CHECK: define{{.*}}i8* @test_InterlockedCompareExchangePointer(i8** nocapture %Destination, i8* %Exchange, i8* %Comparand){{.*}}{
|
2014-12-04 07:52:26 +08:00
|
|
|
// CHECK: %[[DEST:[0-9]+]] = bitcast i8** %Destination to [[iPTR]]*
|
|
|
|
// CHECK: %[[EXCHANGE:[0-9]+]] = ptrtoint i8* %Exchange to [[iPTR]]
|
|
|
|
// CHECK: %[[COMPARAND:[0-9]+]] = ptrtoint i8* %Comparand to [[iPTR]]
|
|
|
|
// CHECK: %[[XCHG:[0-9]+]] = cmpxchg volatile [[iPTR]]* %[[DEST:[0-9]+]], [[iPTR]] %[[COMPARAND:[0-9]+]], [[iPTR]] %[[EXCHANGE:[0-9]+]] seq_cst seq_cst
|
|
|
|
// CHECK: %[[EXTRACT:[0-9]+]] = extractvalue { [[iPTR]], i1 } %[[XCHG]], 0
|
|
|
|
// CHECK: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXTRACT]] to i8*
|
2014-06-19 05:48:44 +08:00
|
|
|
// CHECK: ret i8* %[[RESULT:[0-9]+]]
|
2014-06-19 04:51:10 +08:00
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
long test_InterlockedExchange(long *Target, long Value) {
|
|
|
|
return _InterlockedExchange(Target, Value);
|
|
|
|
}
|
|
|
|
|
2016-02-19 04:02:03 +08:00
|
|
|
// CHECK: define{{.*}}i32 @test_InterlockedExchange(i32* {{[a-z_ ]*}}%Target, i32 %Value){{.*}}{
|
2014-06-19 05:48:44 +08:00
|
|
|
// CHECK: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg i32* %Target, i32 %Value seq_cst
|
|
|
|
// CHECK: ret i32 %[[EXCHANGE:[0-9]+]]
|
2014-06-19 04:51:10 +08:00
|
|
|
// CHECK: }
|
2014-10-30 00:35:41 +08:00
|
|
|
|
|
|
|
#if defined(__i386__)
|
|
|
|
long test__readfsdword(unsigned long Offset) {
|
|
|
|
return __readfsdword(Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-I386: define i32 @test__readfsdword(i32 %Offset){{.*}}{
|
2014-10-30 00:53:16 +08:00
|
|
|
// CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %Offset to i32 addrspace(257)*
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i32, i32 addrspace(257)* [[PTR]], align 4
|
2014-10-30 00:53:16 +08:00
|
|
|
// CHECK-I386: ret i32 [[VALUE:%[0-9]+]]
|
2014-10-30 00:35:41 +08:00
|
|
|
// CHECK-I386: }
|
|
|
|
#endif
|
|
|
|
|
2014-12-04 07:52:26 +08:00
|
|
|
#if defined(__x86_64__)
|
|
|
|
unsigned __int64 test__umulh(unsigned __int64 a, unsigned __int64 b) {
|
|
|
|
return __umulh(a, b);
|
|
|
|
}
|
|
|
|
// CHECK-X64-LABEL: define i64 @test__umulh(i64 %a, i64 %b)
|
2014-12-26 18:29:40 +08:00
|
|
|
// CHECK-X64: = mul nuw i128 %
|
2014-12-04 07:52:26 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|