01234567->0369

谁践踏了优雅 2023-07-18 02:45 24阅读 0赞
  1. void zxfCOMPRESS_LONG(u32 t) {
  2. u32 x = t, t1, t2, t3, t4,t5;
  3. printBinary("x", (&x), 4);
  4. x &= 0x92492492;
  5. //x &= 0xff;
  6. printBinary("x: x &= 0x92492492", (u8*)(&x), 4);
  7. //printBinary("x: x &= 0xff", (u8*)(&x), 4);
  8. t5 = (x << 2);
  9. printBinary("t5 = (x << 2)", (u8*)(&t5), 4);
  10. t1 = (x |t5 );
  11. printBinary("t1: t1 =(x |t5 )", (u8*)(&t1), 4);
  12. x = t1 & 0xc30c30c3;
  13. printBinary("x: x = t1 & 0xc30c30c3;", (u8*)(&x), 4);
  14. t5 = (x << 4);
  15. printBinary("t5 = (x << 4)", (u8*)(&t5), 4);
  16. t2 = (x | t5);
  17. printBinary("t2: t2 = (x |t5);", (u8*)(&t2), 4);
  18. x = t2 & 0xf00f00f0;
  19. printBinary("x: x = t2 & f00f00f0;", (u8*)(&x), 4);
  20. t5 = (x <<8);
  21. printBinary("t5 = (x << 8)", (u8*)(&t5), 4);
  22. t3 = (x | t5);
  23. printBinary("t3: t3 = (x | t5);", (u8*)(&t3), 4);
  24. x = t3 & 0xff0000ff;
  25. printBinary("x: x = t3 & 0x00ff00ff;", (u8*)(&x), 4);
  26. t5 = (x << 16);
  27. printBinary("t5 = (x << 16)", (u8*)(&t5), 4);
  28. t4 = (x | t5);
  29. printBinary("t4: t4 = (x | t5);", (u8*)(&t4), 4);
  30. x = t4 & 0xfff00000;
  31. printBinary("x:x = t4 & 0xfff00000;", (u8*)(&x), 4);
  32. t++;
  33. }
  34. void printBinary(unsigned char * str, u8 *a, int len) {
  35. printf("%8s:\n", str);
  36. int i, j, count = 0;
  37. u8 t;
  38. for (i = len-1; i >=0; i--) {
  39. t = a[i];
  40. for (j = 0; j < 8; j++) {
  41. printf("%d,", t / 0x80);// 下标 ,取最高位
  42. t = t * 2;
  43. }
  44. printf(" ");
  45. }
  46. printf("\n");
  47. for (i = 0; i < len; i++) {
  48. t = a[i];
  49. printf("0x%02x : ", t);
  50. for (j = 0; j < 8; j++) {
  51. printf("[%02d]%d ", (len - 1 - i) * 8 + j, t / 0x80);// 下标 ,取最高位
  52. t = t * 2;
  53. }
  54. printf("\n");
  55. }
  56. printf("\n");
  57. }

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

优化

  1. #define puckU32ToThree_1(x){\ x &= 0x49249249;\ x = (x | (x >> 2)) & 0xc30c30c3;\ x = (x | (x >>4)) & 0x0f00f00f;\ x = (x | (x >> 8)) & 0xff0000ff;\ x = (x | (x >> 16)) & 0xfff;\ }
  2. #define unpuckU32ToThree_1(x){\ x &= 0xfff;\ x = (x | (x << 16)) & 0xff0000ff;\ x = (x | (x << 8)) & 0x0f00f00f;\ x = (x | (x << 4)) & 0xc30c30c3;\ x = (x | (x << 2)) & 0x49249249;\ }
  3. void packU96FormatToThreePacket1(u32 * out, u8 * in) {
  4. u32 temp0[3] = { 0 };
  5. u32 temp1[3] = { 0 };
  6. u32 temp2[3] = { 0 };
  7. temp0[0] = U32BIG(((u32*)in)[0]); temp0[1] = U32BIG(((u32*)in)[0]) >> 1; temp0[2] = U32BIG(((u32*)in)[0]) >> 2;
  8. puckU32ToThree_1(temp0[0]);
  9. puckU32ToThree_1(temp0[1]);
  10. puckU32ToThree_1(temp0[2]);
  11. temp1[0] = U32BIG(((u32*)in)[1]); temp1[1] = U32BIG(((u32*)in)[1]) >>1; temp1[2] = U32BIG(((u32*)in)[1]) >> 2;
  12. puckU32ToThree_1(temp1[0]);
  13. puckU32ToThree_1(temp1[1]);
  14. puckU32ToThree_1(temp1[2]);
  15. temp2[0] = U32BIG(((u32*)in)[2]); temp2[1] = U32BIG(((u32*)in)[2]) >> 1; temp2[2] = U32BIG(((u32*)in)[2]) >> 2;
  16. puckU32ToThree_1(temp2[0]);
  17. puckU32ToThree_1(temp2[1]);
  18. puckU32ToThree_1(temp2[2]);
  19. out[0] = (temp2[1]<<21) |(temp1[0]<<10) |temp0[2];
  20. out[1] = (temp2[0] << 21) | (temp1[2] << 11) | temp0[1];
  21. out[2] = (temp2[2] << 22) | (temp1[1] << 11) | temp0[0];
  22. }
  23. void unpackU96FormatToThreePacket(u8 * out, u32 * in) {
  24. u32 temp0[3] = { 0 };
  25. u32 temp1[3] = { 0 };
  26. u32 temp2[3] = { 0 };
  27. u32 t1_32, t2_64, t2_65;
  28. u32 t[3] = { 0 };
  29. temp0[0] = in[2] & 0x7ff;
  30. temp0[1] = in[1] & 0x7ff;
  31. temp0[2] = in[0] & 0x3ff;
  32. temp1[0] = (in[0]>>10) & 0x7ff;
  33. temp1[1] = (in[2] >>11 ) & 0x7ff;
  34. temp1[2] = (in[1] >> 11) & 0x3ff;
  35. temp2[0] = in[1] >> 21;
  36. temp2[1] = in[0] >> 21;
  37. temp2[2] = in[2] >> 22;
  38. unpuckU32ToThree_1(temp0[0]);
  39. unpuckU32ToThree_1(temp0[1]);
  40. unpuckU32ToThree_1(temp0[2]);
  41. t[0] = temp0[0] | temp0[1] << 1 | temp0[2] << 2;
  42. unpuckU32ToThree_1(temp1[0]);
  43. unpuckU32ToThree_1(temp1[1]);
  44. unpuckU32ToThree_1(temp1[2]);
  45. t[1] = temp1[0] | temp1[1] << 1 | temp1[2] << 2;
  46. unpuckU32ToThree_1(temp2[0]);
  47. unpuckU32ToThree_1(temp2[1]);
  48. unpuckU32ToThree_1(temp2[2]);
  49. t[2] = temp2[0] | temp2[1] << 1 | temp2[2] << 2;
  50. memcpy(out, t, 12 * sizeof(unsigned char));
  51. }

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,24人围观)

还没有评论,来说两句吧...

相关阅读