llviddspenc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2016 Alexandra Hájková
  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 <string.h>
  21. #include "libavutil/common.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "libavutil/mem_internal.h"
  24. #include "libavcodec/lossless_videoencdsp.h"
  25. #include "checkasm.h"
  26. #define randomize_buffers(buf, size) \
  27. do { \
  28. int j; \
  29. for (j = 0; j < size; j+=4) \
  30. AV_WN32(buf + j, rnd()); \
  31. } while (0)
  32. static const struct {uint8_t w, h, s;} planes[] = {
  33. {16,16,16}, {21,23,25}, {32,17,48}, {15,128,16}, {128,127,128}
  34. };
  35. #define MAX_STRIDE 128
  36. #define MAX_HEIGHT 127
  37. static void check_diff_bytes(LLVidEncDSPContext *c)
  38. {
  39. int i;
  40. LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE]);
  41. LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE]);
  42. LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE]);
  43. LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE]);
  44. LOCAL_ALIGNED_32(uint8_t, src2, [MAX_STRIDE]);
  45. LOCAL_ALIGNED_32(uint8_t, src3, [MAX_STRIDE]);
  46. declare_func(void, uint8_t *dst, const uint8_t *src1,
  47. const uint8_t *src2, intptr_t w);
  48. memset(dst0, 0, MAX_STRIDE);
  49. memset(dst1, 0, MAX_STRIDE);
  50. randomize_buffers(src0, MAX_STRIDE);
  51. memcpy(src1, src0, MAX_STRIDE);
  52. randomize_buffers(src2, MAX_STRIDE);
  53. memcpy(src3, src2, MAX_STRIDE);
  54. if (check_func(c->diff_bytes, "diff_bytes")) {
  55. for (i = 0; i < 5; i ++) {
  56. call_ref(dst0, src0, src2, planes[i].w);
  57. call_new(dst1, src1, src3, planes[i].w);
  58. if (memcmp(dst0, dst1, planes[i].w))
  59. fail();
  60. }
  61. bench_new(dst1, src0, src2, planes[4].w);
  62. }
  63. }
  64. static void check_sub_left_pred(LLVidEncDSPContext *c)
  65. {
  66. int i;
  67. LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE * MAX_HEIGHT]);
  68. LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE * MAX_HEIGHT]);
  69. LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE * MAX_HEIGHT]);
  70. LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE * MAX_HEIGHT]);
  71. declare_func(void, uint8_t *dst, const uint8_t *src,
  72. ptrdiff_t stride, ptrdiff_t width, int height);
  73. memset(dst0, 0, MAX_STRIDE * MAX_HEIGHT);
  74. memset(dst1, 0, MAX_STRIDE * MAX_HEIGHT);
  75. randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT);
  76. memcpy(src1, src0, MAX_STRIDE * MAX_HEIGHT);
  77. if (check_func(c->sub_left_predict, "sub_left_predict")) {
  78. for (i = 0; i < 5; i ++) {
  79. call_ref(dst0, src0, planes[i].s, planes[i].w, planes[i].h);
  80. call_new(dst1, src1, planes[i].s, planes[i].w, planes[i].h);
  81. if (memcmp(dst0, dst1, planes[i].w * planes[i].h))
  82. fail();
  83. break;
  84. }
  85. bench_new(dst1, src0, planes[4].s, planes[4].w, planes[4].h);
  86. }
  87. }
  88. void checkasm_check_llviddspenc(void)
  89. {
  90. LLVidEncDSPContext c;
  91. ff_llvidencdsp_init(&c);
  92. check_diff_bytes(&c);
  93. report("diff_bytes");
  94. check_sub_left_pred(&c);
  95. report("sub_left_predict");
  96. }