cowgol icon indicating copy to clipboard operation
cowgol copied to clipboard

small optimization: % poweroftwo -> & poweroftwo-1

Open shattered opened this issue 1 year ago • 2 comments

shattered avatar May 07 '24 13:05 shattered

Thanks --- that's definitely worth having. There are likely to be edge conditions regarding signed values, though. Could you make sure that there are tests for this case?

davidgiven avatar May 07 '24 15:05 davidgiven

I think divrem tests already cover this:

print("four%two==zero"); if four%two==zero then yes(); else no(); end if;

shattered avatar May 07 '24 15:05 shattered

Sorry, I got distracted by other things... also I didn't spot that this just concerns REMU, and not REMS.

Yes, all looks good. Merging.

Trying to do the same optimisation for signed values looks like it'll be nightmare. Getting the result sign right was bad enough just for the normal divmod calculation.

davidgiven avatar May 18 '24 22:05 davidgiven