summaryrefslogtreecommitdiff
path: root/src/common/swap.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Warnings cleanup for GCC 13 and Clang 16Gravatar comex2023-08-251-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Note: For GCC there are still a huge number of `-Warray-bounds` warnings coming from `externals/dynarmic`. I could have added a workaround in `externals/CMakeLists.txt` similar to what this PR does for other externals, but given Dynarmic's close affiliation with Yuzu, it would be better to fix it upstream. Besides that, on my machine, this makes the build warning-free except for some warnings from glslangValidator and AutoMoc. Details: - Disable some warnings in externals. - Disable `-Wnullability-completeness`, which is a Clang warning triggered by the Vulkan SDK where if any pointers in the header are marked _Nullable, it wants all pointers to be marked _Nullable or _Nonnull. Most of them are, but some aren't. Who knows why. - `src/web_service/verify_user_jwt.cpp`: Disable another warning when including `jwt.hpp`. - `src/input_common/input_poller.cpp`: Add missing `override` specifiers. - src/common/swap.h: Remove redundant `operator&`. In general, this file declares three overloads of each operator. Using `+` as an example, the overloads are: - a member function for `swapped_t + integer` - a member function for `swapped_t + swapped_t` - a free function for `integer + swapped_t` But for `operator&`, there was an additional free function for `swapped_t + integer`, which was redundant with the member function. This caused a GCC warning saying "ISO C++ says that these are ambiguous".
* general: fix spelling mistakesGravatar Liam2023-03-121-6/+6
|
* chore: add missing SPDX tagsGravatar Andrea Pappacoda2022-04-281-13/+3
| | | | Follow-up to 99ceb03a1cfcf35968cab589ea188a8c406cda52
* general: Fix various spelling errorsGravatar Morph2021-01-021-2/+2
|
* Revert "core: Fix clang build"Gravatar bunnei2020-10-201-5/+5
|
* core: Fix clang buildGravatar Lioncash2020-10-171-5/+5
| | | | | | | Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795
* common/swap: Make use of std::endianGravatar Lioncash2020-07-141-42/+4
| | | | Allows removing a bunch of defines in favor of a two liner.
* common/swap: Improve codegen of the default swap fallbacksGravatar Lioncash2019-04-121-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* common/swap: Mark byte swapping free functions with [[nodiscard]] and noexceptGravatar Lioncash2019-04-111-11/+11
| | | | | | | | Allows the compiler to inform when the result of a swap function is being ignored (which is 100% a bug in all usage scenarios). We also mark them noexcept to allow other functions using them to be able to be marked as noexcept and play nicely with things that potentially inspect "nothrowability".
* common/swap: Simplify swap function ifdefsGravatar Lioncash2019-04-111-48/+15
| | | | | | | | | | | | | | | | | | | Including every OS' own built-in byte swapping functions is kind of undesirable, since it adds yet another build path to ensure compilation succeeds on. Given we only support clang, GCC, and MSVC for the time being, we can utilize their built-in functions directly instead of going through the OS's API functions. This shrinks the overall code down to just if (msvc) use msvc's functions else if (clang or gcc) use clang/gcc's builtins else use the slow path
* common/swap: Remove 32-bit ARM pathGravatar Lioncash2019-04-111-13/+0
| | | | | We don't plan to support host 32-bit ARM execution environments, so this is essentially dead code.
* Merge pull request #2090 from FearlessTobi/port-4599Gravatar bunnei2019-03-201-35/+139
|\ | | | | Port citra-emu/citra#4244 and citra-emu/citra#4599: Changes to BitField
| * common/swap: remove default value for swap type internal storageGravatar Weiyi Wang2019-02-061-1/+1
| | | | | | | | This is compromise for swap type being used in union. A union has deleted default constructor if it has at least one variant member with non-trivial default constructor, and no variant member of T has a default member initializer. In the use case of Bitfield, all variant members will be the swap type on endianness mismatch, which would all have non-trivial default constructor if default value is specified, and non of them can have member initializer
| * common/swap: use template and tag for LE/BE specificationGravatar Weiyi Wang2019-02-061-39/+91
| | | | | | | | The tag can be useful for other type-generic templates like BitFields to forward the endianness specification
| * common/swap: add swap template for enumGravatar Weiyi Wang2019-02-061-0/+52
| |
* | Remove GCC version checksGravatar tgsm2019-02-241-3/+3
|/ | | | Citra can't be compiled using GCC <7 because of required C++17 support, so these version checks don't need to exist anymore.
* Port #3732 from Citra: "common: Fix compilation on ARM"Gravatar Cameron Cawley2018-07-291-1/+1
|
* common/swap: Remove unnecessary const on return value of swap()Gravatar Lioncash2018-07-191-1/+1
|
* common/swap: Use static_cast where applicableGravatar Lioncash2018-07-191-16/+16
|
* common/swap: Use using aliases where applicableGravatar Lioncash2018-07-191-33/+33
|
* Port #3579 from CitraGravatar fearlessTobi2018-07-071-1/+1
|
* common: fix swap functions on Bitrig and OpenBSDGravatar Daniel Lim Wee Soong2018-04-031-1/+13
| | | | | | | | | swap{16,32,64} are defined as macros on the two, but client code tries to invoke them as Common::swap{16,32,64}, which naturally doesn't work. This hack redefines the macros as inline functions in the Common namespace: the bodies of the functions are the same as the original macros, but relying on OS-specific implementation details like this is of course brittle.
* common: use system bswap* functions on more BSDsGravatar Jan Beich2016-10-271-2/+5
|
* Remove empty newlines in #include blocks.Gravatar Emmanuel Gil Peyrot2016-09-211-2/+0
| | | | | | | This makes clang-format useful on those. Also add a bunch of forgotten transitive includes, which otherwise prevented compilation.
* Manually tweak source formatting and then re-run clang-formatGravatar Yuri Kunde Schlesner2016-09-181-2/+1
|
* Sources: Run clang-format on everything.Gravatar Emmanuel Gil Peyrot2016-09-181-140/+191
|
* swap: Get rid of pointer casting for swapping structsGravatar Lioncash2016-05-081-5/+5
| | | | These shouldn't haphazardly convert types
* swap: Get rid of undefined behavior in swapf and swapdGravatar Lioncash2016-05-081-14/+18
| | | | This isn't well-defined in C++.
* swap: Remove unused methodsGravatar Lioncash2016-05-081-28/+0
| | | | | | | Also gets rid of pointer data variants as this prevents the use of the regular swapping routines as unary predicates in std lib functions. They also cast to stricter alignment types, which is undefined behavior.
* common: Get rid of a cast in swap.hGravatar Lioncash2015-09-111-2/+2
|
* Common: Cleanup memory and misc includes.Gravatar Emmanuel Gil Peyrot2015-06-281-3/+7
|
* Remove every trailing whitespace from the project (but externals).Gravatar Emmanuel Gil Peyrot2015-05-291-1/+1
|
* Removed swap code redundancy and moved common swap code to swap.hGravatar archshift2015-03-051-14/+97
|
* Common: Remove dead platform #ifdefs to make the code more readable.Gravatar Emmanuel Gil Peyrot2015-01-061-4/+0
| | | | | | Symbian, Xbox, Blackberry and iOS got removed. FreeBSD and Android kept due to them potentially being able to run Citra in the future. The iOS specific part also got removed from PPSSPP in order to fix a bug there.
* Fix compile errors in ClangGravatar Yuri Kunde Schlesner2014-10-261-1/+0
|
* fixes to build on linuxGravatar bunnei2014-04-221-13/+13
|
* got rid of 'src' folders in each sub-projectGravatar bunnei2014-04-081-0/+535