Use __builtin_bswap* for GUINT*_SWAP_LE_BE if building with GCC

https://bugzilla.gnome.org/show_bug.cgi?id=531901
This commit is contained in:
Sebastian Dröge
2012-03-17 23:28:48 -04:00
committed by Matthias Clasen
parent e2b47ae9e0
commit 57878d6042
2 changed files with 54 additions and 8 deletions

View File

@@ -207,6 +207,29 @@ test_bits (void)
}
}
static void
test_swap (void)
{
guint16 a16, b16;
guint32 a32, b32;
guint64 a64, b64;
a16 = 0xaabb;
b16 = 0xbbaa;
g_assert_cmpint (GUINT16_SWAP_LE_BE (a16), ==, b16);
a32 = 0xaaaabbbb;
b32 = 0xbbbbaaaa;
g_assert_cmpint (GUINT32_SWAP_LE_BE (a32), ==, b32);
a64 = 0xaaaaaaaabbbbbbbb;
b64 = 0xbbbbbbbbaaaaaaaa;
g_assert_cmpint (GUINT64_SWAP_LE_BE (a64), ==, b64);
}
static void
test_find_program (void)
{
@@ -319,6 +342,7 @@ main (int argc,
g_test_add_func ("/utils/appname", test_appname);
g_test_add_func ("/utils/tmpdir", test_tmpdir);
g_test_add_func ("/utils/bits", test_bits);
g_test_add_func ("/utils/swap", test_swap);
g_test_add_func ("/utils/find-program", test_find_program);
g_test_add_func ("/utils/debug", test_debug);
g_test_add_func ("/utils/codeset", test_codeset);