1 //===- LEB128.cpp - LEB128 utility functions implementation -----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements some utility functions for encoding SLEB128 and
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/LEB128.h"
18 /// Utility function to get the size of the ULEB128-encoded value.
19 unsigned getULEB128Size(uint64_t Value
) {
23 Size
+= sizeof(int8_t);
28 /// Utility function to get the size of the SLEB128-encoded value.
29 unsigned getSLEB128Size(int64_t Value
) {
31 int Sign
= Value
>> (8 * sizeof(Value
) - 1);
35 unsigned Byte
= Value
& 0x7f;
37 IsMore
= Value
!= Sign
|| ((Byte
^ Sign
) & 0x40) != 0;
38 Size
+= sizeof(int8_t);