Project 3 - FarmVille

FAQ

Why my bot performs much worse than the public ones even I just rename a public bot?

When you edit the TARGETS in Makefile, you should consider enabling the compiler optimization for your bot, by adding "FLAGS_[yourbot] = -O3" (it's O not 0 !!)

How to extend "produce" from a byte to a word?

Define your produce (named as "word_produce" if you like) as an unsigned int, assign a word to it by shifting the char "produce" with different offsets, then concatenating them by a bit-wise OR

If I planted a landmine on my opponent's territory and I stepped on it, what will happen?

Your farmer will be stunned for 1,000,000 cycles.

If I thrown a grenade and within 100 cycles I thrown another one, will the stalling time for my opponent be accumulated to 200 cycles, or their effects overlap?

The stalling time will be accumulated.

How to get access to the pointers in stack?

There is a mips_core_data structure, which contains an array R, storing the content in registers.

Does the cache contain memory address or the data contents stored in memory?

It stores the memory contents from the location you fetch.

Can you half fill the cache?

No, the cache will fetch an entire block (256 bytes). It will start to fetch the block containing the address into the cache.

Is it guaranteed that my farmer will get caught when in exploit mode?

No, there is a chance you will get caught/killed only if the opponent is checking its taunt array and accusing farmers.

How do we determine what addresses the opponent currently has in the cache?

Use the rdctag function to read a cache tag. Check titfortat.c for an example of the proper usage

What is the policy for coherence between the cache and memory?

The cache is write-allocate: If you want to write to an address, it must be in the cache first (and therefore you suffer a cache miss if it wasn't in there already). The cache is write-through: Once a line is in the cache, any writes to it immediately appear in memory (and therefore immediately increase your score). Finally, the cache automatically updates from memory: In particular, if you have the taunt array in cache, and a new bot enters exploit mode, the taunt array in cache updates immediately.

How should we time our prefetches? How does prefetching work, anyway?

It's possible to prefetch too early, such that the line you prefetch arrives in the cache while you're still working on a different line. In this case, you'll doubly penalize yourself, as you'll suffer a miss for the line you're currently accessing, and then miss on the line you meant to prefetch in the first place. Oops! Don't do that. If you prefetch slightly late, you only lose the difference. If address 0x01000000 is not in the cache, but you prefetch it, wait 50 cycles, then try to write to/read from it, you'll still miss but only stall 50 cycles instead of the usual 100, since 50 of the cycles were alerady taken up by the prefetch. This is why prefetching is beneficial. If you run the simulator in "very verbose mode" via simulate -vvvv, you'll see messages like "upgrades existing prefetch", and this is the meaning of that message. On the other hand, if address 0x01000400 is in the cache, you prefetch 0x01000200, then try to read/write 0x01000000, the prefetch is canceled, You miss 0x01000000, and stall the full 100 cycles, no matter how far along the prefetch was.