-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
171 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1595 | ||
1597 |
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
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,35 @@ | ||
//! \file | ||
/* | ||
** Copyright (C) - Triton | ||
** | ||
** This program is under the terms of the Apache License 2.0. | ||
*/ | ||
|
||
#ifndef TRITON_SOFTFLOAT_HPP | ||
#define TRITON_SOFTFLOAT_HPP | ||
|
||
#include <cstdint> | ||
|
||
//! The Triton namespace | ||
namespace triton { | ||
/*! | ||
* \addtogroup triton | ||
* @{ | ||
*/ | ||
//! The Softfloat namespace | ||
namespace sf { | ||
/*! | ||
* \ingroup triton | ||
* \addtogroup softfloat | ||
* @{ | ||
*/ | ||
|
||
//! Cast 32-bit floating point value to 16-bit according to IEEE-754 | ||
auto f32_to_f16(float value) -> uint16_t; | ||
|
||
/*! @} End of softfloat namespace */ | ||
}; | ||
/*! @} End of triton namespace */ | ||
}; | ||
|
||
#endif /* TRITON_SOFTFLOAT_HPP */ |
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,49 @@ | ||
//! \file | ||
/* | ||
** Copyright (C) - Triton | ||
** | ||
** This program is under the terms of the Apache License 2.0. | ||
*/ | ||
|
||
#include <triton/softfloat.hpp> | ||
|
||
#include <cstring> | ||
|
||
namespace triton { | ||
namespace sf { | ||
|
||
uint16_t f32_to_f16(float value) { | ||
uint32_t f; | ||
|
||
static_assert(sizeof(float) == sizeof(uint32_t), "Unexpected float type size"); | ||
std::memcpy(&f, &value, sizeof(uint32_t)); | ||
|
||
uint16_t sign = ((f >> 16) & 0x8000); | ||
int16_t exponent = ((f >> 23) & 0xff) - 127 + 15; | ||
uint16_t mantissa = ((f >> 13) & 0x3ff); | ||
|
||
if (exponent <= 0) { | ||
if (exponent < -10) { | ||
return sign; | ||
} | ||
mantissa = (mantissa | 0x400) >> (1 - exponent); | ||
return sign | mantissa; | ||
} | ||
|
||
else if (exponent == 0xff - (127 - 15)) { | ||
if (mantissa) { | ||
return sign | 0x7fff; | ||
} else { | ||
return sign | 0x7c00; | ||
} | ||
} | ||
|
||
else if (exponent > 30) { | ||
return sign | 0x7c00; | ||
} | ||
|
||
return sign | (exponent << 10) | mantissa; | ||
} | ||
|
||
}; /* sf namespace */ | ||
}; /* triton namespace */ |
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