2006-08-06 06:16:31

by Om N.

[permalink] [raw]
Subject: writing portable code based on BITS_PER_LONG?

Hi,
I am trying to port a driver written for IA32. This is a pci driver
and has a chipset doing PCI <-> local bus data transfer, where local
bus is 16 bit. So a number of values are converted by right/left
shifting by 16 bits.

Now that I am doing porting, I would like to make it fully portable
across AMD64 and IA32. What is the best method for this? Should I do
something like,

#if BITS_PER_LONG = 64
shiftwidth = 48
#else if BITS_PER_LONG = 32
shiftwidth = 16
#endif

I don't like this. I would not do it if there is some elegant way.

Is there any other way?


2006-08-06 10:31:46

by Jan-Benedict Glaw

[permalink] [raw]
Subject: Re: writing portable code based on BITS_PER_LONG?

On Sat, 2006-08-05 23:16:29 -0700, Om N. <[email protected]> wrote:
> I am trying to port a driver written for IA32. This is a pci driver
> and has a chipset doing PCI <-> local bus data transfer, where local
> bus is 16 bit. So a number of values are converted by right/left
> shifting by 16 bits.
>
> Now that I am doing porting, I would like to make it fully portable
> across AMD64 and IA32. What is the best method for this? Should I do
> something like,
>
> #if BITS_PER_LONG = 64
> shiftwidth = 48
> #else if BITS_PER_LONG = 32
> shiftwidth = 16
> #endif

I'd probably write some macros that access the parts of the longs you
want to have/set and put these into some header file.

MfG, JBG

--
Jan-Benedict Glaw [email protected] +49-172-7608481
Signature of: Träume nicht von Dein Leben: Lebe Deinen Traum!
the second :


Attachments:
(No filename) (879.00 B)
signature.asc (189.00 B)
Digital signature
Download all attachments

2006-08-06 16:13:24

by Arjan van de Ven

[permalink] [raw]
Subject: Re: writing portable code based on BITS_PER_LONG?

On Sat, 2006-08-05 at 23:16 -0700, Om N. wrote:
> Hi,
> I am trying to port a driver written for IA32. This is a pci driver
> and has a chipset doing PCI <-> local bus data transfer, where local
> bus is 16 bit. So a number of values are converted by right/left
> shifting by 16 bits.
>
> Now that I am doing porting, I would like to make it fully portable
> across AMD64 and IA32. What is the best method for this? Should I do
> something like,
>
> #if BITS_PER_LONG = 64
> shiftwidth = 48
> #else if BITS_PER_LONG = 32
> shiftwidth = 16
> #endif
>
> I don't like this. I would not do it if there is some elegant way.


if you have a fixed sized bus, how about using the linux fixed size data
types?

Also, maybe it would be a good idea to post the url to your code so that
people on this list can do a quick 64-bit safeness audit of your
driver... free work/help and all that ;-)

Greetings,
Arjan van de Ven

--
if you want to mail me at work (you don't), use arjan (at) linux.intel.com


2006-08-06 20:08:11

by Om N.

[permalink] [raw]
Subject: Re: writing portable code based on BITS_PER_LONG?

On 8/6/06, Jan-Benedict Glaw <[email protected]> wrote:
> On Sat, 2006-08-05 23:16:29 -0700, Om N. <[email protected]> wrote:
> > I am trying to port a driver written for IA32. This is a pci driver
> > and has a chipset doing PCI <-> local bus data transfer, where local
> > bus is 16 bit. So a number of values are converted by right/left
> > shifting by 16 bits.
> I'd probably write some macros that access the parts of the longs you
> want to have/set and put these into some header file.
Let me go the macro way. Let me beat the code into some shape and then
post a url to the list for comments on 64bit safeness.

Thanks for ideas,
Regards,
Om.