23#include <simde/x86/sse2.h>
29#ifndef _MM_DENORMALS_ZERO_MASK
30#define _MM_DENORMALS_ZERO_MASK 0x0040
35#if defined(__x86_64__) || defined(_M_X64)
39 static constexpr size_t kRoundShift = 13;
40 static constexpr size_t kRoundMaskVal = SIMDE_MM_ROUND_MASK;
42 static constexpr size_t kFlushMask = SIMDE_MM_FLUSH_ZERO_MASK | _MM_DENORMALS_ZERO_MASK;
44 static constexpr u32 kExceptionMask =
45 (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12);
47 static constexpr u32 kExceptionsMasked = kExceptionMask;
49 static constexpr size_t kGuestToHost[] = {SIMDE_MM_ROUND_NEAREST, SIMDE_MM_ROUND_TOWARD_ZERO,
50 SIMDE_MM_ROUND_UP, SIMDE_MM_ROUND_DOWN};
52 static constexpr u32 kHostToGuest[] = {0, 3, 2, 1};
55 static u32 GetCSR() noexcept {
return simde_mm_getcsr(); }
58 static void SetCSR(u32 csr)
noexcept { simde_mm_setcsr(csr); }
65 static void InitHostExceptions(u32& csr)
noexcept { csr |= kExceptionMask; }
68#elif defined(__aarch64__) || defined(_M_ARM64)
72 static constexpr size_t kRoundShift = 22;
73 static constexpr size_t kRoundMaskVal = 3 << kRoundShift;
74 static constexpr size_t kFlushMask = 1 << 24;
76 static constexpr size_t kGuestToHost[] = {0 << kRoundShift, 3 << kRoundShift, 1 << kRoundShift,
79 static constexpr u32 kHostToGuest[] = {0, 2, 3, 1};
81 static constexpr u32 kExceptionMask =
82 (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12) | (1 << 15);
84 static constexpr u32 kExceptionsMasked = 0;
87 static inline u32 GetCSR() noexcept {
89 __asm__ __volatile__(
"mrs %0, fpcr" :
"=r"(csr));
90 return static_cast<u32
>(csr);
94 static inline void SetCSR(u32 csr)
noexcept {
95 __asm__ __volatile__(
"msr fpcr, %0" : :
"r"(
static_cast<u64
>(csr)));
103 static inline void InitHostExceptions(u32& csr)
noexcept { csr &= ~kExceptionMask; }
107#error "Missing implementation for FPSCR."
116namespace rex::ppc::detail {
153 u32
GetRaw() const noexcept {
return (
lt << 3) | (
gt << 2) | (
eq << 1) | so; }
161 lt = (value >> 3) & 1;
162 gt = (value >> 2) & 1;
163 eq = (value >> 1) & 1;
172 template <
typename T>
182 un = std::isnan(left) || std::isnan(right);
183 lt = !un && (left < right);
184 gt = !un && (left > right);
185 eq = !un && (left == right);
196 int m = simde_mm_movemask_ps(mask);
211 int m = simde_mm_movemask_epi8(mask);
232constexpr u32 kRoundNearest = 0x00;
233constexpr u32 kRoundTowardZero = 0x01;
236constexpr u32 kRoundMask = 0x03;
253 for (u32 rn = 0; rn <= kRoundMask; ++rn) {
261 "kHostToGuest must invert kGuestToHost");
269 u32
GetCSR() noexcept {
return Platform::GetCSR(); }
276 void SetCSR(u32 value)
noexcept { Platform::SetCSR(value); }
301 csr |= Platform::kGuestToHost[value & kRoundMask];
349 Platform::InitHostExceptions(
csr);
364 u32
Read() const noexcept {
return static_cast<u32
>(
sat) | (
static_cast<u32
>(
nj) << 16); }
372 sat =
static_cast<u8
>(word & 1);
373 nj =
static_cast<u8
>((word >> 16) & 1);
443 PPCFPSCRRegister fpscr;
444 PPCVSCRRegister vscr;
652 void SetCR(rex::u32 value)
noexcept {
671 18 *
sizeof(PPCRegister) + 18 *
sizeof(PPCRegister) + 18 *
sizeof(PPCVRegister) +
673 sizeof(PPCFPSCRRegister);
677 std::memcpy(dst, &
r14, 18 *
sizeof(PPCRegister));
678 dst += 18 *
sizeof(PPCRegister);
679 std::memcpy(dst, &
f14, 18 *
sizeof(PPCRegister));
680 dst += 18 *
sizeof(PPCRegister);
681 std::memcpy(dst, &
v14, 18 *
sizeof(PPCVRegister));
682 dst += 18 *
sizeof(PPCVRegister);
683 std::memcpy(dst, &
v64, 64 *
sizeof(PPCVRegister));
684 dst += 64 *
sizeof(PPCVRegister);
687 std::memcpy(dst, &fpscr,
sizeof(PPCFPSCRRegister));
697 std::memcpy(&
r14, src, 18 *
sizeof(PPCRegister));
698 src += 18 *
sizeof(PPCRegister);
699 std::memcpy(&
f14, src, 18 *
sizeof(PPCRegister));
700 src += 18 *
sizeof(PPCRegister);
701 std::memcpy(&
v14, src, 18 *
sizeof(PPCVRegister));
702 src += 18 *
sizeof(PPCVRegister);
703 std::memcpy(&
v64, src, 64 *
sizeof(PPCVRegister));
704 src += 64 *
sizeof(PPCVRegister);
707 PPCFPSCRRegister saved_fpscr;
708 std::memcpy(&saved_fpscr, src,
sizeof(PPCFPSCRRegister));
709 fpscr.RestoreGuestBits(saved_fpscr.csr);
714 "cr2 to cr5 must be contiguous for the non volatile save area");
741inline void CheckHookContext(
const PPCContext&,
const char*) {}
Definition thread_state.h:40
Definition title_runtime.h:33
REX_PPC_API BoundThread GetBoundThread()
constexpr u32 kRoundDown
Definition context.h:235
constexpr u32 kRoundUp
Definition context.h:234
PPCCRRegister cr1
Definition context.h:436
PPCVRegister v20
Definition context.h:518
PPCRegister f6
Definition context.h:466
PPCCRRegister cr4
Definition context.h:439
PPCVRegister v48
Definition context.h:551
PPCVRegister v17
Definition context.h:515
PPCRegister r11
Definition context.h:405
PPCVRegister v124
Definition context.h:627
PPCRegister f21
Definition context.h:481
static constexpr size_t kNonVolatileCRCount
Definition context.h:664
PPCCRRegister cr7
Definition context.h:442
PPCVRegister v108
Definition context.h:611
PPCVRegister v72
Definition context.h:575
const std::atomic< bool > * stop_requested
Definition context.h:634
PPCVRegister v52
Definition context.h:555
PPCVRegister v91
Definition context.h:594
PPCVRegister v95
Definition context.h:598
void SaveNonVolatiles(u8 *dst) const
Definition context.h:676
PPCRegister f30
Definition context.h:490
PPCRegister f17
Definition context.h:477
PPCRegister f20
Definition context.h:480
PPCRegister f18
Definition context.h:478
PPCVRegister v69
Definition context.h:572
PPCRegister r22
Definition context.h:416
PPCVRegister v97
Definition context.h:600
PPCVRegister v98
Definition context.h:601
PPCCRRegister cr5
Definition context.h:440
PPCVRegister v46
Definition context.h:549
PPCVRegister v42
Definition context.h:545
PPCVRegister v66
Definition context.h:569
PPCRegister f1
Definition context.h:461
PPCRegister r14
Definition context.h:408
PPCRegister f19
Definition context.h:479
PPCRegister f16
Definition context.h:476
PPCVRegister v79
Definition context.h:582
PPCRegister r0
Definition context.h:395
PPCVRegister v119
Definition context.h:622
PPCRegister r24
Definition context.h:418
PPCVRegister v38
Definition context.h:541
u64 lr
Definition context.h:428
PPCVRegister v50
Definition context.h:553
PPCVRegister v87
Definition context.h:590
PPCVRegister v111
Definition context.h:614
PPCVRegister v53
Definition context.h:556
PPCVRegister v112
Definition context.h:615
PPCRegister r23
Definition context.h:417
PPCVRegister v34
Definition context.h:537
PPCRegister f31
Definition context.h:491
PPCVRegister v29
Definition context.h:527
PPCRegister f4
Definition context.h:464
PPCVRegister v59
Definition context.h:562
PPCRegister f15
Definition context.h:475
PPCVRegister v121
Definition context.h:624
static constexpr size_t kNonVolatileSaveSize
Definition context.h:670
PPCVRegister v86
Definition context.h:589
PPCVRegister v4
Definition context.h:502
PPCVRegister v125
Definition context.h:628
PPCVRegister v78
Definition context.h:581
PPCVRegister v120
Definition context.h:623
PPCVRegister v85
Definition context.h:588
PPCVRegister v71
Definition context.h:574
u32 msr
Definition context.h:434
PPCVRegister v81
Definition context.h:584
PPCRegister r30
Definition context.h:424
PPCVRegister v44
Definition context.h:547
PPCXERRegister xer
Definition context.h:430
PPCRegister reserved
Definition context.h:432
PPCVRegister v10
Definition context.h:508
PPCVRegister v94
Definition context.h:597
PPCVRegister v24
Definition context.h:522
PPCRegister r9
Definition context.h:403
PPCVRegister v14
Definition context.h:512
PPCVRegister v6
Definition context.h:504
PPCRegister r15
Definition context.h:409
PPCVRegister v114
Definition context.h:617
PPCVRegister v64
Definition context.h:567
PPCRegister f10
Definition context.h:470
PPCVRegister v99
Definition context.h:602
PPCVRegister v75
Definition context.h:578
PPCVRegister v28
Definition context.h:526
PPCVRegister v11
Definition context.h:509
PPCVRegister v103
Definition context.h:606
PPCVRegister v100
Definition context.h:603
rex::u32 GetCR() const noexcept
Definition context.h:641
PPCVRegister v68
Definition context.h:571
PPCVRegister v37
Definition context.h:540
PPCVRegister v19
Definition context.h:517
rex::kernel::ThreadState * thread_state
Definition context.h:450
PPCVRegister v21
Definition context.h:519
PPCVRegister v80
Definition context.h:583
PPCVRegister v117
Definition context.h:620
PPCRegister f2
Definition context.h:462
PPCVRegister v77
Definition context.h:580
PPCRegister f0
Definition context.h:460
PPCVRegister v73
Definition context.h:576
PPCRegister f29
Definition context.h:489
PPCRegister r18
Definition context.h:412
PPCVRegister v105
Definition context.h:608
PPCVRegister v31
Definition context.h:529
PPCVRegister v101
Definition context.h:604
PPCVRegister v33
Definition context.h:536
PPCVRegister v60
Definition context.h:563
PPCRegister f7
Definition context.h:467
PPCVRegister v35
Definition context.h:538
PPCRegister r2
Definition context.h:397
u32 last_indirect_target
Definition context.h:447
PPCRegister r21
Definition context.h:415
PPCRegister f14
Definition context.h:474
PPCRegister f28
Definition context.h:488
PPCRegister r7
Definition context.h:401
PPCRegister f13
Definition context.h:473
PPCRegister f25
Definition context.h:485
PPCRegister f23
Definition context.h:483
PPCVRegister v2
Definition context.h:500
PPCVRegister v126
Definition context.h:629
PPCRegister r3
Definition context.h:389
PPCVRegister v43
Definition context.h:546
PPCVRegister v23
Definition context.h:521
PPCRegister r10
Definition context.h:404
PPCVRegister v51
Definition context.h:554
PPCVRegister v12
Definition context.h:510
PPCVRegister v88
Definition context.h:591
PPCVRegister v92
Definition context.h:595
void RestoreNonVolatiles(const u8 *src)
Definition context.h:696
PPCCRRegister cr0
Definition context.h:435
PPCVRegister v104
Definition context.h:607
PPCRegister r17
Definition context.h:411
PPCVRegister v54
Definition context.h:557
PPCRegister f22
Definition context.h:482
PPCVRegister v123
Definition context.h:626
PPCVRegister v107
Definition context.h:610
PPCVRegister v45
Definition context.h:548
PPCVRegister v16
Definition context.h:514
PPCRegister ctr
Definition context.h:429
PPCVRegister v9
Definition context.h:507
PPCVRegister v116
Definition context.h:619
PPCRegister r8
Definition context.h:402
PPCVRegister v61
Definition context.h:564
PPCVRegister v30
Definition context.h:528
PPCVRegister v27
Definition context.h:525
PPCVRegister v26
Definition context.h:524
PPCRegister r5
Definition context.h:399
PPCVRegister v76
Definition context.h:579
PPCVRegister v102
Definition context.h:605
rex::ppc::detail::DetourFrame * detour_frame
Definition context.h:453
PPCRegister r31
Definition context.h:425
PPCCRRegister cr6
Definition context.h:441
PPCVRegister v25
Definition context.h:523
PPCVRegister v127
Definition context.h:630
PPCVRegister v70
Definition context.h:573
PPCVRegister v1
Definition context.h:499
PPCRegister r29
Definition context.h:423
PPCVRegister v8
Definition context.h:506
PPCVRegister v115
Definition context.h:618
PPCVRegister v15
Definition context.h:513
PPCVRegister v47
Definition context.h:550
PPCVRegister v36
Definition context.h:539
PPCRegister r28
Definition context.h:422
PPCVRegister v62
Definition context.h:565
PPCRegister f3
Definition context.h:463
PPCVRegister v109
Definition context.h:612
PPCRegister r25
Definition context.h:419
PPCRegister f5
Definition context.h:465
PPCRegister r27
Definition context.h:421
PPCVRegister v7
Definition context.h:505
PPCVRegister v84
Definition context.h:587
PPCRegister r4
Definition context.h:398
PPCRegister r13
Definition context.h:407
PPCRegister f27
Definition context.h:487
PPCVRegister v58
Definition context.h:561
PPCVRegister v22
Definition context.h:520
PPCVRegister v32
Definition context.h:535
PPCVRegister v18
Definition context.h:516
PPCRegister r12
Definition context.h:406
PPCVRegister v106
Definition context.h:609
PPCVRegister v89
Definition context.h:592
PPCVRegister v41
Definition context.h:544
PPCVRegister v55
Definition context.h:558
PPCVRegister v110
Definition context.h:613
PPCVRegister v57
Definition context.h:560
PPCRegister f11
Definition context.h:471
PPCVRegister v40
Definition context.h:543
PPCVRegister v83
Definition context.h:586
PPCVRegister v90
Definition context.h:593
PPCVRegister v0
Definition context.h:498
PPCRegister r6
Definition context.h:400
PPCVRegister v13
Definition context.h:511
PPCRegister r19
Definition context.h:413
PPCVRegister v93
Definition context.h:596
PPCVRegister v39
Definition context.h:542
PPCVRegister v3
Definition context.h:501
PPCCRRegister cr2
Definition context.h:437
PPCVRegister v82
Definition context.h:585
PPCCRRegister cr3
Definition context.h:438
PPCVRegister v113
Definition context.h:616
PPCRegister f12
Definition context.h:472
PPCVRegister v74
Definition context.h:577
PPCRegister f26
Definition context.h:486
PPCRegister f8
Definition context.h:468
PPCRegister r20
Definition context.h:414
PPCVRegister v56
Definition context.h:559
PPCVRegister v49
Definition context.h:552
PPCRegister f9
Definition context.h:469
PPCVRegister v122
Definition context.h:625
PPCVRegister v5
Definition context.h:503
PPCVRegister v63
Definition context.h:566
PPCVRegister v65
Definition context.h:568
PPCVRegister v67
Definition context.h:570
PPCRegister r1
Definition context.h:396
PPCRegister f24
Definition context.h:484
PPCRegister r26
Definition context.h:420
void SetCR(rex::u32 value) noexcept
Definition context.h:652
PPCVRegister v96
Definition context.h:599
PPCRegister r16
Definition context.h:410
PPCVRegister v118
Definition context.h:621
PPCContext * ctx
Definition context.h:720
u8 * base
Definition context.h:721
u8 gt
Definition context.h:145
void SetFromMask(simde__m128i mask, int imm) noexcept
Definition context.h:210
void SetRaw(u32 value) noexcept
Definition context.h:160
void Compare(T left, T right, const XERRegister &xer) noexcept
Definition context.h:173
u8 eq
Definition context.h:146
u32 GetRaw() const noexcept
Definition context.h:153
void SetFromMask(simde__m128 mask, int imm) noexcept
Definition context.h:195
void Compare(f64 left, f64 right) noexcept
Definition context.h:181
u8 lt
Definition context.h:144
static constexpr size_t kFlushMask
Definition context.h:249
static constexpr size_t kRoundShift
Definition context.h:245
void SetFlushMode(bool enable) noexcept
Definition context.h:338
void RestoreGuestBits(u32 saved) noexcept
Definition context.h:279
u32 LoadFromHost() noexcept
Definition context.h:289
void EnableFlushMode() noexcept
Definition context.h:318
void DisableFlushMode() noexcept
Definition context.h:326
static constexpr u32 kGuestMask
Definition context.h:264
u32 csr
Definition context.h:240
void EnableFlushModeUnconditional() noexcept
Definition context.h:306
FPSCRPlatform Platform
Definition context.h:243
static constexpr size_t kRoundMaskVal
Definition context.h:247
void StoreToHost(u32 value) noexcept
Definition context.h:299
void SetCSR(u32 value) noexcept
Definition context.h:276
void DisableFlushModeUnconditional() noexcept
Definition context.h:312
void InitHost() noexcept
Definition context.h:347
u32 GetCSR() noexcept
Definition context.h:269
u8 nj
Definition context.h:357
u8 sat
Definition context.h:356
u32 Read() const noexcept
Definition context.h:364
void Write(u32 word) noexcept
Definition context.h:371
u8 ov
Definition context.h:138
u8 ca
Definition context.h:139
u8 so
Definition context.h:137
Integer types, byte order wrappers and size literals.