Jump to content
Eternal Lands Official Forums
0ctane

Endian swapping code cleanup suggestion

Recommended Posts

Going along with ttlanhil's effort to clean code, I would like to make the following suggestions. First, the EL_BIG_ENDIAN macro "#define SwapLEFloat(X) SwapFloat(X)" is hardly used. For example, even though we have this macro, 3d_objects.c at line 892 uses a #ifdef EL_BIG_ENDIAN block around SwapFloat calls. This is silliness, and it happens in many places. I propose that all SwapFloats actually use the macro, and that these #ifdef EL_BIG_ENDIAN blocks be removed. Now someone could suggest that we keep the #ifdef and lose the macro, but my suggestion works much better for OS X programming.

 

My second suggestion involves using native byte-swap routines. I would like to replace all SDL_SwapLE32 and SDL_SwapLE16 calls with SwapLE32 and SwapLE16. Then, in global.h, create new macros as such:

#ifdef EL_BIG_ENDIAN
#define SwapLEFloat(X) SwapFloat(X)
#define SwapLE32(X) SDL_SwapLE32(X)
#define SwapLE16(X) SDL_SwapLE16(X)
#else
#define SwapLEFloat(X) (X)
#define SwapLE32(X) (X)
#define SwapLE16(X) (X)
#endif

For anyone (besides Mac OS X users) that are using big_endian systems, you would get the current SDL_SwapLE32/16 function. For all little_endian folks, the macro would just remove any swapping code.

 

Why do I want to do this? In the #ifdef OSX, I can call OS specific/optimized byteswap routines rather than ones from SDL. More importantly, for the OS X client, I now need to support PowerPC and i386 Macs. By creating these macros, I can build everything on one system (and therefore not delay release schedules for everyone else).

 

My big question for little_endian folks is, Will these macro changes affect you? I do not know if there is any hit in performance by redoing the macros.

Share this post


Link to post
Share on other sites

Edit: I missed the fact that you don't want to use the SDL macros.

But still, can't we get rid of EL_BIG_ENDIAN and use the SDL_BYTEORDER macro instead? Or at least use SDL_BYTEORDER to determine if EL_BIG_ENDIAN should be defined or not. (SDL_BYTEORDER can be either SDL_BIG_ENDIAN or SDL_LIL_ENDIAN)

Edited by Vegar

Share this post


Link to post
Share on other sites
Edit: I missed the fact that you don't want to use the SDL macros.

But still, can't we get rid of EL_BIG_ENDIAN and use the SDL_BYTEORDER macro instead?

Yeah, no SDL_Swap functions for my OS X build is what I want. If it works, I see no problem with checking SDL_BYTEORDER. However, I seem to remember an old argument for keeping around EL_BIG_ENDIAN. Hmmm... We need more core programmers to weigh-in on this issue.

Share this post


Link to post
Share on other sites

As a (theoretical) core programmer, that knows very little about the endian issues (or more over, solutions), and one that hasn't even been around for 3 months, I really really can't comment.

 

Sorry guys. I'll be back sometime soon. Work is getting slower, but Uni is picking up. ><

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×