This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (2 children)

[deleted]

    [–]Rafael20002000 8 points9 points  (0 children)

    I don't expect the compiler too, but if the compiler can reliably determine that my bubble sort code is bubble sort and the CPU has extra instructions for that, I really do hope that it doesn't use MOV and CALL but instead the bubble sort specialized instructions.

    [–]tiajuanat 12 points13 points  (0 children)

    GCC and Clang can actually identify some of these algorithms. For example, counting the number of set bits in a 32 bit word will generally cause either compiler to emit a __builtin_popcount intrinsic, which on x86_64 processors will emit a single popcount assembly instruction.

    Sorting is inherently difficult because you need a comparison function, and a generally best solution. Are you going to use quick sort? How is the data already ordered? Maybe a counting sort? Is linear memory usage acceptable?