AmigaPorts / AmigaPorts/ACE

Should enums be downsized?

未关闭
#149 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement help wanted question
主要语言
C
星标
223
派生
38
平均合并
1 天 5 小时
30 天内合并 PR
6

描述

Currently, most Amiga compilers represent enums as 32-bit ints. GCC compilers have `-fshort-enums` switch, but it comes with a tradeoff:

> Allocate to an enum type only as many bytes as it needs for the declared range of possible values. Specifically, the enum type is equivalent to the smallest integer type that has enough room.
>
> **Warning: the -fshort-enums switch causes GCC to generate code that is not binary compatible with code generated without that switch. Use it to conform to a non-default application binary interface.**

also, `-fshort-enums` is placed on the most not recommended build flags on one of the blog posts I've found: https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags#-fshort-enum

some things to consider:

- binary compatibility doesn't affect us - this will obviously break when linking with stuff compiled without that switch, but all ACE-based games don't have this option - usually they come with all required sources and no binary blobs,
- extra ops to mask out the remaining bytes of the register doesn't affect us, since m68k has .b, .w and .l op variants
- structs changing sizes doesn't affect us because ACE don't even tries to maintain compatibility
I'm still kinda torn about this, but I think having small enums is the way to go - should save some ram space in structs

Still, I have no benchmarks to prove that it doesn't truly affect the performance. One thing to consider is that 68000 has 16-bit data bus and it's always slower to transfer 32-bit data between memory and regs.

Needs more research and benchmarks!

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。