xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/ms-intrinsics.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
2*0a6a1f1dSLionel Sambuc // RUN:         -triple i686--windows -Oz -emit-llvm %s -o - \
3*0a6a1f1dSLionel Sambuc // RUN:         | FileCheck %s -check-prefix CHECK -check-prefix CHECK-I386
4*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
5*0a6a1f1dSLionel Sambuc // RUN:         -triple thumbv7--windows -Oz -emit-llvm %s -o - \
6*0a6a1f1dSLionel Sambuc // RUN:         | FileCheck %s
7*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
8*0a6a1f1dSLionel Sambuc // RUN:         -triple x86_64--windows -Oz -emit-llvm %s -o - \
9*0a6a1f1dSLionel Sambuc // RUN:         | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64
10*0a6a1f1dSLionel Sambuc 
11*0a6a1f1dSLionel Sambuc // Intrin.h needs size_t, but -ffreestanding prevents us from getting it from
12*0a6a1f1dSLionel Sambuc // stddef.h.  Work around it with this typedef.
13*0a6a1f1dSLionel Sambuc typedef __SIZE_TYPE__ size_t;
14*0a6a1f1dSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc #include <Intrin.h>
16*0a6a1f1dSLionel Sambuc 
test_InterlockedExchangePointer(void * volatile * Target,void * Value)17*0a6a1f1dSLionel Sambuc void *test_InterlockedExchangePointer(void * volatile *Target, void *Value) {
18*0a6a1f1dSLionel Sambuc   return _InterlockedExchangePointer(Target, Value);
19*0a6a1f1dSLionel Sambuc }
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc // CHECK: define{{.*}}i8* @test_InterlockedExchangePointer(i8** %Target, i8* %Value){{.*}}{
22*0a6a1f1dSLionel Sambuc // CHECK:   %[[TARGET:[0-9]+]] = bitcast i8** %Target to [[iPTR:i[0-9]+]]*
23*0a6a1f1dSLionel Sambuc // CHECK:   %[[VALUE:[0-9]+]] = ptrtoint i8* %Value to [[iPTR]]
24*0a6a1f1dSLionel Sambuc // CHECK:   %[[EXCHANGE:[0-9]+]] = atomicrmw xchg [[iPTR]]* %[[TARGET]], [[iPTR]] %[[VALUE]] seq_cst
25*0a6a1f1dSLionel Sambuc // CHECK:   %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXCHANGE]] to i8*
26*0a6a1f1dSLionel Sambuc // CHECK:   ret i8* %[[RESULT]]
27*0a6a1f1dSLionel Sambuc // CHECK: }
28*0a6a1f1dSLionel Sambuc 
test_InterlockedCompareExchangePointer(void * volatile * Destination,void * Exchange,void * Comparand)29*0a6a1f1dSLionel Sambuc void *test_InterlockedCompareExchangePointer(void * volatile *Destination,
30*0a6a1f1dSLionel Sambuc                                              void *Exchange, void *Comparand) {
31*0a6a1f1dSLionel Sambuc   return _InterlockedCompareExchangePointer(Destination, Exchange, Comparand);
32*0a6a1f1dSLionel Sambuc }
33*0a6a1f1dSLionel Sambuc 
34*0a6a1f1dSLionel Sambuc // CHECK: define{{.*}}i8* @test_InterlockedCompareExchangePointer(i8** %Destination, i8* %Exchange, i8* %Comparand){{.*}}{
35*0a6a1f1dSLionel Sambuc // CHECK:   %[[DEST:[0-9]+]] = bitcast i8** %Destination to [[iPTR]]*
36*0a6a1f1dSLionel Sambuc // CHECK:   %[[EXCHANGE:[0-9]+]] = ptrtoint i8* %Exchange to [[iPTR]]
37*0a6a1f1dSLionel Sambuc // CHECK:   %[[COMPARAND:[0-9]+]] = ptrtoint i8* %Comparand to [[iPTR]]
38*0a6a1f1dSLionel Sambuc // CHECK:   %[[XCHG:[0-9]+]] = cmpxchg volatile [[iPTR]]* %[[DEST:[0-9]+]], [[iPTR]] %[[COMPARAND:[0-9]+]], [[iPTR]] %[[EXCHANGE:[0-9]+]] seq_cst seq_cst
39*0a6a1f1dSLionel Sambuc // CHECK:   %[[EXTRACT:[0-9]+]] = extractvalue { [[iPTR]], i1 } %[[XCHG]], 0
40*0a6a1f1dSLionel Sambuc // CHECK:   %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXTRACT]] to i8*
41*0a6a1f1dSLionel Sambuc // CHECK:   ret i8* %[[RESULT:[0-9]+]]
42*0a6a1f1dSLionel Sambuc // CHECK: }
43*0a6a1f1dSLionel Sambuc 
test_InterlockedExchange(long * Target,long Value)44*0a6a1f1dSLionel Sambuc long test_InterlockedExchange(long *Target, long Value) {
45*0a6a1f1dSLionel Sambuc   return _InterlockedExchange(Target, Value);
46*0a6a1f1dSLionel Sambuc }
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc // CHECK: define{{.*}}i32 @test_InterlockedExchange(i32* %Target, i32 %Value){{.*}}{
49*0a6a1f1dSLionel Sambuc // CHECK:   %[[EXCHANGE:[0-9]+]] = atomicrmw xchg i32* %Target, i32 %Value seq_cst
50*0a6a1f1dSLionel Sambuc // CHECK:   ret i32 %[[EXCHANGE:[0-9]+]]
51*0a6a1f1dSLionel Sambuc // CHECK: }
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc #if defined(__i386__)
test__readfsdword(unsigned long Offset)54*0a6a1f1dSLionel Sambuc long test__readfsdword(unsigned long Offset) {
55*0a6a1f1dSLionel Sambuc   return __readfsdword(Offset);
56*0a6a1f1dSLionel Sambuc }
57*0a6a1f1dSLionel Sambuc 
58*0a6a1f1dSLionel Sambuc // CHECK-I386: define i32 @test__readfsdword(i32 %Offset){{.*}}{
59*0a6a1f1dSLionel Sambuc // CHECK-I386:   [[PTR:%[0-9]+]] = inttoptr i32 %Offset to i32 addrspace(257)*
60*0a6a1f1dSLionel Sambuc // CHECK-I386:   [[VALUE:%[0-9]+]] = load volatile i32 addrspace(257)* [[PTR]], align 4
61*0a6a1f1dSLionel Sambuc // CHECK-I386:   ret i32 [[VALUE:%[0-9]+]]
62*0a6a1f1dSLionel Sambuc // CHECK-I386: }
63*0a6a1f1dSLionel Sambuc #endif
64*0a6a1f1dSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc #if defined(__x86_64__)
test__umulh(unsigned __int64 a,unsigned __int64 b)66*0a6a1f1dSLionel Sambuc unsigned __int64 test__umulh(unsigned __int64 a, unsigned __int64 b) {
67*0a6a1f1dSLionel Sambuc   return __umulh(a, b);
68*0a6a1f1dSLionel Sambuc }
69*0a6a1f1dSLionel Sambuc // CHECK-X64-LABEL: define i64 @test__umulh(i64 %a, i64 %b)
70*0a6a1f1dSLionel Sambuc // CHECK-X64: = mul nuw i128 %
71*0a6a1f1dSLionel Sambuc 
72*0a6a1f1dSLionel Sambuc #endif
73*0a6a1f1dSLionel Sambuc 
74