linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* writing to a floating point register ?
@ 2003-02-05 10:17 Sven Luther
  2003-02-05 10:28 ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Luther @ 2003-02-05 10:17 UTC (permalink / raw)
  To: linux-fbdev-devel

Hello, ...

while writing a fbdev driver, i need to write a value to a floating
point register. Do we have any macro doing this, or should i need to
calculate the sign, mantissa and exponent by hand ?

Just doing a unsigned int cast would round the value i think, and thus
not give the right result.

Friendly,

Sven Luther


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: writing to a floating point register ?
  2003-02-05 10:17 writing to a floating point register ? Sven Luther
@ 2003-02-05 10:28 ` Geert Uytterhoeven
  2003-02-05 10:38   ` Sven Luther
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2003-02-05 10:28 UTC (permalink / raw)
  To: Sven Luther; +Cc: Linux Frame Buffer Device Development

On Wed, 5 Feb 2003, Sven Luther wrote:
> while writing a fbdev driver, i need to write a value to a floating
> point register. Do we have any macro doing this, or should i need to
> calculate the sign, mantissa and exponent by hand ?
> 
> Just doing a unsigned int cast would round the value i think, and thus
> not give the right result.

You cannot use floating point math in the kernel.

What exactly are you trying to achieve?

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: writing to a floating point register ?
  2003-02-05 10:28 ` Geert Uytterhoeven
@ 2003-02-05 10:38   ` Sven Luther
  2003-02-05 10:44     ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Sven Luther @ 2003-02-05 10:38 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Sven Luther, Linux Frame Buffer Device Development

On Wed, Feb 05, 2003 at 11:28:58AM +0100, Geert Uytterhoeven wrote:
> On Wed, 5 Feb 2003, Sven Luther wrote:
> > while writing a fbdev driver, i need to write a value to a floating
> > point register. Do we have any macro doing this, or should i need to
> > calculate the sign, mantissa and exponent by hand ?
> > 
> > Just doing a unsigned int cast would round the value i think, and thus
> > not give the right result.
> 
> You cannot use floating point math in the kernel.
> 
> What exactly are you trying to achieve?

Well, my framebuffer is not linear, and i have to enable a bypass unit
to fake a linear framebuffer. This bypass unit need that i write the
bytestride/64 32bit floating point value in a register.

for example : 1024 in 32 bpp => 4*1024/64 = 64.

64 is 0100 0000 or 1.0 * 2^6.

So i have sign = 0, exp = 127+6=133 = 10000101, and mantissa = 0.

which gives 0100 0010 1000 0000 ... or 0x42 80 00 00.

I was hoping that i would not need to do this calculation by hand, but i
guess it is not possible, since like you said, we cannot use the FP
unit in the kernel.

Or maybe there are some convenient macros available for that or
something ?

Friendly,

Sven Luther


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: writing to a floating point register ?
  2003-02-05 10:38   ` Sven Luther
@ 2003-02-05 10:44     ` Geert Uytterhoeven
  2003-02-05 11:02       ` Sven Luther
  2003-02-05 12:04       ` Sven Luther
  0 siblings, 2 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2003-02-05 10:44 UTC (permalink / raw)
  To: Sven Luther; +Cc: Linux Frame Buffer Device Development

On Wed, 5 Feb 2003, Sven Luther wrote:
> On Wed, Feb 05, 2003 at 11:28:58AM +0100, Geert Uytterhoeven wrote:
> > On Wed, 5 Feb 2003, Sven Luther wrote:
> > > while writing a fbdev driver, i need to write a value to a floating
> > > point register. Do we have any macro doing this, or should i need to
> > > calculate the sign, mantissa and exponent by hand ?
> > > 
> > > Just doing a unsigned int cast would round the value i think, and thus
> > > not give the right result.
> > 
> > You cannot use floating point math in the kernel.
> > 
> > What exactly are you trying to achieve?
> 
> Well, my framebuffer is not linear, and i have to enable a bypass unit
> to fake a linear framebuffer. This bypass unit need that i write the
> bytestride/64 32bit floating point value in a register.
> 
> for example : 1024 in 32 bpp => 4*1024/64 = 64.
> 
> 64 is 0100 0000 or 1.0 * 2^6.
> 
> So i have sign = 0, exp = 127+6=133 = 10000101, and mantissa = 0.
> 
> which gives 0100 0010 1000 0000 ... or 0x42 80 00 00.
> 
> I was hoping that i would not need to do this calculation by hand, but i
> guess it is not possible, since like you said, we cannot use the FP
> unit in the kernel.

Even if you could, it would work for 32-bit IEEE floating point format only.
Is the hardware register format IEEE compatible.

Anyway, the calculation is not that difficult.
Perhaps you can even restrict line_length to be a multiple of 64 in all cases,
in which case it's even made more easy?
Does the hardware register allow denormalized numbers? Since you want to divide
by 64 only, this would allow you to use a fixed exponent.

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: writing to a floating point register ?
  2003-02-05 10:44     ` Geert Uytterhoeven
@ 2003-02-05 11:02       ` Sven Luther
  2003-02-05 12:04       ` Sven Luther
  1 sibling, 0 replies; 6+ messages in thread
From: Sven Luther @ 2003-02-05 11:02 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Sven Luther, Linux Frame Buffer Device Development

On Wed, Feb 05, 2003 at 11:44:23AM +0100, Geert Uytterhoeven wrote:
> On Wed, 5 Feb 2003, Sven Luther wrote:
> > On Wed, Feb 05, 2003 at 11:28:58AM +0100, Geert Uytterhoeven wrote:
> > > On Wed, 5 Feb 2003, Sven Luther wrote:
> > > > while writing a fbdev driver, i need to write a value to a floating
> > > > point register. Do we have any macro doing this, or should i need to
> > > > calculate the sign, mantissa and exponent by hand ?
> > > > 
> > > > Just doing a unsigned int cast would round the value i think, and thus
> > > > not give the right result.
> > > 
> > > You cannot use floating point math in the kernel.
> > > 
> > > What exactly are you trying to achieve?
> > 
> > Well, my framebuffer is not linear, and i have to enable a bypass unit
> > to fake a linear framebuffer. This bypass unit need that i write the
> > bytestride/64 32bit floating point value in a register.
> > 
> > for example : 1024 in 32 bpp => 4*1024/64 = 64.
> > 
> > 64 is 0100 0000 or 1.0 * 2^6.
> > 
> > So i have sign = 0, exp = 127+6=133 = 10000101, and mantissa = 0.
> > 
> > which gives 0100 0010 1000 0000 ... or 0x42 80 00 00.
> > 
> > I was hoping that i would not need to do this calculation by hand, but i
> > guess it is not possible, since like you said, we cannot use the FP
> > unit in the kernel.
> 
> Even if you could, it would work for 32-bit IEEE floating point format only.
> Is the hardware register format IEEE compatible.

Mmm, sure, didn't think of this. Would endianess and other such issue 
not be a problem for this kind of calculation ? Would it make sense to
have a special macro available for this kind of thing, like we have for
writing 8, 16 or 32 bits ?

> Anyway, the calculation is not that difficult.

Sure ...

> Perhaps you can even restrict line_length to be a multiple of 64 in all cases,
> in which case it's even made more easy?

Are all video modes we want to use multiples of 64 ? I guess yes.

> Does the hardware register allow denormalized numbers? Since you want to divide
> by 64 only, this would allow you to use a fixed exponent.

Erm, no idea, will need to try. That say, i don't know much about
floating point numbers, so i really don't know all that much about
denormalized numbers.

Mmm, i guess you mean that since we divide by 64, the mantissa would
always be 0 (1.000...) and we only need to write 127 + log2(value) in it
?  
Friendly,

Sven Luther


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: writing to a floating point register ?
  2003-02-05 10:44     ` Geert Uytterhoeven
  2003-02-05 11:02       ` Sven Luther
@ 2003-02-05 12:04       ` Sven Luther
  1 sibling, 0 replies; 6+ messages in thread
From: Sven Luther @ 2003-02-05 12:04 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Sven Luther, Linux Frame Buffer Device Development

On Wed, Feb 05, 2003 at 11:44:23AM +0100, Geert Uytterhoeven wrote:
> 
> Even if you could, it would work for 32-bit IEEE floating point format only.
> Is the hardware register format IEEE compatible.


Something like this :

unsigned long cfp32(unsigned long v, unsigned long d) {
        unsigned int x, vx, m, e;
        for (x=0, vx=v; vx>1; x++, vx>>=1);
        m = (x>22?v>>(x-22):v<<(22-x)) & 0x007fffff;
        e = ((x+127-d)<<23) & 0x7f800000;
        return (e | m);
}

Does the job. I don't really test for exponent overflow, but well,
anyone trying a video mode whose exponent is greater than 127 deserves
what gets.

Are there any other subtle things that may break with the above ?

Anyway thanks for your help.

Friendly,

Sven Luther


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-02-05 12:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-05 10:17 writing to a floating point register ? Sven Luther
2003-02-05 10:28 ` Geert Uytterhoeven
2003-02-05 10:38   ` Sven Luther
2003-02-05 10:44     ` Geert Uytterhoeven
2003-02-05 11:02       ` Sven Luther
2003-02-05 12:04       ` Sven Luther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).