Add ROUND_UP and ROUND_DOWN

This commit is contained in:
Alex 2023-05-10 21:49:28 +03:00
parent fa8122659a
commit 79c6a5096d
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 28 additions and 1 deletions

View File

@ -102,6 +102,27 @@ __constructor void TestMacros()
pgs++;
}
}
{
debug("Testing ROUND_UP and ROUND_DOWN");
int x = 0x101;
int y = 0x100;
int result;
result = ROUND_UP(x, y);
if (result != 0x200)
{
error("ERROR: ROUND_UP failed: %d != 0x200\n", result);
inf_loop;
}
result = ROUND_DOWN(x, y);
if (result != 0x100)
{
error("ERROR: ROUND_DOWN failed: %d != 0x100\n", result);
inf_loop;
}
}
}
#endif // DEBUG

View File

@ -81,6 +81,9 @@ typedef __builtin_va_list va_list;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define ROUND_UP(x, y) (((x) + (y)-1) & ~((y)-1))
#define ROUND_DOWN(x, y) ((x) & ~((y)-1))
#define VPOKE(type, address) (*((volatile type *)(address)))
#define POKE(type, address) (*((type *)(address)))
@ -342,10 +345,13 @@ typedef uint48_t uint_fast48_t;
#define __min_vector_width(x) __attribute__((min_vector_width(x)))
// sanitizer
#define __no_sanitize(x) __attribute__((no_sanitize(x)))
#define __no_sanitize_address __attribute__((no_sanitize_address))
#define __no_sanitize_undefined __attribute__((no_sanitize_undefined))
/** @brief The no_address_safety_analysis is a deprecated alias of the no_sanitize_address attribute, new code should use no_sanitize_address. */
#define __no_address_safety_analysis __attribute__((no_address_safety_analysis))
#define __no_sanitize_thread __attribute__((no_sanitize_thread))
#define __no_sanitize_undefined __attribute__((no_sanitize_undefined))
#define __no_sanitize_coverage __attribute__((no_sanitize_coverage))
#define __synchronize __sync_synchronize()
#define __sync __synchronize