Sign in Join

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

Mailing lists / fpc-pascal / 2006-03

64 bits

18 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

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

constantijnw
to Vincent Snijders
Vincent Snijders wrote 12 lines
constantijnw wrote: > Hi, > > FPC programming for 64 bits processors; anyone written some helpful > guidelines, article, etc.? > There is an article on the fpc wiki: http://www.freepascal.org/wiki/index.php/Writing_portable_code_regarding_the_processor_architecture

Thanks, but I can't reach this page...... Is there anything I can do to make www.freepascal.org and its subdirectories accessible for me?

Reply by email

Michael Van Canneyt
to constantijnw
constantijnw wrote 16 lines
Vincent Snijders wrote: > constantijnw wrote: > >> Hi, >> >> FPC programming for 64 bits processors; anyone written some helpful >> guidelines, article, etc.? >> > > There is an article on the fpc wiki: > http://www.freepascal.org/wiki/index.php/Writing_portable_code_regarding_the_processor_architecture > > Thanks, but I can't reach this page...... Is there anything I can do to make www.freepascal.org and its subdirectories accessible for me?

The page is reachable ?

Michael.

Reply by email

constantijnw
to Michael Van Canneyt
Michael Van Canneyt wrote 34 lines
On Mon, 20 Mar 2006, constantijnw wrote: >Vincent Snijders wrote: > > > >>constantijnw wrote: >> >> >> >>>Hi, >>> >>>FPC programming for 64 bits processors; anyone written some helpful >>>guidelines, article, etc.? >>> >>> >>> >>There is an article on the fpc wiki: >>http://www.freepascal.org/wiki/index.php/Writing_portable_code_regarding_the_processor_architecture >> >> >> >> >Thanks, but I can't reach this page...... Is there anything I can do to >make www.freepascal.org and its subdirectories accessible for me? > > The page is reachable ?

No, Firefox (or IE) tells me he/she is "Waiting for www.freepascal.org..." Is a long timne problem.

Reply by email

Paul Davidson
to constantijnw

Works from here

constantijnw wrote 38 lines
Michael Van Canneyt wrote: > On Mon, 20 Mar 2006, constantijnw wrote: > > >> Vincent Snijders wrote: >> >> >>> constantijnw wrote: >>> >>> >>>> Hi, >>>> >>>> FPC programming for 64 bits processors; anyone written some helpful >>>> guidelines, article, etc.? >>>> >>>> >>> There is an article on the fpc wiki: >>> http://www.freepascal.org/wiki/index.php/ >>> Writing_portable_code_regarding_the_processor_architecture >>> >>> >>> >> Thanks, but I can't reach this page...... Is there anything I can do >> to >> make www.freepascal.org and its subdirectories accessible for me? >> > > The page is reachable ? > > No, Firefox (or IE) tells me he/she is "Waiting for www.freepascal.org..." Is a long timne problem. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

P Davidson
Corax Networks Inc.
http://CoraxNetworks.com

IMPORTANT NOTICE: This message is intended only for the use of the individual or entity to which it is addressed. The message may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify Corax Networks immediately by email at Thank you.

Reply by email

Jonas Maebe
to constantijnw: No, Firefox (or IE) tells me he/she is "Waiting for www.freepascal.org..." Is a long…
constantijnw wrote 8 lines
>> Thanks, but I can't reach this page...... Is there anything I can >> do to >> make www.freepascal.org and its subdirectories accessible for me? > > The page is reachable ? No, Firefox (or IE) tells me he/she is "Waiting for www.freepascal.org..." Is a long timne problem.

It is known that some people have a problem accessing www.freepascal.org, but unfortunately no one knows the exact cause. Some people think a certain kind of icmp packets are filtered by the firewall in front of the machine that hosts www.freepascal.org (something with fragmenting packets) and that this causes the problem.

Jonas

Reply by email

Felipe Monteiro de Carvalho
to Jonas Maebe

Also works here. I will paste the contents of the page bellow for you:

Writing portable code regarding the processor architecture

From FPCWiki

There are several main issues when writing code which is portable regarding the processor architecture: endianness and 32 vs. 64 bit processors.
Table of contents [showhide]
1 Endianness
2 Alignment
3 32 Bit vs. 64 Bit
4 Calling conventions

4.1 x86
4.2 ARM
4.3 68K
[edit]
Endianness

Endianness is the way how values larger than a byte (e.g. 16/32/64-bit integers) are stored by the processor.

Generally there are two ways:

1. Store the lowest value on the lowest address; longint(4) encoded as 04 00 00 00 (little endian
(http://en.wikipedia.org/wiki/Little_endian))
2. Store the highest value on the lowest address; longint(4) encoded as 00 00 00 04 (big endian
(http://en.wikipedia.org/wiki/Big_endian))

This is generally a given choice per processor family, but some families of processors can be either big endian or little endian depending on the mainboard they are attached to (ARM, PPC).

The best known little endian processor family is x86, the processor family used in PCs, and its brethren x86-64. Typical big endian processors are PPC (usually, see above note), and m68k (http://en.wikipedia.org/wiki/68k), many older systems such as the PDP-11 (http://en.wikipedia.org/wiki/PDP-11) and HP3000 (http://en.wikipedia.org/wiki/HP3000) minicomputers, and mainframes such as the IBM 370 (http://en.wikipedia.org/wiki/IBM_370) (Z series).

Since TCP/IP specifies that all protocol header structures that go over the wire should be big endian, so this notation is sometimes also refered to as network order.

Endianness is important

1. when exchanging data between different architectures
2. when accessing data sometimes as (an array of) a larger type, like integer, and sometimes as (an array of) a byte.

An example of the latter:

    Type
         Q = RECORD
             case boolean of
                 true: (i:integer);
                 false: (p:array[1..4] of byte)
         END;
    Var x:^Q ;
    begin
         new(x);
         x^.i:=5;
         if x^.p[1]=5 then
             writeln(x^.p[1]); writeln('Your machine is Little Endian')
         else
             if x^.p[4]=5 then
                 writeln(x^.p[1]); Writeln('Your machine is Big Endian')
             else
                 writeln(x^.p[1],' ',x^.p[2],' ',x^.p[3],' ',x^.p[4]);
writeln('Your machine''s endianness is indeterminate; please report
the results to the compiler development team');
         writeln;
        {Make it wait so we can see the results }
         write('Press enter when you finish reading this ');
         readln;
    end.

On little endian machines (PCs), the above code will write 5 (since longint(5) is stored as 05 00 00 00 in memory), while on big endian machines (e.g. Powermacs) it will write 0 (since longint(5) is stored as 00 00 00 05 in memory). (If you get the report your machine is indeterminate, please report on this wiki page what processor does this and what you get!)

To determine the endianness of the processor, use the ENDIAN_BIG or ENDIAN_LITTLE (or FPC_LITTLE_ENDIAN and FPC_BIG_ENDIAN starting from version 1.9) defines that are defined by freepascal automatically depending on the processor.
[edit]
Alignment

Some processors will allow improperly aligned data but with reduced efficiency (IBM 370/zSeries). Some processors generate hardware processor exceptions when data is badly aligned (e.g. Alpha or ARM). Sometimes the hardware exceptions are caught and fixed using emulation by the OS, but this is very slow, and should be avoided. This can also cause records to have different sizes, so always use sizeof(recordtype); as size of a record. If you define a packed record, try to ensure that data is naturally aligned, if possible. Some processors only have alignment requirements for certain types of data, like floating point (e.g. older PowerPCs).

To check if the CPU requires proper alignment, check the FPC_REQUIRES_PROPER_ALIGNMENT (version 1.9 and higher) define. On 32 Bit CPUs this usually means that data up to a size of 4 must be naturally aligned. If you want to access unaligned data, use the move procedure to move it to an aligned location before processing it. The move procedure takes care of unaligned data and handles it properly.

There are multiple strategies for aligning:

* align every field on a multiple of a certain value (typically a power of two, 1,2,4,8. 1 is equivalent to "packed")
* pad before every field such that it is aligned on a multiple of its size (so a longint on 4, an int64 on 8 bytes etc). This is typically done by C compiler, which is why FPC calls it {$packrecords C}.

(For arrays or nested records, the size of their largest sub unit is used)

Mac OS X {$packrecords C} seems to pad the entire record at the end to make it a certain size. This is still being investigated, and probably will be fixed in compiler.
[edit]
32 Bit vs. 64 Bit

To achive maximum compatiblity with older code, FPC doesn't change the size of predefined data types like integer, longint or word when changing from 32 to 64 Bit. However, the size of a pointer is 8 bytes on a 64 bit architecture so constructs like longint(pointer(p)) are doomed to crash on 64 bit architectures. However, to allow you to write portable code, the FPC system unit introduces the types PtrInt and PtrUInt which are signed and unsigned integer data types with the same size as a pointer.

Keep in mind that the size change of the "pointer" type also affects record sizes. If you allocate records with fixed sizes, and not with new or with getmem (<x>,sizeof(<x>)), this will have to be fixed. [edit]
Calling conventions

* For IBM 370 and zSeries, see the ZSeries page for further discussion.

[edit]
x86
[edit]
ARM
[edit]
68K

Reply by email

Michael Van Canneyt
to constantijnw: No, Firefox (or IE) tells me he/she is "Waiting for www.freepascal.org..." Is a long…
constantijnw wrote 38 lines
Michael Van Canneyt wrote: >On Mon, 20 Mar 2006, constantijnw wrote: > > > >>Vincent Snijders wrote: >> >> >> >>>constantijnw wrote: >>> >>> >>> >>>>Hi, >>>> >>>>FPC programming for 64 bits processors; anyone written some helpful >>>>guidelines, article, etc.? >>>> >>>> >>>> >>>There is an article on the fpc wiki: >>>http://www.freepascal.org/wiki/index.php/Writing_portable_code_regarding_the_processor_architecture >>> >>> >>> >>> >>Thanks, but I can't reach this page...... Is there anything I can do to >>make www.freepascal.org and its subdirectories accessible for me? >> >> > >The page is reachable ? > > > No, Firefox (or IE) tells me he/she is "Waiting for www.freepascal.org..." Is a long timne problem.

Strange. From here it works, using Firefox.

Michael.

Reply by email

Johann Glaser
to Jonas Maebe: It is known that some people have a problem accessing www.freepascal.org, but…

Hi!

Show quoted text 5 lines
It is known that some people have a problem accessing www.freepascal.org, but unfortunately no one knows the exact cause. Some people think a certain kind of icmp packets are filtered by the firewall in front of the machine that hosts www.freepascal.org (something with fragmenting packets) and that this causes the problem.

Just as an idea: Did you think of ECN problems (Explicit Congestion Negotiation, RFC 3168 http://www.rfc-editor.org/rfc/rfc3168.txt)? The http://www.kernel.org/ site has a news entry (16.1.2002), which says: --- schnipp ---
Please note that kernel.org uses Explicit Congestion Notification (ECN), as defined in RFC 3168. Some broken firewalls or gateways may have problem connecting to ECN-enabled servers. Please contact your firewall or gateway vendor for necessary updates.
--- schnapp ---
So possibly a broken router which doesn't like the ECN bits in the IP header is the cause of the problems.

You can disable sending packets which use ECN on your Linux box by echo "0" > /proc/sys/net/ipv4/tcp_ecn

Bye
Hansi

Reply by email

constantijnw
to Jonas Maebe: It is known that some people have a problem accessing www.freepascal.org, but…
Jonas Maebe wrote 21 lines
On 20 Mar 2006, at 21:46, constantijnw wrote: >>> Thanks, but I can't reach this page...... Is there anything I can >>> do to >>> make www.freepascal.org and its subdirectories accessible for me? >> >> >> The page is reachable ? > > > No, Firefox (or IE) tells me he/she is "Waiting for > www.freepascal.org..." Is a long timne problem. It is known that some people have a problem accessing www.freepascal.org, but unfortunately no one knows the exact cause. Some people think a certain kind of icmp packets are filtered by the firewall in front of the machine that hosts www.freepascal.org (something with fragmenting packets) and that this causes the problem.

Stupid me! I deleted the much appreciated contribution of Felipe. Can you send it again please?
So, you now know I'm rather clumsy sometimes, but my setup here is nothing special. When can "some people"
reach the site do you think?

Reply by email

constantijnw
to Johann Glaser: Hi! Just as an idea: Did you think of ECN problems (Explicit Congestion Negotiation, RFC…
Johann Glaser wrote 28 lines
Hi! >It is known that some people have a problem accessing >www.freepascal.org, but unfortunately no one knows the exact cause. >Some people think a certain kind of icmp packets are filtered by the >firewall in front of the machine that hosts www.freepascal.org >(something with fragmenting packets) and that this causes the problem. > > Just as an idea: Did you think of ECN problems (Explicit Congestion Negotiation, RFC 3168 http://www.rfc-editor.org/rfc/rfc3168.txt)? The http://www.kernel.org/ site has a news entry (16.1.2002), which says: --- schnipp --- Please note that kernel.org uses Explicit Congestion Notification (ECN), as defined in RFC 3168. Some broken firewalls or gateways may have problem connecting to ECN-enabled servers. Please contact your firewall or gateway vendor for necessary updates. --- schnapp --- So possibly a broken router which doesn't like the ECN bits in the IP header is the cause of the problems. You can disable sending packets which use ECN on your Linux box by echo "0" > /proc/sys/net/ipv4/tcp_ecn

Thanks. I'm on win xp behind a draytek vigor 2200 router, firmware v.2.3.6. Anyone who knows
how to configure this thing so this problem is solved?

Reply by email

Felipe Monteiro de Carvalho
to constantijnw

Ok, as requested, I´m pasting again the contents of the wiki page. =)

Writing portable code regarding the processor architecture

From FPCWiki

There are several main issues when writing code which is portable regarding the processor architecture: endianness and 32 vs. 64 bit processors.
Table of contents [showhide]
1 Endianness
2 Alignment
3 32 Bit vs. 64 Bit
4 Calling conventions

4.1 x86
4.2 ARM
4.3 68K
[edit]
Endianness

Endianness is the way how values larger than a byte (e.g. 16/32/64-bit integers) are stored by the processor.

Generally there are two ways:

1. Store the lowest value on the lowest address; longint(4) encoded as 04 00 00 00 (little endian
(http://en.wikipedia.org/wiki/Little_endian))
2. Store the highest value on the lowest address; longint(4) encoded as 00 00 00 04 (big endian
(http://en.wikipedia.org/wiki/Big_endian))

This is generally a given choice per processor family, but some families of processors can be either big endian or little endian depending on the mainboard they are attached to (ARM, PPC).

The best known little endian processor family is x86, the processor family used in PCs, and its brethren x86-64. Typical big endian processors are PPC (usually, see above note), and m68k (http://en.wikipedia.org/wiki/68k), many older systems such as the PDP-11 (http://en.wikipedia.org/wiki/PDP-11) and HP3000 (http://en.wikipedia.org/wiki/HP3000) minicomputers, and mainframes such as the IBM 370 (http://en.wikipedia.org/wiki/IBM_370) (Z series).

Since TCP/IP specifies that all protocol header structures that go over the wire should be big endian, so this notation is sometimes also refered to as network order.

Endianness is important

1. when exchanging data between different architectures
2. when accessing data sometimes as (an array of) a larger type, like integer, and sometimes as (an array of) a byte.

An example of the latter:

    Type
         Q = RECORD
             case boolean of
                 true: (i:integer);
                 false: (p:array[1..4] of byte)
         END;
    Var x:^Q ;
    begin
         new(x);
         x^.i:=5;
         if x^.p[1]=5 then
             writeln(x^.p[1]); writeln('Your machine is Little Endian')
         else
             if x^.p[4]=5 then
                 writeln(x^.p[1]); Writeln('Your machine is Big Endian')
             else
                 writeln(x^.p[1],' ',x^.p[2],' ',x^.p[3],' ',x^.p[4]);
writeln('Your machine''s endianness is indeterminate; please report
the results to the compiler development team');
         writeln;
        {Make it wait so we can see the results }
         write('Press enter when you finish reading this ');
         readln;
    end.

On little endian machines (PCs), the above code will write 5 (since longint(5) is stored as 05 00 00 00 in memory), while on big endian machines (e.g. Powermacs) it will write 0 (since longint(5) is stored as 00 00 00 05 in memory). (If you get the report your machine is indeterminate, please report on this wiki page what processor does this and what you get!)

To determine the endianness of the processor, use the ENDIAN_BIG or ENDIAN_LITTLE (or FPC_LITTLE_ENDIAN and FPC_BIG_ENDIAN starting from version 1.9) defines that are defined by freepascal automatically depending on the processor.
[edit]
Alignment

Some processors will allow improperly aligned data but with reduced efficiency (IBM 370/zSeries). Some processors generate hardware processor exceptions when data is badly aligned (e.g. Alpha or ARM). Sometimes the hardware exceptions are caught and fixed using emulation by the OS, but this is very slow, and should be avoided. This can also cause records to have different sizes, so always use sizeof(recordtype); as size of a record. If you define a packed record, try to ensure that data is naturally aligned, if possible. Some processors only have alignment requirements for certain types of data, like floating point (e.g. older PowerPCs).

To check if the CPU requires proper alignment, check the FPC_REQUIRES_PROPER_ALIGNMENT (version 1.9 and higher) define. On 32 Bit CPUs this usually means that data up to a size of 4 must be naturally aligned. If you want to access unaligned data, use the move procedure to move it to an aligned location before processing it. The move procedure takes care of unaligned data and handles it properly.

There are multiple strategies for aligning:

* align every field on a multiple of a certain value (typically a power of two, 1,2,4,8. 1 is equivalent to "packed")
* pad before every field such that it is aligned on a multiple of its size (so a longint on 4, an int64 on 8 bytes etc). This is typically done by C compiler, which is why FPC calls it {$packrecords C}.

(For arrays or nested records, the size of their largest sub unit is used)

Mac OS X {$packrecords C} seems to pad the entire record at the end to make it a certain size. This is still being investigated, and probably will be fixed in compiler.
[edit]
32 Bit vs. 64 Bit

To achive maximum compatiblity with older code, FPC doesn't change the size of predefined data types like integer, longint or word when changing from 32 to 64 Bit. However, the size of a pointer is 8 bytes on a 64 bit architecture so constructs like longint(pointer(p)) are doomed to crash on 64 bit architectures. However, to allow you to write portable code, the FPC system unit introduces the types PtrInt and PtrUInt which are signed and unsigned integer data types with the same size as a pointer.

Keep in mind that the size change of the "pointer" type also affects record sizes. If you allocate records with fixed sizes, and not with new or with getmem (<x>,sizeof(<x>)), this will have to be fixed. [edit]
Calling conventions

* For IBM 370 and zSeries, see the ZSeries page for further discussion.

[edit]
x86
[edit]
ARM
[edit]
68K

Reply by email

constantijnw
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
Ok, as requested, I´m pasting again the contents of the wiki page. =)

Great, thanks.

Besides the differences in pointer sizes, should all 32 bit integer types be changed to 64 bit integer types.
Any other things to deal with?

Reply by email

Alexandre Leclerc
to Jonas Maebe: It is known that some people have a problem accessing www.freepascal.org, but…
Jonas Maebe wrote 17 lines
On 20 Mar 2006, at 21:46, constantijnw wrote: >>> Thanks, but I can't reach this page...... Is there anything I can >>> do to >>> make www.freepascal.org and its subdirectories accessible for me? >> >> The page is reachable ? > > No, Firefox (or IE) tells me he/she is "Waiting for > www.freepascal.org..." Is a long timne problem. It is known that some people have a problem accessing www.freepascal.org, but unfortunately no one knows the exact cause. Some people think a certain kind of icmp packets are filtered by the firewall in front of the machine that hosts www.freepascal.org (something with fragmenting packets) and that this causes the problem.

It works from here, but the websites are always very very slow to come. Lazarus, freepascal, doc, etc. everything related to *freepascal.org is slow. At home on my 56kbps modem it is almost as fast as with my 3mb dsl at work. ;) -- When it downloads a file it goes fast, but it seams that resolving/requesting the content to be download by the webbrowser is a pain. I tought it was the server of freepascal, not really my connection...

I don't know why.

Alexandre Leclerc

Reply by email

Florian Klaempfl
to Alexandre Leclerc
Alexandre Leclerc wrote 22 lines
On 3/20/06, Jonas Maebe wrote: > On 20 Mar 2006, at 21:46, constantijnw wrote: > >>>> Thanks, but I can't reach this page...... Is there anything I can >>>> do to >>>> make www.freepascal.org and its subdirectories accessible for me? >>> The page is reachable ? >> No, Firefox (or IE) tells me he/she is "Waiting for >> www.freepascal.org..." Is a long timne problem. > It is known that some people have a problem accessing > www.freepascal.org, but unfortunately no one knows the exact cause. > Some people think a certain kind of icmp packets are filtered by the > firewall in front of the machine that hosts www.freepascal.org > (something with fragmenting packets) and that this causes the problem. It works from here, but the websites are always very very slow to come. Lazarus, freepascal, doc, etc. everything related to *freepascal.org is slow. At home on my 56kbps modem it is almost as fast as with my 3mb dsl at work. ;) -- When it downloads a file it goes fast, but it seams that resolving/requesting the content to be download by the webbrowser is a pain. I tought it was the server of freepascal, not really my connection...

Well, this is strange:
www.freepascal.org
www.lazarus.freepascal.org
wiki.lazarus.freepascal.org

are three different machines with different OSes in different countries :)

Show quoted text 9 lines
I don't know why. -- Alexandre Leclerc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Alexandre Leclerc
to Florian Klaempfl
Florian Klaempfl wrote 30 lines
Alexandre Leclerc wrote: > On 3/20/06, Jonas Maebe wrote: >> On 20 Mar 2006, at 21:46, constantijnw wrote: >> >>>>> Thanks, but I can't reach this page...... Is there anything I can >>>>> do to >>>>> make www.freepascal.org and its subdirectories accessible for me? >>>> The page is reachable ? >>> No, Firefox (or IE) tells me he/she is "Waiting for >>> www.freepascal.org..." Is a long timne problem. >> It is known that some people have a problem accessing >> www.freepascal.org, but unfortunately no one knows the exact cause. >> Some people think a certain kind of icmp packets are filtered by the >> firewall in front of the machine that hosts www.freepascal.org >> (something with fragmenting packets) and that this causes the problem. > > It works from here, but the websites are always very very slow to > come. Lazarus, freepascal, doc, etc. everything related to > *freepascal.org is slow. At home on my 56kbps modem it is almost as > fast as with my 3mb dsl at work. ;) -- When it downloads a file it > goes fast, but it seams that resolving/requesting the content to be > download by the webbrowser is a pain. I tought it was the server of > freepascal, not really my connection... Well, this is strange: www.freepascal.org www.lazarus.freepascal.org wiki.lazarus.freepascal.org are three different machines with different OSes in different countries :)

Well, I'm more confuse. :) The only thing I know is that lazarus is the slowest to is goes not so bad.

This is my ISP then. I'll try to browse from another place. Maybe it will go faster.

Regards.

Alexandre Leclerc

Reply by email