|
| 1 | +// This test is written with an aim to check that experimental::printf behaves |
| 2 | +// in the same way as printf from C99/C11 |
| 3 | +// |
| 4 | +// The test is written using conversion specifiers table from cppreference [1] |
| 5 | +// [1]: https://en.cppreference.com/w/cpp/io/c/fprintf |
| 6 | +// |
| 7 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 8 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER |
| 9 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER |
| 10 | +// RUN: %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER |
| 11 | +// FIXME: Remove dedicated constant address space testing once generic AS |
| 12 | +// support is considered stable. |
| 13 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.constant.out \ |
| 14 | +// RUN: -DTEST_CONSTANT_AS |
| 15 | +// RUN: %CPU_RUN_PLACEHOLDER %t.constant.out %CPU_CHECK_PLACEHOLDER |
| 16 | +// RUN: %GPU_RUN_PLACEHOLDER %t.constant.out %GPU_CHECK_PLACEHOLDER |
| 17 | +// RUN: %ACC_RUN_PLACEHOLDER %t.constant.out %ACC_CHECK_PLACEHOLDER |
| 18 | +// |
| 19 | +// CHECK: float 3.140000e+00, 3.140000E+00 |
| 20 | +// CHECK: double -6.813800e+00, -6.813800E+00 |
| 21 | +// CHECK: mixed 3.140000e+00, -6.813800E+00 |
| 22 | +// CHECK: float 0x1.91eb86{{0*}}p+1, 0X1.91EB86{{0*}}P+1 |
| 23 | +// CHECK: double -0x1.b4154d8cccccdp+2, -0X1.B4154D8CCCCCDP+2 |
| 24 | +// CHECK: mixed 0x1.91eb86{{0*}}p+1, -0X1.B4154D8CCCCCDP+2 |
| 25 | +// CHECK: float 3.14, 3.14 |
| 26 | +// CHECK: double -6.8138, -6.8138 |
| 27 | +// CHECK: mixed 3.14, -6.8138 |
| 28 | + |
| 29 | +#include <CL/sycl.hpp> |
| 30 | + |
| 31 | +#include "helper.hpp" |
| 32 | + |
| 33 | +using namespace sycl; |
| 34 | + |
| 35 | +void do_float_test() { |
| 36 | + { |
| 37 | + // %e, %E floating-point, decimal exponent notation |
| 38 | + FORMAT_STRING(fmt1) = "float %e, %E\n"; |
| 39 | + FORMAT_STRING(fmt2) = "double %e, %E\n"; |
| 40 | + FORMAT_STRING(fmt3) = "mixed %e, %E\n"; |
| 41 | + |
| 42 | + float f = 3.14; |
| 43 | + double d = -f * 2.17; |
| 44 | + ext::oneapi::experimental::printf(fmt1, f, f); |
| 45 | + ext::oneapi::experimental::printf(fmt2, d, d); |
| 46 | + ext::oneapi::experimental::printf(fmt3, f, d); |
| 47 | + } |
| 48 | + |
| 49 | + { |
| 50 | + // %a, %A floating-point, hexadecimal exponent notation |
| 51 | + FORMAT_STRING(fmt1) = "float %a, %A\n"; |
| 52 | + FORMAT_STRING(fmt2) = "double %a, %A\n"; |
| 53 | + FORMAT_STRING(fmt3) = "mixed %a, %A\n"; |
| 54 | + |
| 55 | + float f = 3.14; |
| 56 | + double d = -f * 2.17; |
| 57 | + ext::oneapi::experimental::printf(fmt1, f, f); |
| 58 | + ext::oneapi::experimental::printf(fmt2, d, d); |
| 59 | + ext::oneapi::experimental::printf(fmt3, f, d); |
| 60 | + } |
| 61 | + |
| 62 | + { |
| 63 | + // %g, %G floating-point |
| 64 | + FORMAT_STRING(fmt1) = "float %g, %G\n"; |
| 65 | + FORMAT_STRING(fmt2) = "double %g, %G\n"; |
| 66 | + FORMAT_STRING(fmt3) = "mixed %g, %G\n"; |
| 67 | + |
| 68 | + float f = 3.14; |
| 69 | + double d = -f * 2.17; |
| 70 | + ext::oneapi::experimental::printf(fmt1, f, f); |
| 71 | + ext::oneapi::experimental::printf(fmt2, d, d); |
| 72 | + ext::oneapi::experimental::printf(fmt3, f, d); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +class FloatTest; |
| 77 | + |
| 78 | +int main() { |
| 79 | + queue q; |
| 80 | + |
| 81 | + q.submit([](handler &cgh) { |
| 82 | + cgh.single_task<FloatTest>([]() { do_float_test(); }); |
| 83 | + }); |
| 84 | + q.wait(); |
| 85 | + |
| 86 | + return 0; |
| 87 | +} |
0 commit comments