Skip to content
Snippets Groups Projects
Commit 54729158 authored by Eric Müller's avatar Eric Müller :mountain_bicyclist: Committed by Yannik Stradmann
Browse files

Fix sleep_cycles for small inputs…

Change-Id: I44f6cdd50f3d13b220294a631f96e897837c0211
...@@ -12,6 +12,12 @@ namespace libnux::vx { ...@@ -12,6 +12,12 @@ namespace libnux::vx {
constexpr static uint32_t default_ppu_cycles_per_us = 250; constexpr static uint32_t default_ppu_cycles_per_us = 250;
/*
* Idle for (approx.) `cycles` cycles.
*
* The current implementation uses a narrowing conversion of the user-supplied parameter to
* 'int32_t'. Values that don't fit in this data type will wrap.
*/
void sleep_cycles(uint32_t cycles) ATTRIB_LINK_TO_INTERNAL; void sleep_cycles(uint32_t cycles) ATTRIB_LINK_TO_INTERNAL;
/* /*
......
...@@ -3,15 +3,13 @@ ...@@ -3,15 +3,13 @@
namespace libnux::vx { namespace libnux::vx {
/*
Idle for (approx.) `cycles` cycles.
*/
void __attribute__((optimize("O2"))) sleep_cycles(uint32_t cycles) void __attribute__((optimize("O2"))) sleep_cycles(uint32_t cycles)
{ {
static const uint8_t offset = 9; static const int8_t offset = 9;
time_base_t start; time_base_t start;
start = get_time_base(); start = get_time_base();
while ((uint32_t)(get_time_base() - start) <= (cycles - offset)); while ((int32_t)(get_time_base() - start) <= (static_cast<int32_t>(cycles) - offset))
;
} }
time_base_t now() time_base_t now()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment