Skip to content

Commit 4a9e01c

Browse files
committed
Compiler: Make use of ArithmeticRightShift function
1 parent c124b2f commit 4a9e01c

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

src/NZSL/Ast/ConstantPropagationVisitor_BinaryArithmetics.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// For conditions of distribution and use, see copyright notice in Config.hpp
44

55
#include <NazaraUtils/Algorithm.hpp>
6+
#include <NazaraUtils/MathUtils.hpp>
67
#include <NZSL/ShaderBuilder.hpp>
78
#include <NZSL/Ast/ConstantPropagationVisitor.hpp>
89
#include <NZSL/Lang/Errors.hpp>
@@ -289,24 +290,7 @@ namespace nzsl::Ast
289290
throw CompilerBinaryTooLargeShiftError{ sourceLocation, ConstantToString(lhs), ">>", ConstantToString(rhs), ToString(GetConstantExpressionType<T1>()) };
290291
}
291292

292-
T1 result;
293-
#if NAZARA_CHECK_CPP_VER(NAZARA_CPP20)
294-
// C++20 ensures that right shift performs an arthmetic shift on signed integers
295-
result = lhs >> rhs;
296-
#else
297-
// Implement arithmetic shift on C++ <=17
298-
if constexpr (std::is_signed_v<T2>)
299-
{
300-
if (lhs < 0 && rhs > 0)
301-
result = (lhs >> rhs) | ~(~static_cast<std::make_unsigned_t<T1>>(0u) >> rhs);
302-
else
303-
result = lhs >> rhs;
304-
}
305-
else
306-
result = lhs >> rhs;
307-
#endif
308-
309-
return ShaderBuilder::ConstantValue(result);
293+
return ShaderBuilder::ConstantValue(Nz::ArithmeticRightShift(lhs, rhs));
310294
}
311295
};
312296

xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727

2828
add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo")
2929
add_requires("fmt", { configs = { header_only = true }, system = false })
30-
add_requires("nazarautils >=2024.01.02", "fast_float", "frozen", "ordered_map")
30+
add_requires("nazarautils >=2024.01.13", "fast_float", "frozen", "ordered_map")
3131

3232
if has_config("fs_watcher") then
3333
add_requires("efsw")

0 commit comments

Comments
 (0)