This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C51 - Calculating the parity

Has someone a good hint how to implement a parity-calculation of a byte in the most efficient way on an C51-device?

Parents
  • Another use of the comma operator: you can get the 16bit result from the multiplication of 2 unsigned char without any call to the math clib:

        unsigned char data a, b;
        unsigned int data x;
    
        a = 36;
        b = 130;
    
        // this is 400% faster than a x = (unsigned int) a * b
        *(unsigned char*)&x = ((((unsigned char*)&x)[1] = a * b), B);
    

    I am just too lazy: you can make the int variable a union to access the msb and lsb parts, to improve readability, but the generated code is the same: 11 instruction cycles against 40 cycles using a 16bit cast.

Reply
  • Another use of the comma operator: you can get the 16bit result from the multiplication of 2 unsigned char without any call to the math clib:

        unsigned char data a, b;
        unsigned int data x;
    
        a = 36;
        b = 130;
    
        // this is 400% faster than a x = (unsigned int) a * b
        *(unsigned char*)&x = ((((unsigned char*)&x)[1] = a * b), B);
    

    I am just too lazy: you can make the int variable a union to access the msb and lsb parts, to improve readability, but the generated code is the same: 11 instruction cycles against 40 cycles using a 16bit cast.

Children
No data