Recent

Author Topic: Maximum number of Switches in a CASE  (Read 1810 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 2635
Re: Maximum number of Switches in a CASE
« Reply #15 on: July 08, 2024, 10:04:14 am »
Jamie,

don't forget the "big" difference between a C-Switch and FPC-Case of: Fall-Through!!

I'd first analyse the C-Switch, if there are Conditions for a Fall-Through (which indicate a nested Case of on the FPC-side. See also Thaddy's comment)
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

MarkMLl

  • Hero Member
  • *****
  • Posts: 7518
Re: Maximum number of Switches in a CASE
« Reply #16 on: July 08, 2024, 10:25:42 am »
If there is a case statement that has thousands of choices there is probably a better data structure to implement it.

A case statement based on ordinals can't be improved by static analysis, since it is based on a jump table.

Quote
I wonder what the limitations are for case statements within case statements....

I'd expect those to be precisely the same as for the outer case. Fundamentals of block structured compilers... I think I've tried to make the point that understanding that sort of thing is useful to you in the past.

Having said which... where a language retained some sort of intermediate representation during execution, i.e. relying on a JITC etc., it might be possible to optimise by breaking the original jump table up into smaller chunks some of which relied on locality of code i.e. how much would fit into a cache, using near jumps where possible and so on. The end result might possibly be more efficient than the initial jump table, but there would be a long period of runtime optimisation where the implied "instrumentation" of the code would result in its running significantly less efficiently than the original.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018