look1_iu8lu16n16tu16_binlcase.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "look1_iu8lu16n16tu16_binlcase.h"
  2. #include "rtwtypes.h"
  3. uint16_T look1_iu8lu16n16tu16_binlcase(uint8_T u0, const uint8_T bp0[], const
  4. uint16_T table[], uint32_T maxIndex)
  5. {
  6. uint32_T iLeft;
  7. uint16_T frac;
  8. uint16_T y;
  9. if (u0 <= bp0[0U]) {
  10. iLeft = 0U;
  11. frac = 0U;
  12. } else if (u0 < bp0[maxIndex]) {
  13. uint32_T bpIdx;
  14. uint32_T iRght;
  15. bpIdx = maxIndex >> 1U;
  16. iLeft = 0U;
  17. iRght = maxIndex;
  18. while (iRght - iLeft > 1U) {
  19. if (u0 < bp0[bpIdx]) {
  20. iRght = bpIdx;
  21. } else {
  22. iLeft = bpIdx;
  23. }
  24. bpIdx = (iRght + iLeft) >> 1U;
  25. }
  26. uint8_T bpLeftVar;
  27. bpLeftVar = bp0[iLeft];
  28. frac = (uint16_T)(((uint32_T)(uint8_T)((uint32_T)u0 - bpLeftVar) << 16) /
  29. (uint8_T)((uint32_T)bp0[iLeft + 1U] - bpLeftVar));
  30. } else {
  31. iLeft = maxIndex;
  32. frac = 0U;
  33. }
  34. if (iLeft == maxIndex) {
  35. y = table[iLeft];
  36. } else {
  37. uint16_T yL_0d0;
  38. uint16_T yR_0d0;
  39. yR_0d0 = table[iLeft + 1U];
  40. yL_0d0 = table[iLeft];
  41. if (yR_0d0 >= yL_0d0) {
  42. y = (uint16_T)((uint32_T)(uint16_T)(((uint32_T)(uint16_T)((uint32_T)yR_0d0
  43. - yL_0d0) * frac) >> 16) + yL_0d0);
  44. } else {
  45. y = (uint16_T)((uint32_T)yL_0d0 - (uint16_T)(((uint32_T)(uint16_T)
  46. ((uint32_T)yL_0d0 - yR_0d0) * frac) >> 16));
  47. }
  48. }
  49. return y;
  50. }