Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #334 from lioncash/use-std-minmax
Remove the min/max functions in CommonFuncs.
  • Loading branch information
shuffle2 committed May 30, 2014
2 parents 3097345 + 49b0eef commit 8fc83d8
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 99 deletions.
1 change: 1 addition & 0 deletions Source/Core/AudioCommon/stdafx.h
Expand Up @@ -12,6 +12,7 @@
#endif
*/
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define NOMINMAX // Don't include windows min/max definitions

#include <algorithm>
#include <functional>
9 changes: 0 additions & 9 deletions Source/Core/Common/CommonFuncs.h
Expand Up @@ -158,15 +158,6 @@ extern "C" {
#endif // M_IX86
#endif // WIN32 ndef

// Dolphin's min and max functions
#undef min
#undef max

template<class T>
inline T min(const T& a, const T& b) {return a > b ? b : a;}
template<class T>
inline T max(const T& a, const T& b) {return a > b ? a : b;}

// Generic function to get last error message.
// Call directly after the command or use the error num.
// This function might change the error code.
Expand Down
14 changes: 7 additions & 7 deletions Source/Core/Common/Hash.cpp
Expand Up @@ -2,7 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.


#include <algorithm>
#include "Common/Hash.h"
#if _M_SSE >= 0x402
#include "Common/CPUDetect.h"
Expand Down Expand Up @@ -155,7 +155,7 @@ u64 GetMurmurHash3(const u8 *src, int len, u32 samples)
const u8 * data = (const u8*)src;
const int nblocks = len / 16;
u32 Step = (len / 8);
if (samples == 0) samples = max(Step, 1u);
if (samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if (Step < 1) Step = 1;

Expand Down Expand Up @@ -233,7 +233,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
if (samples == 0) samples = max(Step, 1u);
if (samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if (Step < 1) Step = 1;
while (data < end)
Expand Down Expand Up @@ -265,7 +265,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
if (samples == 0) samples = max(Step, 1u);
if (samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if (Step < 1) Step = 1;
while (data < end)
Expand Down Expand Up @@ -308,7 +308,7 @@ u64 GetCRC32(const u8 *src, int len, u32 samples)
u32 Step = (len/4);
const u32 *data = (const u32 *)src;
const u32 *end = data + Step;
if (samples == 0) samples = max(Step, 1u);
if (samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if (Step < 1) Step = 1;
while (data < end)
Expand Down Expand Up @@ -380,7 +380,7 @@ u64 GetMurmurHash3(const u8* src, int len, u32 samples)
u32 out[2];
const int nblocks = len / 8;
u32 Step = (len / 4);
if (samples == 0) samples = max(Step, 1u);
if (samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if (Step < 1) Step = 1;

Expand Down Expand Up @@ -456,7 +456,7 @@ u64 GetHashHiresTexture(const u8 *src, int len, u32 samples)
u32 Step = (len / 8);
const u64 *data = (const u64 *)src;
const u64 *end = data + Step;
if (samples == 0) samples = max(Step, 1u);
if (samples == 0) samples = std::max(Step, 1u);
Step = Step / samples;
if (Step < 1) Step = 1;
while (data < end)
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Common/SysConf.h
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
Expand Down Expand Up @@ -58,7 +59,7 @@ struct SSysConfEntry
{
if (buffer)
{
memcpy(data, buffer, min<u16>(bufferSize, dataLength));
memcpy(data, buffer, std::min<u16>(bufferSize, dataLength));
return true;
}
return false;
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Common/stdafx.h
Expand Up @@ -9,11 +9,13 @@
#define _WIN32_WINNT 0x501
#endif
#ifndef _WIN32_IE
#define _WIN32_IE 0x0500 // Default value is 0x0400
#define _WIN32_IE 0x0500 // Default value is 0x0400
#endif
*/

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define NOMINMAX // Don't include windows min/max definitions

/*
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Core/FifoPlayer/FifoRecordAnalyzer.cpp
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include <algorithm>

#include "Core/Core.h"
#include "Core/FifoPlayer/FifoAnalyzer.h"
#include "Core/FifoPlayer/FifoRecordAnalyzer.h"
Expand Down Expand Up @@ -289,8 +291,8 @@ void FifoRecordAnalyzer::WriteTexMapMemory(int texMap, u32 &writtenTexMaps)
width >>= 1;
height >>= 1;

width = max(width, fmtWidth);
height = max(height, fmtHeight);
width = std::max(width, fmtWidth);
height = std::max(height, fmtHeight);
u32 size = (width * height * fmtDepth) >> 1;

textureSize += size;
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/HW/SI.cpp
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include <algorithm>

#include "Common/ChunkFile.h"
#include "Common/Common.h"

Expand Down Expand Up @@ -544,7 +546,7 @@ int GetTicksToNextSIPoll()
else if (!g_Poll.Y)
return SystemTimers::GetTicksPerSecond() / 60;

return min(VideoInterface::GetTicksPerFrame() / g_Poll.Y, VideoInterface::GetTicksPerLine() * g_Poll.X);
return std::min(VideoInterface::GetTicksPerFrame() / g_Poll.Y, VideoInterface::GetTicksPerLine() * g_Poll.X);
}

} // end of namespace SerialInterface
4 changes: 3 additions & 1 deletion Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net_ssl.cpp
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include <algorithm>

#include "Common/FileUtil.h"
#include "Core/IPC_HLE/WII_IPC_HLE_Device_net_ssl.h"
#include "Core/IPC_HLE/WII_Socket.h"
Expand Down Expand Up @@ -174,7 +176,7 @@ bool CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
ssl_set_authmode(&ssl->ctx, SSL_VERIFY_NONE);
ssl_set_renegotiation(&ssl->ctx, SSL_RENEGOTIATION_ENABLED);

memcpy(ssl->hostname, hostname, min((int)BufferOutSize2, NET_SSL_MAX_HOSTNAME_LEN));
memcpy(ssl->hostname, hostname, std::min((int)BufferOutSize2, NET_SSL_MAX_HOSTNAME_LEN));
ssl->hostname[NET_SSL_MAX_HOSTNAME_LEN-1] = '\0';
ssl_set_hostname(&ssl->ctx, ssl->hostname);

Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/IPC_HLE/WII_Socket.cpp
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include <algorithm>

#include "Core/Movie.h"
#include "Core/NetPlayProto.h"
#include "Core/IPC_HLE/WII_IPC_HLE.h"
Expand Down Expand Up @@ -589,7 +591,7 @@ void WiiSockMan::Update()
FD_SET(sock.fd, &read_fds);
FD_SET(sock.fd, &write_fds);
FD_SET(sock.fd, &except_fds);
nfds = max(nfds, sock.fd+1);
nfds = std::max(nfds, sock.fd+1);
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp
Expand Up @@ -24,6 +24,8 @@ The register allocation is linear scan allocation.
#pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned
#endif

#include <algorithm>

#include "Common/CPUDetect.h"
#include "Common/MathUtil.h"
#include "Core/HW/ProcessorInterface.h"
Expand Down Expand Up @@ -76,7 +78,7 @@ static void regMarkUse(RegInfo& R, InstLoc I, InstLoc Op, unsigned OpNum) {
unsigned& info = R.IInfo[Op - R.FirstI];
if (info == 0) R.IInfo[I - R.FirstI] |= 1 << (OpNum + 1);
if (info < 2) info++;
R.lastUsed[Op - R.FirstI] = max(R.lastUsed[Op - R.FirstI], I);
R.lastUsed[Op - R.FirstI] = std::max(R.lastUsed[Op - R.FirstI], I);
}

static unsigned regReadUse(RegInfo& R, InstLoc I) {
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/PowerPC/JitArmIL/IR_Arm.cpp
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include <algorithm>

#include "Common/ArmEmitter.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
Expand Down Expand Up @@ -50,7 +52,7 @@ static void regMarkUse(RegInfo& R, InstLoc I, InstLoc Op, unsigned OpNum) {
unsigned& info = R.IInfo[Op - R.FirstI];
if (info == 0) R.IInfo[I - R.FirstI] |= 1 << (OpNum + 1);
if (info < 2) info++;
R.lastUsed[Op - R.FirstI] = max(R.lastUsed[Op - R.FirstI], I);
R.lastUsed[Op - R.FirstI] = std::max(R.lastUsed[Op - R.FirstI], I);
}
static void regClearInst(RegInfo& RI, InstLoc I) {
for (int i = 0; i < RegAllocSize; i++)
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/stdafx.h
Expand Up @@ -6,9 +6,10 @@

#define _WIN32_WINNT 0x501
#ifndef _WIN32_IE
#define _WIN32_IE 0x0500 // Default value is 0x0400
#define _WIN32_IE 0x0500 // Default value is 0x0400
#endif

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define NOMINMAX // Don't include windows min/max definitions

#include <algorithm>
4 changes: 2 additions & 2 deletions Source/Core/DiscIO/CompressedBlob.cpp
Expand Up @@ -193,7 +193,7 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
u64 position = 0;
int num_compressed = 0;
int num_stored = 0;
int progress_monitor = max<int>(1, header.num_blocks / 1000);
int progress_monitor = std::max<int>(1, header.num_blocks / 1000);

for (u32 i = 0; i < header.num_blocks; i++)
{
Expand Down Expand Up @@ -299,7 +299,7 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile,

const CompressedBlobHeader &header = reader->GetHeader();
u8* buffer = new u8[header.block_size];
int progress_monitor = max<int>(1, header.num_blocks / 100);
int progress_monitor = std::max<int>(1, header.num_blocks / 100);

for (u64 i = 0; i < header.num_blocks; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/FileSystemGCWii.cpp
Expand Up @@ -104,7 +104,7 @@ bool CFileSystemGCWii::ExportFile(const std::string& _rFullPath, const std::stri
while (remainingSize)
{
// Limit read size to 128 MB
size_t readSize = (size_t)min(remainingSize, (u64)0x08000000);
size_t readSize = std::min<size_t>(remainingSize, (u64)0x08000000);

std::vector<u8> buffer(readSize);

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/DiscIO/stdafx.h
Expand Up @@ -8,7 +8,8 @@
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define NOMINMAX // Don't include windows min/max definitions

#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinWX/stdafx.h
Expand Up @@ -12,8 +12,9 @@
#define _WIN32_IE 0x0500
#define _RICHEDIT_VER 0x0100

#define WIN32_LEAN_AND_MEAN
#include <wx/wx.h> // wxWidgets
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define NOMINMAX // Don't include windows min/max definitions
#include <wx/wx.h> // wxWidgets

#if _M_X86_32

Expand Down
1 change: 1 addition & 0 deletions Source/Core/InputCommon/stdafx.h
Expand Up @@ -10,5 +10,6 @@
#endif
*/
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define NOMINMAX // Don't include windows min/max definitions

#include <algorithm>
4 changes: 3 additions & 1 deletion Source/Core/VideoBackends/D3D/stdafx.h
Expand Up @@ -5,8 +5,10 @@
#pragma once
#define _WIN32_WINNT 0x501
#ifndef _WIN32_IE
#define _WIN32_IE 0x0500 // Default value is 0x0400
#define _WIN32_IE 0x0500 // Default value is 0x0400
#endif

#define NOMINMAX // Don't include windows min/max definitions

#include <tchar.h>
#include <windows.h>
4 changes: 3 additions & 1 deletion Source/Core/VideoBackends/OGL/stdafx.h
Expand Up @@ -5,8 +5,10 @@
#pragma once
#define _WIN32_WINNT 0x501
#ifndef _WIN32_IE
#define _WIN32_IE 0x0500 // Default value is 0x0400
#define _WIN32_IE 0x0500 // Default value is 0x0400
#endif

#define NOMINMAX // Don't include windows min/max definitions

#include <tchar.h>
#include <windows.h>
25 changes: 13 additions & 12 deletions Source/Core/VideoBackends/Software/Rasterizer.cpp
Expand Up @@ -2,8 +2,9 @@
// Licensed under GPLv2
// Refer to the license.txt file included.

#include "Common/Common.h"
#include <algorithm>

#include "Common/Common.h"
#include "VideoBackends/Software/BPMemLoader.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/HwRasterizer.h"
Expand Down Expand Up @@ -231,12 +232,12 @@ inline void CalculateLOD(s32 &lod, bool &linear, u32 texmap, u32 texcoord)
float *uv1 = rasterBlock.Pixel[1][0].Uv[texcoord];
float *uv2 = rasterBlock.Pixel[0][1].Uv[texcoord];

sDelta = max(fabsf(uv0[0] - uv1[0]), fabsf(uv0[0] - uv2[0]));
tDelta = max(fabsf(uv0[1] - uv1[1]), fabsf(uv0[1] - uv2[1]));
sDelta = std::max(fabsf(uv0[0] - uv1[0]), fabsf(uv0[0] - uv2[0]));
tDelta = std::max(fabsf(uv0[1] - uv1[1]), fabsf(uv0[1] - uv2[1]));
}

// get LOD in s28.4
lod = FixedLog2(max(sDelta, tDelta));
lod = FixedLog2(std::max(sDelta, tDelta));

// bias is s2.5
int bias = tm0.lod_bias;
Expand Down Expand Up @@ -349,16 +350,16 @@ void DrawTriangleFrontFace(OutputVertexData *v0, OutputVertexData *v1, OutputVer
const s32 FDY31 = DY31 << 4;

// Bounding rectangle
s32 minx = (min(min(X1, X2), X3) + 0xF) >> 4;
s32 maxx = (max(max(X1, X2), X3) + 0xF) >> 4;
s32 miny = (min(min(Y1, Y2), Y3) + 0xF) >> 4;
s32 maxy = (max(max(Y1, Y2), Y3) + 0xF) >> 4;
s32 minx = (std::min(std::min(X1, X2), X3) + 0xF) >> 4;
s32 maxx = (std::max(std::max(X1, X2), X3) + 0xF) >> 4;
s32 miny = (std::min(std::min(Y1, Y2), Y3) + 0xF) >> 4;
s32 maxy = (std::max(std::max(Y1, Y2), Y3) + 0xF) >> 4;

// scissor
minx = max(minx, scissorLeft);
maxx = min(maxx, scissorRight);
miny = max(miny, scissorTop);
maxy = min(maxy, scissorBottom);
minx = std::max(minx, scissorLeft);
maxx = std::min(maxx, scissorRight);
miny = std::max(miny, scissorTop);
maxy = std::min(maxy, scissorBottom);

if (minx >= maxx || miny >= maxy)
return;
Expand Down

0 comments on commit 8fc83d8

Please sign in to comment.