Commit 19e20197 authored by Richard Gobeille's avatar Richard Gobeille

Duke3d: optimize VM_GetStruct()

I've heard several times that functions with a single exit point are faster, but profiling showed that removing the intermediate variable and returning directly from the switch wins here.
parent d25fc0b5
......@@ -164,44 +164,38 @@ void Gv_ResetSystemDefaults(void);
void Gv_Init(void);
void Gv_FinalizeWeaponDefaults(void);
#define LABEL_TYPES (LABEL_CHAR|LABEL_SHORT|LABEL_INT|LABEL_UNSIGNED)
static inline int __fastcall VM_GetStruct(uint32_t const flags, intptr_t * const addr)
{
Bassert(flags & (LABEL_CHAR|LABEL_SHORT|LABEL_INT));
int returnValue = 0;
switch (flags & (LABEL_CHAR|LABEL_SHORT|LABEL_INT|LABEL_UNSIGNED))
switch (flags & LABEL_TYPES)
{
case LABEL_CHAR: returnValue = *(int8_t *)addr; break;
case LABEL_CHAR|LABEL_UNSIGNED: returnValue = *(uint8_t *)addr; break;
case LABEL_SHORT: returnValue = *(int16_t *)addr; break;
case LABEL_SHORT|LABEL_UNSIGNED: returnValue = *(uint16_t *)addr; break;
case LABEL_INT: returnValue = *(int32_t *)addr; break;
case LABEL_INT|LABEL_UNSIGNED: returnValue = *(uint32_t *)addr; break;
case LABEL_CHAR: return *(int8_t *)addr;
case LABEL_CHAR|LABEL_UNSIGNED: return *(uint8_t *)addr;
case LABEL_SHORT: return *(int16_t *)addr;
case LABEL_SHORT|LABEL_UNSIGNED: return *(uint16_t *)addr;
case LABEL_INT: return *(int32_t *)addr;
case LABEL_INT|LABEL_UNSIGNED: return *(uint32_t *)addr;
default: EDUKE32_UNREACHABLE_SECTION(break);
}
return returnValue;
}
static FORCE_INLINE void __fastcall VM_SetStruct(uint32_t const flags, intptr_t * const addr, int32_t newValue)
{
Bassert(flags & (LABEL_CHAR|LABEL_SHORT|LABEL_INT));
switch (flags & (LABEL_CHAR|LABEL_SHORT|LABEL_INT|LABEL_UNSIGNED))
switch (flags & LABEL_TYPES)
{
case LABEL_CHAR: *(int8_t *)addr = newValue; break;
case LABEL_CHAR|LABEL_UNSIGNED: *(uint8_t *)addr = newValue; break;
case LABEL_SHORT: *(int16_t *)addr = newValue; break;
case LABEL_CHAR: *(int8_t *)addr = newValue; break;
case LABEL_CHAR|LABEL_UNSIGNED: *(uint8_t *)addr = newValue; break;
case LABEL_SHORT: *(int16_t *)addr = newValue; break;
case LABEL_SHORT|LABEL_UNSIGNED: *(uint16_t *)addr = newValue; break;
case LABEL_INT: *(int32_t *)addr = newValue; break;
case LABEL_INT: *(int32_t *)addr = newValue; break;
case LABEL_INT|LABEL_UNSIGNED: *(uint32_t *)addr = newValue; break;
default: EDUKE32_UNREACHABLE_SECTION(break);
}
}
#undef LABEL_TYPES
#define VM_GAMEVAR_OPERATOR(func, operator) \
static FORCE_INLINE ATTRIBUTE((flatten)) void __fastcall func(int const id, int32_t const operand) \
{ \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment