UCI integer types?
Posted: Tue Oct 28, 2014 4:08 am
The UCI protocol does not specify a minimum (or maximum) range for integers. Most C/C++ programmers probably assume int, and possibly int64_t for node counts (?)
However, in a portable world we know only sizeof(int) >= 2, which is certainly not enough. For node counts, we need 64-bit integers, to avoid overflow in long searches. For all other ints, 32-bit should be enough.
Using int64_t for UCI I/O generic code therefore seems a good idea. Problem is, manipulating 64-bit integers on 32-bit platforms can be quite slow. None of that should be on the hot path, except for node counts...
So I would like an integer type that is the largest possible that translates into efficient code. Should be at least 32-bit on 32-bit platforms, and 64-bit on 64-bit platforms. Can I assume long for that? Is there any C implementation that does not respect that? (i know the C standard does not guarantee it)
However, in a portable world we know only sizeof(int) >= 2, which is certainly not enough. For node counts, we need 64-bit integers, to avoid overflow in long searches. For all other ints, 32-bit should be enough.
Using int64_t for UCI I/O generic code therefore seems a good idea. Problem is, manipulating 64-bit integers on 32-bit platforms can be quite slow. None of that should be on the hot path, except for node counts...
So I would like an integer type that is the largest possible that translates into efficient code. Should be at least 32-bit on 32-bit platforms, and 64-bit on 64-bit platforms. Can I assume long for that? Is there any C implementation that does not respect that? (i know the C standard does not guarantee it)