cmprb
Compare Ranged Byte
Compares a byte value in one register to see if it falls within a range defined by another register.
Details
The cmprb instruction compares the unsigned integer value in bits 56:63 of register RA (src1) with two ranges defined by bits 32:39 and 40:47 (src21lo:src21hi) or bits 48:55 and 56:63 (src22lo:src22hi) of register RB. Depending on the value of L, it sets the CR field BF to indicate if src1 is within one of these ranges.
Pseudocode Operation
src1 ← EXTZ((RA)56:63)
src21hi ← EXTZ((RB)32:39)
src21lo ← EXTZ((RB)40:47)
src22hi ← EXTZ((RB)48:55)
src22lo ← EXTZ((RB)56:63)
if L=0 then
in_range ← (src22lo ≤ src1) & (src1 ≤ src22hi)
else
in_range ← ((src21lo ≤ src1) & (src1 ≤ src21hi)) | ((src22lo ≤ src1) & (src1 ≤ src22hi))
CR4×BF+32:4×BF+35 ← 0b0 || in_range || 0b00
Programming Note
cmprb is useful for implementing character typing functions such as isalpha(), isdigit(), isupper(), and islower() that are implemented using one or two range compares of the character. A single-range compare can be implemented with an addi to load the upper and lower bounds in the range, such as isdigit(). A combination of addi-addis can be used to set up 2 ranges, such as for isalpha().
Example
Encoding
Operands
-
BF
CR Field -
L
Mode -
RA
Byte -
RB
Range -
RT
Target General Purpose Register