On 18/12/2019 12.20, Joel Holdsworth wrote:
[...]
const Packet<uint32_t> E = a * b; // Some expensive calculation
const Packet<uint32_t> x = E + c;
const Packet<uint32_t> y = E + c;
This results in the value of E being stored onto the stack, and then
reloaded twice to calculate x and y.
But of course, I just want E to stay in register.
I'm pretty sure that as long as `E` fits into a (set of) register(s) no
reasonable compiler will store this on the stack, unless it actually
runs out of register space, see e.g.:
https://godbolt.org/z/WxEeNF
Even if the small intermediate was stored on the stack, I assume the
overhead should be negligible.
The problem is different, if you would want to apply your expressions at
once on a set of large arrays. Something like the following will very
likely require `E` getting stored or evaluated twice (unless the
compiler is really smart detecting duplicated code or load after store).
ArrayXi a,b,c,d; // input from somewhere
ArrayXi E = a*b; // some expensive operations
ArrayXi x = E+c, y=E+d;
For solving that problem you may be interested in:
https://gitlab.com/libeigen/eigen/issues/984
[...]
I was wonder if there needs to be a new intermediate-friendly variant of
Eigen::Array where the data is stored in arrays of SIMD types instead of
plain-old-C arrays.
A while ago I started thinking about implementing Meta-Packets, but
mostly to clean-up the current SIMD code base:
https://gitlab.com/libeigen/eigen/issues/692
This includes a proof-of-concept implementation, but I never actually
continued working on that.
Cheers,
Christoph
--
Dr.-Ing. Christoph Hertzberg
Besuchsadresse der Nebengeschäftsstelle:
DFKI GmbH
Robotics Innovation Center
Robert-Hooke-Straße 5
28359 Bremen, Germany
Postadresse der Hauptgeschäftsstelle Standort Bremen:
DFKI GmbH
Robotics Innovation Center
Robert-Hooke-Straße 1
28359 Bremen, Germany
Tel.: +49 421 178 45-4021
Zentrale: +49 421 178 45-0
E-Mail: [email protected]
Weitere Informationen: http://www.dfki.de/robotik
-------------------------------------------------------------
Deutsches Forschungszentrum für Künstliche Intelligenz GmbH
Trippstadter Straße 122, D-67663 Kaiserslautern, Germany
Geschäftsführung:
Prof. Dr. Antonio Krüger (Vorsitzender)
Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats:
Dr. Gabriël Clemens
Amtsgericht Kaiserslautern, HRB 2313
-------------------------------------------------------------