Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-09

Binary compatibility between Intel CPU and PowerPC CPU

8 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Roland Turcan

Hello FPC-Pascal users discussions!

What is the best way to keep the binary compatibility among different CPU architectures.

I need to make our own database engine compatible and other binary files, that user still can use our data from i386 or PowerPC computer.

I really don't like the idea to change the order of all numeric variables on PowerPC, because it costs time of CPU.

There must be easier way how to keep the compatibility.

Could you give me some hints for better solution.

Francisco Reyes
to Roland Turcan
Roland Turcan wrote
I need to make our own database engine compatible and other binary files, that user still can use our data from i386 or PowerPC computer.

Do you mean you are trying to keep your binary data files compatible between these two architectures?

I don't have an answer, but it was not clear (at leat to me) from your post what you are trying to do.

Adriaan van Os
to Roland Turcan: Hello FPC-Pascal users discussions! What is the best way to keep the binary compatibility…
Roland Turcan wrote 14 lines
Hello FPC-Pascal users discussions! What is the best way to keep the binary compatibility among different CPU architectures. I need to make our own database engine compatible and other binary files, that user still can use our data from i386 or PowerPC computer. I really don't like the idea to change the order of all numeric variables on PowerPC, because it costs time of CPU. There must be easier way how to keep the compatibility. Could you give me some hints for better solution.

Whether you "like the idea" or not, the best way is as follows:

- add a byte to the header of source data that indicates the endianness, high-endian for PowerPC, low-endian for i386
- perform byte swapping if the endianness of source data is different from the endianness of the current CPU

With "source data" I mean
- reading files
- reading data over a network

This is best built-into a streaming toolbox, so that it happens automatically.

Adriaan van Os

Adriaan van Os
to Adriaan van Os
Adriaan van Os wrote 29 lines
Roland Turcan wrote: > Hello FPC-Pascal users discussions! > > What is the best way to keep the binary compatibility among different > CPU architectures. > > I need to make our own database engine compatible and other binary > files, that user still can use our data from i386 or PowerPC computer. > > I really don't like the idea to change the order of all numeric > variables on PowerPC, because it costs time of CPU. > > There must be easier way how to keep the compatibility. > > Could you give me some hints for better solution. Whether you "like the idea" or not, the best way is as follows: - add a byte to the header of source data that indicates the endianness, high-endian for PowerPC, low-endian for i386 - perform byte swapping if the endianness of source data is different from the endianness of the current CPU With "source data" I mean - reading files - reading data over a network This is best built-into a streaming toolbox, so that it happens automatically.

I forgot to mention:
- write data in the endianness of the current CPU

To me, this is obvious, but for example Postgres always transfers data high-endian over a network, which is ridicuous. So, for example if they send binary data from an i386 machine to another i386 machine, they perform byte-swapping twice, unnecessary,

Regards,

Adriaan van Os

Jeff Wormsley
to Roland Turcan: Hello FPC-Pascal users discussions! What is the best way to keep the binary compatibility…

Well, the (inefficient / multiplatform - choose one) way is to not store data as binary, instead using something like XML. Probably not an option, but there will be a tradeoff and a penalty no matter what. One way would be store the data in the endianness of the consistently slower platform (so as not to further slow down a system that is already slow). Another would be to pick the endianness of the most popular platform for your product so that it performs as well as possible where the most users are. Its a decision you'll have to make on your own, though.

Jeff.

Roland Turcan wrote 16 lines
Hello FPC-Pascal users discussions! What is the best way to keep the binary compatibility among different CPU architectures. I need to make our own database engine compatible and other binary files, that user still can use our data from i386 or PowerPC computer. I really don't like the idea to change the order of all numeric variables on PowerPC, because it costs time of CPU. There must be easier way how to keep the compatibility. Could you give me some hints for better solution.
I haven't smoked for 2 years, 4 weeks and 2 days, saving $3,427.14 and not smoking 22,847.63 cigarettes.
Roland Turcan
to Jeff Wormsley

Hello all,

Thanks for all responses and I've got the answer I thought I get, but I don't like it. :-|

Never mind. I cannot make any change on the data structure which is on the market about 10 years, but at least I have one advantage. The software was developed and is still used on i386 platform which means, that the endian conversion is needed only for PowerPC computers which are anyway old fashioned and they will vanish soon, because Apple prefers i386 instead. The question still is, how big effort is for PowerPC to make endian convertion.

TRoland;

<<< 16.9.2008 19:26 - Jeff Wormsley "" >>>
JW> Well, the (inefficient / multiplatform - choose one) way is to not store JW> data as binary, instead using something like XML. Probably not an JW> option, but there will be a tradeoff and a penalty no matter what. One JW> way would be store the data in the endianness of the consistently slower JW> platform (so as not to further slow down a system that is already JW> slow). Another would be to pick the endianness of the most popular JW> platform for your product so that it performs as well as possible where JW> the most users are. Its a decision you'll have to make on your own, though.

JW> Jeff.

JW> Roland Turcan wrote 16 lines
> Hello FPC-Pascal users discussions! > > What is the best way to keep the binary compatibility among different > CPU architectures. > > I need to make our own database engine compatible and other binary > files, that user still can use our data from i386 or PowerPC computer. > > I really don't like the idea to change the order of all numeric > variables on PowerPC, because it costs time of CPU. > > There must be easier way how to keep the compatibility. > > Could you give me some hints for better solution. > >

JW> --
JW> I haven't smoked for 2 years, 4 weeks and 2 days, saving $3,427.14 and JW> not smoking 22,847.63 cigarettes.
JW> _______________________________________________ JW> fpc-pascal maillist -
JW> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Vincent Snijders
to Roland Turcan
Roland Turcan wrote 13 lines
Hello all, Thanks for all responses and I've got the answer I thought I get, but I don't like it. :-| Never mind. I cannot make any change on the data structure which is on the market about 10 years, but at least I have one advantage. The software was developed and is still used on i386 platform which means, that the endian conversion is needed only for PowerPC computers which are anyway old fashioned and they will vanish soon, because Apple prefers i386 instead. The question still is, how big effort is for PowerPC to make endian convertion.

There are some useful utilities in the RTL:
http://lazarus-ccr.sourceforge.net/docs/rtl/system/leton.html and friends.

Vincent

Gustavo Enrique Jimenez
to Adriaan van Os: Whether you "like the idea" or not, the best way is as follows: - add a byte to the…

2008/9/16 Adriaan van Os :

Show quoted text 32 lines
Roland Turcan wrote: > > Hello FPC-Pascal users discussions! > > What is the best way to keep the binary compatibility among different > CPU architectures. > > I need to make our own database engine compatible and other binary > files, that user still can use our data from i386 or PowerPC computer. > > I really don't like the idea to change the order of all numeric > variables on PowerPC, because it costs time of CPU. > > There must be easier way how to keep the compatibility. > > Could you give me some hints for better solution. Whether you "like the idea" or not, the best way is as follows: - add a byte to the header of source data that indicates the endianness, high-endian for PowerPC, low-endian for i386 - perform byte swapping if the endianness of source data is different from the endianness of the current CPU With "source data" I mean - reading files - reading data over a network This is best built-into a streaming toolbox, so that it happens automatically. Adriaan van Os

Don't forget to use packed records (see the Free Pascal Language Reference Guide). I've used binary files in that way across linux and windows machines (x86).

Gustavo