@@ -1306,15 +1306,73 @@ float min(float __x, float __y) { return __builtin_fminf(__x, __y); }
1306
1306
__DEVICE__
1307
1307
double min (double __x, double __y) { return __builtin_fmin (__x, __y); }
1308
1308
1309
- #if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
1310
- __host__ inline static int min (int __arg1, int __arg2) {
1311
- return __arg1 < __arg2 ? __arg1 : __arg2;
1309
+ // Define host min/max functions.
1310
+ #if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) && \
1311
+ !defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
1312
+
1313
+ #pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
1314
+ #pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
1315
+ #define DEFINE_MIN_MAX_FUNCTIONS (ret_type, type1, type2 ) \
1316
+ inline ret_type min (const type1 __a, const type2 __b) { \
1317
+ return (__a < __b) ? __a : __b; \
1318
+ } \
1319
+ inline ret_type max (const type1 __a, const type2 __b) { \
1320
+ return (__a > __b) ? __a : __b; \
1321
+ }
1322
+
1323
+ // Define min and max functions for same type comparisons
1324
+ DEFINE_MIN_MAX_FUNCTIONS (int , int , int )
1325
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned int , unsigned int , unsigned int )
1326
+ DEFINE_MIN_MAX_FUNCTIONS(long , long , long )
1327
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned long , unsigned long , unsigned long )
1328
+ DEFINE_MIN_MAX_FUNCTIONS(long long , long long , long long )
1329
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned long long , unsigned long long ,
1330
+ unsigned long long )
1331
+
1332
+ // CUDA defines host min/max functions with mixed signed/unsgined integer
1333
+ // parameters where signed integers are casted to unsigned integers. However,
1334
+ // this may not be users' intention. Therefore do not define them by default
1335
+ // unless users specify -D__HIP_DEFINE_MIXED_HOST_MIN_MAX__.
1336
+ #ifdef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
1337
+ DEFINE_MIN_MAX_FUNCTIONS (unsigned int , int , unsigned int )
1338
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned int , unsigned int , int )
1339
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned long , long , unsigned long )
1340
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned long , unsigned long , long )
1341
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned long long , long long , unsigned long long )
1342
+ DEFINE_MIN_MAX_FUNCTIONS(unsigned long long , unsigned long long , long long )
1343
+ #endif // ifdef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
1344
+
1345
+ // Floating-point comparisons using built-in functions
1346
+ inline float min (float const __a, float const __b) {
1347
+ return __builtin_fminf (__a, __b);
1348
+ }
1349
+ inline double min (double const __a, double const __b) {
1350
+ return __builtin_fmin (__a, __b);
1351
+ }
1352
+ inline double min (float const __a, double const __b) {
1353
+ return __builtin_fmin (__a, __b);
1354
+ }
1355
+ inline double min (double const __a, float const __b) {
1356
+ return __builtin_fmin (__a, __b);
1312
1357
}
1313
1358
1314
- __host__ inline static int max (int __arg1, int __arg2) {
1315
- return __arg1 > __arg2 ? __arg1 : __arg2;
1359
+ inline float max (float const __a, float const __b) {
1360
+ return __builtin_fmaxf (__a, __b);
1361
+ }
1362
+ inline double max (double const __a, double const __b) {
1363
+ return __builtin_fmax (__a, __b);
1364
+ }
1365
+ inline double max (float const __a, double const __b) {
1366
+ return __builtin_fmax (__a, __b);
1316
1367
}
1317
- #endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
1368
+ inline double max (double const __a, float const __b) {
1369
+ return __builtin_fmax (__a, __b);
1370
+ }
1371
+
1372
+ #pragma pop_macro("DEFINE_MIN_MAX_FUNCTIONS")
1373
+
1374
+ #endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) &&
1375
+ // !defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
1318
1376
#endif
1319
1377
1320
1378
#pragma pop_macro("__DEVICE__")
0 commit comments