From 9d36d1cf7b00cb8f4527c0a4a9a8d8d266ff44e4 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sat, 9 Mar 2002 04:02:53 +0000 Subject: [PATCH] converted 64 bit integer division to use do_div --- comedi/drivers/comedi_rt_timer.c | 22 ++-------------- comedi/drivers/comedi_test.c | 45 +++++--------------------------- 2 files changed, 9 insertions(+), 58 deletions(-) diff --git a/comedi/drivers/comedi_rt_timer.c b/comedi/drivers/comedi_rt_timer.c index f07b8d4d..15d49f39 100644 --- a/comedi/drivers/comedi_rt_timer.c +++ b/comedi/drivers/comedi_rt_timer.c @@ -66,6 +66,7 @@ TODO: #include #include #include +#include #ifndef RTLINUX_VERSION_CODE #define RTLINUX_VERSION_CODE 0 @@ -79,26 +80,7 @@ TODO: // this function sole purpose is to divide a long long by 838 static inline RTIME nano2count(long long ns) { - unsigned long denom = 838; // divisor - long ms32 = ns >> 32; // most significant 32 bits - unsigned long ms32rem = ms32 % denom; // remainder of ms32 / denom - unsigned long ls32 = ns & 0xffffffff; // least significant 32 bits - unsigned long ls32rem = ls32 % denom; - unsigned long big = 0xffffffff; - unsigned long big_rem = big % denom; - unsigned long rem_rem; - - // divide most significant bits - ns = ms32 / denom; - ns = ns << 32; - // add corrections due to rounding errors - ns += ms32rem * (big / denom) + (ms32rem * (big_rem + 1)) / denom; - // divide least significant bits - ns += ls32 / denom; - // add really small correction - rem_rem = (ms32rem * (big_rem + 1)) % denom; - ns += (ls32rem + rem_rem) / denom; - + do_div(ns, 838); return ns; } #ifdef rt_get_time() diff --git a/comedi/drivers/comedi_test.c b/comedi/drivers/comedi_test.c index f0d2715d..2ddc7c88 100644 --- a/comedi/drivers/comedi_test.c +++ b/comedi/drivers/comedi_test.c @@ -56,6 +56,7 @@ zero volts). #include #include #include +#include /* Board descriptions */ typedef struct waveform_board_struct{ @@ -395,54 +396,22 @@ static int waveform_ai_cancel(comedi_device *dev, comedi_subdevice *s) return 0; } -// divides an unsigned long long -static unsigned long long my_ull_div(unsigned long long numerator, unsigned long denominator) -{ - u32 value; - unsigned long long remainder; - unsigned int shift = 0; - const unsigned long max_u32 = 0xffffffff; - - if(numerator <= max_u32) - { - // numerator is small enough that we can return correct result - value = numerator; - return value / denominator; - } - - remainder = numerator; - - // otherwise shift most significant bits into 32 bit variable - while(numerator > max_u32) - { - numerator >>= 1; - shift++; - } - value = numerator; - value /= denominator; - value <<= shift; - - remainder -= ((unsigned long long) value) * denominator; - - return value + my_ull_div(remainder, denominator); -} - static sampl_t fake_sawtooth(comedi_device *dev, unsigned int range_index, unsigned long current_time) { comedi_subdevice *s = dev->read_subdev; unsigned int offset = s->maxdata / 2; - unsigned long long value; + u64 value; comedi_krange *krange = &s->range_table->range[range_index]; - unsigned long long binary_amplitude; + u64 binary_amplitude; binary_amplitude = s->maxdata; binary_amplitude *= devpriv->uvolt_amplitude; - binary_amplitude = my_ull_div(binary_amplitude, krange->max - krange->min); + do_div(binary_amplitude, krange->max - krange->min); current_time %= devpriv->usec_period; value = current_time; value *= binary_amplitude * 2; - value = my_ull_div(value, devpriv->usec_period); + do_div(value, devpriv->usec_period); value -= binary_amplitude; // get rid of sawtooth's dc offset return offset + value; @@ -451,13 +420,13 @@ static sampl_t fake_squarewave(comedi_device *dev, unsigned int range_index, uns { comedi_subdevice *s = dev->read_subdev; unsigned int offset = s->maxdata / 2; - unsigned long long value; + u64 value; comedi_krange *krange = &s->range_table->range[range_index]; current_time %= devpriv->usec_period; value = s->maxdata; value *= devpriv->uvolt_amplitude; - value = my_ull_div(value, krange->max - krange->min); + do_div(value, krange->max - krange->min); if(current_time < devpriv->usec_period / 2) value *= -1; -- 2.26.2