uniform.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright 1995-1998,2000-2006,2009-2010,2013-2014,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include "uniform.h"
  19. const size_t scm_i_array_element_type_sizes[SCM_ARRAY_ELEMENT_TYPE_LAST + 1] = {
  20. 0,
  21. 0,
  22. 1,
  23. 8,
  24. 8, 8,
  25. 16, 16,
  26. 32, 32,
  27. 64, 64,
  28. 32, 64,
  29. 64, 128
  30. };
  31. size_t
  32. scm_array_handle_uniform_element_size (scm_t_array_handle *h)
  33. {
  34. size_t ret = scm_i_array_element_type_sizes[h->element_type];
  35. if (ret && ret % 8 == 0)
  36. return ret / 8;
  37. else if (ret)
  38. scm_wrong_type_arg_msg (NULL, 0, h->array, "byte-aligned uniform array");
  39. else
  40. scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
  41. }
  42. size_t
  43. scm_array_handle_uniform_element_bit_size (scm_t_array_handle *h)
  44. {
  45. size_t ret = scm_i_array_element_type_sizes[h->element_type];
  46. if (ret)
  47. return ret;
  48. else
  49. scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
  50. }
  51. const void *
  52. scm_array_handle_uniform_elements (scm_t_array_handle *h)
  53. {
  54. size_t esize;
  55. const uint8_t *ret;
  56. esize = scm_array_handle_uniform_element_size (h);
  57. ret = ((const uint8_t *) h->elements) + h->base * esize;
  58. return ret;
  59. }
  60. void *
  61. scm_array_handle_uniform_writable_elements (scm_t_array_handle *h)
  62. {
  63. if (h->writable_elements != h->elements)
  64. scm_wrong_type_arg_msg (NULL, 0, h->array, "mutable array");
  65. return (void *) scm_array_handle_uniform_elements (h);
  66. }
  67. void
  68. scm_init_uniform (void)
  69. {
  70. #include "uniform.x"
  71. }