[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 10/13: Special case for array-map! with three arguments
From: |
Daniel Llorens |
Subject: |
[Guile-commits] 10/13: Special case for array-map! with three arguments |
Date: |
Tue, 12 Jul 2016 07:30:51 +0000 (UTC) |
lloda pushed a commit to branch lloda-squash0
in repository guile.
commit b3727a29c74fb351627bc8166b293ef34e72c11e
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-squash0 created (now 9e06cd7), Daniel Llorens, 2016/07/12
- [Guile-commits] 02/13: Fix compilation of rank 0 typed array literals, Daniel Llorens, 2016/07/12
- [Guile-commits] 01/13: Compile in C99 mode, Daniel Llorens, 2016/07/12
- [Guile-commits] 07/13: Remove deprecated array functions, Daniel Llorens, 2016/07/12
- [Guile-commits] 08/13: Do not use array handles in scm_vector, Daniel Llorens, 2016/07/12
- [Guile-commits] 04/13: Avoid unneeded internal use of array handles, Daniel Llorens, 2016/07/12
- [Guile-commits] 13/13: Support typed arrays in some sort functions, Daniel Llorens, 2016/07/12
- [Guile-commits] 03/13: Remove scm_from_contiguous_array, array 'contiguous' flag, Daniel Llorens, 2016/07/12
- [Guile-commits] 10/13: Special case for array-map! with three arguments,
Daniel Llorens <=
- [Guile-commits] 12/13: Remove uniform-array-read!, uniform-array-write from the manual, Daniel Llorens, 2016/07/12
- [Guile-commits] 05/13: Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle, Daniel Llorens, 2016/07/12
- [Guile-commits] 06/13: New functions array-from, array-from*, array-set-from!, Daniel Llorens, 2016/07/12
- [Guile-commits] 09/13: Speed up for multi-arg cases of scm_ramap functions, Daniel Llorens, 2016/07/12
- [Guile-commits] 11/13: New functions (array-for-each-cell, array-for-each-cell-in-order), Daniel Llorens, 2016/07/12