-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[DM/MISC] Update MISC API #10993
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
[DM/MISC] Update MISC API #10993
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 |
|---|---|---|
|
|
@@ -23,6 +23,10 @@ | |
|
|
||
| #define RT_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) | ||
|
|
||
| #define RT_DIV_ROUND_DOWN_ULL(ll, d) ({ rt_uint64_t _tmp = (ll); rt_do_div(_tmp, d); _tmp; }) | ||
|
|
||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #define RT_DIV_ROUND_UP_ULL(ll, d) RT_DIV_ROUND_DOWN_ULL((rt_uint64_t)(ll) + (d) - 1, (d)) | ||
|
|
||
| #define RT_DIV_ROUND_CLOSEST(x, divisor) \ | ||
| ({ \ | ||
| typeof(x) __x = x; \ | ||
|
|
@@ -34,6 +38,14 @@ | |
| (((__x) - ((__d) / 2)) / (__d)); \ | ||
| }) | ||
|
|
||
| #define RT_DIV_ROUND_CLOSEST_ULL(x, divisor) \ | ||
| ({ \ | ||
| typeof(divisor) __d = divisor; \ | ||
| rt_uint64_t _tmp = (x) + (__d) / 2; \ | ||
| rt_do_div(_tmp, __d); \ | ||
| _tmp; \ | ||
| }) | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #define __KEY_PLACEHOLDER_1 0, | ||
| #define ____KEY_ENABLED(__ignored, val, ...) val | ||
| #define ___KEY_ENABLED(arg1_or_junk) ____KEY_ENABLED(arg1_or_junk 1, 0) | ||
|
|
@@ -103,14 +115,12 @@ | |
|
|
||
| #define rt_clamp(val, lo, hi) rt_min((typeof(val))rt_max(val, lo), hi) | ||
|
|
||
| #define rt_do_div(n, base) \ | ||
| ({ \ | ||
| rt_uint32_t _base = (base), _rem; \ | ||
| _rem = ((rt_uint64_t)(n)) % _base; \ | ||
| (n) = ((rt_uint64_t)(n)) / _base; \ | ||
| if (_rem > _base / 2) \ | ||
| ++(n); \ | ||
| _rem; \ | ||
| #define rt_do_div(n, base) \ | ||
| ({ \ | ||
| rt_uint32_t _base = (base); \ | ||
| rt_uint32_t _rem = (rt_uint64_t)(n) % _base; \ | ||
| (n) = (rt_uint64_t)(n) / _base; \ | ||
| _rem; \ | ||
| }) | ||
|
|
||
| #define rt_abs(x) \ | ||
|
|
@@ -129,6 +139,18 @@ | |
| ret; \ | ||
| }) | ||
|
|
||
| #define rt_roundup(x, y) \ | ||
| ({ \ | ||
| typeof(y) __y = y; \ | ||
| (((x) + (__y - 1)) / __y) * __y; \ | ||
| }) | ||
|
Comment on lines
+142
to
+146
|
||
|
|
||
| #define rt_rounddown(x, y) \ | ||
| ({ \ | ||
| typeof(x) __x = (x); \ | ||
| __x - (__x % (y)); \ | ||
| }) | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #ifndef rt_ilog2 | ||
| rt_inline int rt_ilog2(rt_ubase_t v) | ||
| { | ||
|
|
@@ -143,4 +165,37 @@ rt_inline int rt_ilog2(rt_ubase_t v) | |
| } | ||
| #endif /* !rt_ilog2 */ | ||
|
|
||
| #ifndef rt_bcd2bin | ||
| rt_inline rt_ubase_t rt_bcd2bin(rt_uint8_t val) | ||
| { | ||
| return (val & 0x0f) + (val >> 4) * 10; | ||
| } | ||
| #endif /* !rt_bcd2bin */ | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #ifndef rt_bin2bcd | ||
| rt_inline rt_uint8_t rt_bin2bcd(rt_ubase_t val) | ||
| { | ||
| return ((val / 10) << 4) + val % 10; | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| #endif /* !rt_bin2bcd */ | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #ifndef rt_div_u64_rem | ||
| rt_inline rt_uint64_t rt_div_u64_rem(rt_uint64_t dividend, rt_uint32_t divisor, | ||
| rt_uint32_t *remainder) | ||
| { | ||
| *remainder = dividend % divisor; | ||
|
|
||
| return dividend / divisor; | ||
| } | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #endif /* !rt_div_u64_rem */ | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #ifndef rt_div_u64 | ||
| rt_inline rt_uint64_t rt_div_u64(rt_uint64_t dividend, rt_uint32_t divisor) | ||
| { | ||
| rt_uint32_t remainder; | ||
|
|
||
| return rt_div_u64_rem(dividend, divisor, &remainder); | ||
| } | ||
| #endif /* !rt_div_u64 */ | ||
GuEe-GUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #endif /* __MISC_H__ */ | ||
Uh oh!
There was an error while loading. Please reload this page.