Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/minmax.h
| /*- | /*- | ||||
| * SPDX-License-Identifier: BSD-2-Clause | * SPDX-License-Identifier: BSD-2-Clause | ||||
| * | * | ||||
| * Copyright (c) 2010 iX Systems, Inc. | * Copyright (c) 2010 iX Systems, Inc. | ||||
| * Copyright (c) 2010 Panasas, Inc. | * Copyright (c) 2010 Panasas, Inc. | ||||
| * Copyright (c) 2015 Hans Petter Selasky <hselasky@FreeBSD.org> | * Copyright (c) 2015 Hans Petter Selasky <hselasky@FreeBSD.org> | ||||
| * Copyright (c) 2016 Matt Macy <mmacy@FreeBSD.org> | * Copyright (c) 2016 Matt Macy <mmacy@FreeBSD.org> | ||||
| * Copyright (c) 2023 Serenity Cyber Security, LLC. | |||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| * modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
| * are met: | * are met: | ||||
| * 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
| * notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
| * 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
| * notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
| Show All 19 Lines | |||||
| #include <linux/compiler.h> | #include <linux/compiler.h> | ||||
| #include <linux/types.h> | #include <linux/types.h> | ||||
| #define min(x, y) ((x) < (y) ? (x) : (y)) | #define min(x, y) ((x) < (y) ? (x) : (y)) | ||||
| #define max(x, y) ((x) > (y) ? (x) : (y)) | #define max(x, y) ((x) > (y) ? (x) : (y)) | ||||
| #define min3(a, b, c) min(a, min(b, c)) | #define min3(a, b, c) min(a, min(b, c)) | ||||
| #define max3(a, b, c) max(a, max(b, c)) | #define max3(a, b, c) max(a, max(b, c)) | ||||
| #define min_not_zero(x, y) ({ \ | |||||
| __typeof(x) __min1 = (x); \ | |||||
| __typeof(y) __min2 = (y); \ | |||||
| __min1 == 0 ? __min2 : ((__min2 == 0) ? __min1 : min(__min1, __min2));\ | |||||
| }) | |||||
| #define clamp(x, lo, hi) min(max(x, lo), hi) | #define clamp(x, lo, hi) min(max(x, lo), hi) | ||||
| #define min_t(type, x, y) ({ \ | #define min_t(type, x, y) ({ \ | ||||
| type __min1 = (x); \ | type __min1 = (x); \ | ||||
| type __min2 = (y); \ | type __min2 = (y); \ | ||||
| __min1 < __min2 ? __min1 : __min2; }) | __min1 < __min2 ? __min1 : __min2; }) | ||||
| Show All 16 Lines | |||||