Skip to content

Commit 93d228f

Browse files
committed
Run ruff check . --fix --unsafe-fixes
1 parent 03906c5 commit 93d228f

File tree

8 files changed

+113
-117
lines changed

8 files changed

+113
-117
lines changed

riscv-ctg/riscv_ctg/constants.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ def gen_sp_dataset(bit_width,sign=True):
8080
:return: a list of integers
8181
'''
8282
if sign:
83-
conv_func = lambda x: twos(x,bit_width)
83+
def conv_func(x):
84+
return twos(x, bit_width)
8485
sqrt_min = int(-sqrt(2**(bit_width-1)))
8586
sqrt_max = int(sqrt((2**(bit_width-1)-1)))
8687
else:
8788
sqrt_min = 0
8889
sqrt_max = int(sqrt((2**bit_width)-1))
89-
conv_func = lambda x:(int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x
90+
def conv_func(x):
91+
return (int(x, 16) if "0x" in x else int(x, 2)) if isinstance(x, str) else x
9092

9193
dataset = [3, "0x"+"".join(["5"]*int(bit_width/4)), "0x"+"".join(["a"]*int(bit_width/4)), 5, "0x"+"".join(["3"]*int(bit_width/4)), "0x"+"".join(["6"]*int(bit_width/4))]
9294
dataset = list(map(conv_func,dataset)) + [int(sqrt(abs(conv_func("0x8"+"".join(["0"]*int((bit_width/4)-1)))))*(-1 if sign else 1))] + [sqrt_min,sqrt_max]
@@ -173,9 +175,11 @@ def gen_bitmanip_dataset(bit_width,sign=True):
173175
:return: a list of integers
174176
'''
175177
if sign:
176-
conv_func = lambda x: twos(x,bit_width)
178+
def conv_func(x):
179+
return twos(x, bit_width)
177180
else:
178-
conv_func = lambda x:(int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x
181+
def conv_func(x):
182+
return (int(x, 16) if "0x" in x else int(x, 2)) if isinstance(x, str) else x
179183

180184
# dataset for 0x5, 0xa, 0x3, 0xc, 0x6, 0x9 patterns
181185

riscv-ctg/riscv_ctg/generator.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def is_fp_instruction(insn):
4646

4747
from riscv_ctg.dsp_function import *
4848

49-
twos_xlen = lambda x: twos(x,xlen)
49+
def twos_xlen(x):
50+
return twos(x, xlen)
5051

5152
def toint(x: str):
5253
if '0x' in x:
@@ -89,7 +90,6 @@ def get_rm(opcode):
8990
'cjformat': [],
9091
'ckformat': ['rs1'],
9192
'kformat': ['rs1','rd'],
92-
'ckformat': ['rs1'],
9393
# 'frformat': ['rs1', 'rs2', 'rd'],
9494
'fsrformat': ['rs1', 'rd'],
9595
# 'fr4format': ['rs1', 'rs2', 'rs3', 'rd'],
@@ -144,7 +144,6 @@ def get_rm(opcode):
144144
'cjformat': "['imm_val']",
145145
'ckformat': "['rs1_val']",
146146
'kformat': "['rs1_val']",
147-
'ckformat': "['rs1_val']",
148147
# 'frformat': "['rs1_val', 'rs2_val', 'rm_val', 'fcsr']",
149148
'fsrformat': "['rs1_val','fcsr'] + get_rm(opcode) + \
150149
([] if not is_nan_box else ['rs1_nan_prefix']) + \
@@ -187,7 +186,8 @@ def isInt(s):
187186

188187
def get_default_registers(ops, datasets):
189188
problem = Problem()
190-
not_x0 = lambda x: x not in ['x0']
189+
def not_x0(x):
190+
return x not in ["x0"]
191191

192192
for op in ops:
193193
dataset = datasets[op]
@@ -348,7 +348,8 @@ def opcomb(self, cgf):
348348
op_conds[op] = set([])
349349
individual = False
350350
nodiff = False
351-
construct_constraint = lambda val: (lambda x: bool(x in val))
351+
def construct_constraint(val):
352+
return lambda x: bool(x in val)
352353
while any([len(op_conds[x])!=0 for x in op_conds]+[len(op_comb)!=0]):
353354
cond_str = ''
354355
cond_vars = []
@@ -536,7 +537,8 @@ def __jfmt_instr__(self,op=None,val=None):
536537
if val:
537538
cond_str += val[-1]
538539
instr = {'inst':self.opcode,'index':'0', 'comment':cond_str}
539-
labelize = lambda x: (str((-x)%2**21),'1b') if x < 0 else (str((x%2**21)),'3f')
540+
def labelize(x):
541+
return (str(-x % 2 ** 21), "1b") if x < 0 else (str(x % 2 ** 21), "3f")
540542
if op:
541543
for var,reg in zip(self.op_vars,op):
542544
instr[var] = str(reg)
@@ -572,7 +574,8 @@ def __bfmt_instr__(self,op=None,val=None):
572574
instr = {'inst':self.opcode,'index':'0', 'comment':cond_str}
573575

574576

575-
labelize = lambda x: (str((-x)%2048),'1b') if x < 0 else (str((x%2048)),'3f')
577+
def labelize(x):
578+
return (str(-x % 2048), "1b") if x < 0 else (str(x % 2048), "3f")
576579

577580
if op:
578581
for var,reg in zip(self.op_vars,op):
@@ -603,7 +606,8 @@ def __cb_instr__(self,op=None,val=None):
603606
instr = {'inst':self.opcode,'index':'0', 'comment':cond_str}
604607

605608

606-
labelize = lambda x: (str((-x)%257),'1b') if x < 0 else (str((x%257)),'3f')
609+
def labelize(x):
610+
return (str(-x % 257), "1b") if x < 0 else (str(x % 257), "3f")
607611

608612
if op:
609613
for var,reg in zip(self.op_vars,op):
@@ -634,7 +638,8 @@ def __cj_instr__(self,op=None,val=None):
634638
instr = {'inst':self.opcode,'index':'0', 'comment':cond_str}
635639

636640

637-
labelize = lambda x: (str((-x)%2048),'1b') if x < 0 else (str((x%2048)),'3f')
641+
def labelize(x):
642+
return (str(-x % 2048), "1b") if x < 0 else (str(x % 2048), "3f")
638643

639644
if op:
640645
for var,reg in zip(self.op_vars,op):
@@ -1264,7 +1269,8 @@ def correct_val(self,instr_dict):
12641269
for i in range(len(instr_dict)):
12651270
instr_dict[i]['correctval_hi'] = '0'
12661271
if self.fmt in ['caformat','crformat']:
1267-
normalise = lambda x,y: 0 if y['rs1']=='x0' else x
1272+
def normalise(x, y):
1273+
return 0 if y["rs1"] == "x0" else x
12681274
else:
12691275
normalise = (lambda x,y: x) if 'rd' not in self.op_vars else (lambda x,y: 0 if y['rd']=='x0' else x)
12701276
if self.operation:

riscv-ctg/riscv_ctg/misc/bitmanip_real_world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267

268268
config_ZKs = ['sm3p0','sm3p1','sm4ed','sm4ks']
269269

270-
if os.path.isdir(os.getcwd()+"/real_world_tests") == False:
270+
if os.path.isdir(os.getcwd()+"/real_world_tests") is False:
271271
os.mkdir(os.getcwd()+"/real_world_tests")
272272
os.mkdir(os.getcwd()+"/real_world_tests/RV32IK")
273273
os.mkdir(os.getcwd()+"/real_world_tests/RV64IK")

riscv-ctg/riscv_ctg/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def gen_format_data():
3535
op_template = load_yaml(const.template_file)
3636

3737
# Initialize nested dictionary
38-
nested_dict = lambda: defaultdict(nested_dict)
38+
def nested_dict():
39+
return defaultdict(nested_dict)
3940
format_dict = nested_dict()
4041

4142
for mnemonic, data in op_template.items():

riscv-isac/riscv_isac/cgf_normalize.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ def simd_imm_val(imm, bit_width):
116116

117117
def sp_vals(bit_width,signed):
118118
if signed:
119-
conv_func = lambda x: twos(x,bit_width)
119+
def conv_func(x):
120+
return twos(x, bit_width)
120121
sqrt_min = int(-sqrt(2**(bit_width-1)))
121122
sqrt_max = int(sqrt((2**(bit_width-1)-1)))
122123
else:
123124
sqrt_min = 0
124125
sqrt_max = int(sqrt((2**bit_width)-1))
125-
conv_func = lambda x: (int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x
126+
def conv_func(x):
127+
return (int(x, 16) if '0x' in x else int(x, 2)) if isinstance(x, str) else x
126128
dataset = [3, "0x"+"".join(["5"]*int(bit_width/4)), "0x"+"".join(["a"]*int(bit_width/4)), 5, "0x"+"".join(["3"]*int(bit_width/4)), "0x"+"".join(["6"]*int(bit_width/4))]
127129
dataset = list(map(conv_func,dataset)) + [int(sqrt(abs(conv_func("0x8"+"".join(["0"]*int((bit_width/4)-1)))))*(-1 if signed else 1))] + [sqrt_min,sqrt_max]
128130
return dataset + [x - 1 if x>0 else 0 for x in dataset] + [x+1 for x in dataset]
@@ -149,9 +151,11 @@ def bitmanip_dataset(bit_width,var_lst=["rs1_val","rs2_val"],signed=True):
149151
datasets = []
150152
coverpoints = []
151153
if signed:
152-
conv_func = lambda x: twos(x,bit_width)
154+
def conv_func(x):
155+
return twos(x, bit_width)
153156
else:
154-
conv_func = lambda x: (int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x
157+
def conv_func(x):
158+
return (int(x, 16) if '0x' in x else int(x, 2)) if isinstance(x, str) else x
155159
# dataset for 0x5, 0xa, 0x3, 0xc, 0x6, 0x9 patterns
156160
dataset = ["0x"+"".join(["5"]*int(bit_width/4)), "0x"+"".join(["a"]*int(bit_width/4)), "0x"+"".join(["3"]*int(bit_width/4)), "0x"+"".join(["c"]*int(bit_width/4)),"0x"+"".join(["6"]*int(bit_width/4)),"0x"+"".join(["9"]*int(bit_width/4))]
157161
dataset = list(map(conv_func,dataset))
@@ -587,7 +591,7 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False):
587591
# Substitute with tuple of instructions
588592
for i in range(len(ops)):
589593
exp_alias = utils.import_instr_alias(ops[i])
590-
if exp_alias != None:
594+
if exp_alias is not None:
591595
ops[i] = tuple(exp_alias).__str__().replace("'", '').replace(" ", '')
592596

593597
data[0] = '[' + ':'.join(ops) + ']'

riscv-isac/riscv_isac/coverage.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@
136136
1005: 'pmpaddr61',
137137
1006: 'pmpaddr62',
138138
1007: 'pmpaddr63',
139-
928: 'pmpcfg0',
140-
929: 'pmpcfg1',
141-
930: 'pmpcfg2',
142-
931: 'pmpcfg3',
143139
932: 'pmpcfg4',
144140
933: 'pmpcfg5',
145141
934: 'pmpcfg6',
@@ -915,7 +911,7 @@ def compute_per_line(queue, event, cgf_queue, stats_queue, cgf, xlen, flen, addr
915911

916912
# Enter the loop only when Event is not set or when the
917913
# instruction object queue is not empty
918-
while (event.is_set() == False) or (queue.empty() == False):
914+
while (event.is_set() is False) or (queue.empty() is False):
919915

920916
# If there are instructions in queue, compute coverage
921917
if queue.empty() is False:

riscv-isac/riscv_isac/data/rvopcodesdecoder.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def setup(self, inxFlag,arch: str):
4242
self.inxFlag = inxFlag
4343

4444
# Create nested dictionary
45-
nested_dict = lambda: defaultdict(nested_dict)
45+
def nested_dict():
46+
return defaultdict(nested_dict)
4647
disassembler.INST_DICT = nested_dict()
4748
disassembler.create_inst_dict('*')
4849

@@ -282,7 +283,7 @@ def build_instr_dict(inst_dict):
282283

283284
new_path = inst_dict[funct[0]][funct[1]]
284285
a = disassembler.build_instr_dict(new_path)
285-
if a == None:
286+
if a is None:
286287
continue
287288
else:
288289
return a
@@ -307,7 +308,7 @@ def get_instr(func_dict, mcode: int):
307308
temp_func_dict = func_dict[key][val]
308309
if temp_func_dict.keys():
309310
a = disassembler.get_instr(temp_func_dict, mcode)
310-
if a == None:
311+
if a is None:
311312
continue
312313
else:
313314
return a
@@ -355,11 +356,11 @@ def decode(self, instrObj_temp):
355356
reg_type = 'x'
356357
if file_name in ['rv_f', 'rv64_f', 'rv_d','rv64_d']:
357358
reg_type = 'f'
358-
if file_name in ['rv_f','rv64_f'] and temp_instrobj.inxFlg == True:
359+
if file_name in ['rv_f','rv64_f'] and temp_instrobj.inxFlg is True:
359360
reg_type = 'x'
360361
if file_name in ['rv_zfh','rv_d_zfh','rv64_zfh']:
361362
reg_type = 'f'
362-
if file_name in ['rv_zfh','rv_d_zfh','rv64_zfh'] and temp_instrobj.inxFlg == True:
363+
if file_name in ['rv_zfh','rv_d_zfh','rv64_zfh'] and temp_instrobj.inxFlg is True:
363364
reg_type = 'x'
364365
for arg in args[:-1]:
365366
if 'rd' in arg:
@@ -370,7 +371,7 @@ def decode(self, instrObj_temp):
370371
treg = 'x'
371372
temp_instrobj.rd = (int(get_arg_val(arg)(mcode), 2), treg)
372373

373-
if 'rd' in arg and self.inxFlag == True:
374+
if 'rd' in arg and self.inxFlag is True:
374375
treg = reg_type
375376
if any([instr_name.startswith(x) for x in [
376377
'fcvt.w','fcvt.l','fmv.s','fmv.d','flt','feq','fle','fclass','fmv.x','fsqrt','fmax','fmin','fadd','fsub','feq','flt','fle','fmul','fdiv','fsgnj','fsgnjn','fsgnjx','fcvt.lu','fcvt.wu']]):
@@ -384,7 +385,7 @@ def decode(self, instrObj_temp):
384385
treg = 'x'
385386
temp_instrobj.rs1 = (int(get_arg_val(arg)(mcode), 2), treg)
386387

387-
if 'rs1' in arg and self.inxFlag == True:
388+
if 'rs1' in arg and self.inxFlag is True:
388389
treg = reg_type
389390
if any([instr_name.startswith(x) for x in [
390391
'fsh', 'fsw','fsd','fcvt.s','fcvt.d','fmv.w','fmv.l','fcvt.h','fmv.h','flh','fclass','fsqrt','fmax','fmin','fadd','fsub','feq','fle','flt','fmul','fdiv','fsgnj','fsgnjn','fsgnjx','fcvt.lu','fcvt.w','fcvt.wu']]):
@@ -394,7 +395,7 @@ def decode(self, instrObj_temp):
394395
if 'rs2' in arg:
395396
treg = reg_type
396397
temp_instrobj.rs2 = (int(get_arg_val(arg)(mcode), 2), treg)
397-
if 'rs2' in arg and self.inxFlag == True:
398+
if 'rs2' in arg and self.inxFlag is True:
398399
treg = reg_type
399400
if any([instr_name.startswith(x) for x in [
400401
'fsh', 'fsw','fsd','fcvt.s','fcvt.d','fmv.w','fmv.l','fcvt.h','fmv.h','flh','fclass','fsqrt','fmax','fmin','fadd','fsub','feq','fle','flt','fmul','fdiv','fsgnj','fsgnjn','fsgnjx']]):

0 commit comments

Comments
 (0)