diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-06 11:28:54 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2010-12-20 10:48:51 -0500 |
commit | 7af990c50728123b969a13ccbacc7f2c829d412d (patch) | |
tree | 3033453328157b9dcfcdf17af11fedadc8770e84 | |
parent | ad5758a483978c274058e080a456b773c4b190b0 (diff) |
Move multiplications out of inner loop
-rw-r--r-- | dda.c | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -87,6 +87,13 @@ dda (test_data_t *testdata) int yi = next_sample_y (y0); int xi = next_sample_x (x0); double e = (sample_to_pos (xi) - x0) * dy - (sample_to_pos (yi) - y0) * dx; + double delta_e_big_x, delta_e_big_y; + double delta_e_small_x, delta_e_small_y; + + delta_e_big_x = BIG_STEP_X * dy; + delta_e_small_x = SMALL_STEP_X * dy; + delta_e_big_y = BIG_STEP_Y * dx; + delta_e_small_y = SMALL_STEP_Y * dx; while (yi < next_sample_y (y1)) { @@ -96,13 +103,13 @@ dda (test_data_t *testdata) { if ((xi & 0xff) == N_GRID_X - 1) { - e += BIG_STEP_X * dy; + e += delta_e_big_x; xi += (1 << 8); xi &= 0xffffff00; } else { - e += SMALL_STEP_X * dy; + e += delta_e_small_x; xi++; } } @@ -112,9 +119,9 @@ dda (test_data_t *testdata) begin: if ((xi & 0xff) == 0) { - if (e > BIG_STEP_X * dy) + if (e > delta_e_big_x) { - e -= BIG_STEP_X * dy; + e -= delta_e_big_x; xi -= (1 << 8); xi |= (N_GRID_X - 1); goto small; @@ -123,9 +130,9 @@ dda (test_data_t *testdata) else { small: - if (e > SMALL_STEP_X * dy) + if (e > delta_e_small_x) { - e -= SMALL_STEP_X * dy; + e -= delta_e_small_x; xi--; goto begin; } @@ -142,15 +149,13 @@ dda (test_data_t *testdata) if ((yi & 0xff) == (N_GRID_Y - 1)) { - e -= BIG_STEP_Y * dx; - + e -= delta_e_big_y; yi += (1 << 8); yi &= 0xffffff00; } else { - e -= SMALL_STEP_Y * dx; - + e -= delta_e_small_y; yi++; } } |