s390x: fix cscal and zscal implementations
authorMarius Hillenbrand <mhillen@linux.ibm.com>
Mon, 14 Sep 2020 16:36:31 +0000 (18:36 +0200)
committerMarius Hillenbrand <mhillen@linux.ibm.com>
Mon, 21 Sep 2020 11:10:05 +0000 (13:10 +0200)
commit22aa81f3e587c85c5ccdcbbe2964cf5f89a00931
treee517fad8b4c73d41d74795da298fb580f36f0a07
parent77ea73f5e5579ea35b6be03bac455643b84e343d
s390x: fix cscal and zscal implementations

The implementation of complex scalar * vector multiplication for Z14
makes some LAPACK tests fail because the numerical differences to the
reference implementation exceed the threshold (as can be seen by running
make lapack-test and replacing kernel/zarch/cscal.c with a generic
implementation for comparison).

The complex multiplication uses terms of the form a * b + c * d for both
real and imaginary parts. The assembly code (and compiler-emitted code
as well) uses fused multiply add operations for the second product and
sum. The results can be "surprising", for example when both terms in the
imaginary part nearly cancel each other out. In that case, the second
product contributes more digits to the sum than the first product that
has been rounded before.

One option is to use separate multiplications (which then round the same
way) and a distinct add. Change the code to pursue that path, by (1)
requesting the compiler not to contract the operations into FMAs and (2)
replacing the assembly kernel with corresponding vectorized C code
(where change 1 also applies).

Signed-off-by: Marius Hillenbrand <mhillen@linux.ibm.com>
kernel/zarch/cscal.c
kernel/zarch/zscal.c