You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

fixed_point.h 2.0 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_LITE_NNACL_QUANTIZATION_FIXED_POINT_H_
  17. #define MINDSPORE_LITE_NNACL_QUANTIZATION_FIXED_POINT_H_
  18. #include <stdint.h>
  19. #include <limits.h>
  20. #ifdef ENABLE_NEON
  21. #include <arm_neon.h>
  22. #endif
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. // returns the high-32 bits of a * b with rounding
  27. // assume that a and b is divided by 2^31, who fall into [-1, 1]
  28. // so the mantissa of a * b is (a / 2^31) * (b / 2^31) * 2^31= (a * b) / 2^31
  29. // actually we compute 2 * a * b / 2^32
  30. // and take 32 bits of mantissa for rounding
  31. int SaturatingRoundingDoublingHighMul(int a, int b);
  32. int16_t SaturatingRoundingDoublingHighMulInt16(int16_t a, int16_t b);
  33. // division by a 2^exponent with rounding
  34. // or arithmetic right shift with rouding
  35. int RoundingDivideByPOT(int x, int exponent);
  36. int MultiplyByQuantizedMultiplier(int32_t value, int32_t multiplier, int32_t left_shift, int32_t right_shift);
  37. int32_t Rescale(int x, int kIntegerBitsSrc, int kIntegerBitsDst);
  38. int CountLeadingSignBits(int32_t x);
  39. int32_t ComputerReciprocal(int32_t x, int x_digits, int *recip_shift);
  40. int exp_on_negative_values(int a, const int tIntegerBits);
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #ifdef ENABLE_NEON
  45. int32x4_t RoundingDivideByPOTInt32x4(int32x4_t x, int exponent);
  46. int32x4_t SaturatingRoundingDoublingHighMulInt32x4(int32x4_t a, int32x4_t b);
  47. #endif
  48. #endif // MINDSPORE_LITE_NNACL_QUANTIZATION_FIXED_POINT_H_