ADSP-21594
Production
Reaching speeds of up to 1 GHz, the ADSP-2159x processors are members of the SHARC® family of products. The ADSP-2159x processor is a dual-SHARC+® core...
Datasheet
ADSP-21594 on Analog.com
In the ADSP-21594 DSP processor, the rand()
function's randomness is affected when the ALU saturation bit is enabled in the MODE1 register. My use case is to generate white noise, but with ALU saturation enabled, rand()
fails to produce proper random values. When disabled, it works fine.
I'm looking for technical insights into why this is happening. Any assistance or suggestions would be greatly appreciated.
Please check the provided link for details on the MODE1 register. Programming reference manual page for MODE1 register.
Hi,
Can you please provide more details about the issue you are facing when both the rand() function and ALU saturation are used?
Is it possible to share the example code to replicate the issue in our side to assist you better on this?
Regards,
Nandini.C
#include <stdio.h> #include <stdint.h> #include <stdlib.h> #define BUFFER_SIZE 512 float TEST_Buffer[BUFFER_SIZE]; void store_rand_values( float *outBuf,// Output buffer address uint32_t outSize // Output size ) { float *outPtr; if( outSize == 0 ) return; outPtr = outBuf; for(int inDex = 0 ; inDex < outSize ; inDex++ ) { // store rand values to buffer *outPtr++ = rand(); } } void main(void) { // take register browser and set the ALU sat bit on MODE1 register //plot the buffer you will be able to see the issue. //After that clear the ALU saturation bit on MODE1 register we will be able to actual rand values. while(1) { store_rand_values(TEST_Buffer,BUFFER_SIZE); } }
Hi,
The behaviour you have mentioned seems to be expected.
The rand function uses a Linear Congruential Generator (LCG) to generate pseudo-random numbers. A linear congruential generator is computed as:
X[n+1] = mod ((X[n] * a) + c), m)
The rand function sets a, c, and m from the formula above as follows:
a = 6364136223846793005
c = 1442695040888963407
m = 2^31
When the ALU bit is set, the multiplier operation can result in overflow or underflow, causing the intermediate result to be either 0x7FFFFFFF or 0x80000000. Adding 0x1442695040888963407 to this saturated value reduces the randomness.
For further details, please refer to the “rand.c” file located at the following path. Also please refer the disassembly view for saturated values:
<installation path>\cces\3.0.1\SHARC\lib\src\libc_src
Regards,
Nandini C