On Dec 30, 2010, at 16:46, John Ehrman wrote:
> Could you elaborate on this statement?
>
>> In some cases the assembler, using 32-bit arithmetic, will generate
>> instructions that produce mathematically incorrect results in 64-bit
>> mode.
>
> Expression evaluation is indeed done using 32-bit arithmetic, but I can't
> see how that would "generate instructions that produce mathematically
> incorrect results in 64-bit mode":
>
> Do you mean (a) 64-bit assembly-time expressions, (b) 64-bit execution-time
> evaluations, or (c) executing in 64-bit addressing mode?
>
(b) and (c). In the sequence (I haven't traced this; simply mental simulation):
(PTF UK59311) Page 1
HLASM R6.0 2010/12/30 17.11
...
Loc Object Code Addr1 Addr2 Stmt Source Statement
000000 00000 0002C 1 NEGD64 CSECT
000000 C41C 0000 0010 00020 2 LGFRL R1,=F'2147483392'
R:1 FFFF00 3 USING 2147483392,R1
000006 4140 1200 00100 4 LA R4,-2147483392
...
000020 20 LTORG
000020 7FFFFF00 21 =F'2147483392'
In AMODE(64):
The instruction at line 2 will place x'0000 0000 7FFF FF00' in 64-bit R1.
The instruction at line 4 will add x'0000 0000 0000 0200' to it, giving:
x'0000 0000 8000 0100' in R4.
(Address arithmetic is always performed to 64 bits; overflows are not
detected; AMODE determines how many bits are stored in the target
register. 12-bit displacements are taken as unsigned quantities.)
While the result is correct modulo 2^24 and modulo 2^31 (and even
modulo 2^32), it is wildly wrong modulo 2^64 according to the source
code; it should be x'FFFF FFFF 8000 0100'. The problem exists because
the negative value was evaluated in 32-bit arithmetic.
I suspect that during base-displacement resolution a fixed-point
overflow occurred and was ignored. I'd prefer to see the overflow
detected and the statement reported as "Base and Displacement can
not be resolved." Or at least a warning issued.
Of course, the assembler doesn't know what AMODE will be in effect
when the program is executed, and the result is arguably correct
in AMODE 24 and AMODE 31. But it's unarguably incorrect in AMODE 64.
-- gil