Re: [PATCH v8 09/14] iio: afe: rescale: fix accuracy for small fractional scales

From: Peter Rosin
Date: Mon Aug 23 2021 - 02:53:18 EST


On 2021-08-21 03:33, Liam Beguin wrote:
> On Fri Aug 20, 2021 at 7:37 PM EDT, kernel test robot wrote:
>> Hi Liam,
>>
>> Thank you for the patch! Yet something to improve:
>>
>> [auto build test ERROR on 6cbb3aa0f9d5d23221df787cf36f74d3866fdb78]
>>
>> url:
>> https://github.com/0day-ci/linux/commits/Liam-Beguin/iio-afe-add-temperature-rescaling-support/20210821-032112
>> base: 6cbb3aa0f9d5d23221df787cf36f74d3866fdb78
>> config: nds32-buildonly-randconfig-r005-20210821 (attached as .config)
>> compiler: nds32le-linux-gcc (GCC) 11.2.0
>> reproduce (this is a W=1 build):
>> wget
>> https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross
>> -O ~/bin/make.cross
>> chmod +x ~/bin/make.cross
>> #
>> https://github.com/0day-ci/linux/commit/e5c2e1505fa3f8cf9fe6d3a21f3a5c585efc6dce
>> git remote add linux-review https://github.com/0day-ci/linux
>> git fetch --no-tags linux-review
>> Liam-Beguin/iio-afe-add-temperature-rescaling-support/20210821-032112
>> git checkout e5c2e1505fa3f8cf9fe6d3a21f3a5c585efc6dce
>> # save the attached .config to linux build tree
>> mkdir build_dir
>> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross
>> O=build_dir ARCH=nds32 SHELL=/bin/bash
>>
>> If you fix the issue, kindly add following tag as appropriate
>> Reported-by: kernel test robot <lkp@xxxxxxxxx>
>>
>> All errors (new ones prefixed by >>):
>>
>> nds32le-linux-ld: drivers/iio/afe/iio-rescale.o: in function
>> `rescale_process_scale':
>>>> iio-rescale.c:(.text+0x5f4): undefined reference to `__divdi3'
>>>> nds32le-linux-ld: iio-rescale.c:(.text+0x5f8): undefined reference to `__divdi3'
>
> My mistake, I'll replace the division by a div64_s64().
>
> --- a/drivers/iio/afe/iio-rescale.c
> +++ b/drivers/iio/afe/iio-rescale.c
> @@ -53,7 +53,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
> else
> tmp = 1 << *val2;
>
> - if (abs(rem) > 10000000 && abs(*val / tmp) < 100) {
> + if (abs(rem) > 10000000 && abs(div64_s64(*val, tmp)) < 100) {
> *val = div_s64_rem(*val, tmp, &rem2);
>
> *val2 = div_s64(rem, tmp);
>

At this point in the code, you know that tmp is a 32-bit value. *val
and rem are also 32-bit. It feels like a waste to not exploit that fact
and spend cycles doing lots of pointless 64-bit math on weakish 32-bit
machines.

Cheers,
Peter

>
> The if statement is also misaligned here. I'll fix that too.
>
> Thanks,
> Liam
>
>>
>> ---
>> 0-DAY CI Kernel Test Service, Intel Corporation
>> https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx
>