dec_uint32.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // If we have native uint32's, pick off 4 bytes at a time for as long as we
  2. // can, but make sure that we quit before seeing any == markers at the end of
  3. // the string. Also, because we write a zero at the end of the output, ensure
  4. // that there are at least 2 valid bytes of input data remaining to close the
  5. // gap. 4 + 2 + 2 = 8 bytes:
  6. while (srclen >= 8)
  7. {
  8. uint32_t str, res, dec;
  9. // Load string:
  10. str = *(uint32_t *)c;
  11. // Shuffle bytes to 32-bit bigendian:
  12. str = cpu_to_be32(str);
  13. // Lookup each byte in the decoding table; if we encounter any
  14. // "invalid" values, fall back on the bytewise code:
  15. if ((dec = neon32_base64_table_dec[str >> 24]) > 63) {
  16. break;
  17. }
  18. res = dec << 26;
  19. if ((dec = neon32_base64_table_dec[(str >> 16) & 0xFF]) > 63) {
  20. break;
  21. }
  22. res |= dec << 20;
  23. if ((dec = neon32_base64_table_dec[(str >> 8) & 0xFF]) > 63) {
  24. break;
  25. }
  26. res |= dec << 14;
  27. if ((dec = neon32_base64_table_dec[str & 0xFF]) > 63) {
  28. break;
  29. }
  30. res |= dec << 8;
  31. // Reshuffle and repack into 3-byte output format:
  32. res = be32_to_cpu(res);
  33. // Store back:
  34. *(uint32_t *)o = res;
  35. c += 4;
  36. o += 3;
  37. outl += 3;
  38. srclen -= 4;
  39. }