On 2024-09-30 at 22:44:37, Junio C Hamano wrote: > "brian m. carlson" <sandals@xxxxxxxxxxxxxxxxxxxx> writes: > > > .... It is designed to be passed and returned by value, not > > pointer, and it is possible to do so in two registers on 64-bit systems. > > Similar functionality works well for error types in Rust and for the > > standard library's lldiv_t, so this should not pose a problem. > > It should not, in the sense that "any reasonable platform should be > able to pass two 64-bit word in a structure by value", but isn't it > optimizing for a wrong (i.e. have error) case? In the case where > there is no error, a "negative return is error, zero is success", > with a pointer to "more detailed error info, in case the call > resulted in an error", would let us take branch based on a zero-ness > check on an integer in a machine-natural word, without even looking > at these two words in the struct. We can adjust the first word so that it's always zero on success, in which case, because it's returned in two registers, the processor will be able to branch on a zero-ness check on one of those registers. (We can even optimize the check by looking at the low 32 bits, which will do the same for 32-bit machines as well.) The performance benefit will be the same, and I should note that Rust does this kind of thing without a problem. We did discuss passing an error accumulating argument to all functions at the contributor summit, but it didn't seem that was the way folks wanted to go: people seemed to prefer a return value. I'm totally open to other proposals here and not particularly tied to this one, but I told Emily that I'd send a proposal to the list, and so here it is. If we like this with changes or prefer something different, that's fine with me. -- brian m. carlson (they/them or he/him) Toronto, Ontario, CA
Attachment:
signature.asc
Description: PGP signature