home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.arch
- Path: sparky!uunet!mcsun!Germany.EU.net!Urmel.Informatik.RWTH-Aachen.DE!martin
- From: martin@math.rwth-aachen.de ( Martin Schoenert)
- Subject: Re: Threaded Code
- Message-ID: <martin.713702167@bert>
- Sender: news@Urmel.Informatik.RWTH-Aachen.DE (Newsfiles Owner)
- Nntp-Posting-Host: bert.math.rwth-aachen.de
- Organization: Rechnerbetrieb Informatik / RWTH Aachen
- References: <GLEW.92Aug7185506@pdx007.intel.com> <1992Aug8.171834.8610@news.eng.convex.com> <1992Aug08.182610.6904@news.th-darmstadt.de> <martin.713456948@bert> <1992Aug10.185713.50527@news.th-darmstadt.de>
- Date: 13 Aug 92 10:36:07 GMT
- Lines: 66
-
- Ulrich Graef writes:
-
- [about whether or not a compiler must generate a range check for
- 'switch ( unsigned-char-var ) { }']
-
- The problem is, a char value and an enumeration type value
- is internally used like an integer (see the function call).
- That is the reason why I mentioned the extension to 2^16 or 2^32
- addresses (the domain of an integer).
-
- I want to make clear the conseqeuences: At every position in the
- statements a char value is converted to an integer. To generate code
- without range check with sources like your example you must change this
- for the switch statement.
-
- Well the compiler must generate code that behaves as if the following
- happens for a switch:
-
- The switch expression is evaluated.
- The value is converted to an integer.
- The integer value is compared with the values of the case labels
- (of which only one may compare equal)
- If one value compares equal,
- control is transferred to this label.
- If no value compares equal and there is a default label,
- control is transferred to the default label.
- If no value compares equal and there is no default label,
- control is transferred to the statement following the switch.
-
- However the important thing is that the code only has to behave as if
- this happens. That means that a compiler may use any information he can
- gather statically to implement a switch statement efficiently. For
- example the following statement sequence
-
- i = 1;
- switch ( i ) {
- case 2: <do-something>;
- case 3: <do-something-else>;
- default i++;
- }
-
- could well be implemented as
-
- load-immediate $i,2
-
- by a compiler (provided 'i' is not declared 'volatile'). No need for a
- conversion, a range check, or a jump table.
-
- Likewise, for the following switch statement
-
- unsigned char * pc;
-
- switch ( *++pc ) {
- ...
- }
-
- the compiler can simply use a jump table with 256 entries. There is no
- need for a range check because the compiler can detect that, even after
- the conversion, the value of the switch expression can only be one of 256
- possible values.
-
- Martin.
-
- --
- Martin Sch"onert, Martin.Schoenert@Math.RWTH-Aachen.DE, +49 241 804551
- Lehrstuhl D f"ur Mathematik, Templergraben 64, RWTH, D 51 Aachen, Germany
-