!!HELP!! Arduino Due runs extremely slow!!

I want to use Due as a controller for my 3D printer.

Here is the part that handle the Steppers.

do
  {
    REG_PIOC_ODSR&=0xFFFFFFFF;
    movecmd=0;
    TestX=TestMove(X_MIN_PIN, X_MAX_PIN, current_steps.x, target_steps.x, x_direction);
    TestY=TestMove(Y_MIN_PIN, Y_MAX_PIN, current_steps.y, target_steps.y, y_direction);
    TestZ=TestMove(Z_MIN_PIN, Z_MAX_PIN, current_steps.z, target_steps.z, z_direction);
    TestE=TestMove(E_MIN_PIN, E_MAX_PIN, current_steps.e, target_steps.e, e_direction);
    if (TestX)
    {
      x_counter += delta_steps.x;
      if (x_counter > 0)
      {
        movecmd+=2;
        x_counter -= max_delta;
        current_steps.x+=x_direction;
      }
    }

    if (TestY)
    {
      y_counter += delta_steps.y;
      if (y_counter > 0)
      {
        movecmd+=4;
        y_counter -= max_delta;
        current_steps.y+=y_direction;
      }
    }

    if (TestZ)
    {
      z_counter += delta_steps.z;
      if (z_counter > 0)
      {
        movecmd+=8;
        z_counter -= max_delta;
        current_steps.z+=z_direction;
      }
    }

    if (TestE)
    {
      e_counter += delta_steps.e;
      if (e_counter > 0)
      {
        movecmd+=16;
        e_counter -= max_delta;
        current_steps.e+=e_direction;
      }
    }
    REG_PIOC_ODSR+=movecmd;
        while ((micros()-start)<(micro_delay));
  }
  while (TestX||TestY||TestZ||TestE);

And the TestMove Function is used to test if the stepper has arrived at the target position or end of the working area.It’s simple.

boolean TestMove(byte MinPin, byte MaxPin, long currentP, long targetP, byte directionP)
{
  if ((targetP == currentP)||((!digitalRead(MinPin)) && !directionP)||((!digitalRead(MaxPin)) && directionP))
    return false;
  return true;
}

I use while ((micros()-start)<(micro_delay)); to delay for proper time.
But when I delete this, the program should run one line after another without delay. Guess what? I only get approximately 50kHz signal output when only X-axis is required to move. I used port manipulation in this program so i think the output speed should be OK…

Can anyone help me to get this run faster??

Have you looked at the code behind digitalRead?

Your code might execute digitalRead twice. Perhaps recode to make 2 or 3 if-statements, so that digitalRead is executed at most once?

actually I tried disabling the TestMove function and the speed is still unsatisfied (About 60kHz). I replaced all the TestMove with true statement.
Any more suggestions?
Thanks all the same.

You say you used port manipulation but there are calls to digitalRead() - from what I can tell the speed up from digitalRead/Write to direct port manipulation is even more dramatic on the Due than the Uno (but someone correct me if I'm wrong).

micros() itself may take a certain amount of time to run, I've not tested that. digitalWrite I think is about 2us.