5 ms·
At first I thought the super-optimizer had made a mistake because the results are not the same but I think the error is in the original where line 6 should be
by damianknz 12y ago
At first I thought the super-optimizer had made a mistake because the results are not the same but I think the error is in the original where line 6 should be
return -1;
Anyway, using assembler for CPU I made up in my head just now, how about
shl r0,1
and r0,1
- danbruc 12y agoDo you mean (r0 << 1) & 1? That would always yield zero.
- david-given 12y agoI don't think that'll work. Consider the positive integer 0b01: the shift yields 0b10, then the and yields 0. I've actually tried to come up with a simpler example. It's tougher than you'd think, and you pretty much have to do weird stuff with flags. The superoptimiser trick is pretty neat.
- vardump 12y agoFaster code for same end result is: xor r0, r0