#include #include "gst_ual.h" #include "gst_cond.h" struct ual_st { int *entree0; int *entree1; int *sortie; int *operation; FIL *sortie_regcond; int nbre_bits; int masque; }; ual_st ual_init (int *entree0, int *entree1, int *sortie, int *operation, int nbre_bits, FIL *sortie_regcond) { ual_st ual = (ual_st) malloc (sizeof (struct ual_st)); assert (ual != NULL); ual->entree0 = entree0; ual->entree1 = entree1; ual->sortie = sortie; ual->operation = operation; ual->nbre_bits = nbre_bits; ual->masque = (1 << nbre_bits) - 1; ual->sortie_regcond = sortie_regcond; return ual; } void ual_evalue (ual_st ual) { int op = (*ual->operation << 2) | (*(ual->operation+1) << 1) | (*(ual->operation+2)); unsigned int res = 0; switch (op) { case 0: res = *ual->entree0; break; case 1: res = *ual->entree1 << 1; break; case 2: res = *ual->entree1 >> 1; break; case 3: res = *ual->entree0 + *ual->entree1; break; case 4: res = *ual->entree0 - *ual->entree1; break; case 5: res = *ual->entree0 & *ual->entree1; break; case 6: res = *ual->entree0 | *ual->entree1; break; case 7: res = ~(*ual->entree0) + 1; break; } ual->sortie_regcond [N] = (res >> (ual->nbre_bits - 1)) > 0; ual->sortie_regcond [Z] = (res == 0); ual->sortie_regcond [C] = (res >> ual->nbre_bits) > 0; ual->sortie_regcond [V] = (res >> ual->nbre_bits) > 1; *ual->sortie = res & ual->masque; } void ual_libere (ual_st ual) { free (ual); }