I've been using a random number seeder for a while and recently found out it's returning the same number each time:
void Randomize()
{
register long ret = 0;
__asm__ volatile("mfc0 %0, $1" : :"r"(ret));
__asm__ volatile("sync.p");
SeedGenerator(ret);
}
SeedGenerator is getting called with the same value for 'ret' each time this is run. Anyone have any ideas what I'm doing wrong please?
thanks,
Raizor
broken random number generator
First, having a look at the generated code could be an idea. Always doing that is great to understand what gcc does.
Second, do you really want $1 ? Not $9 ? CPU clock that is.
Third, you should merge the two asm blocs:
Fourth, you need to say to gcc you want ret to be an *output*. You're putting it as the input field. The correct syntax would finally be:
(notice that: 1) it's not in the same : bloc and 2) the presence of the = to say it's an output)
The last but not the least, there's cpu_ticks in the timer.c's of ps2sdk's kernel which basically does what you asked for :P
Second, do you really want $1 ? Not $9 ? CPU clock that is.
Third, you should merge the two asm blocs:
Code: Select all
__asm__ volatile("mfc0 %0, $1\nsync.p" ...)
Code: Select all
__asm__ volatile("mfc0 %0, $1\nsync.p" : "=r"(ret));
The last but not the least, there's cpu_ticks in the timer.c's of ps2sdk's kernel which basically does what you asked for :P
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.