(10 points) In the programming assignment #1, even though the processor is an in-order processor,
it can cause WAW dependencies. Discuss when WAW dependencies can occur, and how can we solve this problem?
There are at least more than one solution.
[4-5]
A graduate student, Mary, likes drinking coffee. She drinks coffee every day. She wrote a simple program to decide which coffee shop to go every day.
Here is the code. (to simplify the problem, we assume that Mary drinks coffee only Th,F, Sa and Sunday)
class date_c{
public:
void get_coffee();
};
class weekday_c: public date_c{
public:
void get_coffee();
}
class saturday_c:public date{
public:
void get_coffee();
}
class sunday_c:public date{
public:
void get_coffee();
}
void TutoTh_c::get_coffe(){
// beginning of the function body starts at 0x800
If (time >= 7 am && time < 8 am) printf("go to Seattle's Best\n"); // br: pc 0x801
else if (time >= 8 am && time < 1pm ) printf ("go to CCB \n"); // br: pc 0x807
else if (time < 6 pm ) printf ("go to IIB \n"); // br: pc 0x80a
else if (time <=10 pm) printf("go to StarBucks\n"); // br: pc 0x815
else printf("sorry. No more coffee\n");
}
void MF_c::get_coffe(){
// beginning of the function body starts at 0x820
If (time >= 7 am && time < 8 am) printf("go to Seattle's Best\n"); // br: pc 0x821
else if (time >= 8 am && time < 1pm ) printf ("go to CCB \n"); // br: pc 0x827
else if (time < 5 pm ) printf ("go to IIB \n"); // br: pc0x82a
else if (time <=10 pm) printf("go to StarBucks\n"); // br: pc 0x825
else printf("sorry. No more coffee\n");
}
void Sa_c::get_coffee() {
// beginning of the function body starts at 0x900
if (time >= 7 am && time < 10 pm) printf(\"go to Starbucks \n"); // br: pc 0x902
else printf("sorry, No more coffee\n");
}
void Su_c::get_coffee(){
// beginning of the function body starts at 0xa00
if (time> =10 am && time < 6 pm) printf("go to Starbucks \n"); // br: pc 0xa03
else printf("sorry, No more coffee\n");
}
main()
{
// initial code. // week array is initialized
for (today= Thursday ; today <= Sunday; today++) { // br: pc 0x100 : NT: Loop exit
date_c *data = week[today];
for (time = 7 am ; time < 5 pm; time = time + 6) { // br: pc 0x102, NT Loop exit
date->get_coffee(); // indirect branch at PC 0x110
}
}
Assumptions:
- To simplify the problem, we assume that multiple condition branches are handled by only one branch. i.e,
if (time > 7 am && time < 10 pm) correspond to only one branch.
- today is incremented from Th, F, Sa to Su.
each day data->get_coffee calls a different function.
Th : TutoTh_c::get_coffee
F: MF_c::get_coffee
Sa: Sa_c::get_coffee
Su: Su_c::get_coffee