Improve endian.h and stream.h
|Reported by:||SF/nolange||Owned by:||fingolfin|
I improved endian.h and stream.h in various ways, resulting in a notable size-reduction for the scummvm executeable.
x86 architectures likely have the biggest improvment, due having a bswap instruction and good support under gcc (other archtectures just have a generic software-fallback for the byteswap-builtin instead using optimized versions).
On another note, some code assumes that Stream::readByte does return 0 in case of an error, even if the comments are very clear that shouldnt be expected. (xmplparser class for example). Thus the patch still emulates that behaviour.
*) dont use additions if an or is sufficient - this eases up optimization work for the compiler (SWAP_BYTES_16 is now 1 instruction instead of 5 on x86)
*) use byteswap-builtin if compiler supports it. (SWAP_BYTES_32 is now 1 instruction instead of 13 on x86).
*) use compiler-support for unaligned loads, this should reduce instruction count on CPUs which have special support for this (MIPS)
*) use funtions from endian.h where possible
*) avoid multiple virtual-calls in the read/write stream funtions, compilers cant inline them
*) made _bigEndian constant and private in MemoryReadStreamEndian and SeekableSubReadStreamEndian
*) fixed an access to MemoryReadStreamEndian::_bigEndian
Ticket imported from: #2838562. Ticket imported from: patches/1175.