xref: /llvm-project/clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c (revision baeb85b5a99778956117d647b78b55be4f51a129)
1 // RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
2 // RUN:   -mabi=ieeelongdouble | FileCheck --check-prefix=IEEE128 %s
3 // RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
4 // RUN:   | FileCheck --check-prefix=PPC128 %s
5 
6 long double x;
7 char buf[20];
8 
9 // IEEE128-LABEL: define dso_local void @test_printf
10 // IEEE128: call signext i32 (ptr, ...) @__printfieee128
11 // PPC128-LABEL: define dso_local void @test_printf
12 // PPC128: call signext i32 (ptr, ...) @printf
test_printf(void)13 void test_printf(void) {
14   __builtin_printf("%.Lf", x);
15 }
16 
17 // IEEE128-LABEL: define dso_local void @test_vsnprintf
18 // IEEE128: call signext i32 @__vsnprintfieee128
19 // PPC128-LABEL: define dso_local void @test_vsnprintf
20 // PPC128: call signext i32 @vsnprintf
test_vsnprintf(int n,...)21 void test_vsnprintf(int n, ...) {
22   __builtin_va_list va;
23   __builtin_va_start(va, n);
24   __builtin_vsnprintf(buf, 20, "%.Lf", va);
25   __builtin_va_end(va);
26 }
27 
28 // IEEE128-LABEL: define dso_local void @test_vsprintf
29 // IEEE128: call signext i32 @__vsprintfieee128
30 // PPC128-LABEL: define dso_local void @test_vsprintf
31 // PPC128: call signext i32 @vsprintf
test_vsprintf(int n,...)32 void test_vsprintf(int n, ...) {
33   __builtin_va_list va;
34   __builtin_va_start(va, n);
35   __builtin_vsprintf(buf, "%.Lf", va);
36   __builtin_va_end(va);
37 }
38 
39 // IEEE128-LABEL: define dso_local void @test_sprintf
40 // IEEE128: call signext i32 (ptr, ptr, ...) @__sprintfieee128
41 // PPC128-LABEL: define dso_local void @test_sprintf
42 // PPC128: call signext i32 (ptr, ptr, ...) @sprintf
test_sprintf(void)43 void test_sprintf(void) {
44   __builtin_sprintf(buf, "%.Lf", x);
45 }
46 
47 // IEEE128-LABEL: define dso_local void @test_snprintf
48 // IEEE128: call signext i32 (ptr, i64, ptr, ...) @__snprintfieee128
49 // PPC128-LABEL: define dso_local void @test_snprintf
50 // PPC128: call signext i32 (ptr, i64, ptr, ...) @snprintf
test_snprintf(void)51 void test_snprintf(void) {
52   __builtin_snprintf(buf, 20, "%.Lf", x);
53 }
54 
55 // IEEE128-LABEL: define dso_local void @test_scanf
56 // IEEE128: call signext i32 (ptr, ...) @__scanfieee128
57 // PPC128-LABEL: define dso_local void @test_scanf
58 // PPC128: call signext i32 (ptr, ...) @scanf
test_scanf(int * x)59 void test_scanf(int *x) {
60   __builtin_scanf("%d", x);
61 }
62 
63 // IEEE128-LABEL: define dso_local void @test_sscanf
64 // IEEE128: call signext i32 (ptr, ptr, ...) @__sscanfieee128
65 // PPC128-LABEL: define dso_local void @test_sscanf
66 // PPC128: call signext i32 (ptr, ptr, ...) @sscanf
test_sscanf(int * x)67 void test_sscanf(int *x) {
68   __builtin_sscanf(buf, "%d", x);
69 }
70 
71 // IEEE128-LABEL: define dso_local void @test_vprintf
72 // IEEE128: call signext i32 @__vprintfieee128
73 // PPC128-LABEL: define dso_local void @test_vprintf
74 // PPC128: call signext i32 @vprintf
test_vprintf(const char * fmt,...)75 void test_vprintf(const char *fmt, ...) {
76   __builtin_va_list args;
77   __builtin_va_start(args, fmt);
78   __builtin_vprintf(fmt, args);
79   __builtin_va_end(args);
80 }
81 
82 // IEEE128-LABEL: define dso_local void @test_vscanf
83 // IEEE128: call signext i32 @__vscanfieee128
84 // PPC128-LABEL: define dso_local void @test_vscanf
85 // PPC128: call signext i32 @vscanf
test_vscanf(const char * fmt,...)86 void test_vscanf(const char *fmt, ...) {
87   __builtin_va_list args;
88   __builtin_va_start(args, fmt);
89   __builtin_vscanf(fmt, args);
90   __builtin_va_end(args);
91 }
92 
93 // IEEE128-LABEL: define dso_local void @test_vsscanf
94 // IEEE128: call signext i32 @__vsscanfieee128
95 // PPC128-LABEL: define dso_local void @test_vsscanf
96 // PPC128: call signext i32 @vsscanf
test_vsscanf(const char * fmt,...)97 void test_vsscanf(const char *fmt, ...) {
98   __builtin_va_list args;
99   __builtin_va_start(args, fmt);
100   __builtin_vsscanf(buf, fmt, args);
101   __builtin_va_end(args);
102 }
103 
104 // IEEE128-LABEL: define dso_local void @test_snprintf_chk
105 // IEEE128: call signext i32 (ptr, i64, i32, i64, ptr, ...) @__snprintf_chkieee128
106 // PPC128-LABEL: define dso_local void @test_snprintf_chk
107 // PPC128: call signext i32 (ptr, i64, i32, i64, ptr, ...) @__snprintf_chk
test_snprintf_chk(long double x)108 void test_snprintf_chk(long double x) {
109   __builtin___snprintf_chk(buf, 20, 1, 20, "%.Lf", x);
110 }
111 
112 // GLIBC has special handling of 'nexttoward'
113 
114 // IEEE128-LABEL: define dso_local fp128 @test_nexttoward
115 // IEEE128: call fp128 @__nexttowardieee128
116 // PPC128-LABEL: define dso_local ppc_fp128 @test_nexttoward
117 // PPC128: call ppc_fp128 @nexttowardl
test_nexttoward(long double a,long double b)118 long double test_nexttoward(long double a, long double b) {
119   return __builtin_nexttowardl(a, b);
120 }
121