• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef BERBERIS_BASE_CONFIG_H_
18 #define BERBERIS_BASE_CONFIG_H_
19 
20 #include <cstddef>
21 #include <cstdint>
22 
23 namespace berberis::config {
24 
25 // Size of the stack frame allocated in translated code prologue.
26 // As translated code ('slow') prologue executes much less frequently than
27 // region ('fast') prologue, it makes sense to allocate a frame there that
28 // suits most regions. Outstanding regions will expand it in their prologue.
29 // Assume the stack is properly aligned when entering translated code.
30 // TODO(b/232598137): If we discover that most regions don't need stack frame
31 // at all, then we might want to avoid extra altering of stack pointer in
32 // translated code prologue and keep stack misaligned. Then we'll need a
33 // kStackMisalignAtTranslatedCode config variable.
34 // TODO(b/232598137): 12 is what we get on x86-32 after stack alignment, update
35 // with, say, 90-percentile of (dynamic) frame size.
36 inline constexpr uint32_t kFrameSizeAtTranslatedCode = sizeof(size_t) == 4 ? 12u : 8u;
37 // Attention: This flag traces every entry to RunGeneratedCode which
38 // may be *very* slow especially if kAllJumpsExitGeneratedCode flag is
39 // enabled.
40 inline constexpr bool kTraceGeneratedCode = false;
41 // Setting this to true enables instrumentation of every executed region in the
42 // main execution loop (ExecuteGuest).
43 inline constexpr bool kAllJumpsExitGeneratedCode = false;
44 // Eliminate overhead of exiting/reentering generated code by searching in
45 // the translation cache directly from the generated code.
46 inline constexpr bool kLinkJumpsBetweenRegions = !kAllJumpsExitGeneratedCode;
47 // Generate local jumps if jump's target address falls within the
48 // current region. If false dispatch to another region instead.
49 inline constexpr bool kLinkJumpsWithinRegion = !kAllJumpsExitGeneratedCode;
50 // Guest page size. Always 4K for now.
51 inline constexpr size_t kGuestPageSize = 4096;
52 // Number of hard registers assumed by the register allocator.
53 inline constexpr uint32_t kMaxHardRegs = 64u;
54 // Threshold for switching between gears
55 inline constexpr uint32_t kGearSwitchThreshold = 1000;
56 // Scratch area size for use in intrinsics with instructions which may only work with memory.
57 inline constexpr uint32_t kScratchAreaSize = 32;
58 // Scratch area alignment (important if we would use Movaps/Movapd).
59 inline constexpr uint32_t kScratchAreaAlign = 16;
60 // Scratch area slot size if more than one scratch is needed.
61 inline constexpr uint32_t kScratchAreaSlotSize = 8;
62 
63 }  // namespace berberis::config
64 
65 #endif  // BERBERIS_BASE_CONFIG_H_
66