mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2025-12-29 02:35:22 +01:00
u128: Implement u128
For when we need a 128-bit integer
This commit is contained in:
parent
e7409fdfe4
commit
8651c2d10e
3 changed files with 123 additions and 0 deletions
64
src/common/u128.cpp
Normal file
64
src/common/u128.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* This file is part of the dynarmic project.
|
||||
* Copyright (c) 2018 MerryMage
|
||||
* This software may be used and distributed according to the terms of the GNU
|
||||
* General Public License version 2 or any later version.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/u128.h"
|
||||
|
||||
namespace Dynarmic {
|
||||
|
||||
u128 operator<<(u128 operand, int amount) {
|
||||
if (amount < 0) {
|
||||
return operand >> -amount;
|
||||
}
|
||||
|
||||
if (amount == 0) {
|
||||
return operand;
|
||||
}
|
||||
|
||||
if (amount < 64) {
|
||||
u128 result;
|
||||
result.lower = (operand.lower << amount);
|
||||
result.upper = (operand.upper << amount) | (operand.lower >> (64 - amount));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (amount < 128) {
|
||||
u128 result;
|
||||
result.upper = operand.lower << (amount - 64);
|
||||
return result;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
u128 operator>>(u128 operand, int amount) {
|
||||
if (amount < 0) {
|
||||
return operand << -amount;
|
||||
}
|
||||
|
||||
if (amount == 0) {
|
||||
return operand;
|
||||
}
|
||||
|
||||
if (amount < 64) {
|
||||
u128 result;
|
||||
result.lower = (operand.lower >> amount) | (operand.upper << (64 - amount));
|
||||
result.upper = (operand.upper >> amount);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (amount < 128) {
|
||||
u128 result;
|
||||
result.lower = operand.upper >> (amount - 64);
|
||||
return result;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace Dynarmic
|
||||
Loading…
Add table
Add a link
Reference in a new issue