fmtconvert.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2015 Janne Grunau
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <math.h>
  21. #include <stdint.h>
  22. #include <string.h>
  23. #include "libavutil/internal.h"
  24. #include "libavutil/common.h"
  25. #include "libavutil/mem_internal.h"
  26. #include "libavcodec/fmtconvert.h"
  27. #include "checkasm.h"
  28. #define BUF_SIZE 1024
  29. #define randomize_input(len) \
  30. do { \
  31. int k; \
  32. for (k = 0; k < len; k++) { \
  33. in[k] = rnd() - INT32_MAX; \
  34. } \
  35. for ( ; k < BUF_SIZE; k++) { \
  36. in[k] = INT32_MAX; \
  37. } \
  38. } while (0)
  39. void checkasm_check_fmtconvert(void)
  40. {
  41. FmtConvertContext c;
  42. LOCAL_ALIGNED(32, float, dst0, [BUF_SIZE]);
  43. LOCAL_ALIGNED(32, float, dst1, [BUF_SIZE]);
  44. LOCAL_ALIGNED(32, int32_t, in, [BUF_SIZE]);
  45. float scale_arr[128];
  46. int length[] = {8, 16, 24, 56, 72, 128, 512, 520, 656, 768, 992};
  47. int i, j;
  48. for (i = 0; i < FF_ARRAY_ELEMS(scale_arr); i++)
  49. scale_arr[i] = (FF_ARRAY_ELEMS(scale_arr) - FF_ARRAY_ELEMS(scale_arr) / 2) / 13;
  50. ff_fmt_convert_init(&c);
  51. memset(dst0, 0, sizeof(*dst0) * BUF_SIZE);
  52. memset(dst1, 0, sizeof(*dst1) * BUF_SIZE);
  53. if (check_func(c.int32_to_float_fmul_scalar, "int32_to_float_fmul_scalar")) {
  54. declare_func(void, float *, const int32_t *, float, int);
  55. for (i = 0; i < FF_ARRAY_ELEMS(scale_arr); i++) {
  56. for (j = 0; j < FF_ARRAY_ELEMS(length); j++) {
  57. randomize_input(length[j]);
  58. call_ref(dst0, in, scale_arr[i], length[j]);
  59. call_new(dst1, in, scale_arr[i], length[j]);
  60. if (!float_near_ulp_array(dst0, dst1, 3, length[j])) {
  61. fail();
  62. break;
  63. }
  64. bench_new(dst1, in, scale_arr[i], length[j]);
  65. }
  66. }
  67. }
  68. if (check_func(c.int32_to_float_fmul_array8, "int32_to_float_fmul_array8")) {
  69. declare_func(void, FmtConvertContext *, float *, const int32_t *,
  70. const float *, int);
  71. for (i = 0; i < 4; i++) {
  72. for (j = 0; j < FF_ARRAY_ELEMS(length); j++) {
  73. randomize_input(length[j]);
  74. call_ref(&c, dst0, in, scale_arr, length[j]);
  75. call_new(&c, dst1, in, scale_arr, length[j]);
  76. if (!float_near_ulp_array(dst0, dst1, 3, length[j])) {
  77. fail();
  78. fprintf(stderr, "int32_to_float_fmul_array8: len: %d\n", length[j]);
  79. break;
  80. }
  81. bench_new(&c, dst1, in, scale_arr, length[j]);
  82. }
  83. }
  84. }
  85. report("fmtconvert");
  86. }