Commit 5320bc75 authored by Jose Jimenez's avatar Jose Jimenez

fdelay-output.c & tools-util.c: Changed to a better division function

Signed-off-by: 's avatarJose Jimenez <ppjm@correo.ugr.es>
parent fb1cb46f
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <fine-delay.h> #include <fine-delay.h>
#include "hw/fd_main_regs.h" #include "hw/fd_main_regs.h"
#include "hw/fd_channel_regs.h" #include "hw/fd_channel_regs.h"
#include <linux/math64.h>
#define MAX_EXT_ATTR 32 #define MAX_EXT_ATTR 32
#define NSEC_PER_SEC 1000*1000*1000 #define NSEC_PER_SEC 1000*1000*1000
...@@ -56,7 +57,7 @@ static void fdelay_add_ps(struct fdelay_time *p, uint64_t ps) ...@@ -56,7 +57,7 @@ static void fdelay_add_ps(struct fdelay_time *p, uint64_t ps)
/* FIXME: this silently fails with ps > 10^12 = 1s */ /* FIXME: this silently fails with ps > 10^12 = 1s */
tmp = div64_u64_rem(ps, 8000LLU, &ps); tmp = div64_u64_rem(ps, 8000LLU, &ps);
coarse = (uint32_t) tmp; coarse = (uint32_t) tmp;
frac = div_u64_rem((ps << 12), 8000LLU, NULL); frac = div_u64((ps << 12), 8000LLU);
p->frac += frac; p->frac += frac;
if (p->frac >= 4096) if (p->frac >= 4096)
...@@ -80,7 +81,7 @@ static void fdelay_sub_ps(struct fdelay_time *p, uint64_t ps) ...@@ -80,7 +81,7 @@ static void fdelay_sub_ps(struct fdelay_time *p, uint64_t ps)
/* FIXME: this silently fails with ps > 10^12 = 1s */ /* FIXME: this silently fails with ps > 10^12 = 1s */
tmp = div64_u64_rem(ps, 8000LLU, &ps); tmp = div64_u64_rem(ps, 8000LLU, &ps);
coarse_neg = (uint32_t) tmp; coarse_neg = (uint32_t) tmp;
frac_neg = div_u64_rem((ps << 12), 8000LLU, NULL); frac_neg = div_u64((ps << 12), 8000LLU);
if (p->frac < frac_neg) if (p->frac < frac_neg)
{ {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Jose Jimenez <jjimenez.wr@gmail.com>, Copyright (C) 2014 UGR. * Jose Jimenez <jjimenez.wr@gmail.com>, Copyright (C) 2014 UGR.
* Released according to the GNU GPL version 3 (GPLv3) or later. * Released according to the GNU GPL version 3 (GPLv3) or later.
* *
* Adapted from tools-util fine-delay-sw * Adapted from tools-util.c within fine-delay-sw package
*/ */
#include <stdio.h> #include <stdio.h>
...@@ -115,7 +115,7 @@ int sscanf_addhoc_replacement(char *str, unsigned long long *var1, unsigned long ...@@ -115,7 +115,7 @@ int sscanf_addhoc_replacement(char *str, unsigned long long *var1, unsigned long
/* /*
* What it should if we had 64 bit printing * What it should be, if we had 64 bit printing
* *
* Note: LM32-base cores can not divide LL use functions form linux/math64.c * Note: LM32-base cores can not divide LL use functions form linux/math64.c
* I provide you with (that means the fuction donw below has te be fixed) * I provide you with (that means the fuction donw below has te be fixed)
...@@ -154,14 +154,14 @@ void tools_report_time(char *name, struct fdelay_time *t, int umode) ...@@ -154,14 +154,14 @@ void tools_report_time(char *name, struct fdelay_time *t, int umode)
uint64_t temp = mul_u64 ((u64)t->frac, 8000LLU); uint64_t temp = mul_u64 ((u64)t->frac, 8000LLU);
uint64_t picoseconds = uint64_t picoseconds =
mul_u64 ((u64)t->coarse ,8000LLU) + mul_u64 ((u64)t->coarse ,8000LLU) +
div64_u64_rem(temp, 4096LLU, NULL); div64_u64(temp, 4096LLU);
printf("%s ", name); printf("%s ", name);
switch(umode) { switch(umode) {
case TOOLS_UMODE_USER: case TOOLS_UMODE_USER:
/* /*
* This fix make the following looks like sheet (at running time). * This fix make the following looks like shee... not so god (at running time).
* It looks way cooler in the user space! * It looks way cool in user space!
* *
*/ */
mprint_64bit((uint64_t)(t->utc)); mprint_64bit((uint64_t)(t->utc));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment