1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
clz_arm_1:
    orrs  r0, r0, r0, lsr #1
    moveq r0, #32
    bxeq  lr
    ldr   r1, .Lmul
    orr   r0, r0, r0, lsr #2
    orr   r0, r0, r0, lsr #4
    orr   r0, r0, r0, lsr #8
    orr   r0, r0, r0, lsr #16
    eor   r0, r0, r0, lsr #1
    mul   r0, r1, r0
    ldrb  r0, [pc, r0, lsr #27]
    bx    lr
    .byte 31, 30,  3, 29,  2, 17,  7, 28,  1,  9, 11, 16,  6, 14, 27, 23
    .byte  0,  4, 18,  8, 10, 12, 15, 24,  5, 19, 13, 25, 20, 26, 21, 22
.Lmul:
    .word 0x077CB531

clz_arm_2:
    orr  r0, r0, r0, lsr #1
    orr  r0, r0, r0, lsr #2
    orr  r0, r0, r0, lsr #4
    orr  r0, r0, r0, lsr #8
    orr  r0, r0, r0, lsr #16
    eor  r0, r0, r0, lsr #1
    orr  r0, r0, r0, lsl #4
    orr  r0, r0, r0, lsl #6
    rsb  r0, r0, r0, lsr #16
    ldrb r0, [pc, r0, lsr #26]
    bx   lr
    .byte 32,  31,  30,  19,  29,  25,   0,  18
    .byte 28,   0,  24,   0,   0,   0,   0,  17
    .byte 21,  27,   0,   0,  23,   0,   0,   6
    .byte  0,   0,   0,   0,   0,  10,   4,  16
    .byte  0,  20,  26,   0,   0,   0,   0,   0
    .byte 22,   0,   0,   7,   0,   0,  11,   5
    .byte  1,   0,   0,   0,   0,   8,   0,  12
    .byte  2,   0,   9,  13,   3,  14,  15,   0

clz_arm_3:
    mov   r1, #32
    cmp   r0, #32768
    subcs r1, #16
    movcs r0, r0, lsr #16
    cmp   r0, #128
    subcs r1, #8
    movcs r0, r0, lsr #8
    cmp   r0, #8
    subcs r1, #4
    movcs r0, r0, lsr #4
    cmp   r0, #2
    subcs r1, #2
    movcs r0, r0, lsr #2
    tst   r0, #2
    subcs r1, #1
    tst   r0, #1
    subcs r1, #1
    mov   r1, r0
    bx    lr