OVR_CRC32.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /************************************************************************************
  2. PublicHeader: OVR
  3. Filename : OVR_CRC32.h
  4. Content : CRC-32
  5. Created : June 20, 2014
  6. Author : Chris Taylor
  7. Copyright : Copyright 2015 Oculus VR, LLC All Rights reserved.
  8. Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
  9. you may not use the Oculus VR Rift SDK except in compliance with the License,
  10. which is provided at the time of installation or download, or which
  11. otherwise accompanies this software in either electronic or hard copy form.
  12. You may obtain a copy of the License at
  13. http://www.oculusvr.com/licenses/LICENSE-3.2
  14. Unless required by applicable law or agreed to in writing, the Oculus VR SDK
  15. distributed under the License is distributed on an "AS IS" BASIS,
  16. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. See the License for the specific language governing permissions and
  18. limitations under the License.
  19. ************************************************************************************/
  20. #ifndef OVR_CRC32_h
  21. #define OVR_CRC32_h
  22. #include "OVR_Types.h"
  23. #include "OVR_Compiler.h"
  24. namespace OVR {
  25. //-----------------------------------------------------------------------------------
  26. // ***** Oculus Camera CRC-32
  27. // This is a proprietary CRC we have been using for camera EEPROM data.
  28. uint32_t OculusCamera_CRC32(const void* data, int bytes, uint32_t prevCRC = 0);
  29. //-----------------------------------------------------------------------------------
  30. // ***** CRC-32 Internal Details
  31. // Choose one of these tables for calculating the CRC:
  32. // polynomial 0x04C11DB7 - PKZIP, PNG [older]
  33. extern const uint32_t CRC32_Table_CRC32[256];
  34. // polynomial 0x1EDC6F41 - CRC32-C (Castagnoli): SSE4.2 [newer]
  35. extern const uint32_t CRC32_Table_CRC32_C[256];
  36. // CRC32 core algorithm
  37. uint32_t CalculateCRC32(const uint32_t* OVR_RESTRICT table, const void* OVR_RESTRICT data, int bytes, uint32_t crc);
  38. //-----------------------------------------------------------------------------------
  39. // ***** CRC-32 Standards
  40. // This is the version you probably want to call. It's the same one used in PKZIP.
  41. inline uint32_t Standard_CRC32(const void* data, int bytes)
  42. {
  43. return CalculateCRC32(CRC32_Table_CRC32, data, bytes, 0);
  44. }
  45. // This is a version that can be hardware accelerated with SSE4.2 and may be suitable
  46. // for large data in the future.
  47. inline uint32_t Castagnoli_CRC32(const void* data, int bytes)
  48. {
  49. return CalculateCRC32(CRC32_Table_CRC32_C, data, bytes, 0);
  50. }
  51. } // namespace OVR
  52. #endif