Merge branch 'dev'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 14b90fc..59f7792 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 2.6...3.0.2)
 
-project(xbyak LANGUAGES CXX VERSION 6.61.1)
+project(xbyak LANGUAGES CXX VERSION 6.61.2)
 
 file(GLOB headers xbyak/*.h)
 
diff --git a/meson.build b/meson.build
index 02c18f3..e1bdd9a 100644
--- a/meson.build
+++ b/meson.build
@@ -5,7 +5,7 @@
 project(
 	'xbyak',
 	'cpp',
-	version: '6.61.1',
+	version: '6.61.2',
 	license: 'BSD-3-Clause',
 	default_options: 'b_ndebug=if-release'
 )
diff --git a/readme.md b/readme.md
index 830d971..0503aba 100644
--- a/readme.md
+++ b/readme.md
@@ -1,5 +1,5 @@
 
-# Xbyak 6.61.1 [![Badge Build]][Build Status]
+# Xbyak 6.61.2 [![Badge Build]][Build Status]
 
 *A C++ JIT assembler for x86 (IA32), x64 (AMD64, x86-64)*
 
diff --git a/readme.txt b/readme.txt
index a4c6a4c..53dc249 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,5 +1,5 @@
 

-    C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak 6.61.1

+    C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak 6.61.2

 

 -----------------------------------------------------------------------------

 ◎概要

diff --git a/test/misc.cpp b/test/misc.cpp
index 236dfb8..e86c953 100644
--- a/test/misc.cpp
+++ b/test/misc.cpp
@@ -5,6 +5,7 @@
 #include <xbyak/xbyak_util.h>
 #include <cybozu/inttype.hpp>
 #include <cybozu/test.hpp>
+#include <algorithm>
 
 using namespace Xbyak;
 
@@ -1975,3 +1976,10 @@
 	Cpu cpu;
 	CYBOZU_TEST_EQUAL(cpu.has(Cpu::tINTEL) && cpu.has(Cpu::tAMD), cpu.has(Cpu::tINTEL | Cpu::tAMD));
 }
+
+CYBOZU_TEST_AUTO(minmax)
+{
+	using namespace Xbyak::util;
+	CYBOZU_TEST_EQUAL((std::min)(3, 4), local::min_(3, 4));
+	CYBOZU_TEST_EQUAL((std::max)(3, 4), local::max_(3, 4));
+}
diff --git a/xbyak/xbyak.h b/xbyak/xbyak.h
index 00fe411..358ebd3 100644
--- a/xbyak/xbyak.h
+++ b/xbyak/xbyak.h
@@ -148,7 +148,7 @@
 
 enum {
 	DEFAULT_MAX_CODE_SIZE = 4096,
-	VERSION = 0x6611 /* 0xABCD = A.BC(.D) */
+	VERSION = 0x6612 /* 0xABCD = A.BC(.D) */
 };
 
 #ifndef MIE_INTEGER_TYPE_DEFINED
diff --git a/xbyak/xbyak_mnemonic.h b/xbyak/xbyak_mnemonic.h
index 41efe8f..74ceb53 100644
--- a/xbyak/xbyak_mnemonic.h
+++ b/xbyak/xbyak_mnemonic.h
@@ -1,4 +1,4 @@
-const char *getVersionString() const { return "6.61.1"; }
+const char *getVersionString() const { return "6.61.2"; }
 void adc(const Operand& op, uint32_t imm) { opRM_I(op, imm, 0x10, 2); }
 void adc(const Operand& op1, const Operand& op2) { opRM_RM(op1, op2, 0x10); }
 void adcx(const Reg32e& reg, const Operand& op) { opGen(reg, op, 0xF6, 0x66, isREG32_REG32orMEM, NONE, 0x38); }
diff --git a/xbyak/xbyak_util.h b/xbyak/xbyak_util.h
index db8ac00..2508416 100644
--- a/xbyak/xbyak_util.h
+++ b/xbyak/xbyak_util.h
@@ -4,7 +4,6 @@
 #ifdef XBYAK_ONLY_CLASS_CPU
 #include <stdint.h>
 #include <stdlib.h>
-#include <algorithm>
 #include <assert.h>
 #ifndef XBYAK_THROW
 	#define XBYAK_THROW(x) ;
@@ -96,6 +95,11 @@
 template<uint64_t L1, uint64_t H1, uint64_t L2, uint64_t H2>
 TypeT<L1 | L2, H1 | H2> operator|(TypeT<L1, H1>, TypeT<L2, H2>) { return TypeT<L1 | L2, H1 | H2>(); }
 
+template<typename T>
+inline T max_(T x, T y) { return x >= y ? x : y; }
+template<typename T>
+inline T min_(T x, T y) { return x < y ? x : y; }
+
 } // local
 
 /**
@@ -193,8 +197,8 @@
 			/*
 				Fallback values in case a hypervisor has 0xB leaf zeroed-out.
 			*/
-			numCores_[SmtLevel - 1] = (std::max)(1u, numCores_[SmtLevel - 1]);
-			numCores_[CoreLevel - 1] = (std::max)(numCores_[SmtLevel - 1], numCores_[CoreLevel - 1]);
+			numCores_[SmtLevel - 1] = local::max_(1u, numCores_[SmtLevel - 1]);
+			numCores_[CoreLevel - 1] = local::max_(numCores_[SmtLevel - 1], numCores_[CoreLevel - 1]);
 		} else {
 			/*
 				Failed to deremine num of cores without x2APIC support.
@@ -237,7 +241,7 @@
 			if (cacheType == DATA_CACHE || cacheType == UNIFIED_CACHE) {
 				uint32_t actual_logical_cores = extractBit(data[0], 14, 25) + 1;
 				if (logical_cores != 0) { // true only if leaf 0xB is supported and valid
-					actual_logical_cores = (std::min)(actual_logical_cores, logical_cores);
+					actual_logical_cores = local::min_(actual_logical_cores, logical_cores);
 				}
 				assert(actual_logical_cores != 0);
 				dataCacheSize_[dataCacheLevels_] =
@@ -247,7 +251,7 @@
 					* (data[2] + 1);
 				if (cacheType == DATA_CACHE && smt_width == 0) smt_width = actual_logical_cores;
 				assert(smt_width != 0);
-				coresSharignDataCache_[dataCacheLevels_] = (std::max)(actual_logical_cores / smt_width, 1u);
+				coresSharignDataCache_[dataCacheLevels_] = local::max_(actual_logical_cores / smt_width, 1u);
 				dataCacheLevels_++;
 			}
 		}
@@ -771,7 +775,7 @@
 		const int allRegNum = pNum + tNum_ + (useRcx_ ? 1 : 0) + (useRdx_ ? 1 : 0);
 		if (tNum_ < 0 || allRegNum > maxRegNum) XBYAK_THROW(ERR_BAD_TNUM)
 		const Reg64& _rsp = code->rsp;
-		saveNum_ = (std::max)(0, allRegNum - noSaveNum);
+		saveNum_ = local::max_(0, allRegNum - noSaveNum);
 		const int *tbl = getOrderTbl() + noSaveNum;
 		for (int i = 0; i < saveNum_; i++) {
 			code->push(Reg64(tbl[i]));