Author Topic: Range checking...  (Read 1533 times)

0 Members and 1 Guest are viewing this topic.

Offline westfwTopic starter

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Range checking...
« on: March 05, 2021, 12:56:00 am »
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.
Code: [Select]
    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?)
 

Offline retiredfeline

  • Frequent Contributor
  • **
  • Posts: 539
  • Country: au
Re: Range checking...
« Reply #1 on: March 05, 2021, 01:09:06 am »
Here's one hit for a quick search: https://en.wikipedia.org/wiki/Bounds_checking
« Last Edit: March 05, 2021, 01:11:39 am by retiredfeline »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: Range checking...
« Reply #2 on: March 05, 2021, 01:13:47 am »
In particular, you can take a look at Intel MPX: https://en.wikipedia.org/wiki/Intel_MPX
 

Online MK14

  • Super Contributor
  • ***
  • Posts: 4539
  • Country: gb
Re: Range checking...
« Reply #3 on: March 05, 2021, 02:34:09 am »
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
« Last Edit: March 05, 2021, 02:35:56 am by MK14 »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: Range checking...
« Reply #4 on: March 06, 2021, 06:00:08 pm »
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?
 
The following users thanked this post: MK14

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 3915
  • Country: gb
Re: Range checking...
« Reply #5 on: March 06, 2021, 08:19:52 pm »
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?
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf