MCPcopy Create free account
hub / github.com/creatale/node-dv / Log_32f

Function Log_32f

deps/opencv/modules/core/src/mathfuncs.cpp:1451–1597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1449static const double ln_2 = 0.69314718055994530941723212145818;
1450
1451static void Log_32f( const float *_x, float *y, int n )
1452{
1453 static const float shift[] = { 0, -1.f/512 };
1454 static const float
1455 A0 = 0.3333333333333333333333333f,
1456 A1 = -0.5f,
1457 A2 = 1.f;
1458
1459 #undef LOGPOLY
1460 #define LOGPOLY(x) (((A0*(x) + A1)*(x) + A2)*(x))
1461
1462 int i = 0;
1463 Cv32suf buf[4];
1464 const int* x = (const int*)_x;
1465
1466#if CV_SSE2
1467 if( USE_SSE2 )
1468 {
1469 static const __m128d ln2_2 = _mm_set1_pd(ln_2);
1470 static const __m128 _1_4 = _mm_set1_ps(1.f);
1471 static const __m128 shift4 = _mm_set1_ps(-1.f/512);
1472
1473 static const __m128 mA0 = _mm_set1_ps(A0);
1474 static const __m128 mA1 = _mm_set1_ps(A1);
1475 static const __m128 mA2 = _mm_set1_ps(A2);
1476
1477 int CV_DECL_ALIGNED(16) idx[4];
1478
1479 for( ; i <= n - 4; i += 4 )
1480 {
1481 __m128i h0 = _mm_loadu_si128((const __m128i*)(x + i));
1482 __m128i yi0 = _mm_sub_epi32(_mm_and_si128(_mm_srli_epi32(h0, 23), _mm_set1_epi32(255)), _mm_set1_epi32(127));
1483 __m128d yd0 = _mm_mul_pd(_mm_cvtepi32_pd(yi0), ln2_2);
1484 __m128d yd1 = _mm_mul_pd(_mm_cvtepi32_pd(_mm_unpackhi_epi64(yi0,yi0)), ln2_2);
1485
1486 __m128i xi0 = _mm_or_si128(_mm_and_si128(h0, _mm_set1_epi32(LOGTAB_MASK2_32F)), _mm_set1_epi32(127 << 23));
1487
1488 h0 = _mm_and_si128(_mm_srli_epi32(h0, 23 - LOGTAB_SCALE - 1), _mm_set1_epi32(LOGTAB_MASK*2));
1489 _mm_store_si128((__m128i*)idx, h0);
1490 h0 = _mm_cmpeq_epi32(h0, _mm_set1_epi32(510));
1491
1492 __m128d t0, t1, t2, t3, t4;
1493 t0 = _mm_load_pd(icvLogTab + idx[0]);
1494 t2 = _mm_load_pd(icvLogTab + idx[1]);
1495 t1 = _mm_unpackhi_pd(t0, t2);
1496 t0 = _mm_unpacklo_pd(t0, t2);
1497 t2 = _mm_load_pd(icvLogTab + idx[2]);
1498 t4 = _mm_load_pd(icvLogTab + idx[3]);
1499 t3 = _mm_unpackhi_pd(t2, t4);
1500 t2 = _mm_unpacklo_pd(t2, t4);
1501
1502 yd0 = _mm_add_pd(yd0, t0);
1503 yd1 = _mm_add_pd(yd1, t2);
1504
1505 __m128 yf0 = _mm_movelh_ps(_mm_cvtpd_ps(yd0), _mm_cvtpd_ps(yd1));
1506
1507 __m128 xf0 = _mm_sub_ps(_mm_castsi128_ps(xi0), _1_4);
1508 xf0 = _mm_mul_ps(xf0, _mm_movelh_ps(_mm_cvtpd_ps(t1), _mm_cvtpd_ps(t3)));

Callers 2

logFunction · 0.85
powFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected