| 1378 | } |
| 1379 | |
| 1380 | void QuantizeMultiplier(double multiplier_double, |
| 1381 | std::int32_t* multiplier_fixedpoint, |
| 1382 | int* multiplier_exponent) { |
| 1383 | RUY_CHECK_GT(multiplier_double, 0); |
| 1384 | if (multiplier_double == 0.) { |
| 1385 | *multiplier_fixedpoint = 0; |
| 1386 | *multiplier_exponent = 0; |
| 1387 | return; |
| 1388 | } |
| 1389 | const double q = std::frexp(multiplier_double, multiplier_exponent); |
| 1390 | auto q_fixed = static_cast<std::int64_t>(std::round(q * (1ll << 31))); |
| 1391 | RUY_CHECK_LE(q_fixed, (1ll << 31)); |
| 1392 | if (q_fixed == (1ll << 31)) { |
| 1393 | q_fixed /= 2; |
| 1394 | ++*multiplier_exponent; |
| 1395 | } |
| 1396 | RUY_CHECK_LE(q_fixed, std::numeric_limits<std::int32_t>::max()); |
| 1397 | *multiplier_fixedpoint = static_cast<std::int32_t>(q_fixed); |
| 1398 | } |
| 1399 | |
| 1400 | template <typename TestSetType> |
| 1401 | void SwitchMultiplierToPerChannel(TestSetType* test_set) { |
no test coverage detected