File indexing completed on 2026-05-10 08:44:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_SUPPORT_BCD_H
0014 #define LLVM_SUPPORT_BCD_H
0015
0016 #include <assert.h>
0017 #include <cstddef>
0018 #include <cstdint>
0019
0020 namespace llvm {
0021
0022
0023
0024
0025
0026 inline int64_t decodePackedBCD(const uint8_t *Ptr, size_t ByteLen,
0027 bool IsSigned = true) {
0028 assert(ByteLen >= 1 && ByteLen <= 9 && "Invalid BCD number");
0029 int64_t Value = 0;
0030 size_t RunLen = ByteLen - static_cast<unsigned>(IsSigned);
0031 for (size_t I = 0; I < RunLen; ++I) {
0032 uint8_t DecodedByteValue = ((Ptr[I] >> 4) & 0x0f) * 10 + (Ptr[I] & 0x0f);
0033 Value = (Value * 100) + DecodedByteValue;
0034 }
0035 if (IsSigned) {
0036 uint8_t DecodedByteValue = (Ptr[ByteLen - 1] >> 4) & 0x0f;
0037 uint8_t Sign = Ptr[ByteLen - 1] & 0x0f;
0038 Value = (Value * 10) + DecodedByteValue;
0039 if (Sign == 0x0d || Sign == 0x0b)
0040 Value *= -1;
0041 }
0042 return Value;
0043 }
0044
0045 template <typename ResultT, typename ValT>
0046 inline ResultT decodePackedBCD(const ValT Val, bool IsSigned = true) {
0047 return static_cast<ResultT>(decodePackedBCD(
0048 reinterpret_cast<const uint8_t *>(&Val), sizeof(ValT), IsSigned));
0049 }
0050
0051 }
0052
0053 #endif