From: Nuno Santos <nsantos@edigma.com>
To: Paulo Marques <pmarques@grupopie.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Floating point usage inside kernel
Date: Mon, 28 Nov 2011 10:11:30 +0000 [thread overview]
Message-ID: <4ED35E52.5010008@edigma.com> (raw)
In-Reply-To: <4ECFDA1D.3090303@grupopie.com>
Ok, understood!
Just one more question. To do this, do I need to change the data type
from double to int?
Thanks,
Nuno
On 11/25/2011 06:10 PM, Paulo Marques wrote:
> Nuno Santos wrote:
>>> [...]
>>> Unless you have overflow or need more than 16 bits of fractional
>>> precision, you'll have no problem with this approach.
>>>
>>> I hope this helps,
>> Sorry, i'm not sure if I have completely understand your suggestion. Are
>> you telling me to apply this transform only to my input data, or to all
>> the operations that are applied in the function used in kernel?
> Imagine that your matrix coefficients are:
>
> 2.5, 1, 4.7
> 45.3, 0.765, 10
> 0, 0, 1
>
> and your input is:
>
> 3420.56, 5410.76, 1
>
> You start by converting the matrix coefficients:
>
> 2.5 * 65536.0 = 163840
> ....
>
> so the matrix becomes:
>
> 163840 65536 308019
> 2968781 50135 655360
> 0 0 65536
>
> This can be done in userspace and the coefficients can be sent to the
> kernel as fixed point numbers.
>
> You do the same (this time on the kernel) with your input, so it becomes:
>
> 224169820 354599567 65536
>
> Now you can do:
>
> q[0] = fixed_mul(p[0], a[0][0]) + fixed_mul(p[1], a[1][0]) +
> fixed_mul(p[2], a[2][0]);
> ....
>
> where "fixed_mul" is a function that does the multiplication as I
> explained earlier.
>
> To convert the result back to an integer, just shift down by 16.
>
next prev parent reply other threads:[~2011-11-28 10:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <S1754322Ab1KYK6W/20111125105822Z+929@vger.kernel.org>
2011-11-25 11:14 ` Floating point usage inside kernel Nuno Santos
2011-11-25 12:08 ` Jiri Slaby
2011-11-25 16:16 ` Nuno Santos
2011-11-25 17:05 ` Paulo Marques
2011-11-25 17:46 ` Nuno Santos
2011-11-25 18:10 ` Paulo Marques
2011-11-28 10:11 ` Nuno Santos [this message]
2011-11-28 12:50 ` Paulo Marques
2011-11-28 4:00 ` Andy Lutomirski
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=4ED35E52.5010008@edigma.com \
--to=nsantos@edigma.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmarques@grupopie.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.