Mercurial > hg > octave-max
changeset 14879:2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
* src/pt-jit.cc (octave_jit_paren_subsasgn_impl): Use jit_range::update.
(octave_jit_paren_subsasgn_matrix_range, jit_range::all_elements_are_ints):
New function.
(jit_typeinfo::jit_typeinfo): Add support for matrix range paren subsasgn.
* src/pt-jit.h (jit_range::all_elements_are_ints): New Declaration.
(jit_range::jit_range): Use jit_range::update.
(jit_range::update): New function.
author | Max Brister <max@2bass.com> |
---|---|
date | Wed, 27 Jun 2012 18:19:41 -0500 |
parents | 95bfd032f4c7 |
children | d3f9801b1f29 |
files | src/pt-jit.cc src/pt-jit.h |
diffstat | 2 files changed, 64 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pt-jit.cc +++ b/src/pt-jit.cc @@ -249,10 +249,39 @@ double *data = array->fortran_vec (); data[index - 1] = value; - mat->ref_count = array->jit_ref_count (); - mat->slice_data = array->jit_slice_data () - 1; - mat->dimensions = array->jit_dimensions (); - mat->slice_len = array->nelem (); + mat->update (); +} + +extern "C" void +octave_jit_paren_subsasgn_matrix_range (jit_matrix *result, jit_matrix *mat, + jit_range *index, double value) +{ + NDArray *array = mat->array; + bool done = false; + + // optimize for the simple case (no resizing and no errors) + if (*array->jit_ref_count () == 1 + && index->all_elements_are_ints ()) + { + octave_idx_type base = static_cast<octave_idx_type> (index->base); + octave_idx_type nelem = index->nelem; + if (base > 0 && base + nelem <= array->nelem ()) + { + done = true; + double *data = array->jit_slice_data (); + std::fill (data + base - 1, data + base + nelem - 1, value); + } + } + + if (! done) + { + idx_vector idx (*index); + NDArray avalue (dim_vector (1, 1)); + avalue.xelem (0) = value; + array->assign (idx, avalue); + } + + result->update (array); } extern "C" void @@ -311,6 +340,13 @@ } // -------------------- jit_range -------------------- +bool +jit_range::all_elements_are_ints () const +{ + Range r (*this); + return r.all_elements_are_ints (); +} + std::ostream& operator<< (std::ostream& os, const jit_range& rng) { @@ -912,7 +948,12 @@ llvm::verifyFunction (*fn); paren_subsasgn_fn.add_overload (fn, true, matrix, matrix, scalar, scalar); - // paren_subsasgn + fn = create_function ("octave_jit_paren_subsasgn_matrix_range", void_t, + matrix_t->getPointerTo (), matrix_t->getPointerTo (), + range_t->getPointerTo (), scalar_t); + engine->addGlobalMapping (fn, + reinterpret_cast<void *> (&octave_jit_paren_subsasgn_matrix_range)); + paren_subsasgn_fn.add_overload (fn, true, matrix, matrix, range, scalar); casts[any->type_id ()].stash_name ("(any)"); casts[scalar->type_id ()].stash_name ("(scalar)");
--- a/src/pt-jit.h +++ b/src/pt-jit.h @@ -208,6 +208,8 @@ return Range (base, limit, inc); } + bool all_elements_are_ints () const; + double base; double limit; double inc; @@ -221,13 +223,24 @@ struct jit_array { - jit_array (T& from) : ref_count (from.jit_ref_count ()), - slice_data (from.jit_slice_data () - 1), - slice_len (from.capacity ()), - dimensions (from.jit_dimensions ()), - array (new T (from)) + jit_array (T& from) : array (new T (from)) { grab_dimensions (); + update (); + } + + void update (void) + { + ref_count = array->jit_ref_count (); + slice_data = array->jit_slice_data () - 1; + slice_len = array->capacity (); + dimensions = array->jit_dimensions (); + } + + void update (T *aarray) + { + array = aarray; + update (); } void grab_dimensions (void)