frac32 gates
int32 count
int32 max
bool32 generate
bool32 gate
int32 gates
int32 gates
int32 qnt
bool32.mom generate
// number & start/length
int16_t data[32][2];
int i;
int j;
bool gen;
int prv;
bool GEN = 1;
int gates;
if ((GEN > 0) && !gen) {
gen = 1;
gates = param_gates; //___SMMUL(param_gates<<3,inlet_gates<<2);
for (i = 0; i < 32; i++) {
data[i][0] = 0;
data[i][0] = 0;
}
data[0][1] = inlet_max;
for (i = 0; i < (gates - 1); i++) {
int16_t max = 0;
int pos = 0;
for (j = 0; j < (i + 1); j++) {
if (data[j][1] > max) {
max = data[j][1];
pos = j;
}
}
int16_t tmp = ___SMMUL((int32_t)(data[pos][1] - (1 << param_qnt)) << 2,
(int32_t)(GenerateRandomNumber() &
((1 << 30 - param_qnt) - 1))) +
1
<< param_qnt;
data[i + 1][1] = data[pos][1] - tmp;
data[i + 1][0] = data[pos][0] + tmp;
data[pos][1] = tmp;
}
} else if (GEN == 0) {
gen = 0;
}
outlet_gate = 0;
if (!(inlet_count == prv)) {
for (i = 0; i < ___SMMUL(gates << 3, inlet_gates << 2); i++) {
if (inlet_count ==
data[i][0]) //(___SMMUL((int32_t)(data[i][0])<<14,inlet_max<<3)))
{
outlet_gate = 1;
}
}
}
prv = inlet_count;
outlet_gates = gates;
GEN = param_generate + inlet_generate;