uniform.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009, 2010, 2013, 2014 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include "libguile/_scm.h"
  22. #include "libguile/__scm.h"
  23. #include "libguile/uniform.h"
  24. const size_t scm_i_array_element_type_sizes[SCM_ARRAY_ELEMENT_TYPE_LAST + 1] = {
  25. 0,
  26. 0,
  27. 1,
  28. 8,
  29. 8, 8,
  30. 16, 16,
  31. 32, 32,
  32. 64, 64,
  33. 32, 64,
  34. 64, 128
  35. };
  36. size_t
  37. scm_array_handle_uniform_element_size (scm_t_array_handle *h)
  38. {
  39. size_t ret = scm_i_array_element_type_sizes[h->element_type];
  40. if (ret && ret % 8 == 0)
  41. return ret / 8;
  42. else if (ret)
  43. scm_wrong_type_arg_msg (NULL, 0, h->array, "byte-aligned uniform array");
  44. else
  45. scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
  46. }
  47. size_t
  48. scm_array_handle_uniform_element_bit_size (scm_t_array_handle *h)
  49. {
  50. size_t ret = scm_i_array_element_type_sizes[h->element_type];
  51. if (ret)
  52. return ret;
  53. else
  54. scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
  55. }
  56. const void *
  57. scm_array_handle_uniform_elements (scm_t_array_handle *h)
  58. {
  59. return scm_array_handle_uniform_writable_elements (h);
  60. }
  61. void *
  62. scm_array_handle_uniform_writable_elements (scm_t_array_handle *h)
  63. {
  64. size_t esize;
  65. scm_t_uint8 *ret;
  66. esize = scm_array_handle_uniform_element_size (h);
  67. ret = ((scm_t_uint8*) h->writable_elements) + h->base * esize;
  68. return ret;
  69. }
  70. void
  71. scm_init_uniform (void)
  72. {
  73. #include "libguile/uniform.x"
  74. }
  75. /*
  76. Local Variables:
  77. c-file-style: "gnu"
  78. End:
  79. */