Has there ever been an Instruction set Architecture that includes an explicit "range check" instruction?
I'm thinking something that would cause an exception, rather than storing a result.
rangecheck op1, op2, op3 ; raise an exception if op1 is not between op2 and op3.
rangecheck op1, op2 ; raise an exception if op1 is not between zero and op2.Ideally, op2, op3 could be immediate values, or whatever the CPU normally uses for operands (registers on RISC, anything on CISC?)
Yes, the X86 has such an instruction, available for a long time. Which creates an exception, if the bounds are exceeded.
https://www.felixcloutier.com/x86/bound
Here it is, for the 386 cpu (Intel):
https://pdos.csail.mit.edu/6.828/2018/readings/i386/BOUND.htm
Note that the 'bound' instruction is not available in 64-bit mode AFAIK, so in this case, I guess the Intel MPX extension is the alternative for Intel CPUs. (It's more capable than just the original bound instruction too...) It was also known to be actually slower than using several instructions for bound checking starting with the i486...
I'm not aware of similar instructions in ARM and MIPS ISAs, but I'm not a specialist of those either, so if anyone knows?
Has there ever been an Instruction set Architecture that includes an explicit "range check" instruction?
Programmers can use the CHK2 instruction in the Motorola 68000 to check if a number is within a certain range.
Why do you ask it?