… | |
… | |
393 | #endif |
393 | #endif |
394 | |
394 | |
395 | /* try to tell the compiler that some condition is definitely true */ |
395 | /* try to tell the compiler that some condition is definitely true */ |
396 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
396 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
397 | |
397 | |
398 | ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; |
398 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
399 | ecb_function_ unsigned char |
399 | ecb_inline unsigned char |
400 | ecb_byteorder_helper (void) |
400 | ecb_byteorder_helper (void) |
401 | { |
401 | { |
402 | const uint32_t u = 0x11223344; |
402 | const uint32_t u = 0x11223344; |
403 | return *(unsigned char *)&u; |
403 | return *(unsigned char *)&u; |
404 | } |
404 | } |
405 | |
405 | |
406 | ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; |
406 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
407 | ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
407 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
408 | ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; |
408 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
409 | ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
409 | ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
410 | |
410 | |
411 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
411 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
412 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
412 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
413 | #else |
413 | #else |
414 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
414 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |