This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move load_ufloat/sfloat to its own file
Moves load_ufloat and load_sfloat from vr-format to its own file called vr-small-float. That way the same code can be reused for converting a half float to a double.
- Loading branch information
Showing
5 changed files
with
115 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* vkrunner | ||
* | ||
* Copyright (C) 2018, 2019 Intel Corporation | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice (including the next | ||
* paragraph) shall be included in all copies or substantial portions of the | ||
* Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "vr-small-float.h" | ||
|
||
double | ||
vr_small_float_load_unsigned(uint32_t part, | ||
int e_bits, | ||
int m_bits) | ||
{ | ||
int e_max = UINT32_MAX >> (32 - e_bits); | ||
int e = (part >> m_bits) & e_max; | ||
int m = part & (UINT32_MAX >> (32 - m_bits)); | ||
|
||
if (e == e_max) | ||
return m == 0 ? INFINITY : NAN; | ||
|
||
if (e == 0) | ||
e = 1; | ||
else | ||
m += 1 << m_bits; | ||
|
||
return ldexp(m / (double) (1 << m_bits), e - (e_max >> 1)); | ||
} | ||
|
||
double | ||
vr_small_float_load_signed(uint32_t part, | ||
int e_bits, | ||
int m_bits) | ||
{ | ||
double res = vr_small_float_load_unsigned(part, e_bits, m_bits); | ||
|
||
if (res != NAN && (part & (1 << (e_bits + m_bits)))) | ||
res = -res; | ||
|
||
return res; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* vkrunner | ||
* | ||
* Copyright (C) 2019 Intel Corporation | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice (including the next | ||
* paragraph) shall be included in all copies or substantial portions of the | ||
* Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#ifndef VR_SMALL_FLOAT_H | ||
#define VR_SMALL_FLOAT_H | ||
|
||
#include "vr-small-float.h" | ||
|
||
#include <stdint.h> | ||
#include <math.h> | ||
#include <inttypes.h> | ||
|
||
double | ||
vr_small_float_load_unsigned(uint32_t part, | ||
int e_bits, | ||
int m_bits); | ||
|
||
double | ||
vr_small_float_load_signed(uint32_t part, | ||
int e_bits, | ||
int m_bits); | ||
|
||
#endif /* VR_SMALL_FLOAT_H */ |