Gale Paeper wrote:
Now, getting to the relatively large GPC difference with a:=round(a). After looking at the differences in generated code between the compilers (assembly code and algorithms implemented), I think the main difference is that GPC supports rounding to 64 bit integers and CW Pascal only supports rounding to 32 bit integers.
Yes, that's what GPC does. And since it's generally not obvious from the context when 32 bit are sufficient, and we don't want to give up the 64 bit range, the best we could do is probably to detect some special cases to optimize (such as assignment of the result to a 32 bit integer -- which doesn't apply in this test, anyway) ...
As a general PPC performance rule of thumb, it is always a "win" to minimize the number of floating point to/from integer format conversions since the conversion is relatively expensive. With a:=round(a), two conversions are performed (64 bit integers for GPC and 32 bit integers for CW Pascal). The round function involves a floating point to integer conversion and the result is then reconverted back to floating point for storing in variable 'a'. (The back-to-back conversions can't be optimized away due to the possibility of integer overflow in the floating point to integer conversion.)
If you don't require overflow detection and accept "undefined behaviour" there, it might be possible to optimize it away. (Not that I plan to do that any time soon, but it could be a possibility -- if it has any practical relevance ...)
Frank