Commit Graph

1 Commits

Author SHA1 Message Date
Markus Hitter 6f83519a1d Add preprocessor math.
For now this is a square root function which should solve entirely
in the preprocessor. Test results described in the file.

Test code for runtime results, inserted right before the main loop
in mendel.c:

  for (uint32_t i = 0; i < 10000000; i++) {
    uint32_t mathlib = (uint32_t)(sqrt(i) + .5);
    uint32_t preprocessor = (uint32_t)(SQRT(i) + .5);

    if (mathlib != preprocessor) {
      sersendf_P(PSTR("%lu: %lu %lu\n"), i, mathlib, preprocessor);
      break;
    }

    if ((i & 0x00001fff) == 0)
      sersendf_P(PSTR("%lu\n"), i);
  }
  sersendf_P(PSTR("Square root check done.\n"));

Test code for compile time results:

  sersendf_P(PSTR("10000000: %lu\n"), (uint32_t)SQRT(10000000));
  sersendf_P(PSTR("10000000: %lu\n"), (uint32_t)sqrt(10000000));
  sersendf_P(PSTR("20000000: %lu\n"), (uint32_t)SQRT(20000000));
  sersendf_P(PSTR("20000000: %lu\n"), (uint32_t)sqrt(20000000));
  sersendf_P(PSTR("30000000: %lu\n"), (uint32_t)SQRT(30000000));
  sersendf_P(PSTR("30000000: %lu\n"), (uint32_t)sqrt(30000000));
  sersendf_P(PSTR("40000000: %lu\n"), (uint32_t)SQRT(40000000));
  sersendf_P(PSTR("40000000: %lu\n"), (uint32_t)sqrt(40000000));
  sersendf_P(PSTR("50000000: %lu\n"), (uint32_t)SQRT(50000000));
  sersendf_P(PSTR("50000000: %lu\n"), (uint32_t)sqrt(50000000));
  sersendf_P(PSTR("60000000: %lu\n"), (uint32_t)SQRT(60000000));
  sersendf_P(PSTR("60000000: %lu\n"), (uint32_t)sqrt(60000000));
  sersendf_P(PSTR("70000000: %lu\n"), (uint32_t)SQRT(70000000));
  sersendf_P(PSTR("70000000: %lu\n"), (uint32_t)sqrt(70000000));
  sersendf_P(PSTR("80000000: %lu\n"), (uint32_t)SQRT(80000000));
  sersendf_P(PSTR("80000000: %lu\n"), (uint32_t)sqrt(80000000));
  sersendf_P(PSTR("90000000: %lu\n"), (uint32_t)SQRT(90000000));
  sersendf_P(PSTR("90000000: %lu\n"), (uint32_t)sqrt(90000000));
2014-08-31 19:09:59 +02:00