drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_standalone_libraries/lib_float_math.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_standalone_libraries/lib_float_math.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_standalone_libraries/lib_float_math.c
Extension
.c
Size
2993 bytes
Lines
148
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: MIT
//
// Copyright 2024 Advanced Micro Devices, Inc.

#include "lib_float_math.h"

#define ASSERT(condition)

#define isNaN(number) ((number) != (number))

 /*
  * NOTE:
  *   This file is gcc-parseable HW gospel, coming straight from HW engineers.
  *
  * It doesn't adhere to Linux kernel style and sometimes will do things in odd
  * ways. Unless there is something clearly wrong with it the code should
  * remain as-is as it provides us with a guarantee from HW that it is correct.
  */

double math_mod(const double arg1, const double arg2)
{
	if (isNaN(arg1))
		return arg2;
	if (isNaN(arg2))
		return arg1;
	return arg1 - arg2 * ((int)(arg1 / arg2));
}

double math_min2(const double arg1, const double arg2)
{
	if (isNaN(arg1))
		return arg2;
	if (isNaN(arg2))
		return arg1;
	return arg1 < arg2 ? arg1 : arg2;
}

double math_max2(const double arg1, const double arg2)
{
	if (isNaN(arg1))
		return arg2;
	if (isNaN(arg2))
		return arg1;
	return arg1 > arg2 ? arg1 : arg2;
}

double math_floor2(const double arg, const double significance)
{
	ASSERT(significance != 0);

	return ((int)(arg / significance)) * significance;
}

double math_floor(const double arg)
{
	return ((int)(arg));
}

double math_ceil(const double arg)
{
	return (int)(arg + 0.99999);
}

double math_ceil2(const double arg, const double significance)
{
	return ((int)(arg / significance + 0.99999)) * significance;
}

double math_max3(double v1, double v2, double v3)
{
	return v3 > math_max2(v1, v2) ? v3 : math_max2(v1, v2);
}

double math_max4(double v1, double v2, double v3, double v4)
{
	return v4 > math_max3(v1, v2, v3) ? v4 : math_max3(v1, v2, v3);
}

double math_max5(double v1, double v2, double v3, double v4, double v5)
{
	return math_max3(v1, v2, v3) > math_max2(v4, v5) ? math_max3(v1, v2, v3) : math_max2(v4, v5);
}

float math_pow(float a, float exp)
{
	double temp;
	if ((int)exp == 0)
		return 1;
	temp = math_pow(a, (float)((int)(exp / 2)));
	if (((int)exp % 2) == 0) {

Annotation

Implementation Notes