Use new 16-bit unsigned multiply routine that complies with C standards.

This changes unsigned 16-bit multiplies to use the new ~CUMul2 routine in ORCALib, rather than ~UMul2 in SysLib. They differ in that ~CUMul2 gives the low-order 16 bits of the true result in case of overflow. The C standards require this behavior for arithmetic on unsigned types.
This commit is contained in:
Stephen Heumann 2022-07-06 22:22:02 -05:00
parent 11a3195c49
commit 497e5c036b
3 changed files with 10 additions and 6 deletions

11
Gen.pas
View File

@ -6457,12 +6457,13 @@ procedure GenTree {op: icptr};
end {if}
else
LoadX(op^.right);
if op^.opcode = pc_mpi then
GenCall(28)
if op^.opcode = pc_mpi then begin
GenCall(28);
if rangeCheck then
GenCall(25);
end {if}
else {pc_umi}
GenCall(39);
if rangeCheck then
GenCall(25);
GenCall(94);
end; {GenMpi}

View File

@ -2049,6 +2049,7 @@ case callNum of
91: sp := @'~SINGLEPRECISION';
92: sp := @'~DOUBLEPRECISION';
93: sp := @'~COMPPRECISION';
94: sp := @'~CUMUL2';
otherwise:
Error(cge1);
end; {case}

View File

@ -262,7 +262,7 @@ ORCA/C now supports additional forms of expressions known as generic selection e
p. 311
If integer overflow occurs during signed integer multiplication, the resulting value is not predictable. Contrary to what the description in the manual implies, it will not necessarily be the low-order bits from the true product of the operands.
If integer overflow occurs during signed integer multiplication, the resulting value is not predictable. Contrary to what the description in the manual implies, it will not necessarily be the low-order bits from the true product of the operands. (Unsigned integer multiplication does give the low-order bits from the true product.)
p. 321
@ -1861,6 +1861,8 @@ int foo(int[42]);
199. If a file is open for reading and writing, it should be possible to read from it until end-of-file is encountered and then immediately write to it, but an error would be reported when the write was attempted.
200. Arithmetic operations on unsigned integer types should give the low-order bits of the true mathematical result in the event of overflow, but 16-bit unsigned multiplication did not always do this.
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.