1. Си / Говнокод #25929

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    // https://jaycarlson.net/2019/09/06/whats-up-with-these-3-cent-microcontrollers/
    // The C code I used for those original MCU tests looked something like this:
    
    volatile int16_t in[25];
    volatile int16_t out[25];
    const int16_t a0 = 16384;
    const int16_t a1 = -32768;
    const int16_t a2 = 16384;
    const int16_t b1 = -25576;
    const int16_t b2 = 10508;
    int16_t z1, z2;
    int16_t outTemp;
    int16_t inTemp;
    void main()
    {
      while(1) {
        _pa = 2;
        for(i=0;i<25;i++)
        {
          inTemp = in[i];
          outTemp = inTemp * a0 + z1;
          z1 = inTemp * a1 + z2 - b1 * outTemp;
          z2 = inTemp * a2 - b2 * outTemp;
          out[i] = outTemp;
        }
        _pa = 0;
      }
    }
    
    // The Padauk code looks like this:
    
    WORD in[11];
    WORD out[11];
    WORD z1, z2;
    WORD pOut, pIn; // these are pointers, but aren't typed as such
    int i;
    void  FPPA0 (void)
    {
      .ADJUST_IC  SYSCLK=IHRC/2    //  SYSCLK=IHRC/2
      PAC.6 = 1; // make PA6 an output
      while(1) {
        PA.6 = 1;
        pOut = out;
        pIn = in;
        i = 0;
        do {
          *pOut = (*pIn << 14) + z1;
          z1 = -(*pIn << 15) + z2
            + (*pOut << 14)
            + (*pOut << 13)
            + (*pOut << 9)
            + (*pOut << 8)
            + (*pOut << 7)
            + (*pOut << 6)
            + (*pOut << 5)
            + (*pOut << 3);
          z2 = (*pIn << 14)
            - (*pOut << 13)
            - (*pOut << 11)
            - (*pOut << 8)
            - (*pOut << 3)
            - (*pOut << 2);
          i++;
          pOut++;
          pIn++;
        } while(i < 11);
        PA.6 = 0;
      }
    }

    > As for the filter function itself, you’ll see that all the multiplies have been replaced with shift-adds. The Padauk part does not recognize the * operator for multiplication; trying to use it to multiply two variables together results in a syntax error. No, I’m not joking.

    Запостил: j123123, 11 Октября 2019

    Комментарии (58) RSS

    Добавить комментарий