John Liu
John Liu

Reputation: 63

Why do integers process faster than bytes on NDS?

i've noticed that my nds application works a little faster when I replace all the instances of bytes with integers. all the examples online put u8/u16 instances whenever possible. is there a specific reason as to why this is the case?

Upvotes: 6

Views: 821

Answers (2)

Daniel Li
Daniel Li

Reputation: 15379

The main processor the Nintendo DS utilizes is ARM9, a 32-bit processor.

Reference: http://en.wikipedia.org/wiki/ARM9

                    

Typically, CPU will conduct operations in word sizes, in this case, 32-bits. Depending on your operations, having to convert the bytes up to integers or vice-versa may be causing additional strain on the processor. This conversion and the potential lack of instructions for values other than 32-bit integers may be causing the lack of speed.

Upvotes: 16

lvella
lvella

Reputation: 13423

Complementary to what Daniel Li said, memory access on ARM platforms must be word aligned, i.e. memory fetches must be multiple of 32 bits. Fetching a byte variable from memory implies in fetching the whole word containing the relevant byte, and performing the needed bit-wise operations to fit it in the least significant bits of the processor register.

Theses extra instructions are automatically emitted by the compiler, given it knows the actual alignment of your variables.

Upvotes: 7

Related Questions