Counting Sort , , count, .
, 255 . 256B 4 * 256B , , count .
, . L1, count read-modify-write. . , , ( , ). x86 , + .
inputa :
.L15:
movsx rdx, BYTE PTR [rax]
add rax, 1
add DWORD PTR [rsp-120+rdx*4], 1
cmp rax, rcx
jne .L15
: char . ABI x86-64 char , allChars[(int)inputa[i]]++; sign- . (movsx movzx). , ASCII, . allChars[(unsigned char)inputa[i]]++;. , (unsigned) (. ).
, clang (v3.7.1 v3.8, -O3), std::basic_string<...>::_M_leak_hard() . (, , , .) @manlio , , for (auto c : inputa) clang , .
, std::string, char[], std::string. , .
-, , .
inputa:
:
- : ,
inputa, , . - ,
inputb != 0 inputa.
, , . (, int64_t ).
, , , , . , , , , , .
std::is_permutation std::count, SSE/AVX. , - - , gcc, clang. 64- , , . , , , , , ( -O2 -O3 -fno-tree-vectorize).
, count - pcmpeqb/psubb, psadbw 255 . pcmpeqb/pmovmskb/popcnt/add, .
Template specializations in the library can help a lot std::countfor 8, 16, and 32-bit types, whose equality can be checked using bitwise equality (integer ==).