Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
4926e118
Commit
4926e118
authored
Dec 11, 2022
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an optimized rsqrt implementation for SSE-enabled builds.
parent
69f4c65b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
2 deletions
+35
-2
miniaudio.h
miniaudio.h
+35
-2
No files found.
miniaudio.h
View file @
4926e118
...
@@ -12064,6 +12064,40 @@ static MA_INLINE double ma_sqrtd(double x)
...
@@ -12064,6 +12064,40 @@ static MA_INLINE double ma_sqrtd(double x)
}
}
static MA_INLINE float ma_rsqrtf(float x)
{
#if defined(MA_SUPPORT_SSE2) && !defined(MA_NO_SSE2) && (defined(MA_X64) || (defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(__SSE2__))
{
/*
For SSE we can use RSQRTSS.
This Stack Overflow post suggests that compilers don't necessarily generate optimal code
when using intrinsics:
https://web.archive.org/web/20221211012522/https://stackoverflow.com/questions/32687079/getting-fewest-instructions-for-rsqrtss-wrapper
I'm going to do something similar here, but a bit simpler.
*/
#if defined(__GNUC__) || defined(__clang__)
{
float result;
__asm__ __volatile__("rsqrtss %1, %0" : "=x"(result) : "x"(x));
return result;
}
#else
{
return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ps1(x)));
}
#endif
}
#else
{
return 1 / (float)ma_sqrtd(x);
}
#endif
}
static MA_INLINE float ma_sinf(float x)
static MA_INLINE float ma_sinf(float x)
{
{
return (float)ma_sind((float)x);
return (float)ma_sind((float)x);
...
@@ -48579,8 +48613,7 @@ MA_API ma_vec3f ma_vec3f_normalize(ma_vec3f v)
...
@@ -48579,8 +48613,7 @@ MA_API ma_vec3f ma_vec3f_normalize(ma_vec3f v)
return ma_vec3f_init_3f(0, 0, 0);
return ma_vec3f_init_3f(0, 0, 0);
}
}
invLen = 1 / (float)ma_sqrtd(len2); /* TODO: Change this to a fast invese sqrt. Use rsqrtss with SSE enabled hardware. */
invLen = ma_rsqrtf(len2);
v.x *= invLen;
v.x *= invLen;
v.y *= invLen;
v.y *= invLen;
v.z *= invLen;
v.z *= invLen;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment