Assume I have a list of id's, and each id is the index into array of strings. The strings are 0-terminated, and of uniform random length from 1-32 bytes. I want to create an output buffer that consists of the concatenated strings corresponding to the id's in the list.
The pseudo C code would look like this:
char *stringList[NUM_STRINGS]; // strings of length 1-32
int idList[LIST_LEN]; // initialized to rand() % NUM_STRINGS
for (int i = 0; i < LIST_LEN; i++) {
int id = idList[i]; // id from existing list
char *string = stringList[id]; // use id to get string
while (*output++ = *string++); // copy string to output
}
Assume that stringList is large enough that the strings are not in cache, and thus there will be a ~300 cycle latency after each is loaded. Presumably, the "copy" loop will be speculatively executed during this latency. But since the string lengths are random, the termination for this loop can't be well predicted, and since the data for the copy isn't there yet, I'm not sure exactly what happens.Does the processor predict that the string copy loop will never terminate, and keep buffering string copy instructions until the buffers are full? Which buffers? Does it stop speculating at some maximum number of branches? If so, what is this depth? Or does it manage to guess that the inner string copy loop terminates after some reasonable number of iterations so it can issue the outer loop load for the next stringList[id]? If so, how many such loads will it manage to issue?