Data Alignment (Word Size) (NM) (new) [ Introduction to MPE XL for MPE V Programmers Migration Guide ] MPE/iX 5.0 Documentation
Introduction to MPE XL for MPE V Programmers Migration Guide
Data Alignment (Word Size) (NM)
(new)
MPE V/E and MPE XL have different word sizes. MPE V/E and MPE XL CM have
a 16-bit word size; MPE XL has a 32-bit word size. Many data structures
that are aligned on 16-bit boundaries in MPE V/E are aligned on 32-bit
boundaries in MPE XL NM. In MPE XL NM, 32-bit data types are aligned on
32-bit boundaries, by default, to improve performance.
Converting Data between CM and NM
One way to convert data to use across formats is by choosing the
appropriate compiler option. MPE XL compilers offer two directives:
HP3000_16 specifies MPE V/E or MPE XL CM alignment, and HP3000_32
specifies MPE XL NM alignment.
For example, if you are compiling an application that will be run in
Native Mode, but will use MPE V/E compatible data files, you would select
the HP3000_16 compiler directive. This NM option causes the compiler to:
* Align data in records on 16-bit boundaries (as in MPE V/E and MPE XL
CM), instead of on 32-bit boundaries (as in MPE XL NM).
* Select HP3000 format for real numbers, (as in MPE V/E and MPE XL CM),
instead of IEEE floating point representation, (as in MPE XL NM.)
Using the HP3000_16 compiler directive will maintain data alignment and
format compatibility with MPE V/E, but will also impact the use of NM
data in the program.
For an application to use both native aligned data files and MPE V/E
aligned data files, you could specify in the program record definitions
to force MPE XL or MPE V/E aligned records on a structure-by-structure
basis.
For example, when you need to maintain CM data alignment and format, but
also need to create NM data structures, the individual structures that
must be in NM format should be explicitly defined as HP3000_32 while
operating under the HP3000_16 directive.
Another alternative is to create a program that reads data in one mode
and writes it in another.
Data format conversion takes CPU time. To maximize performance, try to
convert your files to the NM format only once.
The considerations for converting files from MPE V/E to MPE XL NM vary
depending on the language. Table 10-1 and Table 10-2 show data type
correspondences for MPE XL NM intrinsics and supported languages.
Table 10-1. NM Data Types: Primitive, Generic, HP Business BASIC/XL, HP C/XL
-------------------------------------------------------------------------------------------------
| | | | |
| Primitive Type | Intrinsics | HP Business | HP C/XL |
| | | BASIC/XL | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Character | C | $ | CHAR or |
| | | dimension as | UNSIGNED |
| | | 1 character | CHAR |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | U16 | N/A | UNSIGNED |
| 16-bit | | | SHORT INT |
| unsigned | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | U32 | N/A | UNSIGNED INT |
| 32-bit | | | or UNSIGNED |
| unsigned | | | LONG INT |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | U64 | N/A | N/A |
| 64-bit | | | |
| unsigned | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | I16 | SHORTINT | SHORT INT |
| 16-bit | | or subrange | |
| signed | | [-32768..32767] | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | I32 | INTEGER | INT or ENUM |
| 32-bit | | | |
| signed | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Integer: | I64 | N/A | N/A |
| 64-bit | | | |
| signed | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Real | R32 | SHORTREAL | FLOAT |
| 32-bit | | | |
| (Single- | | | |
| Precision) | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Real | R64 | REAL | DOUBLE |
| 64-bit | | | |
| (Double- | | | |
| Precision) | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Decimal: Packed | N/A | N/A | N/A |
| or Unpacked | | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Decimal: | N/A | Short Decimal | N/A |
| floating-point | | or Decimal | |
| | | | |
-------------------------------------------------------------------------------------------------
Table 10-2. NM Data Types: Primitive, HP COBOL
II/XL, HP FORTRAN
77/XL, and HP Pascal/XL
--------------------------------------------------------------------------------------------------
| | | | |
| Primitive Type | HP COBOLII/XL | HP FORTRAN | HP Pascal/XL |
| | & HP RPG/XL | 77/XL | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Character | USAGE | CHARACTER | CHARACTER |
| | DISPLAY | | |
| | or group item | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC 9 to | LOGICAL OR | 0..65535 |
| 16-bit | PIC 9(4) | LOGICAL*2 | or any 16-bit |
| unsigned | COMP | | SUBRANGE |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC 9(5) to | LOGICAL OR | Any 32-bit |
| 32-bit | PIC 9(9) | LOGICAL*4 | subrange |
| unsigned | COMP | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC 9(10) to | N/A | N/A |
| 64-bit | PIC 9(18) | | |
| unsigned | COMP | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S(9) to | INTEGER or | SHORTINT or |
| 16-bit | PIC S9(4) | INTEGER *2 | any 16-bit |
| signed | COMP | | subrange |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9(5) to | INTEGER or | INTEGER or |
| 32-bit | PIC S9(9) | INTEGER *4 | any 32-bit |
| signed | COMP | | subrange |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Integer: | PIC S9(10) to | N/A | N/A |
| 64-bit | PIC S9(18) | | |
| signed | COMP | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Real | N/A | REAL or | REAL |
| 32-bit | | REAL*4 | |
| (Single- | | | |
| Precision) | | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Real | N/A | DOUBLE | LONGREAL |
| 64-bit | | PRECISION | |
| (Double- | | or REAL*8 | |
| Precision) | | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Decimal: Packed | USAGE | N/A | N/A |
| | COMP-3 | | |
| | | | |
--------------------------------------------------------------------------------------------------
| | | | |
| Decimal: | | N/A | N/A |
| Unpacked | | | |
| | | | |
--------------------------------------------------------------------------------------------------
NOTE It is a recommended programming practice to pass character data
between languages by using COBOL II alphanumeric data, HP FORTRAN
77 character variables (using $ALIAS with a specified language
option), or Pascal packed arrays of char.
Converting COBOL files. Characteristics of COBOL native alignment are:
* 32-bit aligned on 01 level items, 77 level items, and SYNC items (if
SYNC32 is specified).
* All other data and structures are byte-aligned.
COBOL/V and COBOL/XL have incompatibilities due to data alignment:
indexed data items, and synchronized data items.
COBOL II alphanumeric data is represented as a byte array. A byte
pointer to the first byte is passed by reference.
For further information, refer to HP COBOL II/XL Migration Guide
(31500-90004).
Converting FORTRAN Files. Native alignment of some data types in HP
FORTRAN 77/XL is different from that of HP FORTRAN 77/V, as shown in
Table 10-3. This results in COMMON block layout and data layout
differences in files.
Table 10-3. FORTRAN 77 Native Alignment
----------------------------------------------------------------------------------------------
| DATA TYPE | MPE V/E | MPE XL |
| | Alignment | Alignment |
----------------------------------------------------------------------------------------------
| CHARACTER | 8-BIT | 8-BIT |
----------------------------------------------------------------------------------------------
| INTEGER*2 | 16-BIT | 16-BIT |
| LOGICAL*2 | | |
----------------------------------------------------------------------------------------------
| INTEGER*4 | | |
| LOGICAL*4 | 16-BIT | 32-BIT |
| REAL*4 | | |
----------------------------------------------------------------------------------------------
| REAL*8 | | |
| DOUBLE PRECISION | | |
| COMPLEX*8 | 16-BIT | 64-BIT |
| COMPLEX*16 | | |
| COMMON | | |
----------------------------------------------------------------------------------------------
Figure 10-1 shows an example of how HP FORTRAN 77/XL aligns a COMMON
block in CM and Native Mode (default).
Figure 10-1. HP FORTRAN 77 COMMON Block Data Alignment Example
To align data for maximum performance, the compiler leaves a word, or a
word portion, blank or unused. HP FORTRAN 77/V uses the unused 16-bit
sections, and the COMMON block is more compact.
An HP FORTRAN 77 character variable is represented as a byte array. A
byte pointer to the byte array and a word indicating the length of the
character variable are passed by reference. You must use the ALIAS
directive with a language option to make the compiler pass only a pointer
to the character array.
The procedure for converting FORTRAN binary files from MPE V/E to MPE XL
format is as follows:
1. Real data from file in a subroutine with $HP3000_16 ON.
2. Pass the data to a subroutine that has $HP3000_16 OFF.
3. Call the intrinsic HPFCONVERT to convert real numbers from MPE V/E
to MPE XL floating-point format.
4. Write the data out to a new file.
NOTE A program or subroutine that has $HP3000_16 ON cannot call the
HPFCONVERT intrinsic.
For further information, refer to HP FORTRAN 77/XL Migration Guide
(31501-90004).
Converting Pascal Files. Table 10-4 shows the alignment of simple data
types on HP Pascal/V and HP Pascal/XL.
Table 10-4. Pascal Native Alignment
-----------------------------------------------------------------------------------------------------
| | | |
| Variable Types | HP Pascal/V | HP Pascal/XL |
| | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| | Allocation | Alignment | Allocation | Alignment |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| BOOLEAN | 1 byte | Byte | 1 byte | Byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| CHAR | 1 byte | Byte | 1 byte | Byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | |
| ENUMERATION | 1-256 elements: | 1-256 elements: |
| | | |
| |
| | | | | |
| ENUMERATION | 1 byte | Byte | 1 byte | Byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | |
| ENUMERATION | Any other: | 257-64K elements |
| | | |
| |
| | | | | |
| | 2 bytes | 2 byte | 2 bytes | 2 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | |
| | | Over 64K elements: |
| | | |
| |
| | | | |
| | | 4 bytes | 4 byte |
| | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| INTEGER | 4 bytes | 2 byte | 4 bytes | 4 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| POINTER | 2 bytes | 2 byte | 4 bytes | 4 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| REAL | 4 bytes | 2 byte | 4 bytes | 4 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| LONGREAL | 8 bytes | 2 byte | 8 bytes | 8 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| 0..255 | 1 byte | Byte | 1 byte | Byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| 0..65535 | 4 bytes | 2 byte | 2 bytes | 2 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| -32768..32767 | 2 bytes | 2 byte | 4 bytes | 4 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| OTHERWISE | 4 bytes | 4 byte | 4 bytes | 4 byte |
| | | | | |
-----------------------------------------------------------------------------------------------------
HP Pascal/V and HP Pascal/XL have the following incompatibilities due to
data alignment:
* MPE V/E and IEEE floating-point format.
* Data alignment of simple variables and record elements.
* String format.
* Pointers.
A Pascal packed array of char (PAC) is represented as a byte array. A
pointer to the first byte of the array is passed by reference. A Pascal
string is represented as a byte array prefixed with a word containing the
current length and suffixed with a housekeeping byte. A pointer to the
word containing the current length is passed by reference.
For detailed information on independent variable allocation and alignment
of data in records and other structures, refer to HP Pascal/XL Migration
Guide (31502-90004).
Sample Conversion Program. The following example shows a conversion
program that uses the HP3000_16 compiler directive and several data
types.
_____________________________________________
| |
| Sample Program (part 1 of 2) |
| |
| |
| $HP3000_16$ |
| Program Convertfile(file1,file2); |
| |
| CONST |
| HP3000_32bit=1; |
| IEEE_32bit=3; |
| RoundToZero=1; |
| |
| TYPE |
| ARR1=ARRAY[1..10] of -32768..32767; |
| CMrec=PACKED RECORD |
| f1:char; |
| f2:boolean; |
| f3:String[40]; |
| f4:ARR1; |
| f5:REAL; |
| END; |
| |
| NMARR1=$HP3000_32$ |
| ARRAY[1..10] of -32768..32767;|
| NMrec=$HP3000_32$ |
| PACKED RECORD |
| f1:char; |
| f2:boolean; |
| f3:String[40]; |
| f4:NMARR1; |
| f5:REAL; |
| END; |
| |
| VAR |
| file1:FILE OF CMrec; |
| file2:FILE OF NMrec; |
| V1:CMrec; |
| V2:NMrec; |
| INX:1..10; |
| status:INTEGER; |
| except:-32768..32767; |
_____________________________________________
_______________________________________________________________________________
| |
| Sample Program (part 2 of 2) |
| |
| |
| |
| PROCEDURE HPFPCONVERT; INTRINSIC; |
| |
| BEGIN (*Program Convertfile*) |
| RESET(file1); |
| REWRITE(file2); |
| WHILE NOT EOF(file1) DO |
| BEGIN (*Read and Write*) |
| READ(file1,V1); |
| WITH V1 DO |
| BEGIN (*Assign the component*) |
| V2.f1:=f1; |
| V2.f2:=f2; |
| V2.f3:=f3; |
| FOR INX:=1 to 10 DO |
| V2.f4[INX]:=f4[INX]; |
| |
| HPFPCONVERT(f5,V2.f5,HP3000_32bit,IEEE_bit,status,except,|
| RoundToZero); |
| END; (*Assign the component*) |
| WRITE(file1,V2); |
| END; (*Read and Write*) |
| END. (*Program Convertfile*) |
| |
_______________________________________________________________________________
MPE/iX 5.0 Documentation