Note, with "is" or an intrinsic that only does a range check, it can be made very fast when platform-specific.  For example, for "Result := (Value is TMyEnum);", under x86, if "l" is the Low value and "h" is the High value, then the assembly becomes this (remember that l and h are constants, so h - l is also constant and determined at compile time):

MOV   REG, Value
SUB   REG, l
CMP   REG, (h - l)
SETNA Result

If l = 0, which is very common for most enumerations, then the assembly is even simpler, not requiring a temporary register:

CMP   Value, h
SETNA Result

For "If (Value is TMyEnum) then", the SETNA instruction becomes a conditional jump.

In this instance, the intrinsic's function is similar to how "Inc(X);" is a shorthand for "X := X + 1;", there for convenience more than anything but traditionally able to produce more optimal code.

Gareth aka. Kit


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to