summaryrefslogtreecommitdiffstats
path: root/cpukit/score/inline/rtems/score/address.inl
diff options
context:
space:
mode:
authorGedare Bloom <gedare@rtems.org>2013-02-12 10:20:51 -0500
committerGedare Bloom <gedare@rtems.org>2013-02-12 11:02:01 -0500
commita24bd4696a8a43ffe0841b9df845e89da8d82ce0 (patch)
tree16dc70451d06fa3aa5c8d69baf330015bc550fdd /cpukit/score/inline/rtems/score/address.inl
parentsptests/spfatal11: Update due to API changes (diff)
downloadrtems-a24bd4696a8a43ffe0841b9df845e89da8d82ce0.tar.bz2
score: New routines to align addresses up or down.
Diffstat (limited to '')
-rw-r--r--cpukit/score/inline/rtems/score/address.inl44
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 17bcd0a016..590a80f4a7 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