Digest #229 2023-08-05

Contributions

[305] 2023-08-04 14:24:50 flaagel wrote:

proposal - Include a revised 79-STANDARD Specification for "><" To "Core Ext"

Author:

Francois Laagel

Change Log:

N/A.

Problem:

In networking code, it is often necessary to switch to a network canonical integer representation (big endian). The most commonly used platforms (Intel systems) are little endian so some byte re-ordering is necessary. 79-STANDARD covered this with a specification for "><" but it was restricted to 16 bit cell targets.

Solution:

Add the following specification for "><" to the "Core Ext" word set:

< u1 -- u2 "byte-swap" Return u2 as a representation of u1 in which all individual bytes appear in reversed order.

This allows one to convert a cell from little to big endian byte ordering and conversely.

Typical use: (Optional)

SHA-1 is specified in RFC 3174. The algorithm operates on 512 bit long blocks, the last one of which is to be padded with an extra '1' bit and as many '0' bits as needed so as to end up with a complete 512 bit block. However, the last 64 bits of the last block being 'digested' are to specify the total message length (expressed in bits and not including the padding '1' bit) as a big endian integer.

Proposal:

This should enumerate the changes to the document.

For the wording of word definitions, use existing word definitions as a template. Where possible, include the rationale for the definition.

Reference implementation:

On a 64 bit cell system (GNU Forth 0.7.3), the following code produces the expected results:

: >< ( u1 -- u2 )

R R@ $FF AND 56 LSHIFT R@ $FF00 AND 40 LSHIFT OR R@ $FF0000 AND 24 LSHIFT OR R@ $FF000000 AND 8 LSHIFT OR R@ $FF00000000 AND 8 RSHIFT OR R@ $FF0000000000 AND 24 RSHIFT OR R@ $FF000000000000 AND 40 RSHIFT OR R> $FF00000000000000 AND 56 RSHIFT OR ;

Testing: (Optional)

This should test the words or features introduced by the proposal, in particular, it should test boundary conditions. Test cases should work with the test harness in Appendix F.