public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] ARM: Use do_div() instead of division for "long long".
Date: Tue,  9 Sep 2008 02:08:31 +0200	[thread overview]
Message-ID: <1220918912-15691-1-git-send-email-wd@denx.de> (raw)
In-Reply-To: <1220914771-14645-1-git-send-email-wd@denx.de>

From: Sergei Poselenov <sposelenov@emcraft.com>

Signed-off-by: Sergei Poselenov <sposelenov@emcraft.com>
Signed-off-by: Wolfgang Denk <wd@denx.de>
---

With some (more recent) compiler versions there are problems because
of the use of "long long" divisions in the U-Boot code. For ARM, this
requires the __udivdi3 GCC library function, which currently is not
present in lib_arm. This function was present in older 2.6 kernels,
but at some point it was removed from here, with suggestion to use
do_div() instead. In U-boot, the do_div() function is available, too,
so this patch generally does the replacement of the "long long"
divisions to do_div() to avoid the aforementions issues.

 board/integratorcp/integratorcp.c |    7 ++++++-
 board/trab/tsc2000.c              |   10 ++++++----
 cpu/arm1176/s3c64xx/interrupts.c  |    5 ++++-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/board/integratorcp/integratorcp.c b/board/integratorcp/integratorcp.c
index d6d6e13..220513f 100644
--- a/board/integratorcp/integratorcp.c
+++ b/board/integratorcp/integratorcp.c
@@ -34,6 +34,7 @@
  */
 
 #include <common.h>
+#include <div64.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -244,7 +245,11 @@ ulong get_timer_masked (void)
 		total_count += lastdec - now;
 	}
 	lastdec	  = now;
-	timestamp = (ulong)(total_count/div_timer);
+
+	/* Reuse "now" */
+	now = total_count;
+	do_div(now, div_timer);
+	timestamp = now;
 
 	return timestamp;
 }
diff --git a/board/trab/tsc2000.c b/board/trab/tsc2000.c
index 382a85b..f13a5a9 100644
--- a/board/trab/tsc2000.c
+++ b/board/trab/tsc2000.c
@@ -27,6 +27,7 @@
 
 #include <common.h>
 #include <s3c2400.h>
+#include <div64.h>
 #include "tsc2000.h"
 
 #include "Pt1000_temp_data.h"
@@ -332,6 +333,7 @@ void tsc2000_reg_init (void)
 int tsc2000_interpolate(long value, long data[][2], long *result)
 {
 	int i;
+	unsigned long long val;
 
 	/* the data is sorted and the first element is upper
 	 * limit so we can easily check for out-of-band values
@@ -347,10 +349,10 @@ int tsc2000_interpolate(long value, long data[][2], long *result)
 	   result in 'long long'.
 	*/
 
-	*result = data[i-1][1] +
-		((unsigned long long)(data[i][1] - data[i-1][1])
-		 * (unsigned long long)(value - data[i-1][0]))
-		/ (data[i][0] - data[i-1][0]);
+	val = ((unsigned long long)(data[i][1] - data[i-1][1])
+		   * (unsigned long long)(value - data[i-1][0]));
+	do_div(val, (data[i][0] - data[i-1][0]));
+	*result = data[i-1][1] + val;
 
 	return 0;
 }
diff --git a/cpu/arm1176/s3c64xx/interrupts.c b/cpu/arm1176/s3c64xx/interrupts.c
index 8356ae4..e34369f 100644
--- a/cpu/arm1176/s3c64xx/interrupts.c
+++ b/cpu/arm1176/s3c64xx/interrupts.c
@@ -41,6 +41,7 @@
 #include <common.h>
 #include <asm/proc-armv/ptrace.h>
 #include <s3c6400.h>
+#include <div64.h>
 
 static ulong timer_load_val;
 
@@ -148,7 +149,9 @@ void reset_timer(void)
 
 ulong get_timer_masked(void)
 {
-	return get_ticks() / (timer_load_val / (100 * CFG_HZ));
+	unsigned long long res = get_ticks();
+	do_div (res, (timer_load_val / (100 * CFG_HZ)));
+	return res;
 }
 
 ulong get_timer(ulong base)
-- 
1.5.4.2

  reply	other threads:[~2008-09-09  0:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-08 22:59 [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long" Wolfgang Denk
2008-09-09  0:08 ` Wolfgang Denk [this message]
2008-09-09  0:08   ` [U-Boot] [PATCH] ARM: fix warning: target CPU does not support interworking Wolfgang Denk
2008-09-09 20:55   ` [U-Boot] [PATCH v2] ARM: Use do_div() instead of division for "long long" Guennadi Liakhovetski
2008-09-09 21:07     ` Wolfgang Denk
2008-09-11 22:24   ` Haavard Skinnemoen

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=1220918912-15691-1-git-send-email-wd@denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /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