A
anon.asdf
Hi!
The following code is a snippet where the goto's cannot be removed
"without increasing code-size, or decreasing performance".
/*********A**************/
int var_other_thread;
// value changed by another thread
int var_this_thread;
int array[100];
#define EQUAL \
var_this_thread == var_other_thread
#define NOT_EQUAL \
var_this_thread != var_other_thread
void myfuncA(void)
{
if (EQUAL) goto label2;
label1:
var_this_thread = var_other_thread;
label2:
array[var_this_thread] = 1;
if (NOT_EQUAL) goto label1;
}
/***********************/
Actually one goto can be removed without worsening code-size or
performance:
/*********B**************/
#define EQUAL \
var_this_thread == var_other_thread
void myfuncB(void)
{
if (EQUAL)
goto here;
while(1) {
var_this_thread = var_other_thread;
here:
array[var_this_thread] = 1;
if (EQUAL)
break;
}
}
/***********************/
In terms of machine code, myfuncB(void) will be the same as
myfuncA(void), right???
hmm... the above example is not so good.
I just realized that an optimization would be to leave the first
conditional and always force the assignment, right? Example below:
->
/*********C**************/
#define NOT_EQUAL \
var_this_thread != var_other_thread
void myfuncC(void)
{
do {
var_this_thread = var_other_thread;
array[var_this_thread] = 1;
} while (NOT_EQUAL);
}
/***********************/
-anon.asdf
The following code is a snippet where the goto's cannot be removed
"without increasing code-size, or decreasing performance".
/*********A**************/
int var_other_thread;
// value changed by another thread
int var_this_thread;
int array[100];
#define EQUAL \
var_this_thread == var_other_thread
#define NOT_EQUAL \
var_this_thread != var_other_thread
void myfuncA(void)
{
if (EQUAL) goto label2;
label1:
var_this_thread = var_other_thread;
label2:
array[var_this_thread] = 1;
if (NOT_EQUAL) goto label1;
}
/***********************/
Actually one goto can be removed without worsening code-size or
performance:
/*********B**************/
#define EQUAL \
var_this_thread == var_other_thread
void myfuncB(void)
{
if (EQUAL)
goto here;
while(1) {
var_this_thread = var_other_thread;
here:
array[var_this_thread] = 1;
if (EQUAL)
break;
}
}
/***********************/
In terms of machine code, myfuncB(void) will be the same as
myfuncA(void), right???
hmm... the above example is not so good.
I just realized that an optimization would be to leave the first
conditional and always force the assignment, right? Example below:
->
/*********C**************/
#define NOT_EQUAL \
var_this_thread != var_other_thread
void myfuncC(void)
{
do {
var_this_thread = var_other_thread;
array[var_this_thread] = 1;
} while (NOT_EQUAL);
}
/***********************/
-anon.asdf