#113 common function tail and string tail merging

open
nobody
None
1
2006-01-29
2006-01-29
No

it would be nice to have a merging of both: common
function tails and common string tails:)

-----------8<---------------------------------------------------
/* this code is meant to show that in some cases it
pays off
to merge "common tails" of two (or more) functions.

Merging "common tails" of strings would be fine too
as noted below.
*/

#include <stdio.h>

extern unsigned int subroutine_1(void);
extern unsigned int subroutine_2(unsigned char in);
extern void dosomething(void);

extern volatile bit high_gain;
bit gain_attention = 0;

unsigned int f(void){
unsigned int result = subroutine_1();

if(high_gain){
if( result >= 0x0c00)
gain_attention = 1;
return result/16;
}
else
return result;
}

/* just some function which shares a common tail with f().
(if both return types were unsigned long
then common tail merging would be even more attractive)
*/
unsigned int g(unsigned char c){
unsigned int res = 0x001;

res |= subroutine_2(c);
dosomething();
if(!high_gain){
if( res <= 0x0c00 - 0x100)
gain_attention = 1; /* a ljmp f_common_tail_with_g
would have done! */
return res/16;
}
else
return res;
}

void main(void){
while(1){
printf("\f%04x\n", f());
printf("%04x\n", g(2)); /* I did not really mean to
add another topic but
when looking at the code
segment in the assembly
file I found that the
two printf strings in CSEG
share a few bytes:)
__str_0:
.db 0x0C
; would have been very nice to have
; __str_1: here!!
.ascii "%04x"
.db 0x0A
.db 0x00
__str_1:
.ascii "%04x"
.db 0x0A
.db 0x00
*/
}
}
#if 0
----------->8---------------------------------------------------

PS: most line breaks are mine. Some are added by
Sourceforge.
I simply hate this. Can Sourceforge's web forms ever be
transparent for at least 80 characters? It's
embarassing. I remember buying a 80x25 characters
display card for my Commodore C64 more than 20 years
ago. Sorry I won't adapt to this, it's 2006 IIRC.

1 2 3 4 5
6 7
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4 6 8 0 2 4
6 8 0 2 4 6 8 0 2 4 6 8

To make things complete: no preview either#&%$§#!!(
#endif

Discussion


Log in to post a comment.