Sign in Join

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

Mailing lists / fpc-pascal / 2013-02

x86 asm bswap

8 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

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

Juha Manninen

A Delphi project "DeleD 3-D" which I try to convert, has unit_PNGSupport with method:

function TPNGProcessor.SwapLong( const aValue: Cardinal ): Cardinal; assembler;
asm
    mov eax, aValue
    bswap eax;
end;

What would be a cross-platform replacement?

I read that bswap is used for converting big-endian (Intel) format to little-endian (Motorolla etc.) format.
However this a an old Delphi app, Win32 only.

Later PNG support functions can be replaced with something else, bu that is another story.

Regards,
Juha

Vincent Snijders
to Juha Manninen

2013/2/6 Juha Manninen :

I read that bswap is used for converting big-endian (Intel) format to little-endian (Motorolla etc.) format. However this a an old Delphi app, Win32 only.

I am confused. Intel i386 is little endian. Motorola Powerpc is big endian.

Vincent

Jeppe Græsdal Johansen
to Juha Manninen: A Delphi project "DeleD 3-D" which I try to convert, has unit_PNGSupport with method:…
function TPNGProcessor.SwapLong( const aValue: Cardinal ): Cardinal;
begin
    result := BeToN(aValue);
end;
Juha Manninen wrote 24 lines
A Delphi project "DeleD 3-D" which I try to convert, has unit_PNGSupport with method: function TPNGProcessor.SwapLong( const aValue: Cardinal ): Cardinal; assembler; asm mov eax, aValue bswap eax; end; What would be a cross-platform replacement? I read that bswap is used for converting big-endian (Intel) format to little-endian (Motorolla etc.) format. However this a an old Delphi app, Win32 only. Later PNG support functions can be replaced with something else, bu that is another story. Regards, Juha _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Lukasz Sokol
to Juha Manninen: A Delphi project "DeleD 3-D" which I try to convert, has unit_PNGSupport with method:…
Juha Manninen wrote 15 lines
A Delphi project "DeleD 3-D" which I try to convert, has unit_PNGSupport with method: function TPNGProcessor.SwapLong( const aValue: Cardinal ): Cardinal; assembler; asm mov eax, aValue bswap eax; end; What would be a cross-platform replacement? I read that bswap is used for converting big-endian (Intel) format to little-endian (Motorolla etc.) format. However this a an old Delphi app, Win32 only.

What Vincent said, and...

Show quoted text 6 lines
Later PNG support functions can be replaced with something else, bu that is another story. Regards, Juha

There was a (recent) discussion about Swap and BEtoN, on Lazarus list. (message titles: "Unpack of PHP", mostly on 4/02/2013)

Lukasz

Juha Manninen
to Vincent Snijders: 2013/2/6 Juha Manninen : I am confused. Intel i386 is little endian. Motorola Powerpc is…
Vincent Snijders wrote 6 lines
2013/2/6 Juha Manninen : > I read that bswap is used for converting big-endian (Intel) format to > little-endian (Motorolla etc.) format. > However this a an old Delphi app, Win32 only. I am confused. Intel i386 is little endian. Motorola Powerpc is big endian.

I copied it from here:
http://asm.inightmare.org/opcodelst/index.php?op=BSWAP

I think the author was confused. I am always confused, too, because the big/little endian thing is named wrong IMO.
In human readable numbers, reading from left to right, big numbers (MSB) come first and little numbers (LSB) last.
In essense it is a "little endian" notation as it ends with little numbers. Motorola 68000 and others use the same logic (MSB - LSB) but for some reason it is called " big endian" while Intel which has it upside down, is called "little endian".
IIRC the names refer to memory layout, how those registers are written to memory.

Anyway, I am confused but it does not matter because there are functions made by someone else and I don't need to think of the details. :)

Regards,
Juha

Sven Barth
to Juha Manninen
Juha Manninen wrote 9 lines
On Wed, Feb 6, 2013 at 10:40 AM, Jeppe Græsdal Johansen wrote: > function TPNGProcessor.SwapLong( const aValue: Cardinal ): Cardinal; > begin > result := BeToN(aValue); > end; Thanks, it works! There are so many functions in FPC libraries which I don't know anything about. This was one of them.

It could be that BeToN is the wrong function (it depends on how the method is used). What it does is the following: if the target cpu is big endian (m68k, powerpc) then just return the value, otherwise (i386) swap the endianess.

So you should check what SwapLong is really used for.

There are three possible functions:
BeToN (as mentioned above)
LeToN (leave as is if little endian, convert otherwise) SwapEndian (change always)

Regards,
Sven

Mark Morgan Lloyd
to Juha Manninen: On Wed, Feb 6, 2013 at 10:40 AM, Jeppe Græsdal Johansen Thanks, it works! There are so…
Juha Manninen wrote 10 lines
On Wed, Feb 6, 2013 at 10:40 AM, Jeppe Græsdal Johansen wrote: > function TPNGProcessor.SwapLong( const aValue: Cardinal ): Cardinal; > begin > result := BeToN(aValue); > end; Thanks, it works! There are so many functions in FPC libraries which I don't know anything about. This was one of them.

I wonder whether I could ask a silly question here: is there a way of processing the RTL documentation to extract the description as a single line, so that it can be run through a permuted-index generator?

For example, if index-generation was restricted to ten words the lines

BEToN will rearrange the bytes in a Big-Endian number LEToN will rearrange the bytes in a Little-Endian number

run through the unix ptx utility would index under "Endian" (amongst others).

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]