ARM base instruction -- clz

Count Leading Zeros counts the number of binary zero bits before the first binary one bit in the value of the source register, and writes the result to the destination register.
 
该指令用于计算最高符号位与第一个1之间的0的个数。当一些操作数需要规范化(使其最高位为1)时 ,该指令用于计算操作数需要左移的位数,以及确定一个优先级掩码中最高优先级(最高位的优先级)。

CLZ指令用于计算寄存器中操作数的最高位0的个数,如果操作数的bit[31]为1,则返回0,如果操作数全为0 ,则指令返回 64 或 32 .


32-bit variant
    Applies when sf == 0.
    CLZ ,

64-bit variant
    Applies when sf == 1.
    CLZ ,
Decode for all variants of this encoding

 integer d = UInt(Rd);
 integer n = UInt(Rn);
 integer datasize = if sf == '1' then 64 else 32;


Operation
 integer result;
 bits(datasize) operand1 = X[n];
 
 result = CountLeadingZeroBits(operand1);
 X[d] = result;


 integer CountLeadingZeroBits(bits(N) x)
     return N - (HighestSetBit(x) + 1);


 integer HighestSetBit(bits(N) x)
     for i = N-1 downto 0
         if x == '1' then return i;
     return -1;

你可能感兴趣的:(Assembly,汇编)