summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2019-10-23 23:44:30 -0400
committerGravatar Lioncash2019-10-24 00:25:38 -0400
commit382717172e7c05f7487e6504b9ae98eeea768e1d (patch)
tree3763e62e6f05e46a26c0acf4a7e129e8786ee0fe /src
parentMerge pull request #3022 from DarkLordZach/azure-folder-rename (diff)
downloadyuzu-382717172e7c05f7487e6504b9ae98eeea768e1d.tar.gz
yuzu-382717172e7c05f7487e6504b9ae98eeea768e1d.tar.xz
yuzu-382717172e7c05f7487e6504b9ae98eeea768e1d.zip
shader_ir: Use std::array with pair instead of unordered_map
Given the overall size of the maps are very small, we can use arrays of pairs here instead of always heap allocating a new map every time the functions are called. Given the small size of the maps, the difference in container lookups are negligible, especially given the entries are already sorted.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/shader/shader_ir.cpp120
1 files changed, 67 insertions, 53 deletions
diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp
index c1f2b88c8..b10d376cb 100644
--- a/src/video_core/shader/shader_ir.cpp
+++ b/src/video_core/shader/shader_ir.cpp
@@ -2,8 +2,9 @@
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 <algorithm>
6#include <array>
5#include <cmath> 7#include <cmath>
6#include <unordered_map>
7 8
8#include "common/assert.h" 9#include "common/assert.h"
9#include "common/common_types.h" 10#include "common/common_types.h"
@@ -271,21 +272,24 @@ Node ShaderIR::GetSaturatedHalfFloat(Node value, bool saturate) {
271} 272}
272 273
273Node ShaderIR::GetPredicateComparisonFloat(PredCondition condition, Node op_a, Node op_b) { 274Node ShaderIR::GetPredicateComparisonFloat(PredCondition condition, Node op_a, Node op_b) {
274 const std::unordered_map<PredCondition, OperationCode> PredicateComparisonTable = { 275 static constexpr std::array comparison_table{
275 {PredCondition::LessThan, OperationCode::LogicalFLessThan}, 276 std::pair{PredCondition::LessThan, OperationCode::LogicalFLessThan},
276 {PredCondition::Equal, OperationCode::LogicalFEqual}, 277 std::pair{PredCondition::Equal, OperationCode::LogicalFEqual},
277 {PredCondition::LessEqual, OperationCode::LogicalFLessEqual}, 278 std::pair{PredCondition::LessEqual, OperationCode::LogicalFLessEqual},
278 {PredCondition::GreaterThan, OperationCode::LogicalFGreaterThan}, 279 std::pair{PredCondition::GreaterThan, OperationCode::LogicalFGreaterThan},
279 {PredCondition::NotEqual, OperationCode::LogicalFNotEqual}, 280 std::pair{PredCondition::NotEqual, OperationCode::LogicalFNotEqual},
280 {PredCondition::GreaterEqual, OperationCode::LogicalFGreaterEqual}, 281 std::pair{PredCondition::GreaterEqual, OperationCode::LogicalFGreaterEqual},
281 {PredCondition::LessThanWithNan, OperationCode::LogicalFLessThan}, 282 std::pair{PredCondition::LessThanWithNan, OperationCode::LogicalFLessThan},
282 {PredCondition::NotEqualWithNan, OperationCode::LogicalFNotEqual}, 283 std::pair{PredCondition::NotEqualWithNan, OperationCode::LogicalFNotEqual},
283 {PredCondition::LessEqualWithNan, OperationCode::LogicalFLessEqual}, 284 std::pair{PredCondition::LessEqualWithNan, OperationCode::LogicalFLessEqual},
284 {PredCondition::GreaterThanWithNan, OperationCode::LogicalFGreaterThan}, 285 std::pair{PredCondition::GreaterThanWithNan, OperationCode::LogicalFGreaterThan},
285 {PredCondition::GreaterEqualWithNan, OperationCode::LogicalFGreaterEqual}}; 286 std::pair{PredCondition::GreaterEqualWithNan, OperationCode::LogicalFGreaterEqual},
286 287 };
287 const auto comparison{PredicateComparisonTable.find(condition)}; 288
288 UNIMPLEMENTED_IF_MSG(comparison == PredicateComparisonTable.end(), 289 const auto comparison =
290 std::find_if(comparison_table.cbegin(), comparison_table.cend(),
291 [condition](const auto entry) { return condition == entry.first; });
292 UNIMPLEMENTED_IF_MSG(comparison == comparison_table.cend(),
289 "Unknown predicate comparison operation"); 293 "Unknown predicate comparison operation");
290 294
291 Node predicate = Operation(comparison->second, NO_PRECISE, op_a, op_b); 295 Node predicate = Operation(comparison->second, NO_PRECISE, op_a, op_b);
@@ -306,21 +310,24 @@ Node ShaderIR::GetPredicateComparisonFloat(PredCondition condition, Node op_a, N
306 310
307Node ShaderIR::GetPredicateComparisonInteger(PredCondition condition, bool is_signed, Node op_a, 311Node ShaderIR::GetPredicateComparisonInteger(PredCondition condition, bool is_signed, Node op_a,
308 Node op_b) { 312 Node op_b) {
309 const std::unordered_map<PredCondition, OperationCode> PredicateComparisonTable = { 313 static constexpr std::array comparison_table{
310 {PredCondition::LessThan, OperationCode::LogicalILessThan}, 314 std::pair{PredCondition::LessThan, OperationCode::LogicalILessThan},
311 {PredCondition::Equal, OperationCode::LogicalIEqual}, 315 std::pair{PredCondition::Equal, OperationCode::LogicalIEqual},
312 {PredCondition::LessEqual, OperationCode::LogicalILessEqual}, 316 std::pair{PredCondition::LessEqual, OperationCode::LogicalILessEqual},
313 {PredCondition::GreaterThan, OperationCode::LogicalIGreaterThan}, 317 std::pair{PredCondition::GreaterThan, OperationCode::LogicalIGreaterThan},
314 {PredCondition::NotEqual, OperationCode::LogicalINotEqual}, 318 std::pair{PredCondition::NotEqual, OperationCode::LogicalINotEqual},
315 {PredCondition::GreaterEqual, OperationCode::LogicalIGreaterEqual}, 319 std::pair{PredCondition::GreaterEqual, OperationCode::LogicalIGreaterEqual},
316 {PredCondition::LessThanWithNan, OperationCode::LogicalILessThan}, 320 std::pair{PredCondition::LessThanWithNan, OperationCode::LogicalILessThan},
317 {PredCondition::NotEqualWithNan, OperationCode::LogicalINotEqual}, 321 std::pair{PredCondition::NotEqualWithNan, OperationCode::LogicalINotEqual},
318 {PredCondition::LessEqualWithNan, OperationCode::LogicalILessEqual}, 322 std::pair{PredCondition::LessEqualWithNan, OperationCode::LogicalILessEqual},
319 {PredCondition::GreaterThanWithNan, OperationCode::LogicalIGreaterThan}, 323 std::pair{PredCondition::GreaterThanWithNan, OperationCode::LogicalIGreaterThan},
320 {PredCondition::GreaterEqualWithNan, OperationCode::LogicalIGreaterEqual}}; 324 std::pair{PredCondition::GreaterEqualWithNan, OperationCode::LogicalIGreaterEqual},
321 325 };
322 const auto comparison{PredicateComparisonTable.find(condition)}; 326
323 UNIMPLEMENTED_IF_MSG(comparison == PredicateComparisonTable.end(), 327 const auto comparison =
328 std::find_if(comparison_table.cbegin(), comparison_table.cend(),
329 [condition](const auto entry) { return condition == entry.first; });
330 UNIMPLEMENTED_IF_MSG(comparison == comparison_table.cend(),
324 "Unknown predicate comparison operation"); 331 "Unknown predicate comparison operation");
325 332
326 Node predicate = SignedOperation(comparison->second, is_signed, NO_PRECISE, std::move(op_a), 333 Node predicate = SignedOperation(comparison->second, is_signed, NO_PRECISE, std::move(op_a),
@@ -337,36 +344,43 @@ Node ShaderIR::GetPredicateComparisonInteger(PredCondition condition, bool is_si
337 344
338Node ShaderIR::GetPredicateComparisonHalf(Tegra::Shader::PredCondition condition, Node op_a, 345Node ShaderIR::GetPredicateComparisonHalf(Tegra::Shader::PredCondition condition, Node op_a,
339 Node op_b) { 346 Node op_b) {
340 const std::unordered_map<PredCondition, OperationCode> PredicateComparisonTable = { 347 static constexpr std::array comparison_table{
341 {PredCondition::LessThan, OperationCode::Logical2HLessThan}, 348 std::pair{PredCondition::LessThan, OperationCode::Logical2HLessThan},
342 {PredCondition::Equal, OperationCode::Logical2HEqual}, 349 std::pair{PredCondition::Equal, OperationCode::Logical2HEqual},
343 {PredCondition::LessEqual, OperationCode::Logical2HLessEqual}, 350 std::pair{PredCondition::LessEqual, OperationCode::Logical2HLessEqual},
344 {PredCondition::GreaterThan, OperationCode::Logical2HGreaterThan}, 351 std::pair{PredCondition::GreaterThan, OperationCode::Logical2HGreaterThan},
345 {PredCondition::NotEqual, OperationCode::Logical2HNotEqual}, 352 std::pair{PredCondition::NotEqual, OperationCode::Logical2HNotEqual},
346 {PredCondition::GreaterEqual, OperationCode::Logical2HGreaterEqual}, 353 std::pair{PredCondition::GreaterEqual, OperationCode::Logical2HGreaterEqual},
347 {PredCondition::LessThanWithNan, OperationCode::Logical2HLessThanWithNan}, 354 std::pair{PredCondition::LessThanWithNan, OperationCode::Logical2HLessThanWithNan},
348 {PredCondition::NotEqualWithNan, OperationCode::Logical2HNotEqualWithNan}, 355 std::pair{PredCondition::NotEqualWithNan, OperationCode::Logical2HNotEqualWithNan},
349 {PredCondition::LessEqualWithNan, OperationCode::Logical2HLessEqualWithNan}, 356 std::pair{PredCondition::LessEqualWithNan, OperationCode::Logical2HLessEqualWithNan},
350 {PredCondition::GreaterThanWithNan, OperationCode::Logical2HGreaterThanWithNan}, 357 std::pair{PredCondition::GreaterThanWithNan, OperationCode::Logical2HGreaterThanWithNan},
351 {PredCondition::GreaterEqualWithNan, OperationCode::Logical2HGreaterEqualWithNan}}; 358 std::pair{PredCondition::GreaterEqualWithNan, OperationCode::Logical2HGreaterEqualWithNan},
352 359 };
353 const auto comparison{PredicateComparisonTable.find(condition)}; 360
354 UNIMPLEMENTED_IF_MSG(comparison == PredicateComparisonTable.end(), 361 const auto comparison =
362 std::find_if(comparison_table.cbegin(), comparison_table.cend(),
363 [condition](const auto entry) { return condition == entry.first; });
364 UNIMPLEMENTED_IF_MSG(comparison == comparison_table.cend(),
355 "Unknown predicate comparison operation"); 365 "Unknown predicate comparison operation");
356 366
357 return Operation(comparison->second, NO_PRECISE, std::move(op_a), std::move(op_b)); 367 return Operation(comparison->second, NO_PRECISE, std::move(op_a), std::move(op_b));
358} 368}
359 369
360OperationCode ShaderIR::GetPredicateCombiner(PredOperation operation) { 370OperationCode ShaderIR::GetPredicateCombiner(PredOperation operation) {
361 const std::unordered_map<PredOperation, OperationCode> PredicateOperationTable = { 371 static constexpr std::array operation_table{
362 {PredOperation::And, OperationCode::LogicalAnd}, 372 OperationCode::LogicalAnd,
363 {PredOperation::Or, OperationCode::LogicalOr}, 373 OperationCode::LogicalOr,
364 {PredOperation::Xor, OperationCode::LogicalXor}, 374 OperationCode::LogicalXor,
365 }; 375 };
366 376
367 const auto op = PredicateOperationTable.find(operation); 377 const auto index = static_cast<std::size_t>(operation);
368 UNIMPLEMENTED_IF_MSG(op == PredicateOperationTable.end(), "Unknown predicate operation"); 378 if (index >= operation_table.size()) {
369 return op->second; 379 UNIMPLEMENTED_MSG("Unknown predicate operation.");
380 return {};
381 }
382
383 return operation_table[index];
370} 384}
371 385
372Node ShaderIR::GetConditionCode(Tegra::Shader::ConditionCode cc) const { 386Node ShaderIR::GetConditionCode(Tegra::Shader::ConditionCode cc) const {