[Pixman] [PATCH 1/5] test: Change is_little_endian() into inline function

Siarhei Siamashka siarhei.siamashka at gmail.com
Sun Nov 25 04:08:53 PST 2012


Also dropped redundant volatile keyword because any object
can be accessed via char* pointer without breaking aliasing
rules. The compilers are able to optimize this function to either
constant 0 or 1.
---
 test/utils.c |    8 --------
 test/utils.h |    8 ++++++--
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/test/utils.c b/test/utils.c
index c887a6d..00e74e5 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -237,14 +237,6 @@ compute_crc32_for_image (uint32_t        crc32,
     return crc32;
 }
 
-pixman_bool_t
-is_little_endian (void)
-{
-    volatile uint16_t endian_check_var = 0x1234;
-
-    return (*(volatile uint8_t *)&endian_check_var == 0x34);
-}
-
 /* perform endian conversion of pixel data
  */
 void
diff --git a/test/utils.h b/test/utils.h
index f7ea34c..fa05587 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -69,8 +69,12 @@ compute_crc32_for_image (uint32_t        in_crc32,
 
 /* Returns TRUE if running on a little endian system
  */
-pixman_bool_t
-is_little_endian (void);
+static force_inline pixman_bool_t
+is_little_endian (void)
+{
+    unsigned long endian_check_var = 1;
+    return *(unsigned char *)&endian_check_var == 1;
+}
 
 /* perform endian conversion of pixel data
  */
-- 
1.7.8.6



More information about the Pixman mailing list