GNOME Bugzilla – Bug 101318
New asm for endian swap functions
Last modified: 2004-12-22 21:47:04 UTC
I've reorged the asm stuff for the endian swap routines. I got rid of the obsolete #ifdef for G_HAVE_GINT64, synced up the i386 implementations with glibc 2.3's stuff, brought in ia64 implementations from glibc, and wrote my own x86_64 implementations. I've tested these with glib's testglib and type-test, and with gimp. It'd be nice if it could go into for 2.2.
Created attachment 13013 [details] [review] patch implementing the above
+# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86_64 (val)) +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86_64 (val)) Was wondering why there wasn't a GUINT16_SWAP_LE_BE_X86_64; presumably a straightforward adaption of the ia32 version should work, and be a bit faster. (Of course even the C fallbacks should be running way faster than memory bandwidth...)
After discussing this some with Manish on IRC, it appears that given a sufficiently good definition of a 16-bit endian swap, GCC will generate the right code (use a roll) from the C code for both x86 and x86_64. But the current macro isn't good enough. #define GUINT16_SWAP_LE_BE_CONSTANT(val) \ ((guint16)((guint16)(val) >> 8) | \ (guint16)((guint16)(val) << 8)) Seems to work better.
Wed Dec 18 16:19:08 2002 Manish Singh <yosh@gimp.org> * glib/gtypes.h: new endian asm for ia64 and x86_64, general reorg and clean up. New implementation of GUINT16_SWAP_LE_BE_CONSTANT() that should optimize better. (#101318)