[rtems commit] score: New routines to align addresses up or down.
Gedare Bloom
gedare at rtems.org
Tue Feb 12 15:57:13 UTC 2013
Module: rtems
Branch: master
Commit: a24bd4696a8a43ffe0841b9df845e89da8d82ce0
Changeset: http://git.rtems.org/rtems/commit/?id=a24bd4696a8a43ffe0841b9df845e89da8d82ce0
Author: Gedare Bloom <gedare at rtems.org>
Date: Tue Feb 12 10:20:51 2013 -0500
score: New routines to align addresses up or down.
---
cpukit/score/inline/rtems/score/address.inl | 44 +++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/cpukit/score/inline/rtems/score/address.inl b/cpukit/score/inline/rtems/score/address.inl
index 17bcd0a..590a80f 100644
--- a/cpukit/score/inline/rtems/score/address.inl
+++ b/cpukit/score/inline/rtems/score/address.inl
@@ -142,6 +142,50 @@ RTEMS_INLINE_ROUTINE bool _Addresses_Is_in_range (
return (address >= base && address <= limit);
}
+/**
+ * @brief Align address to nearest multiple of alignment, rounding up.
+ *
+ * This function returns the given address aligned to the given alignment.
+ * If the address already is aligned, or if alignment is 0, the address is
+ * returned as is. The returned address is greater than or equal to the
+ * given address.
+ *
+ * @param[in] address is the address to align.
+ * @param[in] alignment is the boundary for alignment and must be a power of 2
+ *
+ * @return Returns the aligned address.
+ */
+RTEMS_INLINE_ROUTINE void *_Addresses_Align_up(
+ void *address,
+ size_t alignment
+)
+{
+ uintptr_t mask = alignment - (uintptr_t)1;
+ return (void*)(((uintptr_t)address + mask) & ~mask);
+}
+
+/**
+ * @brief Align address to nearest multiple of alignment, truncating.
+ *
+ * This function returns the given address aligned to the given alignment.
+ * If the address already is aligned, or if alignment is 0, the address is
+ * returned as is. The returned address is less than or equal to the
+ * given address.
+ *
+ * @param[in] address is the address to align.
+ * @param[in] alignment is the boundary for alignment and must be a power of 2.
+ *
+ * @return Returns the aligned address.
+ */
+RTEMS_INLINE_ROUTINE void *_Addresses_Align_down(
+ void *address,
+ size_t alignment
+)
+{
+ uintptr_t mask = alignment - (uintptr_t)1;
+ return (void*)((uintptr_t)address & ~mask);
+}
+
/** @} */
#endif
More information about the vc
mailing list