From 06dc234497d8860c4c7fde704ba26c8c3da030a1 Mon Sep 17 00:00:00 2001 From: zy69guqi <richard.angersbach@fau.de> Date: Wed, 29 Jan 2025 11:48:26 +0100 Subject: [PATCH] Use std::numeric_limits as NumericLimitsFunctions backend for cpu --- .../backend/platforms/generic_cpu.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/pystencils/backend/platforms/generic_cpu.py b/src/pystencils/backend/platforms/generic_cpu.py index 58b9c7946..b145b6f76 100644 --- a/src/pystencils/backend/platforms/generic_cpu.py +++ b/src/pystencils/backend/platforms/generic_cpu.py @@ -44,7 +44,7 @@ class GenericCpu(Platform): @property def required_headers(self) -> set[str]: - return {"<math.h>", "<limits.h>", "<float.h>"} + return {"<math.h>", "<limits>"} def materialize_iteration_space( self, body: PsBlock, ispace: IterationSpace @@ -64,22 +64,7 @@ class GenericCpu(Platform): arg_types = (dtype,) * func.num_args if isinstance(dtype, PsScalarType) and func in (NumericLimitsFunctions.Min, NumericLimitsFunctions.Max): - # get type prefix for macro - # TODO: there must be a better way... - tpe = "" - match dtype: - case PsIeeeFloatType(): - match dtype.width: - case 32: - tpe = "FLT" - case 64: - tpe = "DBL" - case _: - raise MaterializationError( - f"No implementation available for function {func} on data type {dtype}" - ) - - return PsLiteralExpr(PsLiteral(f"{tpe}_{func.function_name}".upper(), dtype)) + return PsLiteralExpr(PsLiteral(f"std::numeric_limits<{dtype.c_string()}>::{func.function_name}()", dtype)) if isinstance(dtype, PsIeeeFloatType) and dtype.width in (32, 64): cfunc: CFunction -- GitLab