[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4ECFDA1D.3090303@grupopie.com>
Date: Fri, 25 Nov 2011 18:10:37 +0000
From: Paulo Marques <pmarques@...popie.com>
To: Nuno Santos <nsantos@...gma.com>
CC: Jiri Slaby <jirislaby@...il.com>, linux-kernel@...r.kernel.org
Subject: Re: Floating point usage inside kernel
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.
--
Paulo Marques - www.grupopie.com
"Feed the hungry, save the whales, free the mallocs!"
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists