TRUNC
As in V4, there are three possible settings for the TRUNC option: BIN, STD and OPT.
The recommended option for best performance continues to be TRUNC(OPT), as this allows the compiler the most freedom in determining the most efficient code to generate. For additional information on determining which TRUNC option to specify, see TRUNC in the Enterprise COBOL for z/OS® Programming Guide.
The cost of using TRUNC(STD) has been improved compared to V4, as the divide instruction used to truncate the result back to the number of digits in the PICTURE clause of the BINARY receiving data item is only conditionally executed in V6. The compiler inserts a runtime check for overflow and will branch around the divide if no truncation is required.
However, better performance is still possible when using TRUNC(OPT) as no runtime overflow checks or divide instructions are required at all.
TRUNC(BIN) will often result in poorer performance, and is usually the slowest of the three TRUNC suboptions. Although no divides (conditional or otherwise) are required in order to truncate results, the full 2, 4 or 8 byte value is considered significant and therefore intermediate results grow that much more quickly and require conversions to larger or more complex data types.
For example, when adding two BINARY PIC 9(10) values with TRUNC(STD) or TRUNC(OPT), the maximum result size is 11 digits. No overflow is possible. The addition can be performed using binary arithmetic. When performing the same addition with TRUNC(BIN), each operand can have up to 18 digits, and the maximum result size is 19 digits. This may overflow. Therefore, the operands must be converted to packed decimal before performing the addition. This is slower.
Similarly, when multiplying two BINARY PIC 9(10) values with TRUNC(STD) or TRUNC(BIN), the maximum result size is 20 digits. This is too large for a binary operation, but not too large for packed decimal arithmetic. When performing the same multiplication with TRUNC(BIN), each operand can have up to 18 digits, and the maximum result size is 36 digits. Because hardware support for packed decimal arithmetic is limited to 31 digits, this multiplication requires an expensive runtime call.
Specifically, adding
two BINARY PIC 9(10) items together is 10% faster using TRUNC(OPT)
than TRUNC(STD), and 97% faster using TRUNC(OPT) than TRUNC(BIN).
In one program with a significant amount of binary arithmetic setting TRUNC(BIN) results in a 76% slowdown compared to TRUNC(STD). This performance difference is due to the runtime library calls required for the larger intermediate result sizes.
See BINARY (COMP or COMP-4) for a more detailed discussion and study of BINARY data and interaction with TRUNC suboptions.