| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include <clc/clcmacro.h> |
| 10 |
#include <clc/internal/clc.h> |
| 11 |
#include <clc/relational/clc_isnan.h> |
| 12 |
|
| 13 |
_CLC_DEF _CLC_OVERLOAD float __clc_fmin(float x, float y) { |
| 14 |
// fcanonicalize removes sNaNs and flushes denormals if not enabled. Otherwise |
| 15 |
// fmin instruction flushes the values for comparison, but outputs original |
| 16 |
// denormal |
| 17 |
x = __builtin_canonicalizef(x); |
| 18 |
y = __builtin_canonicalizef(y); |
| 19 |
return __builtin_fminf(x, y); |
| 20 |
} |
| 21 |
|
| 22 |
#ifdef cl_khr_fp64 |
| 23 |
|
| 24 |
#pragma OPENCL EXTENSION cl_khr_fp64 : enable |
| 25 |
|
| 26 |
_CLC_DEF _CLC_OVERLOAD double __clc_fmin(double x, double y) { |
| 27 |
x = __builtin_canonicalize(x); |
| 28 |
y = __builtin_canonicalize(y); |
| 29 |
return __builtin_fmin(x, y); |
| 30 |
} |
| 31 |
|
| 32 |
#endif |
| 33 |
|
| 34 |
#ifdef cl_khr_fp16 |
| 35 |
|
| 36 |
#pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 37 |
|
| 38 |
_CLC_DEF _CLC_OVERLOAD half __clc_fmin(half x, half y) { |
| 39 |
if (__clc_isnan(x)) |
| 40 |
return y; |
| 41 |
if (__clc_isnan(y)) |
| 42 |
return x; |
| 43 |
return (y < x) ? y : x; |
| 44 |
} |
| 45 |
|
| 46 |
#endif |
| 47 |
|
| 48 |
#define FUNCTION __clc_fmin |
| 49 |
#define __CLC_BODY <clc/shared/binary_def_scalarize.inc> |
| 50 |
#include <clc/math/gentype.inc> |