by azalemeth · 7y ago · 0 comments
>"Division. Arrgh. The AGC does have hardware division (and multiplication), but it’s strictly limited to only being able to compute x/y when |x|>|y|. Anything else, you get garbage, including in the y=x case. This hit me several times and trying to deal with all the sign issues, combined with the 1s-complement sign issues above, was really painful."
Not being expert in slightly outdated processor architectures (1s compliment!), might someone more expert than I be able to tell me _why_ this is the case and was a good design decision? It seems like a potential way for unexpected sensor data to bite you in the arse...
If you're creating hardware that's only going to be used a few times, it's probably not worth it to spend a lot of effort into giving it every feature that programmers want.
I think it's literally just to keep the math circuit logic very simple, it'll be identical to MOD (just need to look at the remainder register) and |x| <= |y| will either require some hackery to convert it (with an appropriate test) or the machine having some idea of non-integer numbers.
For implementation of division, you could have the circuit equivalence of:
uint div(x, y){
uint t = x; //temporary (don't want to touch x)
uint c = 0; //counter
while(t >= y){
t = t - y;
c = c + 1;
}
return c; //remainder is in t
}
Not sure about the x == y case though.Of course there would be no checking, hence the garbage out when you misuse it. Your checking would be done manually.