/*
fichier test_init5.c
créé le 5 juin 2007 par Yann Guidon - whygee@f-cpu.org

teste l'influence de la valeur d'initialisation de l'état interne

vérifie la longueur du cycle pour les constantes :
*/

#include <stdio.h>

typedef unsigned int U32;

#define MACRO_tGFSR32x4_SHFT(current, last, ptr) \
  current ^= last;        \
  current ^= ptr;         \
  t = current;            \
  current >>= 1;          \
  t &= 0x01010101;        \
  current &= 0x7F7F7F7F;  \
  t <<= 4;                \
  current ^= t;           \
  t <<= 3;                \
  current ^= t;

U32 GFSR0 = 0x62f08f0aUL;
U32 GFSR1 = 0x115bac5bUL;
U32 GFSR2 = 0xdb93dbb0UL;
U32 GFSR3 = 0x89865d38UL;
U32 a, b, c, d;

int main() {
  U32 r0, r1, r2, r3, t, i, j;
  for (j=0; j<4; j++) {

    a=(GFSR0 >> (j*8)) & 255;
    b=(GFSR1 >> (j*8)) & 255;
    c=(GFSR2 >> (j*8)) & 255;
    d=(GFSR3 >> (j*8)) & 255;

    r0=a; r1=b; r2=c; r3=d; i=0;

    do {
      MACRO_tGFSR32x4_SHFT(r0, r3, 0)
      MACRO_tGFSR32x4_SHFT(r1, r0, 0)
      MACRO_tGFSR32x4_SHFT(r2, r1, 0)
      MACRO_tGFSR32x4_SHFT(r3, r2, 0)
      i++;
    } while ((i<=300000000)
      && !((r0==a) && (r1==b) && (r2==c) && (r3==d)));
    printf("%d\n",i);
  }
  return r0;
}
