Case .. of generates suboptimal code for contiguous ranges.

At least x86-64 and i386 I guess.

I changed my VarInt.Write implementation in !1278 (merged) from this to this (to sacrifice large cases less :D), and noticed that

var
	x: uint32;
begin
	x := random(0);
	case x of
		0 .. 9: x := 0;
		10 .. 19: x := 1;
		20 .. 29: x := 2;
	end;
end.

generates suboptimal code:

; case x of
mov edx,eax
sub edx,$09
jbe +$1D
sub edx,$01
sub edx,$09
jbe +$25
sub edx,$01
sub edx,$09
jbe +$2D
jmp +$3B

It must have been, of course:

mov edx,eax
sub edx,$0A
jb +$1D
sub edx,$0A
jb +$25
sub edx,$0A
jb +$2D
jmp +$3B

and I guess it was so at some point in time (so this must be bisectable, but I’m lazy for now). :\

@FPK2 @CuriousKit your area of expertise.

Edited Feb 02, 2026 by Rika
Assignee Loading
Time tracking Loading