[v6,16/16] ipa: libipa: fixedpoint: Remove unsigned workaround
diff mbox series

Message ID 20260121173737.376113-17-kieran.bingham@ideasonboard.com
State New
Headers show
Series
  • libipa: Introduce a Quantized type
Related show

Commit Message

Kieran Bingham Jan. 21, 2026, 5:37 p.m. UTC
Now that we no longer attempt or allow storing signed negative floats
as an unsigned integer representation, remove the workaround which
required an intermediate cast when converting floats to fixed point values.

Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/ipa/libipa/fixedpoint.h | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Stefan Klug Jan. 23, 2026, 2:34 p.m. UTC | #1
Hi Kieran,

Quoting Kieran Bingham (2026-01-21 18:37:35)
> Now that we no longer attempt or allow storing signed negative floats
> as an unsigned integer representation, remove the workaround which
> required an intermediate cast when converting floats to fixed point values.
> 
> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/ipa/libipa/fixedpoint.h | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h
> index 1a871bc554ef..b7dbb00cadaa 100644
> --- a/src/ipa/libipa/fixedpoint.h
> +++ b/src/ipa/libipa/fixedpoint.h
> @@ -75,12 +75,7 @@ public:
>         {
>                 v = std::clamp(v, min, max);
>  
> -               /*
> -                * The intermediate cast to int is needed on arm platforms to
> -                * properly cast negative values. See
> -                * https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/
> -                */
> -               return static_cast<T>(static_cast<int>(std::round(v * (1 << F)))) & bitMask;
> +               return static_cast<T>(std::round(v * (1 << F))) & bitMask;

I'm a bit sad, loosing that link :-)

Looks good to me.

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Cheers,
Stefan

>         }
>  };
>  
> -- 
> 2.52.0
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h
index 1a871bc554ef..b7dbb00cadaa 100644
--- a/src/ipa/libipa/fixedpoint.h
+++ b/src/ipa/libipa/fixedpoint.h
@@ -75,12 +75,7 @@  public:
 	{
 		v = std::clamp(v, min, max);
 
-		/*
-		 * The intermediate cast to int is needed on arm platforms to
-		 * properly cast negative values. See
-		 * https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/
-		 */
-		return static_cast<T>(static_cast<int>(std::round(v * (1 << F)))) & bitMask;
+		return static_cast<T>(std::round(v * (1 << F))) & bitMask;
 	}
 };