From ad9c9f01833f12d9e01b6c854906e143714e7b31 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 30 Nov 2019 01:28:06 +0300 Subject: [PATCH] C-style cast cleanup II --- rpcs3/Crypto/unedat.cpp | 98 ++++----- rpcs3/Crypto/unedat.h | 2 +- rpcs3/Crypto/unpkg.cpp | 12 +- rpcs3/Emu/Audio/AudioDumper.h | 10 +- rpcs3/Emu/Cell/PPUAnalyser.cpp | 20 +- rpcs3/Emu/Cell/PPUDisAsm.cpp | 2 +- rpcs3/Emu/Cell/PPUFunction.cpp | 2 +- rpcs3/Emu/Cell/PPUInterpreter.cpp | 326 ++++++++++++++--------------- rpcs3/Emu/Cell/PPUModule.cpp | 24 +-- rpcs3/Emu/Cell/SPUDisAsm.cpp | 2 +- rpcs3/Emu/Cell/SPUDisAsm.h | 4 +- rpcs3/Emu/Cell/lv2/sys_event.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_net.cpp | 94 +++++---- rpcs3/Emu/Cell/lv2/sys_overlay.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_tty.cpp | 2 +- rpcs3/Emu/GDB.cpp | 4 +- rpcs3/Loader/TROPUSR.cpp | 14 +- 18 files changed, 314 insertions(+), 308 deletions(-) diff --git a/rpcs3/Crypto/unedat.cpp b/rpcs3/Crypto/unedat.cpp index 178ec33f28..d1f30dbdec 100644 --- a/rpcs3/Crypto/unedat.cpp +++ b/rpcs3/Crypto/unedat.cpp @@ -6,7 +6,7 @@ void generate_key(int crypto_mode, int version, unsigned char *key_final, unsigned char *iv_final, unsigned char *key, unsigned char *iv) { - int mode = (int)(crypto_mode & 0xF0000000); + int mode = crypto_mode & 0xF0000000; switch (mode) { case 0x10000000: @@ -32,7 +32,7 @@ void generate_key(int crypto_mode, int version, unsigned char *key_final, unsign void generate_hash(int hash_mode, int version, unsigned char *hash_final, unsigned char *hash) { - int mode = (int)(hash_mode & 0xF0000000); + int mode = hash_mode & 0xF0000000; switch (mode) { case 0x10000000: @@ -81,7 +81,7 @@ bool decrypt(int hash_mode, int crypto_mode, int version, unsigned char *in, uns LOG_ERROR(LOADER, "EDAT: Unknown crypto algorithm!"); return false; } - + if ((hash_mode & 0xFF) == 0x01) // 0x14 SHA1-HMAC { return hmac_hash_compare(hash_final_14, 0x14, in, length, test_hash, 0x14); @@ -122,9 +122,9 @@ std::tuple dec_section(unsigned char* metadata) dec[0x0E] = (metadata[0x6] ^ metadata[0x2] ^ metadata[0x1E]); dec[0x0F] = (metadata[0x7] ^ metadata[0x3] ^ metadata[0x1F]); - u64 offset = swap64(*(u64*)&dec[0]); - s32 length = swap32(*(s32*)&dec[8]); - s32 compression_end = swap32(*(s32*)&dec[12]); + u64 offset = swap64(*reinterpret_cast(&dec[0])); + s32 length = swap32(*reinterpret_cast(&dec[8])); + s32 compression_end = swap32(*reinterpret_cast(&dec[12])); return std::make_tuple(offset, length, compression_end); } @@ -168,7 +168,7 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np // Decrypt the metadata. if ((edat->flags & EDAT_COMPRESSED_FLAG) != 0) { - metadata_sec_offset = metadata_offset + (unsigned long long) block_num * metadata_section_size; + metadata_sec_offset = metadata_offset + u64{block_num} * metadata_section_size; in->seek(file_offset + metadata_sec_offset); @@ -180,9 +180,9 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np // NOTE: For NPD version 1 the metadata is not encrypted. if (npd->version <= 1) { - offset = swap64(*(unsigned long long*)&metadata[0x10]); - length = swap32(*(int*)&metadata[0x18]); - compression_end = swap32(*(int*)&metadata[0x1C]); + offset = swap64(*reinterpret_cast(&metadata[0x10])); + length = swap32(*reinterpret_cast(&metadata[0x18])); + compression_end = swap32(*reinterpret_cast(&metadata[0x1C])); } else { @@ -194,7 +194,7 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np else if ((edat->flags & EDAT_FLAG_0x20) != 0) { // If FLAG 0x20, the metadata precedes each data block. - metadata_sec_offset = metadata_offset + (u64) block_num * (metadata_section_size + edat->block_size); + metadata_sec_offset = metadata_offset + u64{block_num} * (metadata_section_size + edat->block_size); in->seek(file_offset + metadata_sec_offset); unsigned char metadata[0x20]; @@ -204,30 +204,30 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np // If FLAG 0x20 is set, apply custom xor. for (int j = 0; j < 0x10; j++) - hash_result[j] = (unsigned char)(metadata[j] ^ metadata[j + 0x10]); + hash_result[j] = metadata[j] ^ metadata[j + 0x10]; offset = metadata_sec_offset + 0x20; length = edat->block_size; if ((block_num == (total_blocks - 1)) && (edat->file_size % edat->block_size)) - length = (int)(edat->file_size % edat->block_size); + length = static_cast(edat->file_size % edat->block_size); } else { - metadata_sec_offset = metadata_offset + (u64) block_num * metadata_section_size; + metadata_sec_offset = metadata_offset + u64{block_num} * metadata_section_size; in->seek(file_offset + metadata_sec_offset); in->read(hash_result, 0x10); - offset = metadata_offset + (u64) block_num * edat->block_size + total_blocks * metadata_section_size; + offset = metadata_offset + u64{block_num} * edat->block_size + total_blocks * metadata_section_size; length = edat->block_size; if ((block_num == (total_blocks - 1)) && (edat->file_size % edat->block_size)) - length = (int)(edat->file_size % edat->block_size); + length = static_cast(edat->file_size % edat->block_size); } // Locate the real data. const int pad_length = length; - length = (int)((pad_length + 0xF) & 0xFFFFFFF0); + length = (pad_length + 0xF) & 0xFFFFFFF0; // Setup buffers for decryption and read the data. enc_data.reset(new u8[length]{ 0 }); @@ -280,7 +280,7 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np // Call main crypto routine on this data block. if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), enc_data.get(), dec_data.get(), length, key_result, iv, hash, hash_result)) { - LOG_ERROR(LOADER, "EDAT: Block at offset 0x%llx has invalid hash!", (u64)offset); + LOG_ERROR(LOADER, "EDAT: Block at offset 0x%llx has invalid hash!", offset); return -1; } } @@ -313,8 +313,8 @@ s64 decrypt_block(const fs::file* in, u8* out, EDAT_HEADER *edat, NPD_HEADER *np // reset file to beginning of data before calling int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD_HEADER *npd, unsigned char* crypt_key, bool verbose) { - const int total_blocks = (int)((edat->file_size + edat->block_size - 1) / edat->block_size); - u64 size_left = (int)edat->file_size; + const int total_blocks = static_cast((edat->file_size + edat->block_size - 1) / edat->block_size); + u64 size_left = edat->file_size; std::unique_ptr data(new u8[edat->block_size]); for (int i = 0; i < total_blocks; i++) @@ -341,7 +341,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs: u8 empty_header[0xA0] = { 0 }; u8 header_hash[0x10] = { 0 }; u8 metadata_hash[0x10] = { 0 }; - + const u64 file_offset = f->pos(); // Check NPD version and flags. @@ -397,7 +397,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs: // Setup header key and iv buffers. unsigned char header_key[0x10] = { 0 }; unsigned char header_iv[0x10] = { 0 }; - + // Test the header hash (located at offset 0xA0). if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), header, empty_header, 0xA0, header_key, header_iv, key, header_hash)) { @@ -420,7 +420,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs: LOG_WARNING(LOADER, "EDAT: COMPRESSED data detected!"); } - const int block_num = (int)((edat->file_size + edat->block_size - 1) / edat->block_size); + const int block_num = static_cast((edat->file_size + edat->block_size - 1) / edat->block_size); const int metadata_offset = 0x100; const int metadata_size = metadata_section_size * block_num; u64 metadata_section_offset = metadata_offset; @@ -465,7 +465,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs: unsigned char signature_r[0x15] = { 0 }; unsigned char signature_s[0x15] = { 0 }; unsigned char zero_buf[0x15] = { 0 }; - + // Setup ECDSA curve and public key. ecdsa_set_curve(VSH_CURVE_P, VSH_CURVE_A, VSH_CURVE_B, VSH_CURVE_N, VSH_CURVE_GX, VSH_CURVE_GY); ecdsa_set_pub(VSH_PUB); @@ -498,7 +498,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs: if (!ecdsa_verify(signature_hash, signature_r, signature_s)) { LOG_WARNING(LOADER, "EDAT: Metadata signature is invalid!"); - if (((unsigned long long)edat->block_size * block_num) > 0x100000000) + if (((edat->block_size + 0ull) * block_num) > 0x100000000) LOG_WARNING(LOADER, "EDAT: *Due to large file size, metadata signature status may be incorrect!"); } } @@ -576,9 +576,9 @@ int validate_npd_hashes(const char* file_name, const u8* klicensee, NPD_HEADER * int title_hash_result = 0; int dev_hash_result = 0; - const int file_name_length = (int) strlen(file_name); + const auto file_name_length = std::strlen(file_name); std::unique_ptr buf(new u8[0x30 + file_name_length]); - + // Build the title buffer (content_id + file_name). memcpy(buf.get(), npd->content_id, 0x30); memcpy(buf.get() + 0x30, file_name, file_name_length); @@ -594,7 +594,7 @@ int validate_npd_hashes(const char* file_name, const u8* klicensee, NPD_HEADER * LOG_WARNING(LOADER, "EDAT: NPD title hash is invalid!"); } - + dev_hash_result = validate_dev_klic(klicensee, npd); return (title_hash_result && dev_hash_result); @@ -608,19 +608,19 @@ void read_npd_edat_header(const fs::file* input, NPD_HEADER& NPD, EDAT_HEADER& E input->read(edat_header, sizeof(edat_header)); memcpy(&NPD.magic, npd_header, 4); - NPD.version = swap32(*(int*)&npd_header[4]); - NPD.license = swap32(*(int*)&npd_header[8]); - NPD.type = swap32(*(int*)&npd_header[12]); - memcpy(NPD.content_id, (unsigned char*)&npd_header[16], 0x30); - memcpy(NPD.digest, (unsigned char*)&npd_header[64], 0x10); - memcpy(NPD.title_hash, (unsigned char*)&npd_header[80], 0x10); - memcpy(NPD.dev_hash, (unsigned char*)&npd_header[96], 0x10); - NPD.unk1 = swap64(*(u64*)&npd_header[112]); - NPD.unk2 = swap64(*(u64*)&npd_header[120]); + NPD.version = swap32(*reinterpret_cast(&npd_header[4])); + NPD.license = swap32(*reinterpret_cast(&npd_header[8])); + NPD.type = swap32(*reinterpret_cast(&npd_header[12])); + memcpy(NPD.content_id, &npd_header[16], 0x30); + memcpy(NPD.digest, &npd_header[64], 0x10); + memcpy(NPD.title_hash, &npd_header[80], 0x10); + memcpy(NPD.dev_hash, &npd_header[96], 0x10); + NPD.unk1 = swap64(*reinterpret_cast(&npd_header[112])); + NPD.unk2 = swap64(*reinterpret_cast(&npd_header[120])); - EDAT.flags = swap32(*(int*)&edat_header[0]); - EDAT.block_size = swap32(*(int*)&edat_header[4]); - EDAT.file_size = swap64(*(u64*)&edat_header[8]); + EDAT.flags = swap32(*reinterpret_cast(&edat_header[0])); + EDAT.block_size = swap32(*reinterpret_cast(&edat_header[4])); + EDAT.file_size = swap64(*reinterpret_cast(&edat_header[8])); } bool extract_all_data(const fs::file* input, const fs::file* output, const char* input_file_name, unsigned char* devklic, unsigned char* rifkey, bool verbose) @@ -658,7 +658,7 @@ bool extract_all_data(const fs::file* input, const fs::file* output, const char* LOG_NOTICE(LOADER, "SDAT HEADER"); LOG_NOTICE(LOADER, "SDAT flags: 0x%08X", EDAT.flags); LOG_NOTICE(LOADER, "SDAT block size: 0x%08X", EDAT.block_size); - LOG_NOTICE(LOADER, "SDAT file size: 0x%08X", (u64)EDAT.file_size); + LOG_NOTICE(LOADER, "SDAT file size: 0x%08X", EDAT.file_size); } // Generate SDAT key. @@ -671,7 +671,7 @@ bool extract_all_data(const fs::file* input, const fs::file* output, const char* LOG_NOTICE(LOADER, "EDAT HEADER"); LOG_NOTICE(LOADER, "EDAT flags: 0x%08X", EDAT.flags); LOG_NOTICE(LOADER, "EDAT block size: 0x%08X", EDAT.block_size); - LOG_NOTICE(LOADER, "EDAT file size: 0x%08X", (u64)EDAT.file_size); + LOG_NOTICE(LOADER, "EDAT file size: 0x%08X", EDAT.file_size); } // Perform header validation (EDAT only). @@ -815,9 +815,9 @@ fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, // Set keys (RIF and DEVKLIC). std::array rifKey{ 0 }; unsigned char devklic[0x10] = { 0 }; - + // Select the EDAT key mode. - switch (mode) + switch (mode) { case 0: break; @@ -842,7 +842,7 @@ fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, case 7: memcpy(devklic, NP_PSP_KEY_2, 0x10); break; - case 8: + case 8: { if (custom_klic != NULL) memcpy(devklic, custom_klic, 0x10); @@ -873,7 +873,7 @@ fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, output.release(); return fs::file{}; } - + output.seek(0); return output; } @@ -911,7 +911,7 @@ bool EDATADecrypter::ReadHeader() else if ((npdHeader.license & 0x2) == 0x2) // Type 2: Use key from RAP file (RIF key). { dec_key = std::move(rif_key); - + if (dec_key == std::array{0}) { LOG_WARNING(LOADER, "EDAT: Empty Dec key!"); @@ -935,7 +935,7 @@ bool EDATADecrypter::ReadHeader() }*/ file_size = edatHeader.file_size; - total_blocks = (u32)((edatHeader.file_size + edatHeader.block_size - 1) / edatHeader.block_size); + total_blocks = static_cast((edatHeader.file_size + edatHeader.block_size - 1) / edatHeader.block_size); return true; } @@ -948,7 +948,7 @@ u64 EDATADecrypter::ReadData(u64 pos, u8* data, u64 size) // now we need to offset things to account for the actual 'range' requested const u64 startOffset = pos % edatHeader.block_size; - const u32 num_blocks = static_cast(std::ceil((startOffset + size) / (double)edatHeader.block_size)); + const u32 num_blocks = static_cast(std::ceil((startOffset + size) / (0. + edatHeader.block_size))); const u64 bufSize = num_blocks*edatHeader.block_size; if (data_buf_size < (bufSize)) { diff --git a/rpcs3/Crypto/unedat.h b/rpcs3/Crypto/unedat.h index 4a231486fb..f345d09d7a 100644 --- a/rpcs3/Crypto/unedat.h +++ b/rpcs3/Crypto/unedat.h @@ -98,7 +98,7 @@ public: } u64 read(void* buffer, u64 size) override { - u64 bytesRead = ReadData(pos, (u8*)buffer, size); + u64 bytesRead = ReadData(pos, static_cast(buffer), size); pos += bytesRead; return bytesRead; } diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index 959784ba0c..de3a00db84 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -37,13 +37,13 @@ bool pkg_install(const std::string& path, atomic_t& sync) } }; - auto archive_read = [&](const void *data_ptr, const u64 num_bytes) + auto archive_read = [&](void* data_ptr, const u64 num_bytes) { u64 num_bytes_left = filelist[cur_file].size() - cur_file_offset; //check if it continues in another file if (num_bytes > num_bytes_left) { - filelist[cur_file].read((u8 *)data_ptr, num_bytes_left); + filelist[cur_file].read(data_ptr, num_bytes_left); if ((cur_file + 1) < filelist.size()) cur_file++; else { @@ -51,13 +51,13 @@ bool pkg_install(const std::string& path, atomic_t& sync) cur_file_offset = filelist[cur_file].size(); return num_bytes_left; } - u64 num_read = filelist[cur_file].read((u8 *)data_ptr + num_bytes_left, num_bytes - num_bytes_left); + u64 num_read = filelist[cur_file].read(static_cast(data_ptr) + num_bytes_left, num_bytes - num_bytes_left); cur_offset += (num_read + num_bytes_left); cur_file_offset = num_read; return (num_read+num_bytes_left); } - u64 num_read = filelist[cur_file].read((u8 *)data_ptr, num_bytes); + u64 num_read = filelist[cur_file].read(data_ptr, num_bytes); cur_offset += num_read; cur_file_offset += num_read; @@ -153,7 +153,7 @@ bool pkg_install(const std::string& path, atomic_t& sync) be_t id; be_t size; } packet; - + archive_read(&packet, sizeof(packet)); // TODO @@ -244,7 +244,7 @@ bool pkg_install(const std::string& path, atomic_t& sync) u8 data[20]; u128 _v128; } hash; - + sha1(reinterpret_cast(input), sizeof(input), hash.data); buf[i] ^= hash._v128; diff --git a/rpcs3/Emu/Audio/AudioDumper.h b/rpcs3/Emu/Audio/AudioDumper.h index a1fe4bcdaa..5bca84402c 100644 --- a/rpcs3/Emu/Audio/AudioDumper.h +++ b/rpcs3/Emu/Audio/AudioDumper.h @@ -14,8 +14,8 @@ struct WAVHeader RIFFHeader() = default; RIFFHeader(u32 size) - : ID(*(u32*)"RIFF") - , WAVE(*(u32*)"WAVE") + : ID("RIFF"_u32) + , WAVE("WAVE"_u32) , Size(size) { } @@ -35,7 +35,7 @@ struct WAVHeader FMTHeader() = default; FMTHeader(u16 ch) - : ID(*(u32*)"fmt ") + : ID("fmt "_u32) , Size(16) , AudioFormat(3) , NumChannels(ch) @@ -53,7 +53,7 @@ struct WAVHeader WAVHeader() = default; WAVHeader(u16 ch) - : ID(*(u32*)"data") + : ID("data"_u32) , Size(0) , FMT(ch) , RIFF(sizeof(RIFFHeader) + sizeof(FMTHeader)) @@ -65,7 +65,7 @@ class AudioDumper { WAVHeader m_header; fs::file m_output; - + public: AudioDumper(u16 ch); ~AudioDumper(); diff --git a/rpcs3/Emu/Cell/PPUAnalyser.cpp b/rpcs3/Emu/Cell/PPUAnalyser.cpp index a668efb3c9..b6e29fbff5 100644 --- a/rpcs3/Emu/Cell/PPUAnalyser.cpp +++ b/rpcs3/Emu/Cell/PPUAnalyser.cpp @@ -1019,7 +1019,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry) continue; } } - + if (ptr + 4 <= fend && ptr[0] == STD(r2, r1, 0x28) && (ptr[1] & 0xffff0000) == ADDIS(r2, r2, {}) && @@ -2177,7 +2177,7 @@ void ppu_acontext::ADDI(ppu_opcode_t op) void ppu_acontext::ADDIS(ppu_opcode_t op) { - gpr[op.rd] = op.ra ? gpr[op.ra] + spec_gpr::fixed((u64)op.simm16 << 16) : spec_gpr::fixed((u64)op.simm16 << 16); + gpr[op.rd] = op.ra ? gpr[op.ra] + spec_gpr::fixed(op.simm16 * 65536) : spec_gpr::fixed(op.simm16 * 65536); } void ppu_acontext::BC(ppu_opcode_t op) @@ -2250,14 +2250,14 @@ void ppu_acontext::RLWIMI(ppu_opcode_t op) if (op.mb32 <= op.me32) { // 32-bit op, including mnemonics: INSLWI, INSRWI (TODO) - min = utils::rol32((u32)min, op.sh32) & mask; - max = utils::rol32((u32)max, op.sh32) & mask; + min = utils::rol32(static_cast(min), op.sh32) & mask; + max = utils::rol32(static_cast(max), op.sh32) & mask; } else { // Full 64-bit op with duplication - min = utils::rol64((u32)min | min << 32, op.sh32) & mask; - max = utils::rol64((u32)max | max << 32, op.sh32) & mask; + min = utils::rol64(static_cast(min) | min << 32, op.sh32) & mask; + max = utils::rol64(static_cast(max) | max << 32, op.sh32) & mask; } if (mask != -1) @@ -2306,14 +2306,14 @@ void ppu_acontext::RLWINM(ppu_opcode_t op) // EXTRWI and other possible mnemonics } - min = utils::rol32((u32)min, op.sh32) & mask; - max = utils::rol32((u32)max, op.sh32) & mask; + min = utils::rol32(static_cast(min), op.sh32) & mask; + max = utils::rol32(static_cast(max), op.sh32) & mask; } else { // Full 64-bit op with duplication - min = utils::rol64((u32)min | min << 32, op.sh32) & mask; - max = utils::rol64((u32)max | max << 32, op.sh32) & mask; + min = utils::rol64(static_cast(min) | min << 32, op.sh32) & mask; + max = utils::rol64(static_cast(max) | max << 32, op.sh32) & mask; } gpr[op.ra] = spec_gpr::approx(min, max); diff --git a/rpcs3/Emu/Cell/PPUDisAsm.cpp b/rpcs3/Emu/Cell/PPUDisAsm.cpp index 3675e17e79..6196822f28 100644 --- a/rpcs3/Emu/Cell/PPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/PPUDisAsm.cpp @@ -6,7 +6,7 @@ const ppu_decoder s_ppu_disasm; u32 PPUDisAsm::disasm(u32 pc) { - const u32 op = *(be_t*)(offset + pc); + const u32 op = *reinterpret_cast*>(offset + pc); (this->*(s_ppu_disasm.decode(op)))({ op }); return 4; } diff --git a/rpcs3/Emu/Cell/PPUFunction.cpp b/rpcs3/Emu/Cell/PPUFunction.cpp index 2fee6c5b5d..5c9b3bffdb 100644 --- a/rpcs3/Emu/Cell/PPUFunction.cpp +++ b/rpcs3/Emu/Cell/PPUFunction.cpp @@ -2526,7 +2526,7 @@ std::vector& ppu_function_manager::access() { LOG_ERROR(PPU, "Unregistered function called (LR=0x%x)", ppu.lr); ppu.gpr[3] = 0; - ppu.cia = (u32)ppu.lr & ~3; + ppu.cia = static_cast(ppu.lr) & ~3; return false; }, [](ppu_thread& ppu) -> bool diff --git a/rpcs3/Emu/Cell/PPUInterpreter.cpp b/rpcs3/Emu/Cell/PPUInterpreter.cpp index d2f97707b3..d34b700ac7 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.cpp +++ b/rpcs3/Emu/Cell/PPUInterpreter.cpp @@ -28,7 +28,7 @@ inline void ppu_cr_set(ppu_thread& ppu, u32 field, bool le, bool gt, bool eq, bo if (UNLIKELY(g_cfg.core.ppu_debug)) { - *(u32*)(vm::g_stat_addr + ppu.cia) |= *(u32*)(ppu.cr.bits + field * 4); + *reinterpret_cast(vm::g_stat_addr + ppu.cia) |= *reinterpret_cast(ppu.cr.bits + field * 4); } } @@ -65,7 +65,7 @@ inline void ppu_fpcc_set(ppu_thread& ppu, const T& a, const T& b, const bool rc, if (UNLIKELY(g_cfg.core.ppu_debug)) { - *(u32*)(vm::g_stat_addr + ppu.cia) |= ppu.cr.fields[cr_field]; + *reinterpret_cast(vm::g_stat_addr + ppu.cia) |= ppu.cr.fields[cr_field]; } } } @@ -149,7 +149,7 @@ extern __m128i sse_altivec_vperm_v0(__m128i A, __m128i B, __m128i C) for (int i = 0; i < 16; i++) { - res._u8[i] = ((u8*)+ab)[index._u8[i]]; + res._u8[i] = reinterpret_cast(+ab)[index._u8[i]]; } return res.vi; @@ -177,7 +177,7 @@ extern __m128i sse_altivec_lvsl(u64 addr) { 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f }, }; - return _mm_load_si128((__m128i*)lvsl_values[addr & 0xf]); + return _mm_load_si128(reinterpret_cast(+lvsl_values[addr & 0xf])); } extern __m128i sse_altivec_lvsr(u64 addr) @@ -202,7 +202,7 @@ extern __m128i sse_altivec_lvsr(u64 addr) { 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }, }; - return _mm_load_si128((__m128i*)lvsr_values[addr & 0xf]); + return _mm_load_si128(reinterpret_cast(+lvsr_values[addr & 0xf])); } static const __m128i lvlx_masks[0x10] = @@ -247,42 +247,42 @@ static const __m128i lvrx_masks[0x10] = extern SSSE3_FUNC __m128i sse_cellbe_lvlx(u64 addr) { - return _mm_shuffle_epi8(_mm_load_si128((__m128i*)vm::base(addr & ~0xf)), lvlx_masks[addr & 0xf]); + return _mm_shuffle_epi8(_mm_load_si128(vm::_ptr(addr & ~0xf)), lvlx_masks[addr & 0xf]); } extern SSSE3_FUNC void sse_cellbe_stvlx(u64 addr, __m128i a) { - _mm_maskmoveu_si128(_mm_shuffle_epi8(a, lvlx_masks[addr & 0xf]), lvrx_masks[addr & 0xf], (char*)vm::base(addr & ~0xf)); + _mm_maskmoveu_si128(_mm_shuffle_epi8(a, lvlx_masks[addr & 0xf]), lvrx_masks[addr & 0xf], vm::_ptr(addr & ~0xf)); } extern SSSE3_FUNC __m128i sse_cellbe_lvrx(u64 addr) { - return _mm_shuffle_epi8(_mm_load_si128((__m128i*)vm::base(addr & ~0xf)), lvrx_masks[addr & 0xf]); + return _mm_shuffle_epi8(_mm_load_si128(vm::_ptr(addr & ~0xf)), lvrx_masks[addr & 0xf]); } extern SSSE3_FUNC void sse_cellbe_stvrx(u64 addr, __m128i a) { - _mm_maskmoveu_si128(_mm_shuffle_epi8(a, lvrx_masks[addr & 0xf]), lvlx_masks[addr & 0xf], (char*)vm::base(addr & ~0xf)); + _mm_maskmoveu_si128(_mm_shuffle_epi8(a, lvrx_masks[addr & 0xf]), lvlx_masks[addr & 0xf], vm::_ptr(addr & ~0xf)); } extern __m128i sse_cellbe_lvlx_v0(u64 addr) { - return sse_pshufb(_mm_load_si128((__m128i*)vm::base(addr & ~0xf)), lvlx_masks[addr & 0xf]); + return sse_pshufb(_mm_load_si128(vm::_ptr(addr & ~0xf)), lvlx_masks[addr & 0xf]); } extern void sse_cellbe_stvlx_v0(u64 addr, __m128i a) { - _mm_maskmoveu_si128(sse_pshufb(a, lvlx_masks[addr & 0xf]), lvrx_masks[addr & 0xf], (char*)vm::base(addr & ~0xf)); + _mm_maskmoveu_si128(sse_pshufb(a, lvlx_masks[addr & 0xf]), lvrx_masks[addr & 0xf], vm::_ptr(addr & ~0xf)); } extern __m128i sse_cellbe_lvrx_v0(u64 addr) { - return sse_pshufb(_mm_load_si128((__m128i*)vm::base(addr & ~0xf)), lvrx_masks[addr & 0xf]); + return sse_pshufb(_mm_load_si128(vm::_ptr(addr & ~0xf)), lvrx_masks[addr & 0xf]); } extern void sse_cellbe_stvrx_v0(u64 addr, __m128i a) { - _mm_maskmoveu_si128(sse_pshufb(a, lvrx_masks[addr & 0xf]), lvlx_masks[addr & 0xf], (char*)vm::base(addr & ~0xf)); + _mm_maskmoveu_si128(sse_pshufb(a, lvrx_masks[addr & 0xf]), lvlx_masks[addr & 0xf], vm::_ptr(addr & ~0xf)); } template @@ -406,7 +406,7 @@ bool ppu_interpreter_precise::VADDSBS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s8[i] = (s8)sum; + d._s8[i] = static_cast(sum); } } @@ -441,7 +441,7 @@ bool ppu_interpreter_precise::VADDSHS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s16[i] = (s16)sum; + d._s16[i] = static_cast(sum); } } @@ -469,7 +469,7 @@ bool ppu_interpreter_precise::VADDSWS(ppu_thread& ppu, ppu_opcode_t op) for (u8 i = 0; i < 4; i++) { - const s64 sum = (s64)a._s32[i] + (s64)b._s32[i]; + const s64 sum = s64{a._s32[i]} + b._s32[i]; if (sum < INT32_MIN) { @@ -483,7 +483,7 @@ bool ppu_interpreter_precise::VADDSWS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s32[i] = (s32)sum; + d._s32[i] = static_cast(sum); } } @@ -519,7 +519,7 @@ bool ppu_interpreter_precise::VADDUBS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._u8[i] = (u8)sum; + d._u8[i] = static_cast(sum); } } @@ -555,7 +555,7 @@ bool ppu_interpreter_precise::VADDUHS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._u16[i] = (u16)sum; + d._u16[i] = static_cast(sum); } } @@ -585,7 +585,7 @@ bool ppu_interpreter_precise::VADDUWS(ppu_thread& ppu, ppu_opcode_t op) for (u8 i = 0; i < 4; i++) { - const u64 sum = (u64)a._u32[i] + (u64)b._u32[i]; + const u64 sum = u64{a._u32[i]} + b._u32[i]; if (sum > UINT32_MAX) { @@ -594,7 +594,7 @@ bool ppu_interpreter_precise::VADDUWS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._u32[i] = (u32)sum; + d._u32[i] = static_cast(sum); } } @@ -796,9 +796,9 @@ bool ppu_interpreter_precise::VCTSXS(ppu_thread& ppu, ppu_opcode_t op) { const f32 X = b._f[i]; const bool sign = std::signbit(X); - const u8 exp = (u8)fexpf(X); + const s32 exp = fexpf(X); const u32 frac = std::bit_cast(X) << 9; - const s16 exp2 = exp + uim - 127; + const s32 exp2 = exp + uim - 127; if (exp == 255) { @@ -849,9 +849,9 @@ bool ppu_interpreter_precise::VCTUXS(ppu_thread& ppu, ppu_opcode_t op) { const f32 X = b._f[i]; const bool sign = std::signbit(X); - const u8 exp = (u8)fexpf(X); + const s32 exp = fexpf(X); const u32 frac = std::bit_cast(X) << 9; - const s16 exp2 = exp + uim - 127; + const s32 exp2 = exp + uim - 127; if (exp == 255) { @@ -1009,7 +1009,7 @@ bool ppu_interpreter_precise::VMHADDSHS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s16[i] = (s16)sum; + d._s16[i] = static_cast(sum); } } @@ -1058,7 +1058,7 @@ bool ppu_interpreter_precise::VMHRADDSHS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s16[i] = (s16)sum; + d._s16[i] = static_cast(sum); } } @@ -1205,12 +1205,12 @@ bool ppu_interpreter_fast::VMSUMSHS(ppu_thread& ppu, ppu_opcode_t op) { saturated = 0x7fffffff; } - else if (result < (s64)(s32)0x80000000) + else if (result < -0x80000000) { saturated = 0x80000000; } else - saturated = (s32)result; + saturated = static_cast(result); d._s32[w] = saturated; } @@ -1241,13 +1241,13 @@ bool ppu_interpreter_precise::VMSUMSHS(ppu_thread& ppu, ppu_opcode_t op) saturated = 0x7fffffff; ppu.sat = true; } - else if (result < (s64)(s32)0x80000000) + else if (result < -0x80000000) { saturated = 0x80000000; ppu.sat = true; } else - saturated = (s32)result; + saturated = static_cast(result); d._s32[w] = saturated; } @@ -1297,7 +1297,7 @@ bool ppu_interpreter_fast::VMSUMUHS(ppu_thread& ppu, ppu_opcode_t op) for (uint h = 0; h < 2; h++) { - result += (u64)a._u16[w * 2 + h] * (u64)b._u16[w * 2 + h]; + result += u64{a._u16[w * 2 + h]} * b._u16[w * 2 + h]; } result += c._u32[w]; @@ -1307,7 +1307,7 @@ bool ppu_interpreter_fast::VMSUMUHS(ppu_thread& ppu, ppu_opcode_t op) saturated = 0xffffffff; } else - saturated = (u32)result; + saturated = static_cast(result); d._u32[w] = saturated; } @@ -1328,7 +1328,7 @@ bool ppu_interpreter_precise::VMSUMUHS(ppu_thread& ppu, ppu_opcode_t op) for (uint h = 0; h < 2; h++) { - result += (u64)a._u16[w * 2 + h] * (u64)b._u16[w * 2 + h]; + result += u64{a._u16[w * 2 + h]} * b._u16[w * 2 + h]; } result += c._u32[w]; @@ -1339,7 +1339,7 @@ bool ppu_interpreter_precise::VMSUMUHS(ppu_thread& ppu, ppu_opcode_t op) ppu.sat = true; } else - saturated = (u32)result; + saturated = static_cast(result); d._u32[w] = saturated; } @@ -1484,7 +1484,7 @@ bool ppu_interpreter_precise::VPKSHSS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s8[i + 8] = (s8)result; + d._s8[i + 8] = static_cast(result); } result = b._s16[i]; @@ -1501,7 +1501,7 @@ bool ppu_interpreter_precise::VPKSHSS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s8[i] = (s8)result; + d._s8[i] = static_cast(result); } } @@ -1562,7 +1562,7 @@ bool ppu_interpreter_precise::VPKSWSS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s16[i + 4] = (s16)result; + d._s16[i + 4] = static_cast(result); } result = b._s32[i]; @@ -1579,7 +1579,7 @@ bool ppu_interpreter_precise::VPKSWSS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s16[i] = (s16)result; + d._s16[i] = static_cast(result); } } @@ -1692,7 +1692,7 @@ bool ppu_interpreter_fast::VPKUHUS(ppu_thread& ppu, ppu_opcode_t op) result = UINT8_MAX; } - d._u8[b + 8] = (u8)result; + d._u8[b + 8] = static_cast(result); result = VB._u16[b]; @@ -1701,7 +1701,7 @@ bool ppu_interpreter_fast::VPKUHUS(ppu_thread& ppu, ppu_opcode_t op) result = UINT8_MAX; } - d._u8[b] = (u8)result; + d._u8[b] = static_cast(result); } return true; } @@ -1721,7 +1721,7 @@ bool ppu_interpreter_precise::VPKUHUS(ppu_thread& ppu, ppu_opcode_t op) ppu.sat = true; } - d._u8[b + 8] = (u8)result; + d._u8[b + 8] = static_cast(result); result = VB._u16[b]; @@ -1731,7 +1731,7 @@ bool ppu_interpreter_precise::VPKUHUS(ppu_thread& ppu, ppu_opcode_t op) ppu.sat = true; } - d._u8[b] = (u8)result; + d._u8[b] = static_cast(result); } return true; } @@ -2231,7 +2231,7 @@ bool ppu_interpreter_precise::VSUBSBS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s8[i] = (s8)diff; + d._s8[i] = static_cast(diff); } } @@ -2266,7 +2266,7 @@ bool ppu_interpreter_precise::VSUBSHS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._s16[i] = (s16)diff; + d._s16[i] = static_cast(diff); } } @@ -2281,18 +2281,18 @@ bool ppu_interpreter_fast::VSUBSWS(ppu_thread& ppu, ppu_opcode_t op) for (uint w = 0; w < 4; w++) { - s64 result = (s64)a._s32[w] - (s64)b._s32[w]; + const s64 result = s64{a._s32[w]} - b._s32[w]; if (result < INT32_MIN) { - d._s32[w] = (s32)INT32_MIN; + d._s32[w] = INT32_MIN; } else if (result > INT32_MAX) { - d._s32[w] = (s32)INT32_MAX; + d._s32[w] = INT32_MAX; } else - d._s32[w] = (s32)result; + d._s32[w] = static_cast(result); } return true; } @@ -2305,20 +2305,20 @@ bool ppu_interpreter_precise::VSUBSWS(ppu_thread& ppu, ppu_opcode_t op) for (uint w = 0; w < 4; w++) { - s64 result = (s64)a._s32[w] - (s64)b._s32[w]; + const s64 result = s64{a._s32[w]} - b._s32[w]; if (result < INT32_MIN) { - d._s32[w] = (s32)INT32_MIN; + d._s32[w] = INT32_MIN; ppu.sat = true; } else if (result > INT32_MAX) { - d._s32[w] = (s32)INT32_MAX; + d._s32[w] = INT32_MAX; ppu.sat = true; } else - d._s32[w] = (s32)result; + d._s32[w] = static_cast(result); } return true; } @@ -2357,7 +2357,7 @@ bool ppu_interpreter_precise::VSUBUBS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._u8[i] = (u8)diff; + d._u8[i] = static_cast(diff); } } @@ -2398,7 +2398,7 @@ bool ppu_interpreter_precise::VSUBUHS(ppu_thread& ppu, ppu_opcode_t op) } else { - d._u16[i] = (u16)diff; + d._u16[i] = static_cast(diff); } } @@ -2419,14 +2419,14 @@ bool ppu_interpreter_fast::VSUBUWS(ppu_thread& ppu, ppu_opcode_t op) for (uint w = 0; w < 4; w++) { - s64 result = (s64)a._u32[w] - (s64)b._u32[w]; + const s64 result = s64{a._u32[w]} - b._u32[w]; if (result < 0) { d._u32[w] = 0; } else - d._u32[w] = (u32)result; + d._u32[w] = static_cast(result); } return true; } @@ -2439,7 +2439,7 @@ bool ppu_interpreter_precise::VSUBUWS(ppu_thread& ppu, ppu_opcode_t op) for (uint w = 0; w < 4; w++) { - s64 result = (s64)a._u32[w] - (s64)b._u32[w]; + const s64 result = s64{a._u32[w]} - b._u32[w]; if (result < 0) { @@ -2447,7 +2447,7 @@ bool ppu_interpreter_precise::VSUBUWS(ppu_thread& ppu, ppu_opcode_t op) ppu.sat = true; } else - d._u32[w] = (u32)result; + d._u32[w] = static_cast(result); } return true; } @@ -2468,14 +2468,14 @@ bool ppu_interpreter_fast::VSUMSWS(ppu_thread& ppu, ppu_opcode_t op) d.clear(); if (sum > INT32_MAX) { - d._s32[0] = (s32)INT32_MAX; + d._s32[0] = INT32_MAX; } else if (sum < INT32_MIN) { - d._s32[0] = (s32)INT32_MIN; + d._s32[0] = INT32_MIN; } else - d._s32[0] = (s32)sum; + d._s32[0] = static_cast(sum); return true; } @@ -2495,16 +2495,16 @@ bool ppu_interpreter_precise::VSUMSWS(ppu_thread& ppu, ppu_opcode_t op) d.clear(); if (sum > INT32_MAX) { - d._s32[0] = (s32)INT32_MAX; + d._s32[0] = INT32_MAX; ppu.sat = true; } else if (sum < INT32_MIN) { - d._s32[0] = (s32)INT32_MIN; + d._s32[0] = INT32_MIN; ppu.sat = true; } else - d._s32[0] = (s32)sum; + d._s32[0] = static_cast(sum); return true; } @@ -2516,18 +2516,18 @@ bool ppu_interpreter_fast::VSUM2SWS(ppu_thread& ppu, ppu_opcode_t op) for (uint n = 0; n < 2; n++) { - s64 sum = (s64)a._s32[n * 2] + a._s32[n * 2 + 1] + b._s32[n * 2]; + const s64 sum = s64{a._s32[n * 2]} + a._s32[n * 2 + 1] + b._s32[n * 2]; if (sum > INT32_MAX) { - d._s32[n * 2] = (s32)INT32_MAX; + d._s32[n * 2] = INT32_MAX; } else if (sum < INT32_MIN) { - d._s32[n * 2] = (s32)INT32_MIN; + d._s32[n * 2] = INT32_MIN; } else - d._s32[n * 2] = (s32)sum; + d._s32[n * 2] = static_cast(sum); } d._s32[1] = 0; d._s32[3] = 0; @@ -2543,20 +2543,20 @@ bool ppu_interpreter_precise::VSUM2SWS(ppu_thread& ppu, ppu_opcode_t op) for (uint n = 0; n < 2; n++) { - s64 sum = (s64)a._s32[n * 2] + a._s32[n * 2 + 1] + b._s32[n * 2]; + const s64 sum = s64{a._s32[n * 2]} + a._s32[n * 2 + 1] + b._s32[n * 2]; if (sum > INT32_MAX) { - d._s32[n * 2] = (s32)INT32_MAX; + d._s32[n * 2] = INT32_MAX; ppu.sat = true; } else if (sum < INT32_MIN) { - d._s32[n * 2] = (s32)INT32_MIN; + d._s32[n * 2] = INT32_MIN; ppu.sat = true; } else - d._s32[n * 2] = (s32)sum; + d._s32[n * 2] = static_cast(sum); } d._s32[1] = 0; @@ -2582,14 +2582,14 @@ bool ppu_interpreter_fast::VSUM4SBS(ppu_thread& ppu, ppu_opcode_t op) if (sum > INT32_MAX) { - d._s32[w] = (s32)INT32_MAX; + d._s32[w] = INT32_MAX; } else if (sum < INT32_MIN) { - d._s32[w] = (s32)INT32_MIN; + d._s32[w] = INT32_MIN; } else - d._s32[w] = (s32)sum; + d._s32[w] = static_cast(sum); } return true; } @@ -2611,16 +2611,16 @@ bool ppu_interpreter_precise::VSUM4SBS(ppu_thread& ppu, ppu_opcode_t op) if (sum > INT32_MAX) { - d._s32[w] = (s32)INT32_MAX; + d._s32[w] = INT32_MAX; ppu.sat = true; } else if (sum < INT32_MIN) { - d._s32[w] = (s32)INT32_MIN; + d._s32[w] = INT32_MIN; ppu.sat = true; } else - d._s32[w] = (s32)sum; + d._s32[w] = static_cast(sum); } return true; } @@ -2642,14 +2642,14 @@ bool ppu_interpreter_fast::VSUM4SHS(ppu_thread& ppu, ppu_opcode_t op) if (sum > INT32_MAX) { - d._s32[w] = (s32)INT32_MAX; + d._s32[w] = INT32_MAX; } else if (sum < INT32_MIN) { - d._s32[w] = (s32)INT32_MIN; + d._s32[w] = INT32_MIN; } else - d._s32[w] = (s32)sum; + d._s32[w] = static_cast(sum); } return true; } @@ -2671,16 +2671,16 @@ bool ppu_interpreter_precise::VSUM4SHS(ppu_thread& ppu, ppu_opcode_t op) if (sum > INT32_MAX) { - d._s32[w] = (s32)INT32_MAX; + d._s32[w] = INT32_MAX; ppu.sat = true; } else if (sum < INT32_MIN) { - d._s32[w] = (s32)INT32_MIN; + d._s32[w] = INT32_MIN; ppu.sat = true; } else - d._s32[w] = (s32)sum; + d._s32[w] = static_cast(sum); } return true; } @@ -2702,10 +2702,10 @@ bool ppu_interpreter_fast::VSUM4UBS(ppu_thread& ppu, ppu_opcode_t op) if (sum > UINT32_MAX) { - d._u32[w] = (u32)UINT32_MAX; + d._u32[w] = UINT32_MAX; } else - d._u32[w] = (u32)sum; + d._u32[w] = static_cast(sum); } return true; } @@ -2727,11 +2727,11 @@ bool ppu_interpreter_precise::VSUM4UBS(ppu_thread& ppu, ppu_opcode_t op) if (sum > UINT32_MAX) { - d._u32[w] = (u32)UINT32_MAX; + d._u32[w] = UINT32_MAX; ppu.sat = true; } else - d._u32[w] = (u32)sum; + d._u32[w] = static_cast(sum); } return true; } @@ -2833,7 +2833,7 @@ bool ppu_interpreter::TDI(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::TWI(ppu_thread& ppu, ppu_opcode_t op) { - const s32 a = u32(ppu.gpr[op.ra]), b = op.simm16; + const s32 a = static_cast(ppu.gpr[op.ra]), b = op.simm16; const u32 a_ = a, b_ = b; if (((op.bo & 0x10) && a < b) || @@ -2850,7 +2850,7 @@ bool ppu_interpreter::TWI(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::MULLI(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.rd] = (s64)ppu.gpr[op.ra] * op.simm16; + ppu.gpr[op.rd] = static_cast(ppu.gpr[op.ra]) * op.simm16; return true; } @@ -2872,7 +2872,7 @@ bool ppu_interpreter::CMPLI(ppu_thread& ppu, ppu_opcode_t op) } else { - ppu_cr_set(ppu, op.crfd, u32(ppu.gpr[op.ra]), op.uimm16); + ppu_cr_set(ppu, op.crfd, static_cast(ppu.gpr[op.ra]), op.uimm16); } return true; } @@ -2885,7 +2885,7 @@ bool ppu_interpreter::CMPI(ppu_thread& ppu, ppu_opcode_t op) } else { - ppu_cr_set(ppu, op.crfd, u32(ppu.gpr[op.ra]), op.simm16); + ppu_cr_set(ppu, op.crfd, static_cast(ppu.gpr[op.ra]), op.simm16); } return true; } @@ -2903,13 +2903,13 @@ bool ppu_interpreter::ADDIC(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::ADDI(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.rd] = op.ra ? ((s64)ppu.gpr[op.ra] + op.simm16) : op.simm16; + ppu.gpr[op.rd] = op.ra ? ppu.gpr[op.ra] + op.simm16 : op.simm16; return true; } bool ppu_interpreter::ADDIS(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.rd] = op.ra ? ((s64)ppu.gpr[op.ra] + (op.simm16 << 16)) : (op.simm16 << 16); + ppu.gpr[op.rd] = op.ra ? ppu.gpr[op.ra] + (op.simm16 * 65536) : (op.simm16 * 65536); return true; } @@ -2975,7 +2975,7 @@ bool ppu_interpreter::BCLR(ppu_thread& ppu, ppu_opcode_t op) const bool ctr_ok = bo2 | ((ppu.ctr != 0) ^ bo3); const bool cond_ok = bo0 | (ppu.cr[op.bi] ^ (bo1 ^ true)); - const u32 target = (u32)ppu.lr & ~3; + const u32 target = static_cast(ppu.lr) & ~3; if (op.lk) ppu.lr = ppu.cia + 4; if (ctr_ok && cond_ok) @@ -3049,7 +3049,7 @@ bool ppu_interpreter::BCCTR(ppu_thread& ppu, ppu_opcode_t op) if (op.bo & 0x10 || ppu.cr[op.bi] == ((op.bo & 0x8) != 0)) { - ppu.cia = (u32)ppu.ctr & ~3; + ppu.cia = static_cast(ppu.ctr) & ~3; return false; } @@ -3059,21 +3059,21 @@ bool ppu_interpreter::BCCTR(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::RLWIMI(ppu_thread& ppu, ppu_opcode_t op) { const u64 mask = ppu_rotate_mask(32 + op.mb32, 32 + op.me32); - ppu.gpr[op.ra] = (ppu.gpr[op.ra] & ~mask) | (dup32(utils::rol32(u32(ppu.gpr[op.rs]), op.sh32)) & mask); + ppu.gpr[op.ra] = (ppu.gpr[op.ra] & ~mask) | (dup32(utils::rol32(static_cast(ppu.gpr[op.rs]), op.sh32)) & mask); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } bool ppu_interpreter::RLWINM(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = dup32(utils::rol32(u32(ppu.gpr[op.rs]), op.sh32)) & ppu_rotate_mask(32 + op.mb32, 32 + op.me32); + ppu.gpr[op.ra] = dup32(utils::rol32(static_cast(ppu.gpr[op.rs]), op.sh32)) & ppu_rotate_mask(32 + op.mb32, 32 + op.me32); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } bool ppu_interpreter::RLWNM(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = dup32(utils::rol32(u32(ppu.gpr[op.rs]), ppu.gpr[op.rb] & 0x1f)) & ppu_rotate_mask(32 + op.mb32, 32 + op.me32); + ppu.gpr[op.ra] = dup32(utils::rol32(static_cast(ppu.gpr[op.rs]), ppu.gpr[op.rb] & 0x1f)) & ppu_rotate_mask(32 + op.mb32, 32 + op.me32); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } @@ -3086,7 +3086,7 @@ bool ppu_interpreter::ORI(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::ORIS(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = ppu.gpr[op.rs] | ((u64)op.uimm16 << 16); + ppu.gpr[op.ra] = ppu.gpr[op.rs] | (u64{op.uimm16} << 16); return true; } @@ -3098,7 +3098,7 @@ bool ppu_interpreter::XORI(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::XORIS(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = ppu.gpr[op.rs] ^ ((u64)op.uimm16 << 16); + ppu.gpr[op.ra] = ppu.gpr[op.rs] ^ (u64{op.uimm16} << 16); return true; } @@ -3111,7 +3111,7 @@ bool ppu_interpreter::ANDI(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::ANDIS(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = ppu.gpr[op.rs] & ((u64)op.uimm16 << 16); + ppu.gpr[op.ra] = ppu.gpr[op.rs] & (u64{op.uimm16} << 16); ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } @@ -3167,21 +3167,21 @@ bool ppu_interpreter::CMP(ppu_thread& ppu, ppu_opcode_t op) } else { - ppu_cr_set(ppu, op.crfd, u32(ppu.gpr[op.ra]), u32(ppu.gpr[op.rb])); + ppu_cr_set(ppu, op.crfd, static_cast(ppu.gpr[op.ra]), static_cast(ppu.gpr[op.rb])); } return true; } bool ppu_interpreter::TW(ppu_thread& ppu, ppu_opcode_t op) { - s32 a = (s32)ppu.gpr[op.ra]; - s32 b = (s32)ppu.gpr[op.rb]; + s32 a = static_cast(ppu.gpr[op.ra]); + s32 b = static_cast(ppu.gpr[op.rb]); if ((a < b && (op.bo & 0x10)) || (a > b && (op.bo & 0x8)) || (a == b && (op.bo & 0x4)) || - ((u32)a < (u32)b && (op.bo & 0x2)) || - ((u32)a >(u32)b && (op.bo & 0x1))) + (static_cast(a) < static_cast(b) && (op.bo & 0x2)) || + (static_cast(a) > static_cast(b) && (op.bo & 0x1))) { fmt::throw_exception("Trap!" HERE); } @@ -3234,9 +3234,9 @@ bool ppu_interpreter::ADDC(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::MULHWU(ppu_thread& ppu, ppu_opcode_t op) { - u32 a = (u32)ppu.gpr[op.ra]; - u32 b = (u32)ppu.gpr[op.rb]; - ppu.gpr[op.rd] = ((u64)a * (u64)b) >> 32; + u32 a = static_cast(ppu.gpr[op.ra]); + u32 b = static_cast(ppu.gpr[op.rb]); + ppu.gpr[op.rd] = (u64{a} * b) >> 32; if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, false, false, false, ppu.xer.so); return true; } @@ -3288,14 +3288,14 @@ bool ppu_interpreter::LWZX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::SLW(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = u32(ppu.gpr[op.rs] << (ppu.gpr[op.rb] & 0x3f)); + ppu.gpr[op.ra] = static_cast(ppu.gpr[op.rs] << (ppu.gpr[op.rb] & 0x3f)); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } bool ppu_interpreter::CNTLZW(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = utils::cntlz32(u32(ppu.gpr[op.rs])); + ppu.gpr[op.ra] = utils::cntlz32(static_cast(ppu.gpr[op.rs])); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } @@ -3323,7 +3323,7 @@ bool ppu_interpreter::CMPL(ppu_thread& ppu, ppu_opcode_t op) } else { - ppu_cr_set(ppu, op.crfd, u32(ppu.gpr[op.ra]), u32(ppu.gpr[op.rb])); + ppu_cr_set(ppu, op.crfd, static_cast(ppu.gpr[op.ra]), static_cast(ppu.gpr[op.rb])); } return true; } @@ -3416,9 +3416,9 @@ bool ppu_interpreter::MULHD(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::MULHW(ppu_thread& ppu, ppu_opcode_t op) { - s32 a = (s32)ppu.gpr[op.ra]; - s32 b = (s32)ppu.gpr[op.rb]; - ppu.gpr[op.rd] = ((s64)a * (s64)b) >> 32; + s32 a = static_cast(ppu.gpr[op.ra]); + s32 b = static_cast(ppu.gpr[op.rb]); + ppu.gpr[op.rd] = (s64{a} * b) >> 32; if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, false, false, false, ppu.xer.so); return true; } @@ -3535,7 +3535,7 @@ bool ppu_interpreter::MTOCRF(ppu_thread& ppu, ppu_opcode_t op) const u32 n = utils::cntlz32(op.crm) & 7; const u64 v = (s >> ((n * 4) ^ 0x1c)) & 0xf; - ppu.cr.fields[n] = *(u32*)(s_table + v); + ppu.cr.fields[n] = *reinterpret_cast(s_table + v); } else { @@ -3546,7 +3546,7 @@ bool ppu_interpreter::MTOCRF(ppu_thread& ppu, ppu_opcode_t op) if (op.crm & (128 >> i)) { const u64 v = (s >> ((i * 4) ^ 0x1c)) & 0xf; - ppu.cr.fields[i] = *(u32*)(s_table + v); + ppu.cr.fields[i] = *reinterpret_cast(s_table + v); } } } @@ -3563,14 +3563,14 @@ bool ppu_interpreter::STDX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STWCX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - ppu_cr_set(ppu, 0, false, false, ppu_stwcx(ppu, vm::cast(addr, HERE), (u32)ppu.gpr[op.rs]), ppu.xer.so); + ppu_cr_set(ppu, 0, false, false, ppu_stwcx(ppu, vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])), ppu.xer.so); return true; } bool ppu_interpreter::STWX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - vm::write32(vm::cast(addr, HERE), (u32)ppu.gpr[op.rs]); + vm::write32(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); return true; } @@ -3593,7 +3593,7 @@ bool ppu_interpreter::STDUX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STWUX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = ppu.gpr[op.ra] + ppu.gpr[op.rb]; - vm::write32(vm::cast(addr, HERE), (u32)ppu.gpr[op.rs]); + vm::write32(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); ppu.gpr[op.ra] = addr; return true; } @@ -3638,7 +3638,7 @@ bool ppu_interpreter::STDCX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STBX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - vm::write8(vm::cast(addr, HERE), (u8)ppu.gpr[op.rs]); + vm::write8(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); return true; } @@ -3653,7 +3653,7 @@ bool ppu_interpreter::MULLD(ppu_thread& ppu, ppu_opcode_t op) { const s64 RA = ppu.gpr[op.ra]; const s64 RB = ppu.gpr[op.rb]; - ppu.gpr[op.rd] = (s64)(RA * RB); + ppu.gpr[op.rd] = RA * RB; if (UNLIKELY(op.oe)) { const s64 high = utils::mulh64(RA, RB); @@ -3687,7 +3687,7 @@ bool ppu_interpreter::ADDME(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::MULLW(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.rd] = (s64)((s64)(s32)ppu.gpr[op.ra] * (s64)(s32)ppu.gpr[op.rb]); + ppu.gpr[op.rd] = s64{static_cast(ppu.gpr[op.ra])} * static_cast(ppu.gpr[op.rb]); if (UNLIKELY(op.oe)) ppu_ov_set(ppu, s64(ppu.gpr[op.rd]) < INT32_MIN || s64(ppu.gpr[op.rd]) > INT32_MAX); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; @@ -3701,7 +3701,7 @@ bool ppu_interpreter::DCBTST(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STBUX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = ppu.gpr[op.ra] + ppu.gpr[op.rb]; - vm::write8(vm::cast(addr, HERE), (u8)ppu.gpr[op.rs]); + vm::write8(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); ppu.gpr[op.ra] = addr; return true; } @@ -3777,7 +3777,7 @@ bool ppu_interpreter::MFSPR(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::LWAX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - ppu.gpr[op.rd] = (s64)(s32)vm::read32(vm::cast(addr, HERE)); + ppu.gpr[op.rd] = static_cast(vm::read32(vm::cast(addr, HERE))); return true; } @@ -3789,7 +3789,7 @@ bool ppu_interpreter::DST(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::LHAX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - ppu.gpr[op.rd] = (s64)(s16)vm::read16(vm::cast(addr, HERE)); + ppu.gpr[op.rd] = static_cast(vm::read16(vm::cast(addr, HERE))); return true; } @@ -3817,7 +3817,7 @@ bool ppu_interpreter::MFTB(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::LWAUX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - ppu.gpr[op.rd] = (s64)(s32)vm::read32(vm::cast(addr, HERE)); + ppu.gpr[op.rd] = static_cast(vm::read32(vm::cast(addr, HERE))); ppu.gpr[op.ra] = addr; return true; } @@ -3830,7 +3830,7 @@ bool ppu_interpreter::DSTST(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::LHAUX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - ppu.gpr[op.rd] = (s64)(s16)vm::read16(vm::cast(addr, HERE)); + ppu.gpr[op.rd] = static_cast(vm::read16(vm::cast(addr, HERE))); ppu.gpr[op.ra] = addr; return true; } @@ -3838,7 +3838,7 @@ bool ppu_interpreter::LHAUX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STHX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - vm::write16(vm::cast(addr, HERE), (u16)ppu.gpr[op.rs]); + vm::write16(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); return true; } @@ -3857,7 +3857,7 @@ bool ppu_interpreter::ECOWX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STHUX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = ppu.gpr[op.ra] + ppu.gpr[op.rb]; - vm::write16(vm::cast(addr, HERE), (u16)ppu.gpr[op.rs]); + vm::write16(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); ppu.gpr[op.ra] = addr; return true; } @@ -3881,8 +3881,8 @@ bool ppu_interpreter::DIVDU(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::DIVWU(ppu_thread& ppu, ppu_opcode_t op) { - const u32 RA = (u32)ppu.gpr[op.ra]; - const u32 RB = (u32)ppu.gpr[op.rb]; + const u32 RA = static_cast(ppu.gpr[op.ra]); + const u32 RB = static_cast(ppu.gpr[op.rb]); ppu.gpr[op.rd] = RB == 0 ? 0 : RA / RB; if (UNLIKELY(op.oe)) ppu_ov_set(ppu, RB == 0); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, false, false, false, ppu.xer.so); @@ -3906,7 +3906,7 @@ bool ppu_interpreter::MTSPR(ppu_thread& ppu, ppu_opcode_t op) } case 0x008: ppu.lr = ppu.gpr[op.rs]; break; case 0x009: ppu.ctr = ppu.gpr[op.rs]; break; - case 0x100: ppu.vrsave = (u32)ppu.gpr[op.rs]; break; + case 0x100: ppu.vrsave = static_cast(ppu.gpr[op.rs]); break; default: fmt::throw_exception("MTSPR 0x%x" HERE, n); } @@ -3936,7 +3936,7 @@ bool ppu_interpreter::DIVD(ppu_thread& ppu, ppu_opcode_t op) { const s64 RA = ppu.gpr[op.ra]; const s64 RB = ppu.gpr[op.rb]; - const bool o = RB == 0 || ((u64)RA == (1ULL << 63) && RB == -1); + const bool o = RB == 0 || (RA == INT64_MIN && RB == -1); ppu.gpr[op.rd] = o ? 0 : RA / RB; if (UNLIKELY(op.oe)) ppu_ov_set(ppu, o); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.rd], 0); @@ -3945,10 +3945,10 @@ bool ppu_interpreter::DIVD(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::DIVW(ppu_thread& ppu, ppu_opcode_t op) { - const s32 RA = (s32)ppu.gpr[op.ra]; - const s32 RB = (s32)ppu.gpr[op.rb]; - const bool o = RB == 0 || ((u32)RA == (1 << 31) && RB == -1); - ppu.gpr[op.rd] = o ? 0 : u32(RA / RB); + const s32 RA = static_cast(ppu.gpr[op.ra]); + const s32 RB = static_cast(ppu.gpr[op.rb]); + const bool o = RB == 0 || (RA == INT32_MIN && RB == -1); + ppu.gpr[op.rd] = o ? 0 : static_cast(RA / RB); if (UNLIKELY(op.oe)) ppu_ov_set(ppu, o); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, false, false, false, ppu.xer.so); return true; @@ -4127,14 +4127,14 @@ bool ppu_interpreter::STSWX(ppu_thread& ppu, ppu_opcode_t op) u32 count = ppu.xer.cnt & 0x7F; for (; count >= 4; count -= 4, addr += 4, op.rs = (op.rs + 1) & 31) { - vm::write32(vm::cast(addr, HERE), (u32)ppu.gpr[op.rs]); + vm::write32(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); } if (count) { - u32 value = (u32)ppu.gpr[op.rs]; + u32 value = static_cast(ppu.gpr[op.rs]); for (u32 byte = 0; byte < count; byte++) { - u32 byte_value = (u8)(value >> ((3 ^ byte) * 8)); + u8 byte_value = static_cast(value >> ((3 ^ byte) * 8)); vm::write8(vm::cast(addr + byte, HERE), byte_value); } } @@ -4144,7 +4144,7 @@ bool ppu_interpreter::STSWX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STWBRX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - vm::_ref>(vm::cast(addr, HERE)) = (u32)ppu.gpr[op.rs]; + vm::_ref>(vm::cast(addr, HERE)) = static_cast(ppu.gpr[op.rs]); return true; } @@ -4187,13 +4187,13 @@ bool ppu_interpreter::STSWI(ppu_thread& ppu, ppu_opcode_t op) { if (N > 3) { - vm::write32(vm::cast(addr, HERE), (u32)ppu.gpr[reg]); + vm::write32(vm::cast(addr, HERE), static_cast(ppu.gpr[reg])); addr += 4; N -= 4; } else { - u32 buf = (u32)ppu.gpr[reg]; + u32 buf = static_cast(ppu.gpr[reg]); while (N > 0) { N = N - 1; @@ -4241,7 +4241,7 @@ bool ppu_interpreter::LHBRX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::SRAW(ppu_thread& ppu, ppu_opcode_t op) { - s32 RS = (s32)ppu.gpr[op.rs]; + s32 RS = static_cast(ppu.gpr[op.rs]); u8 shift = ppu.gpr[op.rb] & 63; if (shift > 31) { @@ -4294,9 +4294,9 @@ bool ppu_interpreter::DSS(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::SRAWI(ppu_thread& ppu, ppu_opcode_t op) { - s32 RS = (u32)ppu.gpr[op.rs]; + s32 RS = static_cast(ppu.gpr[op.rs]); ppu.gpr[op.ra] = RS >> op.sh32; - ppu.xer.ca = (RS < 0) && ((u32)(ppu.gpr[op.ra] << op.sh32) != RS); + ppu.xer.ca = (RS < 0) && (static_cast(ppu.gpr[op.ra] << op.sh32) != RS); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; @@ -4332,13 +4332,13 @@ bool ppu_interpreter_fast::STVLXL(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STHBRX(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + ppu.gpr[op.rb] : ppu.gpr[op.rb]; - vm::_ref>(vm::cast(addr, HERE)) = (u16)ppu.gpr[op.rs]; + vm::_ref>(vm::cast(addr, HERE)) = static_cast(ppu.gpr[op.rs]); return true; } bool ppu_interpreter::EXTSH(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = (s64)(s16)ppu.gpr[op.rs]; + ppu.gpr[op.ra] = static_cast(ppu.gpr[op.rs]); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } @@ -4355,7 +4355,7 @@ bool ppu_interpreter_fast::STVRXL(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::EXTSB(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = (s64)(s8)ppu.gpr[op.rs]; + ppu.gpr[op.ra] = static_cast(ppu.gpr[op.rs]); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } @@ -4369,7 +4369,7 @@ bool ppu_interpreter::STFIWX(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::EXTSW(ppu_thread& ppu, ppu_opcode_t op) { - ppu.gpr[op.ra] = (s64)(s32)ppu.gpr[op.rs]; + ppu.gpr[op.ra] = static_cast(ppu.gpr[op.rs]); if (UNLIKELY(op.rc)) ppu_cr_set(ppu, 0, ppu.gpr[op.ra], 0); return true; } @@ -4420,7 +4420,7 @@ bool ppu_interpreter::LBZU(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STW(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + op.simm16 : op.simm16; - const u32 value = (u32)ppu.gpr[op.rs]; + const u32 value = static_cast(ppu.gpr[op.rs]); vm::write32(vm::cast(addr, HERE), value); //Insomniac engine v3 & v4 (newer R&C, Fuse, Resitance 3) @@ -4435,7 +4435,7 @@ bool ppu_interpreter::STW(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STWU(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = ppu.gpr[op.ra] + op.simm16; - vm::write32(vm::cast(addr, HERE), (u32)ppu.gpr[op.rs]); + vm::write32(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); ppu.gpr[op.ra] = addr; return true; } @@ -4443,14 +4443,14 @@ bool ppu_interpreter::STWU(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STB(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + op.simm16 : op.simm16; - vm::write8(vm::cast(addr, HERE), (u8)ppu.gpr[op.rs]); + vm::write8(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); return true; } bool ppu_interpreter::STBU(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = ppu.gpr[op.ra] + op.simm16; - vm::write8(vm::cast(addr, HERE), (u8)ppu.gpr[op.rs]); + vm::write8(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); ppu.gpr[op.ra] = addr; return true; } @@ -4473,14 +4473,14 @@ bool ppu_interpreter::LHZU(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::LHA(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + op.simm16 : op.simm16; - ppu.gpr[op.rd] = (s64)(s16)vm::read16(vm::cast(addr, HERE)); + ppu.gpr[op.rd] = static_cast(vm::read16(vm::cast(addr, HERE))); return true; } bool ppu_interpreter::LHAU(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = ppu.gpr[op.ra] + op.simm16; - ppu.gpr[op.rd] = (s64)(s16)vm::read16(vm::cast(addr, HERE)); + ppu.gpr[op.rd] = static_cast(vm::read16(vm::cast(addr, HERE))); ppu.gpr[op.ra] = addr; return true; } @@ -4488,14 +4488,14 @@ bool ppu_interpreter::LHAU(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::STH(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = op.ra ? ppu.gpr[op.ra] + op.simm16 : op.simm16; - vm::write16(vm::cast(addr, HERE), (u16)ppu.gpr[op.rs]); + vm::write16(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); return true; } bool ppu_interpreter::STHU(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = ppu.gpr[op.ra] + op.simm16; - vm::write16(vm::cast(addr, HERE), (u16)ppu.gpr[op.rs]); + vm::write16(vm::cast(addr, HERE), static_cast(ppu.gpr[op.rs])); ppu.gpr[op.ra] = addr; return true; } @@ -4515,7 +4515,7 @@ bool ppu_interpreter::STMW(ppu_thread& ppu, ppu_opcode_t op) u64 addr = op.ra ? ppu.gpr[op.ra] + op.simm16 : op.simm16; for (u32 i = op.rs; i<32; ++i, addr += 4) { - vm::write32(vm::cast(addr, HERE), (u32)ppu.gpr[i]); + vm::write32(vm::cast(addr, HERE), static_cast(ppu.gpr[i])); } return true; } @@ -4598,7 +4598,7 @@ bool ppu_interpreter::LDU(ppu_thread& ppu, ppu_opcode_t op) bool ppu_interpreter::LWA(ppu_thread& ppu, ppu_opcode_t op) { const u64 addr = (op.simm16 & ~3) + (op.ra ? ppu.gpr[op.ra] : 0); - ppu.gpr[op.rd] = (s64)(s32)vm::read32(vm::cast(addr, HERE)); + ppu.gpr[op.rd] = static_cast(vm::read32(vm::cast(addr, HERE))); return true; } diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 686d14fcbc..ba745113ce 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -738,8 +738,8 @@ std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::stri LOG_NOTICE(LOADER, "** Segment: p_type=0x%x, p_vaddr=0x%llx, p_filesz=0x%llx, p_memsz=0x%llx, flags=0x%x", prog.p_type, prog.p_vaddr, prog.p_filesz, prog.p_memsz, prog.p_flags); // Hash big-endian values - sha1_update(&sha, (uchar*)&prog.p_type, sizeof(prog.p_type)); - sha1_update(&sha, (uchar*)&prog.p_flags, sizeof(prog.p_flags)); + sha1_update(&sha, reinterpret_cast(&prog.p_type), sizeof(prog.p_type)); + sha1_update(&sha, reinterpret_cast(&prog.p_flags), sizeof(prog.p_flags)); switch (const u32 p_type = prog.p_type) { @@ -764,8 +764,8 @@ std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::stri LOG_WARNING(LOADER, "**** Loaded to 0x%x (size=0x%x)", addr, mem_size); // Hash segment - sha1_update(&sha, (uchar*)&prog.p_vaddr, sizeof(prog.p_vaddr)); - sha1_update(&sha, (uchar*)&prog.p_memsz, sizeof(prog.p_memsz)); + sha1_update(&sha, reinterpret_cast(&prog.p_vaddr), sizeof(prog.p_vaddr)); + sha1_update(&sha, reinterpret_cast(&prog.p_memsz), sizeof(prog.p_memsz)); sha1_update(&sha, prog.bin.data(), prog.bin.size()); // Initialize executable code if necessary @@ -1077,8 +1077,8 @@ void ppu_load_exec(const ppu_exec_object& elf) _seg.filesz = ::narrow(prog.p_filesz, "p_filesz" HERE); // Hash big-endian values - sha1_update(&sha, (uchar*)&prog.p_type, sizeof(prog.p_type)); - sha1_update(&sha, (uchar*)&prog.p_flags, sizeof(prog.p_flags)); + sha1_update(&sha, reinterpret_cast(&prog.p_type), sizeof(prog.p_type)); + sha1_update(&sha, reinterpret_cast(&prog.p_flags), sizeof(prog.p_flags)); if (type == 0x1 /* LOAD */ && prog.p_memsz) { @@ -1090,8 +1090,8 @@ void ppu_load_exec(const ppu_exec_object& elf) // Copy segment data, hash it std::memcpy(vm::base(addr), prog.bin.data(), prog.bin.size()); - sha1_update(&sha, (uchar*)&prog.p_vaddr, sizeof(prog.p_vaddr)); - sha1_update(&sha, (uchar*)&prog.p_memsz, sizeof(prog.p_memsz)); + sha1_update(&sha, reinterpret_cast(&prog.p_vaddr), sizeof(prog.p_vaddr)); + sha1_update(&sha, reinterpret_cast(&prog.p_memsz), sizeof(prog.p_memsz)); sha1_update(&sha, prog.bin.data(), prog.bin.size()); // Initialize executable code if necessary @@ -1548,8 +1548,8 @@ std::shared_ptr ppu_load_overlay(const ppu_exec_object& elf, const _seg.filesz = ::narrow(prog.p_filesz, "p_filesz" HERE); // Hash big-endian values - sha1_update(&sha, (uchar*)&prog.p_type, sizeof(prog.p_type)); - sha1_update(&sha, (uchar*)&prog.p_flags, sizeof(prog.p_flags)); + sha1_update(&sha, reinterpret_cast(&prog.p_type), sizeof(prog.p_type)); + sha1_update(&sha, reinterpret_cast(&prog.p_flags), sizeof(prog.p_flags)); if (type == 0x1 /* LOAD */ && prog.p_memsz) { @@ -1561,8 +1561,8 @@ std::shared_ptr ppu_load_overlay(const ppu_exec_object& elf, const // Copy segment data, hash it std::memcpy(vm::base(addr), prog.bin.data(), prog.bin.size()); - sha1_update(&sha, (uchar*)&prog.p_vaddr, sizeof(prog.p_vaddr)); - sha1_update(&sha, (uchar*)&prog.p_memsz, sizeof(prog.p_memsz)); + sha1_update(&sha, reinterpret_cast(&prog.p_vaddr), sizeof(prog.p_vaddr)); + sha1_update(&sha, reinterpret_cast(&prog.p_memsz), sizeof(prog.p_memsz)); sha1_update(&sha, prog.bin.data(), prog.bin.size()); // Initialize executable code if necessary diff --git a/rpcs3/Emu/Cell/SPUDisAsm.cpp b/rpcs3/Emu/Cell/SPUDisAsm.cpp index 85b5eeb14e..0eb8a2a330 100644 --- a/rpcs3/Emu/Cell/SPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/SPUDisAsm.cpp @@ -5,7 +5,7 @@ const spu_decoder s_spu_disasm; u32 SPUDisAsm::disasm(u32 pc) { - const u32 op = *(be_t*)(offset + pc); + const u32 op = *reinterpret_cast*>(offset + pc); (this->*(s_spu_disasm.decode(op)))({ op }); return 4; } diff --git a/rpcs3/Emu/Cell/SPUDisAsm.h b/rpcs3/Emu/Cell/SPUDisAsm.h index 67e8bab172..db5fc7d4c1 100644 --- a/rpcs3/Emu/Cell/SPUDisAsm.h +++ b/rpcs3/Emu/Cell/SPUDisAsm.h @@ -90,14 +90,14 @@ private: case 0b01: return "e"; case 0b10: return "d"; //case 0b11: return "(undef)"; - default: return ""; + default: return ""; } } private: std::string& FixOp(std::string& op) { - op.append(std::max(10 - (int)op.length(), 0),' '); + op.append(std::max(10 - ::narrow(op.size()), 0),' '); return op; } void DisAsm(const char* op) diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index a3269e202d..b1b00e5d28 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -488,7 +488,7 @@ error_code sys_event_port_send(u32 eport_id, u64 data1, u64 data2, u64 data3) { if (const auto queue = port.queue.lock()) { - const u64 source = port.name ? port.name : ((u64)process_getpid() << 32) | (u64)eport_id; + const u64 source = port.name ? port.name : (s64{process_getpid()} << 32) | u64{eport_id}; if (queue->send(source, data1, data2, data3)) { diff --git a/rpcs3/Emu/Cell/lv2/sys_net.cpp b/rpcs3/Emu/Cell/lv2/sys_net.cpp index b617e58a59..a9a627dc7c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net.cpp @@ -353,7 +353,7 @@ error_code sys_net_bnet_accept(ppu_thread& ppu, s32 s, vm::ptr #ifdef _WIN32 sock.ev_set &= ~FD_ACCEPT; #endif - native_socket = ::accept(sock.socket, (::sockaddr*)&native_addr, &native_addrlen); + native_socket = ::accept(sock.socket, reinterpret_cast(&native_addr), &native_addrlen); if (native_socket != -1) { @@ -377,7 +377,7 @@ error_code sys_net_bnet_accept(ppu_thread& ppu, s32 s, vm::ptr #ifdef _WIN32 sock.ev_set &= ~FD_ACCEPT; #endif - native_socket = ::accept(sock.socket, (::sockaddr*)&native_addr, &native_addrlen); + native_socket = ::accept(sock.socket, reinterpret_cast(&native_addr), &native_addrlen); if (native_socket != -1 || (result = get_last_error(!sock.so_nbio))) { @@ -459,8 +459,8 @@ error_code sys_net_bnet_accept(ppu_thread& ppu, s32 s, vm::ptr paddr->sin_len = sizeof(sys_net_sockaddr_in); paddr->sin_family = SYS_NET_AF_INET; - paddr->sin_port = ntohs(((::sockaddr_in*)&native_addr)->sin_port); - paddr->sin_addr = ntohl(((::sockaddr_in*)&native_addr)->sin_addr.s_addr); + paddr->sin_port = ntohs(reinterpret_cast(&native_addr)->sin_port); + paddr->sin_addr = ntohl(reinterpret_cast(&native_addr)->sin_addr.s_addr); paddr->sin_zero = 0; } @@ -480,17 +480,19 @@ error_code sys_net_bnet_bind(ppu_thread& ppu, s32 s, vm::cptr return -SYS_NET_EAFNOSUPPORT; } + const auto psa_in = vm::_ptr(addr.addr()); + ::sockaddr_in name{}; name.sin_family = AF_INET; - name.sin_port = htons(((sys_net_sockaddr_in*)addr.get_ptr())->sin_port); - name.sin_addr.s_addr = htonl(((sys_net_sockaddr_in*)addr.get_ptr())->sin_addr); + name.sin_port = htons(psa_in->sin_port); + name.sin_addr.s_addr = htonl(psa_in->sin_addr); ::socklen_t namelen = sizeof(name); const auto sock = idm::check(s, [&](lv2_socket& sock) -> sys_net_error { std::lock_guard lock(sock.mutex); - if (::bind(sock.socket, (::sockaddr*)&name, namelen) == 0) + if (::bind(sock.socket, reinterpret_cast(&name), namelen) == 0) { return {}; } @@ -517,27 +519,29 @@ error_code sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr(addr.addr()); + s32 result = 0; ::sockaddr_in name{}; name.sin_family = AF_INET; - name.sin_port = htons(((sys_net_sockaddr_in*)addr.get_ptr())->sin_port); - name.sin_addr.s_addr = htonl(((sys_net_sockaddr_in*)addr.get_ptr())->sin_addr); + name.sin_port = htons(psa_in->sin_port); + name.sin_addr.s_addr = htonl(psa_in->sin_addr); ::socklen_t namelen = sizeof(name); const auto sock = idm::check(s, [&](lv2_socket& sock) { std::lock_guard lock(sock.mutex); - if (addr->sa_family == 0 && !((sys_net_sockaddr_in*)addr.get_ptr())->sin_port && !((sys_net_sockaddr_in*)addr.get_ptr())->sin_addr) + if (addr->sa_family == 0 && !psa_in->sin_port && !psa_in->sin_addr) { // Hack for DNS (8.8.8.8:53) name.sin_port = htons(53); name.sin_addr.s_addr = 0x08080808; // Overwrite arg (probably used to validate recvfrom addr) - ((sys_net_sockaddr_in*)addr.get_ptr())->sin_family = SYS_NET_AF_INET; - ((sys_net_sockaddr_in*)addr.get_ptr())->sin_port = 53; - ((sys_net_sockaddr_in*)addr.get_ptr())->sin_addr = 0x08080808; + psa_in->sin_family = SYS_NET_AF_INET; + psa_in->sin_port = 53; + psa_in->sin_addr = 0x08080808; sys_net.warning("sys_net_bnet_connect(s=%d): using DNS 8.8.8.8:53..."); } else if (addr->sa_family != SYS_NET_AF_INET) @@ -545,7 +549,7 @@ error_code sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptrsa_family); } - if (::connect(sock.socket, (::sockaddr*)&name, namelen) == 0) + if (::connect(sock.socket, reinterpret_cast(&name), namelen) == 0) { return true; } @@ -573,7 +577,7 @@ error_code sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr(&native_error), &size) != 0 || size != sizeof(int)) { sock.so_error = 1; } @@ -604,7 +608,7 @@ error_code sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr(&native_error), &size) != 0 || size != sizeof(int)) { result = 1; } @@ -680,7 +684,7 @@ error_code sys_net_bnet_getpeername(ppu_thread& ppu, s32 s, vm::ptr(&native_addr), &native_addrlen) == 0) { verify(HERE), native_addr.ss_family == AF_INET; @@ -693,8 +697,8 @@ error_code sys_net_bnet_getpeername(ppu_thread& ppu, s32 s, vm::ptrsin_len = sizeof(sys_net_sockaddr_in); paddr->sin_family = SYS_NET_AF_INET; - paddr->sin_port = ntohs(((::sockaddr_in*)&native_addr)->sin_port); - paddr->sin_addr = ntohl(((::sockaddr_in*)&native_addr)->sin_addr.s_addr); + paddr->sin_port = ntohs(reinterpret_cast(&native_addr)->sin_port); + paddr->sin_addr = ntohl(reinterpret_cast(&native_addr)->sin_addr.s_addr); paddr->sin_zero = 0; return {}; } @@ -728,7 +732,7 @@ error_code sys_net_bnet_getsockname(ppu_thread& ppu, s32 s, vm::ptr(&native_addr), &native_addrlen) == 0) { verify(HERE), native_addr.ss_family == AF_INET; @@ -741,8 +745,8 @@ error_code sys_net_bnet_getsockname(ppu_thread& ppu, s32 s, vm::ptrsin_len = sizeof(sys_net_sockaddr_in); paddr->sin_family = SYS_NET_AF_INET; - paddr->sin_port = ntohs(((::sockaddr_in*)&native_addr)->sin_port); - paddr->sin_addr = ntohl(((::sockaddr_in*)&native_addr)->sin_addr.s_addr); + paddr->sin_port = ntohs(reinterpret_cast(&native_addr)->sin_port); + paddr->sin_addr = ntohl(reinterpret_cast(&native_addr)->sin_addr.s_addr); paddr->sin_zero = 0; return {}; } @@ -799,13 +803,13 @@ error_code sys_net_bnet_getsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam case SYS_NET_SO_NBIO: { // Special - *(be_t*)optval.get_ptr() = sock.so_nbio; + vm::_ref(optval.addr()) = sock.so_nbio; return {}; } case SYS_NET_SO_ERROR: { // Special - *(be_t*)optval.get_ptr() = std::exchange(sock.so_error, 0); + vm::_ref(optval.addr()) = std::exchange(sock.so_error, 0); return {}; } case SYS_NET_SO_KEEPALIVE: @@ -841,12 +845,12 @@ error_code sys_net_bnet_getsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam #ifdef _WIN32 case SYS_NET_SO_REUSEADDR: { - *(be_t*)optval.get_ptr() = sock.so_reuseaddr; + vm::_ref(optval.addr()) = sock.so_reuseaddr; return {}; } case SYS_NET_SO_REUSEPORT: { - *(be_t*)optval.get_ptr() = sock.so_reuseport; + vm::_ref(optval.addr()) = sock.so_reuseport; return {}; } #else @@ -894,7 +898,7 @@ error_code sys_net_bnet_getsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam case SYS_NET_TCP_MAXSEG: { // Special (no effect) - *(be_t*)optval.get_ptr() = sock.so_tcp_maxseg; + vm::_ref(optval.addr()) = sock.so_tcp_maxseg; return {}; } case SYS_NET_TCP_NODELAY: @@ -928,20 +932,20 @@ error_code sys_net_bnet_getsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam case SYS_NET_SO_RCVTIMEO: { // TODO - *(sys_net_timeval*)optval.get_ptr() = { ::narrow(native_val.timeo.tv_sec), ::narrow(native_val.timeo.tv_usec) }; + vm::_ref(optval.addr()) = { ::narrow(native_val.timeo.tv_sec), ::narrow(native_val.timeo.tv_usec) }; return {}; } case SYS_NET_SO_LINGER: { // TODO - *(sys_net_linger*)optval.get_ptr() = { ::narrow(native_val.linger.l_onoff), ::narrow(native_val.linger.l_linger) }; + vm::_ref(optval.addr()) = { ::narrow(native_val.linger.l_onoff), ::narrow(native_val.linger.l_linger) }; return {}; } } } // Fallback to int - *(be_t*)optval.get_ptr() = native_val._int; + vm::_ref(optval.addr()) = native_val._int; return {}; }); @@ -1025,7 +1029,7 @@ error_code sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr buf, u32 #ifdef _WIN32 if (!(native_flags & MSG_PEEK)) sock.ev_set &= ~FD_READ; #endif - native_result = ::recvfrom(sock.socket, (char*)buf.get_ptr(), len, native_flags, (::sockaddr*)&native_addr, &native_addrlen); + native_result = ::recvfrom(sock.socket, reinterpret_cast(buf.get_ptr()), len, native_flags, reinterpret_cast(&native_addr), &native_addrlen); if (native_result >= 0) { @@ -1049,7 +1053,7 @@ error_code sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr buf, u32 #ifdef _WIN32 if (!(native_flags & MSG_PEEK)) sock.ev_set &= ~FD_READ; #endif - native_result = ::recvfrom(sock.socket, (char*)buf.get_ptr(), len, native_flags, (::sockaddr*)&native_addr, &native_addrlen); + native_result = ::recvfrom(sock.socket, reinterpret_cast(buf.get_ptr()), len, native_flags, reinterpret_cast(&native_addr), &native_addrlen); if (native_result >= 0 || (result = get_last_error(!sock.so_nbio && (flags & SYS_NET_MSG_DONTWAIT) == 0))) { @@ -1123,8 +1127,8 @@ error_code sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr buf, u32 paddr->sin_len = sizeof(sys_net_sockaddr_in); paddr->sin_family = SYS_NET_AF_INET; - paddr->sin_port = ntohs(((::sockaddr_in*)&native_addr)->sin_port); - paddr->sin_addr = ntohl(((::sockaddr_in*)&native_addr)->sin_addr.s_addr); + paddr->sin_port = ntohs(reinterpret_cast(&native_addr)->sin_port); + paddr->sin_addr = ntohl(reinterpret_cast(&native_addr)->sin_addr.s_addr); paddr->sin_zero = 0; } @@ -1171,6 +1175,8 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l return -SYS_NET_EAFNOSUPPORT; } + const auto psa_in = vm::_ptr(addr.addr()); + int native_flags = 0; int native_result = -1; ::sockaddr_in name{}; @@ -1178,8 +1184,8 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l if (addr) { name.sin_family = AF_INET; - name.sin_port = htons(((sys_net_sockaddr_in*)addr.get_ptr())->sin_port); - name.sin_addr.s_addr = htonl(((sys_net_sockaddr_in*)addr.get_ptr())->sin_addr); + name.sin_port = htons(psa_in->sin_port); + name.sin_addr.s_addr = htonl(psa_in->sin_addr); } ::socklen_t namelen = sizeof(name); @@ -1199,7 +1205,7 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l #ifdef _WIN32 sock.ev_set &= ~FD_WRITE; #endif - native_result = ::sendto(sock.socket, (const char*)buf.get_ptr(), len, native_flags, addr ? (::sockaddr*)&name : nullptr, addr ? namelen : 0); + native_result = ::sendto(sock.socket, reinterpret_cast(buf.get_ptr()), len, native_flags, addr ? reinterpret_cast(&name) : nullptr, addr ? namelen : 0); if (native_result >= 0) { @@ -1223,7 +1229,7 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l #ifdef _WIN32 sock.ev_set &= ~FD_WRITE; #endif - native_result = ::sendto(sock.socket, (const char*)buf.get_ptr(), len, native_flags, addr ? (::sockaddr*)&name : nullptr, addr ? namelen : 0); + native_result = ::sendto(sock.socket, reinterpret_cast(buf.get_ptr()), len, native_flags, addr ? reinterpret_cast(&name) : nullptr, addr ? namelen : 0); if (native_result >= 0 || (result = get_last_error(!sock.so_nbio && (flags & SYS_NET_MSG_DONTWAIT) == 0))) { @@ -1302,7 +1308,7 @@ error_code sys_net_bnet_setsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam if (optlen >= sizeof(int)) { - native_int = *(const be_t*)optval.get_ptr(); + native_int = vm::_ref(optval.addr()); } else { @@ -1387,8 +1393,8 @@ error_code sys_net_bnet_setsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam native_opt = optname == SYS_NET_SO_SNDTIMEO ? SO_SNDTIMEO : SO_RCVTIMEO; native_val = &native_timeo; native_len = sizeof(native_timeo); - native_timeo.tv_sec = ::narrow(((const sys_net_timeval*)optval.get_ptr())->tv_sec); - native_timeo.tv_usec = ::narrow(((const sys_net_timeval*)optval.get_ptr())->tv_usec); + native_timeo.tv_sec = ::narrow(vm::_ptr(optval.addr())->tv_sec); + native_timeo.tv_usec = ::narrow(vm::_ptr(optval.addr())->tv_usec); break; } case SYS_NET_SO_LINGER: @@ -1400,8 +1406,8 @@ error_code sys_net_bnet_setsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam native_opt = SO_LINGER; native_val = &native_linger; native_len = sizeof(native_linger); - native_linger.l_onoff = ((const sys_net_linger*)optval.get_ptr())->l_onoff; - native_linger.l_linger = ((const sys_net_linger*)optval.get_ptr())->l_linger; + native_linger.l_onoff = vm::_ptr(optval.addr())->l_onoff; + native_linger.l_linger = vm::_ptr(optval.addr())->l_linger; break; } case SYS_NET_SO_USECRYPTO: @@ -1453,7 +1459,7 @@ error_code sys_net_bnet_setsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam return SYS_NET_EINVAL; } - if (::setsockopt(sock.socket, native_level, native_opt, (const char*)native_val, native_len) == 0) + if (::setsockopt(sock.socket, native_level, native_opt, reinterpret_cast(native_val), native_len) == 0) { return {}; } diff --git a/rpcs3/Emu/Cell/lv2/sys_overlay.cpp b/rpcs3/Emu/Cell/lv2/sys_overlay.cpp index 01a7b1fad4..3a22470b30 100644 --- a/rpcs3/Emu/Cell/lv2/sys_overlay.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_overlay.cpp @@ -73,7 +73,7 @@ error_code sys_overlay_load_module_by_fd(vm::ptr ovlmid, u32 fd, u64 offset return CELL_ENOSYS; } - if ((s64)offset < 0) + if (static_cast(offset) < 0) { return CELL_EINVAL; } diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index ddcbf5ed9b..82f000b76c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -238,7 +238,7 @@ error_code sys_timer_connect_event_queue(ppu_thread& ppu, u32 timer_id, u32 queu // Connect event queue timer.port = std::static_pointer_cast(found->second); - timer.source = name ? name : ((u64)process_getpid() << 32) | timer_id; + timer.source = name ? name : (s64{process_getpid()} << 32) | u64{timer_id}; timer.data1 = data1; timer.data2 = data2; return {}; diff --git a/rpcs3/Emu/Cell/lv2/sys_tty.cpp b/rpcs3/Emu/Cell/lv2/sys_tty.cpp index abf47ca28d..dd266ce38e 100644 --- a/rpcs3/Emu/Cell/lv2/sys_tty.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_tty.cpp @@ -75,7 +75,7 @@ error_code sys_tty_read(s32 ch, vm::ptr buf, u32 len, vm::ptr preadle return CELL_EFAULT; } - *preadlen = (u32)chars_to_read; + *preadlen = static_cast(chars_to_read); if (chars_to_read > 0) { diff --git a/rpcs3/Emu/GDB.cpp b/rpcs3/Emu/GDB.cpp index 43bee185fd..071ec489b6 100644 --- a/rpcs3/Emu/GDB.cpp +++ b/rpcs3/Emu/GDB.cpp @@ -187,7 +187,7 @@ void gdb_thread::start_server() unix_saddr.sun_family = AF_UNIX; strcpy_trunc(unix_saddr.sun_path, g_cfg.misc.gdb_server.get()); - if (bind(server_socket, (struct sockaddr*) &unix_saddr, sizeof(unix_saddr)) != 0) + if (bind(server_socket, reinterpret_cast(&unix_saddr), sizeof(unix_saddr)) != 0) { GDB.error("Failed to bind Unix socket '%s'.", g_cfg.misc.gdb_server.get()); return; @@ -846,7 +846,7 @@ void gdb_thread::operator()() { sockaddr_in client; socklen_t client_len = sizeof(client); - client_socket = accept(server_socket, (struct sockaddr *) &client, &client_len); + client_socket = accept(server_socket, reinterpret_cast(&client), &client_len); if (client_socket == -1) { diff --git a/rpcs3/Loader/TROPUSR.cpp b/rpcs3/Loader/TROPUSR.cpp index ba209a884a..c658eaaf37 100644 --- a/rpcs3/Loader/TROPUSR.cpp +++ b/rpcs3/Loader/TROPUSR.cpp @@ -160,7 +160,7 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con { u32 trophy_id = std::atoi(n->GetAttribute("id").c_str()); u32 trophy_grade; - switch (((const char *)n->GetAttribute("ttype").c_str())[0]) + switch (n->GetAttribute("ttype")[0]) { case 'B': trophy_grade = 4; break; case 'S': trophy_grade = 3; break; @@ -169,8 +169,8 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con default: trophy_grade = 0; } - TROPUSREntry4 entry4 = { 4, u32{sizeof(TROPUSREntry4)} - 0x10, (u32)m_table4.size(), 0, trophy_id, trophy_grade, 0xFFFFFFFF }; - TROPUSREntry6 entry6 = { 6, u32{sizeof(TROPUSREntry6)} - 0x10, (u32)m_table6.size(), 0, trophy_id }; + TROPUSREntry4 entry4 = { 4, u32{sizeof(TROPUSREntry4)} - 0x10, ::size32(m_table4), 0, trophy_id, trophy_grade, 0xFFFFFFFF }; + TROPUSREntry6 entry6 = { 6, u32{sizeof(TROPUSREntry6)} - 0x10, ::size32(m_table6), 0, trophy_id }; m_table4.push_back(entry4); m_table6.push_back(entry6); @@ -178,9 +178,9 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con } u64 offset = sizeof(TROPUSRHeader) + 2 * sizeof(TROPUSRTableHeader); - TROPUSRTableHeader table4header = { 4, u32{sizeof(TROPUSREntry4)} - 0x10, 1, (u32)m_table4.size(), offset }; + TROPUSRTableHeader table4header = { 4, u32{sizeof(TROPUSREntry4)} - 0x10, 1, ::size32(m_table4), offset }; offset += m_table4.size() * sizeof(TROPUSREntry4); - TROPUSRTableHeader table6header = { 6, u32{sizeof(TROPUSREntry6)} - 0x10, 1, (u32)m_table6.size(), offset }; + TROPUSRTableHeader table6header = { 6, u32{sizeof(TROPUSREntry6)} - 0x10, 1, ::size32(m_table6), offset }; offset += m_table6.size() * sizeof(TROPUSREntry6); m_tableHeaders.clear(); @@ -189,7 +189,7 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con m_header.magic = 0x818F54AD; m_header.unk1 = 0x00010000; - m_header.tables_count = (u32)m_tableHeaders.size(); + m_header.tables_count = ::size32(m_tableHeaders); m_header.unk2 = 0; Save(filepath); @@ -199,7 +199,7 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con u32 TROPUSRLoader::GetTrophiesCount() { - return (u32)m_table6.size(); + return ::size32(m_table6); } u32 TROPUSRLoader::GetUnlockedTrophiesCount()