blob: 5f1ccef8a9cad644a3a2cca6c4728a05d0676b96 [file] [log] [blame]
metzman40132972019-01-09 21:46:09 +00001//===- FuzzerBuiltins.h - Internal header for builtins ----------*- C++ -* ===//
2//
chandlerc40284492019-01-19 08:50:56 +00003// 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
metzman40132972019-01-09 21:46:09 +00006//
7//===----------------------------------------------------------------------===//
8// Wrapper functions and marcos around builtin functions.
9//===----------------------------------------------------------------------===//
10
11#ifndef LLVM_FUZZER_BUILTINS_H
12#define LLVM_FUZZER_BUILTINS_H
13
14#include "FuzzerDefs.h"
15
16#if !LIBFUZZER_MSVC
17#include <cstdint>
18
19#define GET_CALLER_PC() __builtin_return_address(0)
20
21namespace fuzzer {
22
23inline uint8_t Bswap(uint8_t x) { return x; }
24inline uint16_t Bswap(uint16_t x) { return __builtin_bswap16(x); }
25inline uint32_t Bswap(uint32_t x) { return __builtin_bswap32(x); }
26inline uint64_t Bswap(uint64_t x) { return __builtin_bswap64(x); }
27
28inline uint32_t Clzll(unsigned long long X) { return __builtin_clzll(X); }
29inline uint32_t Clz(unsigned long long X) { return __builtin_clz(X); }
30inline int Popcountll(unsigned long long X) { return __builtin_popcountll(X); }
31
32} // namespace fuzzer
33
34#endif // !LIBFUZZER_MSVC
35#endif // LLVM_FUZZER_BUILTINS_H