Long Branches

Robert Firth firth at sei.cmu.edu
Tue Jan 20 07:38:57 AEST 1987


In article <6552 at alice.uUCp> ark at alice.UUCP writes:
>In article <3950006 at nucsrl.UUCP>, ram at nucsrl.UUCP writes:
>> 
>>    I have a problem in using the C compiler and VAX assembler in our local
>> 4.3BSD(VAX) site.  I have a program which has a huge(>900lines) case statement.
>> 
>>        /*   Whoever said that programmers(pro) don't use case/switch */
>> 
>> The assembler chokes on (>32K long) long branches.  Apparently
>> there is a flag "-J" for such purposes (in the assembler)
>> which does not seem to work.
>
>The trouble is that a case statement does not generate jump instructions
>on the VAX.  Instead it generates a CASE instruction.  This instruction
>also comes in three flavors: byte, word, and longword offsets.  It would
>not be enough for the assembler to translate the CASEW the compiler
>probably generates into a CASEL: the jump table must be translated from
>words to longwords too.

Sorry, the B/W/L forms refer to the size of the INDEX into the case
statement.  The displacements are always encoded as 16-bit relative
offests.

>Portable solutions?  I suppose the best bet is to make the switch statement
>smaller.  One way to do this might be to replace some of the bigger cases
>by jumps to code outside the switch statement itself.  Ick.

Replace the code in the case arms by routine calls.  A monolithic chunk of
code more than 32k bytes long might even be improved by this change.



More information about the Comp.lang.c mailing list