diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2011-08-16 05:00:45 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2011-08-16 05:00:45 +0000 |
commit | 34781781278f0fb2557b7c5dd9c0de54ad2aba09 (patch) | |
tree | 0e1f274269d8ac2f80bb73e532721e843b01705d /LUFA | |
parent | ef4cff29c3cea77d545869ad71bdd043e5475482 (diff) | |
download | lufa-34781781278f0fb2557b7c5dd9c0de54ad2aba09.tar.gz lufa-34781781278f0fb2557b7c5dd9c0de54ad2aba09.tar.bz2 lufa-34781781278f0fb2557b7c5dd9c0de54ad2aba09.zip |
Add shortcuts to SwapEndian_16() and SwapEndian_32() internal functions to improve optimization if called with constant inputs.
Diffstat (limited to 'LUFA')
-rw-r--r-- | LUFA/Common/CompilerSpecific.h | 10 | ||||
-rw-r--r-- | LUFA/Common/Endianness.h | 6 | ||||
-rw-r--r-- | LUFA/ManPages/ChangeLog.txt | 1 |
3 files changed, 12 insertions, 5 deletions
diff --git a/LUFA/Common/CompilerSpecific.h b/LUFA/Common/CompilerSpecific.h index 6b4826aa5..938cbe66c 100644 --- a/LUFA/Common/CompilerSpecific.h +++ b/LUFA/Common/CompilerSpecific.h @@ -70,26 +70,26 @@ * * \param[in, out] StructPtr Pointer to a structure which is to be forced into indirect access mode. */ - #define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr)) + #define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr)) /** Forces GCC to create a memory barrier, ensuring that memory accesses are not reordered past the barrier point. * This can be used before ordering-critical operations, to ensure that the compiler does not re-order the resulting * assembly output in an unexpected manner on sections of code that are ordering-specific. */ - #define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory"); + #define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory"); /** Evaluates to boolean true if the specified value can be determined at compile time to be a constant value * when compiling under GCC. * * \param[in] x Value to check compile time constantness of. * - * \return Boolean true if the given value is known to be a compile time constant. + * \return Boolean true if the given value is known to be a compile time constant, false otherwise. */ - #define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x) + #define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x) #else #define GCC_FORCE_POINTER_ACCESS(StructPtr) #define GCC_MEMORY_BARRIER() - #define GCC_IS_COMPILE_CONST(x) 0 + #define GCC_IS_COMPILE_CONST(x) 0 #endif #endif diff --git a/LUFA/Common/Endianness.h b/LUFA/Common/Endianness.h index 123ad425f..e26314975 100644 --- a/LUFA/Common/Endianness.h +++ b/LUFA/Common/Endianness.h @@ -394,6 +394,9 @@ static inline uint16_t SwapEndian_16(const uint16_t Word) ATTR_WARN_UNUSED_RESULT ATTR_CONST; static inline uint16_t SwapEndian_16(const uint16_t Word) { + if (GCC_IS_COMPILE_CONST(Word)) + return SWAPENDIAN_16(Word); + uint8_t Temp; union @@ -420,6 +423,9 @@ static inline uint32_t SwapEndian_32(const uint32_t DWord) ATTR_WARN_UNUSED_RESULT ATTR_CONST; static inline uint32_t SwapEndian_32(const uint32_t DWord) { + if (GCC_IS_COMPILE_CONST(DWord)) + return SWAPENDIAN_32(DWord); + uint8_t Temp; union diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index e6b279ed4..1bf8dae2a 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -75,6 +75,7 @@ * - Fixed KeyboardHost and KeyboardHostWithParser demos displaying incorrect values when numerical keys were pressed * - Fixed compile errors in the incomplete BluetoothHost demo application (thanks to Timo Lindfors) * - Fixed incorrect Dataflash buffer use in the DataflashManager_WriteBlocks_RAM() function of several demos/projects (thanks to Jeremy Willden) + * - Fixed incorrect logging interval (always 500ms longer than requested) in the TempDataLogger project * * \section Sec_ChangeLog110528 Version 110528 * <b>New:</b> |