| 1 |
/* |
| 2 |
* Copyright 2014 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "src/base/SkHalf.h" |
| 9 |
|
| 10 |
#include "include/private/base/SkFloatingPoint.h" |
| 11 |
#include "src/base/SkVx.h" |
| 12 |
|
| 13 |
// NOTE: These are defined within the CPP compilation unit so that they are not inlined everywhere |
| 14 |
// and increase code size. Performance critical code is likely already using skvx directly, and |
| 15 |
// they will be inlined where performance vs. code size is worth it. |
| 16 |
SkHalf SkFloatToHalf(float f) { |
| 17 |
if (std::isnan(f)) { |
| 18 |
return SK_HalfNaN; |
| 19 |
} else { |
| 20 |
return to_half(skvx::Vec<1,float>(f))[0]; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
float SkHalfToFloat(SkHalf h) { |
| 25 |
return from_half(skvx::Vec<1,uint16_t>(h))[0]; |
| 26 |
} |