forked from JonathanSalwan/Triton
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ move fp operand feature to Imm ctor
- Loading branch information
Showing
7 changed files
with
144 additions
and
51 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
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,34 @@ | ||
//! \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; | ||
|
||
} | ||
|
||
} | ||
|
||
#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,42 @@ | ||
//! \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 { | ||
|
||
auto f32_to_f16(float value) -> uint16_t { | ||
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 */ |