| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
г. |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_COMMON_ARCH_AARCH64_BITS_INT_LOG2_H_ |
| 23 |
#define LSP_PLUG_IN_COMMON_ARCH_AARCH64_BITS_INT_LOG2_H_ |
| 24 |
|
| 25 |
#ifndef LSP_PLUG_IN_COMMON_BITS_IMPL |
| 26 |
#error "This file should not be included directly" |
| 27 |
#endif |
| 28 |
|
| 29 |
namespace lsp |
| 30 |
{ |
| 31 |
inline int __lsp_forced_inline int_log2(uint8_t v) |
| 32 |
{ |
| 33 |
int32_t res; |
| 34 |
ARCH_AARCH64_ASM ( |
| 35 |
__ASM_EMIT("subs %w[res], %w[v], #0") |
| 36 |
__ASM_EMIT("b.eq 1f") |
| 37 |
__ASM_EMIT("clz %w[res], %w[v]") |
| 38 |
__ASM_EMIT("mov %w[v], #31") |
| 39 |
__ASM_EMIT("sub %w[res], %w[v], %w[res]") |
| 40 |
__ASM_EMIT("1:") |
| 41 |
: [res] "=r" (res), [v] "+r" (v) |
| 42 |
: : "cc" |
| 43 |
); |
| 44 |
return res; |
| 45 |
} |
| 46 |
|
| 47 |
inline int __lsp_forced_inline int_log2(int8_t v) |
| 48 |
{ |
| 49 |
int32_t res; |
| 50 |
ARCH_AARCH64_ASM ( |
| 51 |
__ASM_EMIT("subs %w[res], %w[v], #0") |
| 52 |
__ASM_EMIT("b.eq 1f") |
| 53 |
__ASM_EMIT("clz %w[res], %w[v]") |
| 54 |
__ASM_EMIT("mov %w[v], #31") |
| 55 |
__ASM_EMIT("sub %w[res], %w[v], %w[res]") |
| 56 |
__ASM_EMIT("1:") |
| 57 |
: [res] "=r" (res), [v] "+r" (v) |
| 58 |
: : "cc" |
| 59 |
); |
| 60 |
return res; |
| 61 |
} |
| 62 |
|
| 63 |
inline int __lsp_forced_inline int_log2(uint16_t v) |
| 64 |
{ |
| 65 |
int32_t res; |
| 66 |
ARCH_AARCH64_ASM ( |
| 67 |
__ASM_EMIT("subs %w[res], %w[v], #0") |
| 68 |
__ASM_EMIT("b.eq 1f") |
| 69 |
__ASM_EMIT("clz %w[res], %w[v]") |
| 70 |
__ASM_EMIT("mov %w[v], #31") |
| 71 |
__ASM_EMIT("sub %w[res], %w[v], %w[res]") |
| 72 |
__ASM_EMIT("1:") |
| 73 |
: [res] "=r" (res), [v] "+r" (v) |
| 74 |
: : "cc" |
| 75 |
); |
| 76 |
return res; |
| 77 |
} |
| 78 |
|
| 79 |
inline int __lsp_forced_inline int_log2(int16_t v) |
| 80 |
{ |
| 81 |
int32_t res; |
| 82 |
ARCH_AARCH64_ASM ( |
| 83 |
__ASM_EMIT("subs %w[res], %w[v], #0") |
| 84 |
__ASM_EMIT("b.eq 1f") |
| 85 |
__ASM_EMIT("clz %w[res], %w[v]") |
| 86 |
__ASM_EMIT("mov %w[v], #31") |
| 87 |
__ASM_EMIT("sub %w[res], %w[v], %w[res]") |
| 88 |
__ASM_EMIT("1:") |
| 89 |
: [res] "=r" (res), [v] "+r" (v) |
| 90 |
: : "cc" |
| 91 |
); |
| 92 |
return res; |
| 93 |
} |
| 94 |
|
| 95 |
inline int __lsp_forced_inline int_log2(uint32_t v) |
| 96 |
{ |
| 97 |
int32_t res; |
| 98 |
ARCH_AARCH64_ASM ( |
| 99 |
__ASM_EMIT("subs %w[res], %w[v], #0") |
| 100 |
__ASM_EMIT("b.eq 1f") |
| 101 |
__ASM_EMIT("clz %w[res], %w[v]") |
| 102 |
__ASM_EMIT("mov %w[v], #31") |
| 103 |
__ASM_EMIT("sub %w[res], %w[v], %w[res]") |
| 104 |
__ASM_EMIT("1:") |
| 105 |
: [res] "=r" (res), [v] "+r" (v) |
| 106 |
: : "cc" |
| 107 |
); |
| 108 |
return res; |
| 109 |
} |
| 110 |
|
| 111 |
inline int __lsp_forced_inline int_log2(int32_t v) |
| 112 |
{ |
| 113 |
int32_t res; |
| 114 |
ARCH_AARCH64_ASM ( |
| 115 |
__ASM_EMIT("subs %w[res], %w[v], #0") |
| 116 |
__ASM_EMIT("b.eq 1f") |
| 117 |
__ASM_EMIT("clz %w[res], %w[v]") |
| 118 |
__ASM_EMIT("mov %w[v], #31") |
| 119 |
__ASM_EMIT("sub %w[res], %w[v], %w[res]") |
| 120 |
__ASM_EMIT("1:") |
| 121 |
: [res] "=r" (res), [v] "+r" (v) |
| 122 |
: : "cc" |
| 123 |
); |
| 124 |
return res; |
| 125 |
} |
| 126 |
|
| 127 |
inline int __lsp_forced_inline int_log2(uint64_t v) |
| 128 |
{ |
| 129 |
int32_t res; |
| 130 |
ARCH_AARCH64_ASM ( |
| 131 |
__ASM_EMIT("subs %x[res], %x[v], #0") |
| 132 |
__ASM_EMIT("b.eq 1f") |
| 133 |
__ASM_EMIT("clz %x[res], %x[v]") |
| 134 |
__ASM_EMIT("mov %x[v], #63") |
| 135 |
__ASM_EMIT("sub %x[res], %x[v], %x[res]") |
| 136 |
__ASM_EMIT("1:") |
| 137 |
: [res] "=r" (res), [v] "+r" (v) |
| 138 |
: : "cc" |
| 139 |
); |
| 140 |
return res; |
| 141 |
} |
| 142 |
|
| 143 |
inline int __lsp_forced_inline int_log2(int64_t v) |
| 144 |
{ |
| 145 |
int32_t res; |
| 146 |
ARCH_AARCH64_ASM ( |
| 147 |
__ASM_EMIT("subs %x[res], %x[v], #0") |
| 148 |
__ASM_EMIT("b.eq 1f") |
| 149 |
__ASM_EMIT("clz %x[res], %x[v]") |
| 150 |
__ASM_EMIT("mov %x[v], #63") |
| 151 |
__ASM_EMIT("sub %x[res], %x[v], %x[res]") |
| 152 |
__ASM_EMIT("1:") |
| 153 |
: [res] "=r" (res), [v] "+r" (v) |
| 154 |
: : "cc" |
| 155 |
); |
| 156 |
return res; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
#endif |