Skip to content

Defs: util

synco instruction (in a form compatible with sh3eb-elf)

#define synco (()) __asm__ volatile (".word 0x00ab":::"memory")

min(), max() (without double evaluation)

#define min ((a, b)) ({ \
GAUTOTYPE _a = (a); \
GAUTOTYPE _b = (b); \
_a < _b ? _a : _b; \
})

sgn() (without double evaluation)

#define sgn ((s)) ({ \
GAUTOTYPE _s = (s); \
_s < 0 ? -1 : \
_s > 0 ? +1 : \
0; \
})

swap() - exchange two variables of the same type

#define swap ((a, b)) ({ \
GAUTOTYPE _tmp = (a); \
(a) = (b); \
(b) = _tmp; \
})
#define GAUTOTYPE __auto_type
#define max ((a, b)) ({ \
GAUTOTYPE _a = (a); \
GAUTOTYPE _b = (b); \
_a > _b ? _a : _b; \
})