Skip to content

Commit acb06dc

Browse files
committed
Apply editorial changes
1 parent 7ebe625 commit acb06dc

File tree

10 files changed

+72
-78
lines changed

10 files changed

+72
-78
lines changed

src/emulate.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static bool has_loops = false;
410410
#include "rv32_template.c"
411411
#undef RVOP
412412

413-
/* multiple lui */
413+
/* multiple LUI */
414414
static bool do_fuse1(riscv_t *rv, rv_insn_t *ir, uint64_t cycle, uint32_t PC)
415415
{
416416
cycle += ir->imm2;
@@ -1050,12 +1050,13 @@ static block_t *block_find_or_translate(riscv_t *rv)
10501050
#if RV32_HAS(JIT)
10511051
static bool runtime_profiler(riscv_t *rv, block_t *block)
10521052
{
1053-
/* Based on our observation, a high percentage of true hotspots involve high
1054-
* using frequency, loops or backward jumps. Therefore, we believe our
1055-
* profiler can use three indices to detect hotspots */
1056-
uint32_t freq = cache_freq(rv->block_cache, block->pc_start);
1057-
/* to profile the block after chaining, the block should be executed first
1053+
/* Based on our observations, a significant number of true hotspots are
1054+
* characterized by high usage frequency, including loops or backward
1055+
* jumps. Consequently, we posit that our profiler could effectively
1056+
* identify hotspots using three key indicators.
10581057
*/
1058+
uint32_t freq = cache_freq(rv->block_cache, block->pc_start);
1059+
/* To profile a block after chaining, it must first be executed. */
10591060
if (unlikely(freq >= 2 && (block->backward || block->has_loops)))
10601061
return true;
10611062
/* using frequency exceeds predetermined threshold */

src/jit.c

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -132,45 +132,45 @@ typedef enum {
132132
AS_SUB = 2,
133133
AS_SUBS = 3,
134134
/* LogicalOpcode */
135-
LOG_AND = 0x00000000U, // 0000_0000_0000_0000_0000_0000_0000_0000
136-
LOG_ORR = 0x20000000U, // 0010_0000_0000_0000_0000_0000_0000_0000
137-
LOG_ORN = 0x20200000U, // 0010_0000_0010_0000_0000_0000_0000_0000
138-
LOG_EOR = 0x40000000U, // 0100_0000_0000_0000_0000_0000_0000_0000
135+
LOG_AND = 0x00000000U, /* 0000_0000_0000_0000_0000_0000_0000_0000 */
136+
LOG_ORR = 0x20000000U, /* 0010_0000_0000_0000_0000_0000_0000_0000 */
137+
LOG_ORN = 0x20200000U, /* 0010_0000_0010_0000_0000_0000_0000_0000 */
138+
LOG_EOR = 0x40000000U, /* 0100_0000_0000_0000_0000_0000_0000_0000 */
139139
/* LoadStoreOpcode */
140-
LS_STRB = 0x00000000U, // 0000_0000_0000_0000_0000_0000_0000_0000
141-
LS_LDRB = 0x00400000U, // 0000_0000_0100_0000_0000_0000_0000_0000
142-
LS_LDRSBW = 0x00c00000U, // 0000_0000_1100_0000_0000_0000_0000_0000
143-
LS_STRH = 0x40000000U, // 0100_0000_0000_0000_0000_0000_0000_0000
144-
LS_LDRH = 0x40400000U, // 0100_0000_0100_0000_0000_0000_0000_0000
145-
LS_LDRSHW = 0x40c00000U, // 0100_0000_1100_0000_0000_0000_0000_0000
146-
LS_STRW = 0x80000000U, // 1000_0000_0000_0000_0000_0000_0000_0000
147-
LS_LDRW = 0x80400000U, // 1000_0000_0100_0000_0000_0000_0000_0000
148-
LS_LDRSW = 0x80800000U, // 1000_0000_1000_0000_0000_0000_0000_0000
149-
LS_STRX = 0xc0000000U, // 1100_0000_0000_0000_0000_0000_0000_0000
150-
LS_LDRX = 0xc0400000U, // 1100_0000_0100_0000_0000_0000_0000_0000
140+
LS_STRB = 0x00000000U, /* 0000_0000_0000_0000_0000_0000_0000_0000 */
141+
LS_LDRB = 0x00400000U, /* 0000_0000_0100_0000_0000_0000_0000_0000 */
142+
LS_LDRSBW = 0x00c00000U, /* 0000_0000_1100_0000_0000_0000_0000_0000 */
143+
LS_STRH = 0x40000000U, /* 0100_0000_0000_0000_0000_0000_0000_0000 */
144+
LS_LDRH = 0x40400000U, /* 0100_0000_0100_0000_0000_0000_0000_0000 */
145+
LS_LDRSHW = 0x40c00000U, /* 0100_0000_1100_0000_0000_0000_0000_0000 */
146+
LS_STRW = 0x80000000U, /* 1000_0000_0000_0000_0000_0000_0000_0000 */
147+
LS_LDRW = 0x80400000U, /* 1000_0000_0100_0000_0000_0000_0000_0000 */
148+
LS_LDRSW = 0x80800000U, /* 1000_0000_1000_0000_0000_0000_0000_0000 */
149+
LS_STRX = 0xc0000000U, /* 1100_0000_0000_0000_0000_0000_0000_0000 */
150+
LS_LDRX = 0xc0400000U, /* 1100_0000_0100_0000_0000_0000_0000_0000 */
151151
/* LoadStorePairOpcode */
152-
LSP_STPX = 0xa9000000U, // 1010_1001_0000_0000_0000_0000_0000_0000
153-
LSP_LDPX = 0xa9400000U, // 1010_1001_0100_0000_0000_0000_0000_0000
152+
LSP_STPX = 0xa9000000U, /* 1010_1001_0000_0000_0000_0000_0000_0000 */
153+
LSP_LDPX = 0xa9400000U, /* 1010_1001_0100_0000_0000_0000_0000_0000 */
154154
/* UnconditionalBranchOpcode */
155-
BR_BR = 0xd61f0000U, // 1101_0110_0001_1111_0000_0000_0000_0000
156-
BR_BLR = 0xd63f0000U, // 1101_0110_0011_1111_0000_0000_0000_0000
157-
BR_RET = 0xd65f0000U, // 1101_0110_0101_1111_0000_0000_0000_0000
155+
BR_BR = 0xd61f0000U, /* 1101_0110_0001_1111_0000_0000_0000_0000 */
156+
BR_BLR = 0xd63f0000U, /* 1101_0110_0011_1111_0000_0000_0000_0000 */
157+
BR_RET = 0xd65f0000U, /* 1101_0110_0101_1111_0000_0000_0000_0000 */
158158
/* UnconditionalBranchImmediateOpcode */
159-
UBR_B = 0x14000000U, // 0001_0100_0000_0000_0000_0000_0000_0000
159+
UBR_B = 0x14000000U, /* 0001_0100_0000_0000_0000_0000_0000_0000 */
160160
/* ConditionalBranchImmediateOpcode */
161161
BR_Bcond = 0x54000000U,
162162
/* DP2Opcode */
163-
DP2_UDIV = 0x1ac00800U, // 0001_1010_1100_0000_0000_1000_0000_0000
164-
DP2_LSLV = 0x1ac02000U, // 0001_1010_1100_0000_0010_0000_0000_0000
165-
DP2_LSRV = 0x1ac02400U, // 0001_1010_1100_0000_0010_0100_0000_0000
166-
DP2_ASRV = 0x1ac02800U, // 0001_1010_1100_0000_0010_1000_0000_0000
163+
DP2_UDIV = 0x1ac00800U, /* 0001_1010_1100_0000_0000_1000_0000_0000 */
164+
DP2_LSLV = 0x1ac02000U, /* 0001_1010_1100_0000_0010_0000_0000_0000 */
165+
DP2_LSRV = 0x1ac02400U, /* 0001_1010_1100_0000_0010_0100_0000_0000 */
166+
DP2_ASRV = 0x1ac02800U, /* 0001_1010_1100_0000_0010_1000_0000_0000 */
167167
/* DP3Opcode */
168-
DP3_MADD = 0x1b000000U, // 0001_1011_0000_0000_0000_0000_0000_0000
169-
DP3_MSUB = 0x1b008000U, // 0001_1011_0000_0000_1000_0000_0000_0000
168+
DP3_MADD = 0x1b000000U, /* 0001_1011_0000_0000_0000_0000_0000_0000 */
169+
DP3_MSUB = 0x1b008000U, /* 0001_1011_0000_0000_1000_0000_0000_0000 */
170170
/* MoveWideOpcode */
171-
MW_MOVN = 0x12800000U, // 0001_0010_1000_0000_0000_0000_0000_0000
172-
MW_MOVZ = 0x52800000U, // 0101_0010_1000_0000_0000_0000_0000_0000
173-
MW_MOVK = 0x72800000U, // 0111_0010_1000_0000_0000_0000_0000_0000
171+
MW_MOVN = 0x12800000U, /* 0001_0010_1000_0000_0000_0000_0000_0000 */
172+
MW_MOVZ = 0x52800000U, /* 0101_0010_1000_0000_0000_0000_0000_0000 */
173+
MW_MOVK = 0x72800000U, /* 0111_0010_1000_0000_0000_0000_0000_0000 */
174174
} a64opcode_t;
175175

176176
enum condition {
@@ -219,21 +219,21 @@ static int temp_reg = RCX;
219219
#endif
220220
#elif defined(__aarch64__)
221221
/* callee_reg - this must be a multiple of two because of how we save the stack
222-
* later on. */
222+
* later on.
223+
*/
223224
static const int callee_reg[] = {R19, R20, R21, R22, R23, R24, R25, R26};
224225
/* parameter_reg (Caller saved registers) */
225226
static const int parameter_reg[] = {R0, R1, R2, R3, R4};
226227
static int temp_reg = R8;
227228

228-
/* Register assignments:
229-
* Arm64 Usage
230-
* r0 - r4 Function parameters, caller-saved
231-
* r6 - r8 Temp - used for storing calculated value during execution
232-
* r19 - r23 Callee-saved registers
233-
* r24 Temp - used for generating 32-bit immediates
234-
* r25 Temp - used for modulous calculations
229+
/* Register assignments:
230+
* Arm64 Usage
231+
* r0 - r4 Function parameters, caller-saved
232+
* r6 - r8 Temp - used for storing calculated value during execution
233+
* r19 - r23 Callee-saved registers
234+
* r24 Temp - used for generating 32-bit immediates
235+
* r25 Temp - used for modulous calculations
235236
*/
236-
237237
static const int register_map[] = {
238238
R5, R6, R7, R9, R11, R12, R13, R14, R15, R16, R17, R18, R26,
239239
};
@@ -435,7 +435,8 @@ static inline void emit_movewide_imm(struct jit_state *state,
435435
}
436436

437437
/* Iterate over 16-bit elements of imm, outputting an appropriate move
438-
* instruction. */
438+
* instruction.
439+
*/
439440
bool invert = (count0000 < countffff);
440441
a64opcode_t op = invert ? MW_MOVN : MW_MOVZ;
441442
uint64_t skip_pattern = invert ? 0xffff : 0;
@@ -453,9 +454,8 @@ static inline void emit_movewide_imm(struct jit_state *state,
453454
}
454455

455456
/* Tidy up for the case imm = 0 or imm == -1. */
456-
if (op != MW_MOVK) {
457+
if (op != MW_MOVK)
457458
emit_a64(state, sz(is64) | op | (0 << 21) | (0 << 5) | rd);
458-
}
459459
}
460460

461461
/* [ARM-A]: C4.1.66: Load/store register (unscaled immediate). */
@@ -527,7 +527,7 @@ static void update_branch_imm(struct jit_state *state,
527527
memcpy(&insn, state->buf + offset, sizeof(uint32_t));
528528
if ((insn & 0xfe000000U) == 0x54000000U /* Conditional branch immediate. */
529529
|| (insn & 0x7e000000U) ==
530-
0x34000000U) { /* Compare and branch immediate. */
530+
0x34000000U) { /* Compare and branch immediate. */
531531
assert((imm >> 19) == INT64_C(-1) || (imm >> 19) == 0);
532532
insn |= (imm & 0x7ffff) << 5;
533533
} else if ((insn & 0x7c000000U) == 0x14000000U) {
@@ -1206,9 +1206,8 @@ static int vm_reg[3] = {0};
12061206
static void reset_reg()
12071207
{
12081208
count = 0;
1209-
for (int i = 0; i < 32; i++) {
1209+
for (int i = 0; i < 32; i++)
12101210
reg_table[i] = -1;
1211-
}
12121211
}
12131212

12141213
static void store_back(struct jit_state *state)

src/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static map_node_t *map_create_node(void *key,
558558

559559
/* copy over the key and values.
560560
* If the parameter passed in is NULL, make the element blank instead of
561-
* a segfault.
561+
* a segmentation fault.
562562
*/
563563
if (!key)
564564
memset(node->key, 0, ksize);

src/map.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* "LICENSE" for information on usage and redistribution of this file.
44
*/
55

6-
/*
7-
* C Implementation for C++ std::map using red-black tree.
6+
/* C Implementation for C++ std::map using red-black tree.
87
*
98
* Any data type can be stored in a map, just like std::map.
109
* A map instance requires the specification of two file types:

src/riscv.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,16 @@ typedef struct {
237237
/* vm memory object */
238238
memory_t *mem;
239239

240-
/*
241-
* max memory size is 2^32 - 1 bytes
242-
*
243-
* it is for portable on both 32-bit and 64-bit platforms. In this way,
240+
/* max memory size is 2^32 - 1 bytes.
241+
* It is for portable on both 32-bit and 64-bit platforms. In this way,
244242
* emulator can access any segment of the memory on either platform.
245243
*/
246244
uint32_t mem_size;
247245

248246
/* vm main stack size */
249247
uint32_t stack_size;
250248

251-
/*
252-
* To deal with the RV32 ABI for accessing args list,
249+
/* To deal with the RV32 ABI for accessing args list,
253250
* offset of args data have to be saved.
254251
*
255252
* args_offset_size is the memory size to store the offset
@@ -259,7 +256,7 @@ typedef struct {
259256
/* arguments of emulation program */
260257
int argc;
261258
char **argv;
262-
/* FIXME: rv32emu cannot access envp yet */
259+
/* FIXME: cannot access envp yet */
263260

264261
/* emulation program exit code */
265262
int exit_code;
@@ -279,23 +276,18 @@ typedef struct {
279276
/* allow misaligned memory access */
280277
bool allow_misalign;
281278

282-
/*
283-
* run flag, it is the bitwise OR from
279+
/* run flag, it is the bitwise OR from
284280
* RV_RUN_TRACE, RV_RUN_GDBSTUB, and RV_RUN_PROFILE
285281
*/
286282
uint8_t run_flag;
287283

288284
/* profiling output file if RV_RUN_PROFILE is set in run_flag */
289285
char *profile_output_file;
290286

291-
/*
292-
* set by rv_create during initialization
293-
*
287+
/* set by rv_create during initialization.
294288
* use rv_remap_stdstream to overwrite them
295289
*/
296-
int fd_stdin;
297-
int fd_stdout;
298-
int fd_stderr;
290+
int fd_stdin, fd_stdout, fd_stderr;
299291

300292
/* vm file descriptor map: int -> (FILE *) */
301293
map_t fd_map;

src/riscv_private.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ struct riscv_internal {
142142
/* GDB instruction breakpoint */
143143
breakpoint_map_t breakpoint_map;
144144

145-
/* The flag to notify interrupt from GDB client: it should
146-
* be accessed by atomic operation when starting the GDBSTUB. */
145+
/* The flag to notify interrupt from GDB client: it should be accessed by
146+
* atomic operation when starting the GDBSTUB.
147+
*/
147148
bool is_interrupted;
148149
#endif
149150
};

src/rv32_template.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ RVOP(
246246
MUST_TAIL return block->ir_head->impl(rv, block->ir_head, cycle, PC); \
247247
}
248248
#endif
249+
249250
/* The indirect jump instruction JALR uses the I-type encoding. The target
250251
* address is obtained by adding the sign-extended 12-bit I-immediate to the
251252
* register rs1, then setting the least-significant bit of the result to zero.

src/syscall.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,7 @@ void syscall_handler(riscv_t *rv)
383383
break;
384384
}
385385

386-
/*
387-
* save return code
388-
*
386+
/* save return code.
389387
* the application decides the usage of the return code
390388
*/
391389
vm_attr_t *attr = PRIV(rv);

src/utils.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ char *sanitize_path(const char *input)
8181
return NULL;
8282

8383
/* After sanitization, the new path will only be shorter than the original
84-
* one. Thus, we can reuse the space */
84+
* one. Thus, we can reuse the space.
85+
*/
8586
if (n == 0) {
8687
ret[0] = '.';
8788
return ret;
@@ -93,8 +94,8 @@ char *sanitize_path(const char *input)
9394
* reading from path; r is index of next byte to process -> path[r]
9495
* writing to buf; w is index of next byte to write -> ret[strlen(ret)]
9596
* dotdot is index in buf where .. must stop, either because:
96-
* a) it is the leading slash;
97-
* b) it is a leading ../../.. prefix.
97+
* (a) it is the leading slash;
98+
* (b) it is a leading ../../.. prefix.
9899
*/
99100
size_t w = 0, r = 0;
100101
size_t dotdot = 0;

src/utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static inline uintptr_t align_up(uintptr_t sz, size_t alignment)
5757
return (((sz + mask) / alignment) * alignment);
5858
}
5959

60+
/* Linux-like List API */
61+
6062
struct list_head {
6163
struct list_head *prev, *next;
6264
};
@@ -68,7 +70,7 @@ static inline void INIT_LIST_HEAD(struct list_head *head)
6870

6971
static inline bool list_empty(const struct list_head *head)
7072
{
71-
return (head->next == head);
73+
return head->next == head;
7274
}
7375

7476
static inline void list_add(struct list_head *node, struct list_head *head)

0 commit comments

Comments
 (0)