From 5ba5a6615d2994bd3decffba31aabbcc4e551eef Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Fri, 1 Apr 2022 13:47:06 +0200 Subject: [PATCH] AK: Add vector variants of sqrt and rsqrt --- AK/SIMDMath.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/AK/SIMDMath.h b/AK/SIMDMath.h index a8726963eb..5fff5c361d 100644 --- a/AK/SIMDMath.h +++ b/AK/SIMDMath.h @@ -6,7 +6,11 @@ #pragma once +#ifndef __SSE__ +# include +#endif #include +#include #include // Functions returning vectors or accepting vector arguments have different calling conventions @@ -59,6 +63,34 @@ ALWAYS_INLINE static f32x4 exp(f32x4 v) }; } +ALWAYS_INLINE static f32x4 sqrt(f32x4 v) +{ +#ifdef __SSE__ + return __builtin_ia32_sqrtps(v); +#else + return f32x4 { + AK::sqrt(v[0]), + AK::sqrt(v[1]), + AK::sqrt(v[2]), + AK::sqrt(v[3]), + }; +#endif +} + +ALWAYS_INLINE static f32x4 rsqrt(f32x4 v) +{ +#ifdef __SSE__ + return __builtin_ia32_rsqrtps(v); +#else + return f32x4 { + 1.f / AK::sqrt(v[0]), + 1.f / AK::sqrt(v[1]), + 1.f / AK::sqrt(v[2]), + 1.f / AK::sqrt(v[3]), + }; +#endif +} + } #pragma GCC diagnostic pop