COBOL COMP-3 moves now execute faster
GCC's COBOL frontend optimizes COMP-3 to COMP-3 moves by avoiding unnecessary binary conversions, directly manipulating packed-decimal bytes for improved perfo…
The GCC COBOL compiler now performs COMP-3 to COMP-3 moves more efficiently by directly manipulating packed-decimal representations. Previously, these moves involved a slower intermediate conversion to binary and back. This change bypasses that overhead, either directly moving bytes or performing a half-byte shift when necessary, resulting in faster execution. The implementation involved refactoring move-related functionality into a new move.cc file.
In Details
This change in the COBOL frontend optimizes numeric MOVE operations involving COMP-3 data types. COMP-3 (packed-decimal) stores two decimal digits per byte, with the sign in the last nibble. Previously, genapi.cc implemented COMP-3 to COMP-3 moves via a generic binary conversion path. The new move.cc introduces specialized logic to recognize COMP-3 to COMP-3 moves and perform direct byte manipulation or a nibble shift, significantly reducing overhead for common COBOL data transformations. This affects code generation efficiency for COBOL applications heavily reliant on packe…
For Context
In COBOL programming, COMP-3 is a way to store numbers efficiently, packing two decimal digits into each byte. When your program moves a number from one COMP-3 variable to another, the compiler needs to translate this operation into low-level machine instructions. This commit improves how the GCC compiler handles these COMP-3 to COMP-3 moves. Previously, the compiler would convert the packed-decimal number into a binary format, and then convert it back to packed-decimal, which was inefficient. Now, the compiler directly moves or subtly shifts the bytes that represent the packed-decimal number, avoiding the costly intermediate conversions. This makes programs that frequently use COMP-3 numbers run faster, as the compiler generates more optimized code for these common data manipulations.