Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: naked switches Date: Thu, 08 Jul 2021 01:00:29 -0700 Organization: None to speak of Lines: 39 Message-ID: <8735sp8cbm.fsf@nosuchdomain.example.com> References: <06a0049a-2d7d-40f0-899a-fb35c9a15d5fn@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="44779ad397759924e0661cc3b6d84a15"; logging-data="29299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vGtUpbB/iiAw36I/rUmwj" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:WpZyKfDPkQI+TVkDM45HWJAtA2A= sha1:TteDbcz78o1tuEPqwOSv/az5+Jk= Xref: csiph.com comp.lang.c:161741 Robert Finch writes: > I have been working on a C/C++ like compiler. One feature supported in > the compiler is naked switches. A naked switch omits the range > checking code that is normally associated with the switch > statement. Omitting this code can improve performance at the risk of a > crash if invalid cases are processed. I am wondering if there is a > similar option in other C compilers? Or would this just be an > automatic optimization at high levels? What range checking code are you referring to? Can you give an example in C that demonstrates the change in behavior? How does a default: label affect it? > Normal Switch: > > ; switch(x) { > ldo $t0,64[$fp] > sge $t1,$t0,#1 ; x varies between 1 and 12 > sle $t2,$t0,#12 > and $t1,$t1,$t2 > beq $t1,TestSwitch_89 > sub $t0,$t0,#1 > sll $t0,$t0,#4 > ldo $t0,TestSwitch_116[$t0] > jmp $t0 > > Naked Switch > ; switch(x; naked) { > ldo $t0,64[$fp] > sub $t0,$t0,#1 > sll $t0,$t0,#4 > ldo $t0,TestSwitch_144[$t0] > jmp $t0 > -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */