Paul Koning
2018-10-28 17:39:16 UTC
I was reviewing some back end code that handles integer values of various sizes, and got confused reading about CONST_INT and CONST_DOUBLE.
It's pretty clear that CONST_DOUBLE is used for values bigger than HOST_WIDE_INT. But the description of INTVAL is contradictory. In some places, it states that its type is HOST_WIDE_INT; in others it says that it it "int". For example, in section 17.6 of the internals manual:
Be careful when doing this, because the result of INTVAL is an integer on the host machine. If the host machine has more bits in an int than the target machine has in the mode in which the constant will be used, then some of the bits you get from INTVAL will be superfluous.
A related problem is that it isn't clearly stated what the properties of HOST_WIDE_INT are. Judging by hwint.h, it is always specifically a 64 bit integer. If that is intended to be the case, it would be good for that to be documented. Alternatively, if the intent is that it is at least 64 bits but might be bigger, that should be stated. As it stands, I have some code I need to repair because it picks apart integer constants from INTVAL in a way that's incorrect if a 64-bit value is passed.
paul
It's pretty clear that CONST_DOUBLE is used for values bigger than HOST_WIDE_INT. But the description of INTVAL is contradictory. In some places, it states that its type is HOST_WIDE_INT; in others it says that it it "int". For example, in section 17.6 of the internals manual:
Be careful when doing this, because the result of INTVAL is an integer on the host machine. If the host machine has more bits in an int than the target machine has in the mode in which the constant will be used, then some of the bits you get from INTVAL will be superfluous.
A related problem is that it isn't clearly stated what the properties of HOST_WIDE_INT are. Judging by hwint.h, it is always specifically a 64 bit integer. If that is intended to be the case, it would be good for that to be documented. Alternatively, if the intent is that it is at least 64 bits but might be bigger, that should be stated. As it stands, I have some code I need to repair because it picks apart integer constants from INTVAL in a way that's incorrect if a 64-bit value is passed.
paul