From 7af990c50728123b969a13ccbacc7f2c829d412d Mon Sep 17 00:00:00 2001 From: Søren Sandmann Pedersen Date: Mon, 6 Dec 2010 11:28:54 -0500 Subject: Move multiplications out of inner loop --- dda.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/dda.c b/dda.c index 677638f..e6fe822 100644 --- a/dda.c +++ b/dda.c @@ -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++; } } -- cgit v1.2.3