Skip to content

Commit

Permalink
переведено на использование стандартных функций.
Browse files Browse the repository at this point in the history
  • Loading branch information
abramcumner committed May 7, 2018
1 parent 84d7c3b commit ffcf599
Showing 1 changed file with 5 additions and 46 deletions.
51 changes: 5 additions & 46 deletions xray/xrCore/_bitwise.h
Expand Up @@ -77,45 +77,14 @@ IC u64 btwCount1(u64 v)
return btwCount1(u32(v&u32(-1)))+btwCount1(u32(v>>u64(32)));
}


ICF int iFloor (float x)
{
int a = *(const int*)(&x);
int exponent = (127 + 31) - ((a >> 23) & 0xFF);
int r = (((u32)(a) << 8) | (1U << 31)) >> exponent;
exponent += 31-127;
{
int imask = (!(((( (1<<(exponent)))-1)>>8)&a));
exponent -= (31-127)+32;
exponent >>= 31;
a >>= 31;
r -= (imask&a);
r &= exponent;
r ^= a;
}
return r;
return (int)std::floor(x);
}

/* intCeil() is a non-interesting variant, since effectively
ceil(x) == -floor(-x)
*/
ICF int iCeil (float x)
{
int a = (*(const int*)(&x));
int exponent = (127 + 31) - ((a >> 23) & 0xFF);
int r = (((u32)(a) << 8) | (1U << 31)) >> exponent;
exponent += 31-127;
{
int imask = (!(((( (1<<(exponent)))-1)>>8)&a));
exponent -= (31-127)+32;
exponent >>= 31;
a = ~((a-1)>>31); /* change sign */
r -= (imask&a);
r &= exponent;
r ^= a;
r = -r; /* change sign */
}
return r; /* r = (int)(ceil(f)) */
return (int)std::ceil(x);
}

// Validity checks
Expand All @@ -132,27 +101,17 @@ IC bool fis_denormal ( const float &f )
// Approximated calculations
IC float apx_InvSqrt( const float& n )
{
long tmp = (long(0xBE800000) - *(long*)&n) >> 1;
float y = *(float*)&tmp;
return y * (1.47f - 0.47f * n * y * y);
return 1.0f / std::sqrt(n);
}
// Only for [0..1] (positive) range
IC float apx_asin (const float x)
{
const float c1 = 0.892399f;
const float c3 = 1.693204f;
const float c5 =-3.853735f;
const float c7 = 2.838933f;

const float x2 = x * x;
const float d = x * (c1 + x2 * (c3 + x2 * (c5 + x2 * c7)));

return d;
return std::asin(x);
}
// Only for [0..1] (positive) range
IC float apx_acos (const float x)
{
return PI_DIV_2 - apx_asin(x);
return std::acos(x);
}

#endif

4 comments on commit ffcf599

@Xottab-DUTY
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А как по производительности?

@abramcumner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пофиг на производительность, они на х64 глючили :) С ними, например, аи-сетка корежилась.

@redpython
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот так корёжилась

ss_dmitry_05-08-18_12-41-19_ escape

@Xottab-DUTY
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оххх, вон оно как его перекорёжило то...

Please sign in to comment.