Examples of their use are two very efficient functions to return the lowest value and the highest value in a set:
Code: Select all
PROCEDURE* MaxElement(s: SET): INTEGER;
RETURN 31 - SYSTEM.CLZ(ORD(s))
END MaxElement;
PROCEDURE* MinElement(s: SET): INTEGER;
RETURN SYSTEM.CLZ(SYSTEM.RBIT(ORD(s)))
END MinElement;
Code: Select all
MinElement({5..25}) = 5
MaxElement({2, 4, 6, 8} = 8
Code: Select all
MinElement({}) = 32
MaxElement({}) = -1
Code: Select all
PROCEDURE* MinElement:
rbit r10,r11
clz r11,r10
bx lr
PROCEDURE* MaxElement:
clz r10,r11
rsbs.w r11,r10,31
bx lr