citra-nightly/src/common
Lioncash b8d43d4dfb common/swap: Improve codegen of the default swap fallbacks
Uses arithmetic that can be identified more trivially by compilers for
optimizations. e.g. Rather than shifting the halves of the value and
then swapping and combining them, we can swap them in place.

e.g. for the original swap32 code on x86-64, clang 8.0 would generate:

    mov     ecx, edi
    rol     cx, 8
    shl     ecx, 16
    shr     edi, 16
    rol     di, 8
    movzx   eax, di
    or      eax, ecx
    ret

while GCC 8.3 would generate the ideal:

    mov     eax, edi
    bswap   eax
    ret

now both generate the same optimal output.

MSVC used to generate the following with the old code:

    mov     eax, ecx
    rol     cx, 8
    shr     eax, 16
    rol     ax, 8
    movzx   ecx, cx
    movzx   eax, ax
    shl     ecx, 16
    or      eax, ecx
    ret     0

Now MSVC also generates a similar, but equally optimal result as clang/GCC:

    bswap   ecx
    mov     eax, ecx
    ret     0

====

In the swap64 case, for the original code, clang 8.0 would generate:

    mov     eax, edi
    bswap   eax
    shl     rax, 32
    shr     rdi, 32
    bswap   edi
    or      rax, rdi
    ret

(almost there, but still missing the mark)

while, again, GCC 8.3 would generate the more ideal:

    mov     rax, rdi
    bswap   rax
    ret

now clang also generates the optimal sequence for this fallback as well.

This is a case where MSVC unfortunately falls short, despite the new
code, this one still generates a doozy of an output.

    mov     r8, rcx
    mov     r9, rcx
    mov     rax, 71776119061217280
    mov     rdx, r8
    and     r9, rax
    and     edx, 65280
    mov     rax, rcx
    shr     rax, 16
    or      r9, rax
    mov     rax, rcx
    shr     r9, 16
    mov     rcx, 280375465082880
    and     rax, rcx
    mov     rcx, 1095216660480
    or      r9, rax
    mov     rax, r8
    and     rax, rcx
    shr     r9, 16
    or      r9, rax
    mov     rcx, r8
    mov     rax, r8
    shr     r9, 8
    shl     rax, 16
    and     ecx, 16711680
    or      rdx, rax
    mov     eax, -16777216
    and     rax, r8
    shl     rdx, 16
    or      rdx, rcx
    shl     rdx, 16
    or      rax, rdx
    shl     rax, 8
    or      rax, r9
    ret     0

which is pretty unfortunate.
2019-04-15 17:56:16 +02:00
..
logging Merge pull request #4726 from FearlessTobi/port-2312 2019-04-13 18:00:09 -04:00
x64 Prefix all size_t with std:: 2018-09-06 16:03:28 -04:00
alignment.h Prefix all size_t with std:: 2018-09-06 16:03:28 -04:00
announce_multiplayer_room.h core, web_service: Changes to announce service 2018-12-15 11:02:52 +08:00
assert.h reformat all files with clang-format 2018-06-29 16:56:12 +03:00
bit_field.h common/bit_field: Make BitField trivially copyable 2019-03-16 04:10:03 +01:00
bit_set.h Prefix all size_t with std:: 2018-09-06 16:03:28 -04:00
chunk_file.h reformat all files with clang-format 2018-06-29 16:56:12 +03:00
cityhash.cpp Prefix all size_t with std:: 2018-09-06 16:03:28 -04:00
cityhash.h Prefix all size_t with std:: 2018-09-06 16:03:28 -04:00
CMakeLists.txt common/thread_queue_list: Remove unnecessary dependency on boost 2019-03-22 23:13:30 +01:00
color.h common/vector_math: Move Vec[x] types into the Common namespace 2019-03-02 15:04:13 +01:00
common_funcs.h Merge pull request #4021 from FearlessTobi/port-709 2018-08-02 11:00:53 -06:00
common_paths.h FFmpegDL: Added external_dlls folder to user folder 2019-02-09 11:52:31 +01:00
common_types.h Sources: Run clang-format on everything. 2016-09-18 09:38:01 +09:00
detached_tasks.cpp general: Use deducation guides for std::lock_guard and std::unique_lock 2019-04-07 15:14:29 +02:00
detached_tasks.h Review comments - part 5 2018-10-20 10:35:55 -04:00
file_util.cpp appease clang format 2019-03-09 19:15:35 -06:00
file_util.h common: decouple getting and setting user paths 2019-02-15 14:48:31 -06:00
hash.h Prefix all size_t with std:: 2018-09-06 16:03:28 -04:00
linear_disk_cache.h Sources: Run clang-format on everything. 2016-09-18 09:38:01 +09:00
math_util.h common/math_util: Move contents into the Common namespace 2019-03-02 18:13:10 +01:00
microprofile.cpp Integrate the MicroProfile profiling library 2015-08-24 22:16:28 -03:00
microprofile.h Sources: Run clang-format on everything. 2016-09-18 09:38:01 +09:00
microprofileui.h Common: Remove section measurement from profiler (#1731) 2016-04-29 00:07:10 -07:00
misc.cpp Prefix all size_t with std:: 2018-09-06 16:03:28 -04:00
param_package.cpp citra_qt/configuration: misc input tab improvements 2018-09-08 11:26:10 +08:00
param_package.h citra_qt/configuration: misc input tab improvements 2018-09-08 11:26:10 +08:00
quaternion.h common/vector_math: Move Vec[x] types into the Common namespace 2019-03-02 15:04:13 +01:00
ring_buffer.h ring_buffer: Fix Push 2018-09-19 07:14:36 +01:00
scm_rev.cpp.in common: Parse Nightly/Canary build version 2018-06-20 09:30:26 +08:00
scm_rev.h common: Parse Nightly/Canary build version 2018-06-20 09:30:26 +08:00
scope_exit.h common/scope_exit: Replace std::move with std::forward in ScopeExit() 2019-04-15 17:55:44 +02:00
string_util.cpp remove Common::TrimSourcePath 2019-03-10 19:18:09 -05:00
string_util.h remove Common::TrimSourcePath 2019-03-10 19:18:09 -05:00
swap.h common/swap: Improve codegen of the default swap fallbacks 2019-04-15 17:56:16 +02:00
telemetry.cpp common: Add a generic interface for logging telemetry fields. 2017-05-24 19:16:21 -04:00
telemetry.h compatdb: Use a seperate endpoint for testcase submission 2018-10-27 12:20:03 +02:00
thread.cpp common/thread: Drop Hungarian notation on SetCurrentThreadName's parameter 2018-11-23 18:23:06 +01:00
thread.h general: Use deducation guides for std::lock_guard and std::unique_lock 2019-04-07 15:14:29 +02:00
thread_queue_list.h common/thread_queue_list: Remove unnecessary dependency on boost 2019-03-22 23:13:30 +01:00
threadsafe_queue.h general: Use deducation guides for std::lock_guard and std::unique_lock 2019-04-07 15:14:29 +02:00
timer.cpp Address review comments 2018-09-06 00:00:21 +02:00
timer.h common/timer: use std::chrono, avoid platform-dependent code 2018-07-22 15:40:07 +08:00
vector_math.h common/vector_math: Move Vec[x] types into the Common namespace 2019-03-02 15:04:13 +01:00
web_result.h Put WebResult into a seperate file 2018-10-27 00:39:02 +02:00