divu_const.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*Daala video codec
  2. Copyright (c) 2013 Daala project contributors. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. - Redistributions of source code must retain the above copyright notice, this
  6. list of conditions and the following disclaimer.
  7. - Redistributions in binary form must reproduce the above copyright notice,
  8. this list of conditions and the following disclaimer in the documentation
  9. and/or other materials provided with the distribution.
  10. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
  11. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  13. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  14. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  15. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  16. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  17. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  18. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  19. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include "../src/odintrin.h"
  26. #define NBITS (32)
  27. /*This program generates the constants for use with OD_DIVU_SMALL().*/
  28. int main(int argc, char *argv[]) {
  29. if (argc != 2) {
  30. printf("usage: %s <max>\n", argv[0]);
  31. return EXIT_FAILURE;
  32. }
  33. else {
  34. int max;
  35. int d;
  36. max = atoi(argv[1]);
  37. printf("ogg_uint32_t OD_DIVU_SMALL_CONSTS[OD_DIVU_DMAX][2]={\n");
  38. for (d = 1; d <= max; d++) {
  39. if ((d & (d - 1)) == 0) {
  40. printf(" {0xFFFFFFFF,0xFFFFFFFF},\n");
  41. }
  42. else {
  43. unsigned long long t;
  44. unsigned long long r;
  45. int m;
  46. m = OD_LOG2(d);
  47. t = (1UL << m + NBITS)/d;
  48. r = (t*d + d) & ((1UL << NBITS) - 1);
  49. if (r <= 1UL << m) {
  50. printf(" {0x%llX, 0},\n", t + 1);
  51. }
  52. else {
  53. printf(" {0x%llX,0x%llX},\n", t, t);
  54. }
  55. }
  56. }
  57. printf("};\n");
  58. return EXIT_SUCCESS;
  59. }
  60. }