Skip to content

Commit

Permalink
Fast specialized posits (#384)
Browse files Browse the repository at this point in the history
* enabling fast specialized posit regression test for missing standard posits

* adding posit<8,2> skeleton

* value conversion of fast posit<8,2> implementation

* compilation fix for clang and gcc, those compilers do not support multi-valued case statements

* unifying the specialized posit test benches

---------

Signed-off-by: Theodore Omtzigt <[email protected]>
  • Loading branch information
Ravenwater authored Nov 24, 2023
1 parent f75b4a9 commit 92d0834
Show file tree
Hide file tree
Showing 25 changed files with 1,747 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CMake

on:
push:
branches: [ v3.73, dev, main ]
branches: [ v3.74, dev, main ]
pull_request:
branches: [ main ]

Expand Down
4 changes: 4 additions & 0 deletions include/universal/number/posit/specializations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
#define POSIT_FAST_POSIT_3_1 1
#define POSIT_FAST_POSIT_4_0 1
#define POSIT_FAST_POSIT_8_0 1
#define POSIT_FAST_POSIT_8_2 1
#define POSIT_FAST_POSIT_16_1 1
#define POSIT_FAST_POSIT_16_2 1
#define POSIT_FAST_POSIT_32_2 1
#define POSIT_FAST_POSIT_48_2 0
#define POSIT_FAST_POSIT_64_2 0
#define POSIT_FAST_POSIT_64_3 0
#define POSIT_FAST_POSIT_128_2 0
#define POSIT_FAST_POSIT_128_4 0
#define POSIT_FAST_POSIT_256_2 0
#define POSIT_FAST_POSIT_256_5 0
#endif

Expand Down
38 changes: 20 additions & 18 deletions include/universal/number/posit/specialized/posit_16_1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace sw { namespace universal {
#if POSIT_FAST_POSIT_16_1
#ifdef _MSC_VER
#pragma message("Fast specialization of posit<16,1>")
//#else
//#else some compile time message that indicates that we are using a specialization for non MS compilers
//#warning("Fast specialization of posit<16,1>")
#endif

Expand Down Expand Up @@ -884,22 +884,6 @@ inline std::string to_string(const posit<NBITS_IS_16, ES_IS_1>& p, std::streamsi
return ss.str();
}

inline bool twosComplementLessThan(std::uint16_t lhs, std::uint16_t rhs) {
// comparison of the sign bit
uint32_t mask = 0x8000;
if ((lhs & mask) == 0 && (rhs & mask) == mask) return false;
if ((lhs & mask) == mask && (rhs & mask) == 0) return true;
// sign is equal, compare the remaining bits
mask >>= 1;
while (mask > 0) {
if ((lhs & mask) == 0 && (rhs & mask) == mask) return true;
if ((lhs & mask) == mask && (rhs & mask) == 0) return false;
mask >>= 1;
}
// numbers are equal
return false;
}

// posit - posit binary logic operators
inline bool operator==(const posit<NBITS_IS_16, ES_IS_1>& lhs, const posit<NBITS_IS_16, ES_IS_1>& rhs) {
return lhs._bits == rhs._bits;
Expand Down Expand Up @@ -968,8 +952,26 @@ inline bool operator>=(int lhs, const posit<NBITS_IS_16, ES_IS_1>& rhs) {
return !operator<(posit<NBITS_IS_16, ES_IS_1>(lhs), rhs);
}

/*
inline bool twosComplementLessThan(std::uint16_t lhs, std::uint16_t rhs) {
// comparison of the sign bit
uint32_t mask = 0x8000;
if ((lhs & mask) == 0 && (rhs & mask) == mask) return false;
if ((lhs & mask) == mask && (rhs & mask) == 0) return true;
// sign is equal, compare the remaining bits
mask >>= 1;
while (mask > 0) {
if ((lhs & mask) == 0 && (rhs & mask) == mask) return true;
if ((lhs & mask) == mask && (rhs & mask) == 0) return false;
mask >>= 1;
}
// numbers are equal
return false;
}
*/

inline bool operator< (const posit<NBITS_IS_16, ES_IS_1>& lhs, double rhs) {
return twosComplementLessThan(lhs._bits, posit<NBITS_IS_16, ES_IS_1>(rhs)._bits);
return int16_t(lhs._bits) < int16_t(posit<NBITS_IS_16, ES_IS_1>(rhs)._bits);
}

#endif // POSIT_ENABLE_LITERALS
Expand Down
Loading

0 comments on commit 92d0834

Please sign in to comment.