[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 18/24: Special case for array-map! with three arguments
From: |
Daniel Llorens |
Subject: |
[Guile-commits] 18/24: Special case for array-map! with three arguments |
Date: |
Thu, 23 Jun 2016 11:22:43 +0000 (UTC) |
lloda pushed a commit to branch lloda-array-support
in repository guile.
commit 67f794ecab1761ab4a4001785a10225632a5e1d3
Author: Daniel Llorens <address@hidden>
Date: Wed Dec 9 13:10:48 2015 +0100
Special case for array-map! with three arguments
Benchmark:
(define type #t)
(define A (make-typed-array 's32 0 10000 1000))
(define B (make-typed-array 's32 0 10000 1000))
(define C (make-typed-array 's32 0 10000 1000))
before:
scheme@(guile-user)> ,time (array-map! C + A B)
;; 0.792653s real time, 0.790970s run time. 0.000000s spent in GC.
after:
scheme@(guile-user)> ,time (array-map! C + A B)
;; 0.598513s real time, 0.597146s run time. 0.000000s spent in GC.
* libguile/array-map.c (ramap): Add special case with 3 arguments.
---
libguile/array-map.c | 56 +++++++++++++++++++++++++++++++-------------------
1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/libguile/array-map.c b/libguile/array-map.c
index 058b6fe..f07fd00 100644
--- a/libguile/array-map.c
+++ b/libguile/array-map.c
@@ -320,32 +320,46 @@ ramap (SCM ra0, SCM proc, SCM ras)
h0.vset (h0.vector, i0, scm_call_1 (proc, h1.vref (h1.vector, i1)));
else
{
- size_t restn = scm_ilength (ras);
-
- SCM args = SCM_EOL;
- SCM *p = &args;
- SCM **sa = scm_gc_malloc (sizeof(SCM *) * restn, vi_gc_hint);
- for (size_t k = 0; k < restn; ++k)
+ SCM ra2 = SCM_CAR (ras);
+ ras = SCM_CDR (ras);
+ size_t i2 = SCM_I_ARRAY_BASE (ra2);
+ ssize_t inc2 = SCM_I_ARRAY_DIMS (ra2)->inc;
+ ra2 = SCM_I_ARRAY_V (ra2);
+ scm_t_array_handle h2;
+ scm_array_get_handle (ra2, &h2);
+ if (scm_is_null (ras))
+ for (; n--; i0 += inc0, i1 += inc1, i2 += inc2)
+ h0.vset (h0.vector, i0, scm_call_2 (proc, h1.vref (h1.vector,
i1), h2.vref (h2.vector, i2)));
+ else
{
- *p = scm_cons (SCM_UNSPECIFIED, SCM_EOL);
- sa[k] = SCM_CARLOC (*p);
- p = SCM_CDRLOC (*p);
- }
+ size_t restn = scm_ilength (ras);
- scm_t_array_handle *hs = scm_gc_malloc
- (sizeof(scm_t_array_handle) * restn, vi_gc_hint);
- for (size_t k = 0; k < restn; ++k, ras = scm_cdr (ras))
- scm_array_get_handle (scm_car (ras), hs+k);
+ SCM args = SCM_EOL;
+ SCM *p = &args;
+ SCM **sa = scm_gc_malloc (sizeof(SCM *) * restn, vi_gc_hint);
+ for (size_t k = 0; k < restn; ++k)
+ {
+ *p = scm_cons (SCM_UNSPECIFIED, SCM_EOL);
+ sa[k] = SCM_CARLOC (*p);
+ p = SCM_CDRLOC (*p);
+ }
+
+ scm_t_array_handle *hs = scm_gc_malloc
+ (sizeof(scm_t_array_handle) * restn, vi_gc_hint);
+ for (size_t k = 0; k < restn; ++k, ras = scm_cdr (ras))
+ scm_array_get_handle (scm_car (ras), hs+k);
+
+ for (ssize_t i = 0; n--; i0 += inc0, i1 += inc1, i2 += inc2, ++i)
+ {
+ for (size_t k = 0; k < restn; ++k)
+ *(sa[k]) = scm_array_handle_ref (hs+k,
i*hs[k].dims[0].inc);
+ h0.vset (h0.vector, i0, scm_apply_2 (proc, h1.vref
(h1.vector, i1), h2.vref (h2.vector, i2), args));
+ }
- for (ssize_t i = 0; n--; i0 += inc0, i1 += inc1, ++i)
- {
for (size_t k = 0; k < restn; ++k)
- *(sa[k]) = scm_array_handle_ref (hs+k, i*hs[k].dims[0].inc);
- h0.vset (h0.vector, i0, scm_apply_1 (proc, h1.vref (h1.vector,
i1), args));
+ scm_array_handle_release (hs+k);
}
-
- for (size_t k = 0; k < restn; ++k)
- scm_array_handle_release (hs+k);
+ scm_array_handle_release (&h2);
}
scm_array_handle_release (&h1);
}
- [Guile-commits] branch lloda-array-support updated (f7fdd8b -> b7adfdc), Daniel Llorens, 2016/06/23
- [Guile-commits] 01/24: Avoid unneeded internal use of array handles, Daniel Llorens, 2016/06/23
- [Guile-commits] 05/24: Compile in C99 mode, Daniel Llorens, 2016/06/23
- [Guile-commits] 10/24: Fix compilation of rank 0 typed array literals, Daniel Llorens, 2016/06/23
- [Guile-commits] 17/24: New export (array-for-each-cell-in-order), Daniel Llorens, 2016/06/23
- [Guile-commits] 18/24: Special case for array-map! with three arguments,
Daniel Llorens <=
- [Guile-commits] 08/24: Rename array-set-from!, scm_array_set_from_x to array-amend!, scm_array_amend_x, Daniel Llorens, 2016/06/23
- [Guile-commits] 19/24: Avoid variable stack use in scm_array_for_each_cell(), Daniel Llorens, 2016/06/23
- [Guile-commits] 24/24: Remove uniform-array-read!, uniform-array-write from the manual, Daniel Llorens, 2016/06/23
- [Guile-commits] 09/24: Don't use array handles in scm_c_array_rank, Daniel Llorens, 2016/06/23
- [Guile-commits] 16/24: Draft documentation for (array-for-each-cell), Daniel Llorens, 2016/06/23
- [Guile-commits] 04/24: Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle, Daniel Llorens, 2016/06/23
- [Guile-commits] 03/24: Unuse array 'contiguous' flag, Daniel Llorens, 2016/06/23
- [Guile-commits] 07/24: Tests & doc for array-from, array-from*, array-set-from!, Daniel Llorens, 2016/06/23
- [Guile-commits] 11/24: Remove deprecated array functions, Daniel Llorens, 2016/06/23
- [Guile-commits] 12/24: Speed up for multi-arg cases of scm_ramap functions, Daniel Llorens, 2016/06/23