mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/5] include: Add round_up/round_down macros from kernel
Date: Tue, 15 Jul 2014 15:49:30 +0200	[thread overview]
Message-ID: <1405432173-22448-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1405432173-22448-1-git-send-email-s.hauer@pengutronix.de>

Yes, we already have roundup/rounddown. Unlike these macros
round_up/round_down are optimized to (and only work with)
power-of-2 arguments. It's a poor name, but kernel code needs
it, so add it to barebox aswell.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/linux/kernel.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4322f01..b90d8f7 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -5,6 +5,19 @@
 #include <linux/barebox-wrapper.h>
 
 /*
+ * This looks more complex than it should be. But we need to
+ * get the type for the ~ right in round_down (it needs to be
+ * as wide as the result!), and we want to evaluate the macro
+ * arguments just once each.
+ *
+ * NOTE these functions only round to power-of-2 arguments. Use
+ * roundup/rounddown for non power-of-2-arguments.
+ */
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
+/*
  * min()/max()/clamp() macros that also do
  * strict type-checking.. See the
  * "unnecessary" pointer comparison.
-- 
2.0.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-07-15 13:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-15 13:49 Update/include some functions from the Kernel Sascha Hauer
2014-07-15 13:49 ` [PATCH 1/5] include: Add DECLARE_BITMAP from kernel Sascha Hauer
2014-07-15 13:49 ` Sascha Hauer [this message]
2014-07-15 13:49 ` [PATCH 3/5] include: Add foreign endianess adding functions " Sascha Hauer
2014-07-15 13:49 ` [PATCH 4/5] lib: Add bitmap " Sascha Hauer
2014-07-15 13:49 ` [PATCH 5/5] include: update bitop " Sascha Hauer
2014-07-15 18:42 ` Update/include some functions from the Kernel Antony Pavlov
2014-07-16  8:27   ` Sascha Hauer
2014-07-16 23:15 ` Sebastian Hesselbarth
2014-07-17  5:33   ` Sascha Hauer
2014-07-17  9:29     ` Sebastian Hesselbarth
2014-07-17 12:41       ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1405432173-22448-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox