I'm trying to check multiple conditions. If any are true while others are false, I want the result to be 1. Basically an IF statement with multiple OR conditions. If I use an SLT or SGT, a false comparison after any true comparison will "erase" the correct result. I can do this with multiple branches. My program would be half the size if there were comparisons that did not set zero. If there's a better way to think about this problem I'd love to hear about it. Thanks.
Asked
Active
Viewed 75 times
1
-
what do the compilers have to say about it? – old_timer Jul 14 '21 at 23:20
-
@old_timer I wouldn't even know where to start. I'm playing a game that implemented MIPS for an in-game logic system. Should I just look at the source of a compiler? Any recommendations? – Michael McDonald Jul 14 '21 at 23:34
-
No, MIPS doesn't have that, AFAIK. (It doesn't even have `sgt`!) If you tell us more what problem you're trying to solve we might be able to help thinking outside the box, for example, show a larger code sequence in C or in MIPS assembly that you want to optimize. As stated, the problem is constrained. – Erik Eidt Jul 15 '21 at 00:34
-
you write the code in C then see what a compiler does with it...If you cant write it in C then you cant write it in asm. – old_timer Jul 15 '21 at 01:26
-
This question might be helpful: https://stackoverflow.com/questions/15375267/mutiple-conditions-in-if-in-mips/15397460#15397460 – markgz Jul 15 '21 at 02:44
-
@ErikEidt I'm comparing registers to my chosen min and max values. If any are true, I'm setting a register to 1 as a flag for later use. In C terms, if(pressure < minPressure || temp < minTemp || oxygen > maxOxygen) {flag = 1} I was hoping that MIPS would allow me to do this without jumps but it seems like that's the best option after all. Especially after reading the question markgz linked. – Michael McDonald Jul 15 '21 at 03:42
-
2You can try `flag = (pressure < minPressure) | (temp < minTemp) | (oxygen > maxOxygen);` (Note `|` not `||`, that can avoid branching, and since you don't need short circuit evaluation for this..) – Erik Eidt Jul 15 '21 at 04:09
-
You could use MIPS IV `movz` or `movn` conditional move to select between two values according to a condition in another register, with the original value as one of the things you select from. https://www.cs.cornell.edu/courses/cs3410/2008fa/MIPS_Vol2.pdf . But you'd need the `1` (true) in another register to start with, so maybe `slt` / `movn` – Peter Cordes Feb 09 '23 at 01:22