stefanharjes wrote:Hi Segher,
Did you compile the code and did it work? You complained about me not posting the complete code, then I would expect that you at least tried to run it in the simulator.
In my case there is no difference in the program's output using either %d, %lli or %lld.
Stefan
Hi Stefan, I tried your code and looked at the assembler for it and variations of it. Although error messages from the compiler indicate that printf (and sprintf) understand %lld (for a signed long long) It fails to format them properly. i tried appending LL to integer constants because I was worried it might be trying to sign extend integers into long long ints but it didn't help. The compiler does understand long long ints and does appear to generate correct code when performing arithmetic but the printf fails to work properly. In your code you had result = result + i which probably wasn't the intention given what you put in the sprintf(); ie. ("a + b = %lu") This made the result look even stranger.
Incidentally, the XS1 architecture manual claims that MUL performs an unsigned word multiply with an unsigned word result. This is not what I see reading compiler output and tracing the code: I see it performing a signed multiply operation between 2 words with a signed word result.
EDIT: I have now realised that if one ignores the overflow that an unsigned multiply also works with 2's complement numbers, so it's not wrong, but as I observe below, it's perhaps not the whole story.
There is no difference between an unsigned add or subtract and a "signed" add or subtract anyway when using 2's complement arithmetic apart from the detection of overflow(which the XS1 doesn't do anyway) so the naming of these instructions as unsigned operations is not particularly instructive.
If I was feeling really keen with nothing better to do I could disassemble the implementation of printf and tell you exactly why it's broken but I'm not feeling that enthusiastic. I could be mistaken but nothing obvious seems to work.
Regards Max.