summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Rodrigo Locatti2021-01-15 04:48:58 -0300
committerGravatar GitHub2021-01-15 04:48:58 -0300
commit5b9aedfc215e2f7227a8604d2d28fb462949d537 (patch)
treeed1f105b1fef3fc9a5209c5106accaaee283ebf2 /src/core
parentMerge pull request #5354 from ReinUsesLisp/remove-common-color (diff)
parentcommon/bit_util: Replace CLZ/CTZ operations with standardized ones (diff)
downloadyuzu-5b9aedfc215e2f7227a8604d2d28fb462949d537.tar.gz
yuzu-5b9aedfc215e2f7227a8604d2d28fb462949d537.tar.xz
yuzu-5b9aedfc215e2f7227a8604d2d28fb462949d537.zip
Merge pull request #5356 from lioncash/clz
common/bit_util: Replace CLZ/CTZ operations with standardized ones
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/kernel/k_priority_queue.h4
-rw-r--r--src/core/hle/kernel/k_scheduler.cpp8
-rw-r--r--src/core/hle/kernel/memory/page_heap.h4
-rw-r--r--src/core/hle/kernel/process_capability.cpp4
4 files changed, 12 insertions, 8 deletions
diff --git a/src/core/hle/kernel/k_priority_queue.h b/src/core/hle/kernel/k_priority_queue.h
index 99fb8fe93..0dc929040 100644
--- a/src/core/hle/kernel/k_priority_queue.h
+++ b/src/core/hle/kernel/k_priority_queue.h
@@ -8,11 +8,11 @@
8#pragma once 8#pragma once
9 9
10#include <array> 10#include <array>
11#include <bit>
11#include <concepts> 12#include <concepts>
12 13
13#include "common/assert.h" 14#include "common/assert.h"
14#include "common/bit_set.h" 15#include "common/bit_set.h"
15#include "common/bit_util.h"
16#include "common/common_types.h" 16#include "common/common_types.h"
17#include "common/concepts.h" 17#include "common/concepts.h"
18 18
@@ -268,7 +268,7 @@ private:
268 } 268 }
269 269
270 constexpr s32 GetNextCore(u64& affinity) { 270 constexpr s32 GetNextCore(u64& affinity) {
271 const s32 core = Common::CountTrailingZeroes64(affinity); 271 const s32 core = std::countr_zero(affinity);
272 ClearAffinityBit(affinity, core); 272 ClearAffinityBit(affinity, core);
273 return core; 273 return core;
274 } 274 }
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp
index 42f0ea483..12b5619fb 100644
--- a/src/core/hle/kernel/k_scheduler.cpp
+++ b/src/core/hle/kernel/k_scheduler.cpp
@@ -5,6 +5,8 @@
5// This file references various implementation details from Atmosphere, an open-source firmware for 5// This file references various implementation details from Atmosphere, an open-source firmware for
6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX. 6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
7 7
8#include <bit>
9
8#include "common/assert.h" 10#include "common/assert.h"
9#include "common/bit_util.h" 11#include "common/bit_util.h"
10#include "common/fiber.h" 12#include "common/fiber.h"
@@ -31,12 +33,12 @@ static void IncrementScheduledCount(Kernel::Thread* thread) {
31 33
32void KScheduler::RescheduleCores(KernelCore& kernel, u64 cores_pending_reschedule, 34void KScheduler::RescheduleCores(KernelCore& kernel, u64 cores_pending_reschedule,
33 Core::EmuThreadHandle global_thread) { 35 Core::EmuThreadHandle global_thread) {
34 u32 current_core = global_thread.host_handle; 36 const u32 current_core = global_thread.host_handle;
35 bool must_context_switch = global_thread.guest_handle != InvalidHandle && 37 bool must_context_switch = global_thread.guest_handle != InvalidHandle &&
36 (current_core < Core::Hardware::NUM_CPU_CORES); 38 (current_core < Core::Hardware::NUM_CPU_CORES);
37 39
38 while (cores_pending_reschedule != 0) { 40 while (cores_pending_reschedule != 0) {
39 u32 core = Common::CountTrailingZeroes64(cores_pending_reschedule); 41 const auto core = static_cast<u32>(std::countr_zero(cores_pending_reschedule));
40 ASSERT(core < Core::Hardware::NUM_CPU_CORES); 42 ASSERT(core < Core::Hardware::NUM_CPU_CORES);
41 if (!must_context_switch || core != current_core) { 43 if (!must_context_switch || core != current_core) {
42 auto& phys_core = kernel.PhysicalCore(core); 44 auto& phys_core = kernel.PhysicalCore(core);
@@ -109,7 +111,7 @@ u64 KScheduler::UpdateHighestPriorityThreadsImpl(KernelCore& kernel) {
109 111
110 // Idle cores are bad. We're going to try to migrate threads to each idle core in turn. 112 // Idle cores are bad. We're going to try to migrate threads to each idle core in turn.
111 while (idle_cores != 0) { 113 while (idle_cores != 0) {
112 u32 core_id = Common::CountTrailingZeroes64(idle_cores); 114 const auto core_id = static_cast<u32>(std::countr_zero(idle_cores));
113 if (Thread* suggested = priority_queue.GetSuggestedFront(core_id); suggested != nullptr) { 115 if (Thread* suggested = priority_queue.GetSuggestedFront(core_id); suggested != nullptr) {
114 s32 migration_candidates[Core::Hardware::NUM_CPU_CORES]; 116 s32 migration_candidates[Core::Hardware::NUM_CPU_CORES];
115 size_t num_candidates = 0; 117 size_t num_candidates = 0;
diff --git a/src/core/hle/kernel/memory/page_heap.h b/src/core/hle/kernel/memory/page_heap.h
index 22b0de860..131093284 100644
--- a/src/core/hle/kernel/memory/page_heap.h
+++ b/src/core/hle/kernel/memory/page_heap.h
@@ -8,11 +8,11 @@
8#pragma once 8#pragma once
9 9
10#include <array> 10#include <array>
11#include <bit>
11#include <vector> 12#include <vector>
12 13
13#include "common/alignment.h" 14#include "common/alignment.h"
14#include "common/assert.h" 15#include "common/assert.h"
15#include "common/bit_util.h"
16#include "common/common_funcs.h" 16#include "common/common_funcs.h"
17#include "common/common_types.h" 17#include "common/common_types.h"
18#include "core/hle/kernel/memory/memory_types.h" 18#include "core/hle/kernel/memory/memory_types.h"
@@ -105,7 +105,7 @@ private:
105 ASSERT(depth == 0); 105 ASSERT(depth == 0);
106 return -1; 106 return -1;
107 } 107 }
108 offset = offset * 64 + Common::CountTrailingZeroes64(v); 108 offset = offset * 64 + static_cast<u32>(std::countr_zero(v));
109 ++depth; 109 ++depth;
110 } while (depth < static_cast<s32>(used_depths)); 110 } while (depth < static_cast<s32>(used_depths));
111 111
diff --git a/src/core/hle/kernel/process_capability.cpp b/src/core/hle/kernel/process_capability.cpp
index 0f128c586..0566311b6 100644
--- a/src/core/hle/kernel/process_capability.cpp
+++ b/src/core/hle/kernel/process_capability.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <bit>
6
5#include "common/bit_util.h" 7#include "common/bit_util.h"
6#include "common/logging/log.h" 8#include "common/logging/log.h"
7#include "core/hle/kernel/errors.h" 9#include "core/hle/kernel/errors.h"
@@ -60,7 +62,7 @@ constexpr CapabilityType GetCapabilityType(u32 value) {
60 62
61u32 GetFlagBitOffset(CapabilityType type) { 63u32 GetFlagBitOffset(CapabilityType type) {
62 const auto value = static_cast<u32>(type); 64 const auto value = static_cast<u32>(type);
63 return static_cast<u32>(Common::BitSize<u32>() - Common::CountLeadingZeroes32(value)); 65 return static_cast<u32>(Common::BitSize<u32>() - static_cast<u32>(std::countl_zero(value)));
64} 66}
65 67
66} // Anonymous namespace 68} // Anonymous namespace