mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
(SDK) Document retro_endianness.h/retro_miscellaneous.h
This commit is contained in:
parent
2779298371
commit
4e17e365fa
@ -38,6 +38,14 @@
|
||||
(((uint32_t)(x) & 0xff000000) >> 24) \
|
||||
))
|
||||
|
||||
/**
|
||||
* is_little_endian:
|
||||
*
|
||||
* Checks if the system is little endian or big-endian.
|
||||
*
|
||||
* Returns: greater than 0 if little-endian,
|
||||
* otherwise big-endian.
|
||||
**/
|
||||
static INLINE uint8_t is_little_endian(void)
|
||||
{
|
||||
union
|
||||
@ -50,6 +58,15 @@ static INLINE uint8_t is_little_endian(void)
|
||||
return u.y[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* swap_if_big32:
|
||||
* @val : unsigned 32-bit value
|
||||
*
|
||||
* Byteswap unsigned 32-bit value if system is big-endian.
|
||||
*
|
||||
* Returns: Byteswapped value in case system is big-endian,
|
||||
* otherwise returns same value.
|
||||
**/
|
||||
static INLINE uint32_t swap_if_big32(uint32_t val)
|
||||
{
|
||||
if (is_little_endian())
|
||||
@ -58,6 +75,15 @@ static INLINE uint32_t swap_if_big32(uint32_t val)
|
||||
((val << 8) & 0xFF0000) | (val << 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* swap_if_little32:
|
||||
* @val : unsigned 32-bit value
|
||||
*
|
||||
* Byteswap unsigned 32-bit value if system is little-endian.
|
||||
*
|
||||
* Returns: Byteswapped value in case system is little-endian,
|
||||
* otherwise returns same value.
|
||||
**/
|
||||
static INLINE uint32_t swap_if_little32(uint32_t val)
|
||||
{
|
||||
if (is_little_endian())
|
||||
@ -66,6 +92,15 @@ static INLINE uint32_t swap_if_little32(uint32_t val)
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* swap_if_big16:
|
||||
* @val : unsigned 16-bit value
|
||||
*
|
||||
* Byteswap unsigned 16-bit value if system is big-endian.
|
||||
*
|
||||
* Returns: Byteswapped value in case system is big-endian,
|
||||
* otherwise returns same value.
|
||||
**/
|
||||
static INLINE uint16_t swap_if_big16(uint16_t val)
|
||||
{
|
||||
if (is_little_endian())
|
||||
@ -73,6 +108,15 @@ static INLINE uint16_t swap_if_big16(uint16_t val)
|
||||
return (val >> 8) | (val << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* swap_if_little16:
|
||||
* @val : unsigned 16-bit value
|
||||
*
|
||||
* Byteswap unsigned 16-bit value if system is little-endian.
|
||||
*
|
||||
* Returns: Byteswapped value in case system is little-endian,
|
||||
* otherwise returns same value.
|
||||
**/
|
||||
static INLINE uint16_t swap_if_little16(uint16_t val)
|
||||
{
|
||||
if (is_little_endian())
|
||||
@ -80,11 +124,27 @@ static INLINE uint16_t swap_if_little16(uint16_t val)
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* store32be:
|
||||
* @addr : pointer to unsigned 32-bit buffer
|
||||
* @data : unsigned 32-bit value to write
|
||||
*
|
||||
* Write data to address. Endian-safe. Byteswaps the data
|
||||
* first if necessary before storing it.
|
||||
**/
|
||||
static INLINE void store32be(uint32_t *addr, uint32_t data)
|
||||
{
|
||||
*addr = is_little_endian() ? SWAP32(data) : data;
|
||||
}
|
||||
|
||||
/**
|
||||
* load32be:
|
||||
* @addr : pointer to unsigned 32-bit buffer
|
||||
*
|
||||
* Load value from address. Endian-safe.
|
||||
*
|
||||
* Returns: value from address, byte-swapped if necessary.
|
||||
**/
|
||||
static INLINE uint32_t load32be(const uint32_t *addr)
|
||||
{
|
||||
return is_little_endian() ? SWAP32(*addr) : *addr;
|
||||
|
@ -51,12 +51,6 @@
|
||||
#include <retro_endianness.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Some platforms do not set this value.
|
||||
* Just assume a value. It's usually 4KiB.
|
||||
* Platforms with a known value (like Win32)
|
||||
* set this value explicitly in platform specific headers.
|
||||
*/
|
||||
|
||||
#ifndef PATH_MAX_LENGTH
|
||||
#define PATH_MAX_LENGTH 4096
|
||||
#endif
|
||||
@ -81,6 +75,12 @@
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#define RARCH_SCALE_BASE 256
|
||||
|
||||
/**
|
||||
* rarch_sleep:
|
||||
* @msec : amount in milliseconds to sleep
|
||||
*
|
||||
* Sleeps for a specified amount of milliseconds (@msec).
|
||||
**/
|
||||
static INLINE void rarch_sleep(unsigned msec)
|
||||
{
|
||||
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
|
||||
@ -101,6 +101,14 @@ static INLINE void rarch_sleep(unsigned msec)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* next_pow2:
|
||||
* @v : initial value
|
||||
*
|
||||
* Increase initial value to next power of 2 value.
|
||||
*
|
||||
* Returns: next power of 2 value (derived from @v).
|
||||
**/
|
||||
static INLINE uint32_t next_pow2(uint32_t v)
|
||||
{
|
||||
v--;
|
||||
@ -113,6 +121,14 @@ static INLINE uint32_t next_pow2(uint32_t v)
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* prev_pow2:
|
||||
* @v : initial value
|
||||
*
|
||||
* Increase initial value to previous power of 2 value.
|
||||
*
|
||||
* Returns: previous power of 2 value (derived from @v).
|
||||
**/
|
||||
static INLINE uint32_t prev_pow2(uint32_t v)
|
||||
{
|
||||
v |= v >> 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user