Assembler Format Op Code R
l
, D2 (X
2
, 8
2
)
AU 6,0(0,13)
is executed, the two numbers are added as follows:FPR6: 43 08 21 00 Guard
Digit
Shifted number from storage: 4300 12 34 5
Sum: 4308 33 34 5
The guard digit participates in the addition but isdis carded. The unnormalized sum replaces the high-order por tion of FPR6.
If the result in FPR6 is converted to a normalized number
(42 83 3340 00 00 00 00) and is compared to the result in
FPR6 when ADD NORMALIZED was used (4283 334500 0000(0), it is apparent in this case that the use of ADD
NORMALIZED (with the retention of the guard digit) has
preserved some additional significance in the result.COmparE! (CE, CER, CD, CDR)
Assume that FPR4 contains 4300000000000000 ( = 0), and FPR6 contains 34 12 34 56 78 9A BC DE (a positive
number). The contents of the two registers are to becom pared with the following long-precision instruction:
Machine FormatOp Code Rl R2 Assembler Format Op Code R
l
, R2 CDR 4,6
When this instruction is executed, the number with the
smaller characteristic is taken from the register andright shifted until the two characteristics agree. The shifted con tents of FPR6 are 43 00000000000000, with a guard
digit of zero. Therefore, when the two numbers arecom pared, condition code 0 is set, indicating an equality.
As the above example implies, when floating-pointnum bers are compared, more than two numbers may compare
equally if one of the numbers is unnormalized. For example,
the unnormalized floating-point number 4100 1234 56 78
9ABC compares equally with all numbers of the form 3F
12 34 56 78 9ABC OX (X represents any hexadecimal num ber). When the COMPARE instruction is executed, the two
low-order digits are shifted right two places, the0 becomes
the guard digit, and the X does not participate in the
comparison.
Note, however, that when two normalized floating-point
numbers are compared, the relationship between numbers
that compare equally is unique: each digit in one number
must be identical to the corresponding digit in the other
number.310 System/370 Principles of Opera tion MULTIPROCESSING EXAMPLES
Compare andSwap (CS, CDS) The COMPARE AND SWAP and COMPARE DOUBLE AND
SWAP instructions can be used in multiprogramming or
multiprocessing environments to serialize access to counters,
control words, and other common storage areas.
Setting a Single Bit
In a multiprocessing system, two central processors have
access to the same main storage, and both can fetch, modify,
and store data in the same locations (such as in a systemcon trol block). In this configuration, if the OR (immediate) in struction is used to modify storage, such as when setting a
flag bit, program logic errors may occur.
Example of a Program Failure UsingOR Immediate
Assume that two independently processing programs wish to
set different bits to one in a common byte in storage. The
following example shows how the use of the instructionOR immediate (01) can fail to accomplish this, if the programs
are executed nearly simultaneously on two differentCPUs. One of the possible error situations is depicted.
Execution of Instruction01 FLAGS,X'01' on CPU A
FetchFLAGS X'OO' OR X'Ol' into X'OO' Store X'Ol' into FLAGS Execution of Instruction 01 FLAGS,X'80' on FLAGS CPU B X'OO' X'OO' X'OO' X'OO' X'80' X'Ol' Fetch FLAGS X'OO' OR X'80' into X'OO' Store X'80' into FLAGS FLAGS should have value of X'8l' following both updates.
The problem shown here is that the value stored by the01 instruction executed on CPU A overlays the value that was
stored byCPU B. The X'80' flag bit was erroneously turned
off, and the program executing onCPU B now has invalid
data.
TheCOMPARE AND SWAP (CS) instruction is included
in System/370 to overcome this and similar problems. TheCS instruction first checks the value of a storage location
and then modifies it only if it is the same as the program
expects; normally, this would be a previously fetched value.
If the location is not what the program expects, then thelo cation is not modified, but rather the current value of the
location is loaded into a general register, in preparation for
the program to loop back and try again. During theCS execution, no other CPU can access the subject storage
location.
The following instruction sequence shows how theCS in struction can be used to update a single bit in storage.
Assume that FLAGS is the first byte of a word in storage
called"WORD."
l
,
2
, 8
2
)
AU 6,0(0,13)
is executed, the two numbers are added as follows:
Digit
Shifted number from storage: 43
Sum: 43
The guard digit participates in the addition but is
If the result in FPR6 is converted to a normalized number
(42 83 33
FPR6 when ADD NORMALIZED was used (4283 3345
NORMALIZED (with the retention of the guard digit) has
preserved some additional significance in the result.
Assume that FPR4 contains 43
number). The contents of the two registers are to be
Machine Format
l
,
When this instruction is executed, the number with the
smaller characteristic is taken from the register and
digit of zero. Therefore, when the two numbers are
As the above example implies, when floating-point
equally if one of the numbers is unnormalized. For example,
the unnormalized floating-point number 41
9A
12 34 56 78 9A
low-order digits are shifted right two places, the
the guard digit, and the X does not participate in the
comparison.
Note, however, that when two normalized floating-point
numbers are compared, the relationship between numbers
that compare equally is unique: each digit in one number
must be identical to the corresponding digit in the other
number.
Compare and
SWAP instructions can be used in multiprogramming or
multiprocessing environments to serialize access to counters,
control words, and other common storage areas.
Setting a Single Bit
In a multiprocessing system, two central processors have
access to the same main storage, and both can fetch, modify,
and store data in the same locations (such as in a system
flag bit, program logic errors may occur.
Example of a Program Failure Using
Assume that two independently processing programs wish to
set different bits to one in a common byte in storage. The
following example shows how the use of the instruction
are executed nearly simultaneously on two different
Execution of Instruction
Fetch
The problem shown here is that the value stored by the
stored by
off, and the program executing on
data.
The
in System/370 to overcome this and similar problems. The
and then modifies it only if it is the same as the program
expects; normally, this would be a previously fetched value.
If the location is not what the program expects, then the
location is loaded into a general register, in preparation for
the program to loop back and try again. During the
location.
The following instruction sequence shows how the
Assume that FLAGS is the first byte of a word in storage
called