Hello, On Thu, 29 Jun 2023, Krister Walfridsson wrote:
> > The thing with signed bools is that the two relevant values are -1 (true) > > and 0 (false), those are used for vector bool components where we also > > need them to be of wider type (32bits in this case). > > My main confusion comes from seeing IR doing arithmetic such as > > <signed-boolean:32> _127; > <signed-boolean:32> _169; > ... > _169 = _127 + -1; > > or > > <signed-boolean:32> _127; > <signed-boolean:32> _169; > ... > _169 = -_127; > > and it was unclear to me what kind of arithmetic is allowed. > > I have now verified that all cases seems to be just one operation of this form > (where _127 has the value 0 or 1), so it cannot construct values such as 42. > But the wide signed Boolean can have the three different values 1, 0, and -1, > which I still think is at least one too many. :) It definitely is. For signed bool it should be -1 and 0, for unsigned bool 1 and 0. And of course, arithmetic on bools is always dubious, that should all be logical operations. Modulo-arithmetic (mod 2) could be made to work, but then we would have to give up the idea of signed bools and always use conversions to signed int to get a bitmaks of all-ones. And as mod-2-arithmetic is equivalent to logical ops it seems a bit futile to go that way. Of course, enforcing this all might lead to a surprising heap of errors, but one has to start somewhere, so ... > I'll update my tool to complain if the value is outside the range [-1, > 1]. ... maybe not do that, at least optionally, that maybe somewhen someone can look into fixing that all up? :-) -fdubious-bools? Ciao, Michael.