-
Notifications
You must be signed in to change notification settings - Fork 41
Add inline, remove unused exception variable name, safe float computation #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,10 +56,14 @@ inline uint16_t float_to_float16_untyped_slow(const float x) { | |
| const uint32_t b = bitcast_float_to_uint32(x) + 0x00001000; | ||
| const uint32_t e = (b & 0x7F800000) >> 23; // exponent | ||
| const uint32_t m = b & 0x007FFFFF; // mantissa | ||
| // Compute denormalized shift safely: only valid when 101 < e < 113, | ||
| // which means shift amount (125 - e) is in range [13, 23]. | ||
| // Clamp e to avoid undefined behavior when e > 125 or e < 102. | ||
| const uint32_t safe_e = (e > 101 && e < 113) ? e : 112; | ||
| return (b & 0x80000000) >> 16 | | ||
| static_cast<uint32_t>(e > 112) * ((((e - 112) << 10) & 0x7C00) | m >> 13) | | ||
| static_cast<uint32_t>((e < 113) && (e > 101)) * | ||
| ((((0x007FF000 + m) >> (125 - e)) + 1) >> 1) | | ||
| ((((0x007FF000 + m) >> (125 - safe_e)) + 1) >> 1) | | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, in case when return (b & 0x80000000) >> 16 |
... |
static_cast<uint32_t>((e < 113) && (e > 101)) *
((((0x007FF000 + m) >> (125 - safe_e)) + 1) >> 1) |
// equal to:
return (b & 0x80000000) >> 16 |
... |
static_cast<uint32_t>(e > 101 && e < 113) *
((((0x007FF000 + m) >> (125 - safe_e)) + 1) >> 1) |
// equal to:
return (b & 0x80000000) >> 16 |
... |
static_cast<uint32_t>(false) *
((((0x007FF000 + m) >> (125 - safe_e)) + 1) >> 1) |
//equal to:
return (b & 0x80000000) >> 16 |
... |
0 *
((((0x007FF000 + m) >> (125 - safe_e)) + 1) >> 1) |
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rfsaliev please read this comment above: |
||
| static_cast<uint32_t>(e > 143) * | ||
| 0x7FFF; // sign : normalized : denormalized : saturate | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -855,8 +855,10 @@ template <typename T = telemetry::NoTelemetry> class ThreadImpl { | |||||
| // Wait for the future to become available and rethrow the exception. | ||||||
| wait_for_result(); | ||||||
| get_result(); | ||||||
| throw ANNEXCEPTION("Expected to get an exception from a crashed thread but no " | ||||||
| "exception was thrown!"); | ||||||
| throw ANNEXCEPTION( | ||||||
| "Expected to get an exception from a crashed thread but no " | ||||||
| "exception was thrown!" | ||||||
| ); | ||||||
|
Comment on lines
+858
to
+861
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, use SVS formatting rules. |
||||||
| } | ||||||
|
|
||||||
| // Assign Work | ||||||
|
|
@@ -888,7 +890,7 @@ template <typename T = telemetry::NoTelemetry> class ThreadImpl { | |||||
| // * Catch this exception and wrap its message inside a `ThreadError`. | ||||||
| try { | ||||||
| unsafe_assign(fn); | ||||||
| } catch (const ThreadCrashedError& err) { | ||||||
| } catch (const ThreadCrashedError&) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| try { | ||||||
| unsafe_get_exception(); | ||||||
| } catch (const std::exception& inner_error) { throw ThreadError{inner_error}; } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, this change will negatively affect usability and maintainability for further API major versions.
Instead, a macro can be used here which value defined in
version.hdepending onSVS_RUNTIME_API_VERSION, e.g.:With usage aka: