[genius] Wed Jun 01 20:33:17 2011 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Wed Jun 01 20:33:17 2011 Jiri (George) Lebl <jirka 5z com>
- Date: Thu, 2 Jun 2011 03:33:37 +0000 (UTC)
commit 2e5454581797a17273f842acdd4ed4ed0d0b88d6
Author: Jiri (George) Lebl <jirka 5z com>
Date: Wed Jun 1 20:33:21 2011 -0700
Wed Jun 01 20:33:17 2011 Jiri (George) Lebl <jirka 5z com>
* src/dict.c, src/eval.c, src/funclib.c, src/matrix.c, src/matrix.h,
src/matrixw.c: order matrix traversals in a more cache friendly way
ChangeLog | 5 +++++
src/dict.c | 2 +-
src/eval.c | 10 ++++++----
src/funclib.c | 8 ++++----
src/matrix.c | 16 +++++++++-------
src/matrix.h | 2 +-
src/matrixw.c | 40 ++++++++++++++++++++--------------------
7 files changed, 46 insertions(+), 37 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fe61e67..a109abc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jun 01 20:33:17 2011 Jiri (George) Lebl <jirka 5z com>
+
+ * src/dict.c, src/eval.c, src/funclib.c, src/matrix.c, src/matrix.h,
+ src/matrixw.c: order matrix traversals in a more cache friendly way
+
Tue Mar 29 01:41:20 2011 Jiri (George) Lebl <jirka 5z com>
* help/C/genius.xml: define missing entities
diff --git a/src/dict.c b/src/dict.c
index 3600ef7..6f3572a 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -513,7 +513,7 @@ d_intern (const char *id)
return NULL;
tok = g_hash_table_lookup (dictionary, id);
- if (tok == NULL) {
+ if G_UNLIKELY (tok == NULL) {
tok = g_new0 (GelToken, 1);
tok->token = g_strdup (id);
g_hash_table_insert (dictionary, tok->token, tok);
diff --git a/src/eval.c b/src/eval.c
index 102acd5..45d3a05 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1240,8 +1240,8 @@ gel_expandmatrix (GelETree *n)
if (just_denull) {
int j;
- for (i = 0; i < m->width; i++) {
- for (j = 0; j < m->height; j++) {
+ for (j = 0; j < m->height; j++) {
+ for (i = 0; i < m->width; i++) {
GelETree *et
= gel_matrix_index (m, i, j);
if (et != NULL &&
@@ -5304,10 +5304,12 @@ iter_get_index_regions (GelETree *i1, GelETree *i2,
int **reg1, int **reg2,
int *l1, int *l2)
{
- if ( ! iter_get_index_region (i1, max1, reg1, l1))
+ if G_UNLIKELY ( ! iter_get_index_region (i1, max1, reg1, l1))
return FALSE;
- if ( ! iter_get_index_region (i2, max2, reg2, l2))
+ if G_UNLIKELY ( ! iter_get_index_region (i2, max2, reg2, l2)) {
+ g_free (reg1);
return FALSE;
+ }
return TRUE;
}
diff --git a/src/funclib.c b/src/funclib.c
index 6147ace..dd372ef 100644
--- a/src/funclib.c
+++ b/src/funclib.c
@@ -626,8 +626,8 @@ rand_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
m = gel_matrix_new ();
gel_matrix_set_size (m, sizex, sizey, FALSE /* padding */);
- for (i = 0; i < sizex; i++) {
- for (j = 0; j < sizey; j++) {
+ for (j = 0; j < sizey; j++) {
+ for (i = 0; i < sizex; i++) {
mpw_t fr;
mpw_init (fr);
mpw_rand (fr);
@@ -739,8 +739,8 @@ randint_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
m = gel_matrix_new ();
gel_matrix_set_size (m, sizex, sizey, FALSE /* padding */);
- for (i = 0; i < sizex; i++) {
- for (j = 0; j < sizey; j++) {
+ for (j = 0; j < sizey; j++) {
+ for (i = 0; i < sizex; i++) {
mpw_t fr;
mpw_init (fr);
mpw_randint (fr, a[0]->val.value);
diff --git a/src/matrix.c b/src/matrix.c
index 5dcd301..5b072b9 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -81,7 +81,7 @@ gel_matrix_set_size (GelMatrix *matrix, int width, int height, gboolean padding)
g_return_if_fail(width>0);
g_return_if_fail(height>0);
- if ( ! padding) {
+ if (! padding) {
wpadding = 0;
hpadding = 0;
} else {
@@ -196,16 +196,17 @@ gel_matrix_copy(GelMatrix *source, GelElementCopyFunc el_copy, gpointer func_dat
/*copy the data*/
if(el_copy) {
- for(i=0;i<source->width;i++)
- for(j=0;j<source->height;j++) {
+ for(j=0;j<source->height;j++) {
+ for(i=0;i<source->width;i++) {
gpointer data = gel_matrix_index(source,i,j);
if(data)
gel_matrix_index(matrix,i,j) =
(*el_copy)(data, func_data);
}
+ }
} else {
- for(i=0;i<source->width;i++)
- for(j=0;j<source->height;j++)
+ for(j=0;j<source->height;j++)
+ for(i=0;i<source->width;i++)
gel_matrix_index(matrix,i,j) =
gel_matrix_index(source,i,j);
}
@@ -247,12 +248,13 @@ gel_matrix_foreach(GelMatrix *matrix, GFunc func, gpointer func_data)
if (matrix->thedata == NULL)
return;
- for(i=0;i<matrix->width;i++)
- for(j=0;j<matrix->height;j++) {
+ for(j=0;j<matrix->height;j++) {
+ for(i=0;i<matrix->width;i++) {
gpointer data = gel_matrix_index(matrix,i,j);
if(data)
(*func)(data,func_data);
}
+ }
}
/*free a matrix*/
diff --git a/src/matrix.h b/src/matrix.h
index 941c5d1..e35fd75 100644
--- a/src/matrix.h
+++ b/src/matrix.h
@@ -65,6 +65,6 @@ void gel_matrix_foreach(GelMatrix *matrix, GFunc func, gpointer func_data);
void gel_matrix_free(GelMatrix *matrix);
/*get the value at*/
-#define gel_matrix_index(m,x,y) ((m)->thedata[(x)+(y)*(m)->realwidth])
+#define gel_matrix_index(m,x,y) ((m)->thedata[(x)+(y)*((m)->realwidth)])
#endif
diff --git a/src/matrixw.c b/src/matrixw.c
index b454105..aecb501 100644
--- a/src/matrixw.c
+++ b/src/matrixw.c
@@ -74,8 +74,8 @@ internal_matrix_free (GelMatrix *m)
#ifdef MATRIX_DEBUG
/*debug*/printf ("ACTUALLY FREE\n");
#endif
- for (i = 0; i < m->width; i++) {
- for (j = 0; j < m->height; j++) {
+ for (j = 0; j < m->height; j++) {
+ for (i = 0; i < m->width; i++) {
GelETree *t = gel_matrix_index (m, i, j);
if (t != NULL)
gel_freetree (t);
@@ -291,8 +291,8 @@ make_us_a_copy (GelMatrixW *m, int neww, int newh)
gel_matrix_set_size (m->m, neww, newh, TRUE /* padding */);
w = MIN (neww, m->regw);
h = MIN (newh, m->regh);
- for (i = 0; i < w; i++) {
- for(j = 0; j < h; j++) {
+ for(j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
int mi = m->regx ? m->regx[i] : i;
int mj = m->regy ? m->regy[j] : j;
GelETree *t = gel_matrix_index (old, mi, mj);
@@ -333,8 +333,8 @@ copy_with_region (GelMatrixW *m, int *regx, int *regy, int w, int h)
gel_matrix_set_size (m->m, w, h, TRUE /* padding */);
cw = MIN (w, m->regw);
ch = MIN (h, m->regh);
- for (i = 0; i < cw; i++) {
- for(j = 0; j < ch; j++) {
+ for(j = 0; j < ch; j++) {
+ for (i = 0; i < cw; i++) {
int mi = m->regx ? m->regx[regx[i]] : regx[i];
int mj = m->regy ? m->regy[regy[j]] : regy[j];
GelETree *t = gel_matrix_index (old, mi, mj);
@@ -372,8 +372,8 @@ copy_internal_region (GelMatrixW *m, int w, int h)
gel_matrix_set_size (m->m, w, h, TRUE /* padding */);
cw = MIN (w, m->regw);
ch = MIN (h, m->regh);
- for (i = 0; i < cw; i++) {
- for(j = 0; j < ch; j++) {
+ for (j = 0; j < ch; j++) {
+ for (i = 0; i < cw; i++) {
int mi = m->regx ? m->regx[i] : i;
int mj = m->regy ? m->regy[j] : j;
GelETree *t = gel_matrix_index (old, mi, mj);
@@ -427,8 +427,8 @@ ensure_at_least_size (GelMatrixW *m, int w, int h)
gel_matrix_set_size (m->m, w, h, TRUE /* padding */);
nw = MIN (w, m->regw);
nh = MIN (h, m->regh);
- for (i = 0; i < nw; i++) {
- for (j = 0; j < nh; j++) {
+ for (j = 0; j < nh; j++) {
+ for (i = 0; i < nw; i++) {
int mi = m->regx ? m->regx[i] : i;
int mj = m->regy ? m->regy[j] : j;
GelETree *t = gel_matrix_index (old, mi, mj);
@@ -438,8 +438,8 @@ ensure_at_least_size (GelMatrixW *m, int w, int h)
}
}
}
- for (i = 0; i < old->width; i++) {
- for (j = 0; j < old->height; j++) {
+ for (j = 0; j < old->height; j++) {
+ for (i = 0; i < old->width; i++) {
GelETree *t = gel_matrix_index (old,i,j);
if (t != NULL)
gel_freetree (t);
@@ -499,8 +499,8 @@ gel_matrixw_set_size (GelMatrixW *m, int nwidth, int nheight)
internal_matrix_free (old);
return;
}
- for (i = width; i < m->regw; i++) {
- for (j = 0; j < m->regh; j++) {
+ for (j = 0; j < m->regh; j++) {
+ for (i = width; i < m->regw; i++) {
int mi = m->regx ? m->regx[i] : i;
int mj = m->regy ? m->regy[j] : j;
if (gel_matrix_index (m->m, mi, mj) != NULL) {
@@ -509,8 +509,8 @@ gel_matrixw_set_size (GelMatrixW *m, int nwidth, int nheight)
}
}
}
- for (i = 0; i < width; i++) {
- for (j = height; j < m->regh; j++) {
+ for (j = height; j < m->regh; j++) {
+ for (i = 0; i < width; i++) {
int mi = m->regx ? m->regx[i] : i;
int mj = m->regy ? m->regy[j] : j;
if (gel_matrix_index (m->m, mi, mj) != NULL) {
@@ -764,8 +764,8 @@ gel_matrixw_set_region(GelMatrixW *m, GelMatrixW *src,
/* assume that's what ensure/make_us_a_copy does */
g_assert (m->regx == NULL && m->regy == NULL);
- for (i = 0; i < w; i++) {
- for ( j = 0; j < h; j++) {
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
int si, sj;
GelETree *t = gel_matrix_index (m->m, destx[i], desty[j]);
if (m->tr == src->tr) {
@@ -828,8 +828,8 @@ gel_matrixw_set_region_etree (GelMatrixW *m, GelETree *src,
/* assume that's what ensure/make_us_a_copy does */
g_assert (m->regx == NULL && m->regy == NULL);
- for (i = 0; i < w; i++) {
- for ( j = 0; j < h; j++) {
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
GelETree *t = gel_matrix_index (m->m, destx[i], desty[j]);
gel_matrix_index (m->m, destx[i], desty[j]) = gel_copynode (src);
if (t != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]