From 497e5c036bb3f29f8ffcd8c9fae88bedd1784547 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 6 Jul 2022 22:22:02 -0500 Subject: [PATCH] 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. --- Gen.pas | 11 ++++++----- Native.pas | 1 + cc.notes | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Gen.pas b/Gen.pas index 2faf765..2aed6d0 100644 --- a/Gen.pas +++ b/Gen.pas @@ -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} diff --git a/Native.pas b/Native.pas index 7947096..1de7f29 100644 --- a/Native.pas +++ b/Native.pas @@ -2049,6 +2049,7 @@ case callNum of 91: sp := @'~SINGLEPRECISION'; 92: sp := @'~DOUBLEPRECISION'; 93: sp := @'~COMPPRECISION'; + 94: sp := @'~CUMUL2'; otherwise: Error(cge1); end; {case} diff --git a/cc.notes b/cc.notes index 4c133d0..f49955c 100644 --- a/cc.notes +++ b/cc.notes @@ -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.