How to use func3 method in refurb

Best Python code snippet using refurb_python

model_mkbitmanip.py

Source:model_mkbitmanip.py Github

copy

Full Screen

1# See LICENSE.iitm for details2from cocotb.binary import BinaryValue3import os4import sys5import operator6from cocotb.result import ReturnValue7def bitmanip(mav_putvalue_instr, mav_putvalue_src1,mav_putvalue_src2, mav_putvalue_c):8 instr=hex(mav_putvalue_instr)[2:]9 le=int(instr,16) #convert Hex to int10 le=bin(le)[2:] #convert int to binary11 le=le.zfill(32)12 length=len(le)13 opcode = le[-7::]14 func3 = le[length-15:length-12]15 func7 = le[length-32:length-25]16 func7_imm = le[length-32:length-27]17 func7_2bit = le[length-27:length-25]18 func7_1bit = le[length-28:length-27]19 func7_fsri_1bit = le[length-27:length-26]20 func7_imm_SHFL = le[length-32:length-26]21 imm_value = le[length-25:length-20]22 imm_value_1 = le[length-25:length-20]23 fsr_imm_value = le[length-26:length-20]24 fsr_imm_value=(int(str(fsr_imm_value),2))25 imm_value=(int(str(imm_value),2))26 shamt_imm= imm_value & (31)27 shamt1= mav_putvalue_src2 & (31)28 #print("func7 {0} immvalue1 {1} : func3 {2} opcode {3} ".format(func7,imm_value_1,func3,opcode))29 #print("func7_imm {0} func7_imm_SHFL {1} func7_1bit {2} ".format(func7_imm, func7_imm_SHFL, func7_1bit))30 if((func7 == "0000000") and (func3 == "111") and (opcode == "0110011") ):31 print('--AND 1')32 mav_putvalue=(mav_putvalue_src1 & mav_putvalue_src2)33 mav_putvalue=mav_putvalue & 0xffffffff34 # mav_putvalue=(mav_putvalue>>1)35 # mav_putvalue=mav_putvalue+0x10000000036 return mav_putvalue37 if((func7 == "0000000") and (func3 == "110") and (opcode == "0110011") ):38 print('--OR 1')39 mav_putvalue=(mav_putvalue_src1 | mav_putvalue_src2)40 mav_putvalue=mav_putvalue & 0xffffffff41 # mav_putvalue=(mav_putvalue<<1)|142 return mav_putvalue43 if((func7 == "0000000") and (func3 == "100") and (opcode == "0110011") ):44 print('--XOR 1')45 mav_putvalue=(mav_putvalue_src1 ^ mav_putvalue_src2)46 # mav_putvalue=mav_putvalue & 0xffffffff47 # mav_putvalue=(mav_putvalue<<1)|148 return mav_putvalue49 if((func7 == "0100000") and (func3 == "111") and (opcode == "0110011") ):50 print('--ANDN 1')51 mav_putvalue=~(mav_putvalue_src1 & mav_putvalue_src2)52 mav_putvalue=mav_putvalue & 0xffffffff53 mav_putvalue=(mav_putvalue<<1)|0b154 return mav_putvalue55 if((func7 == "0100000") and (func3 == "110") and (opcode == "0110011")):56 print('--ORN 2')57 mav_putvalue=mav_putvalue_src1 | (~mav_putvalue_src2)58 mav_putvalue=mav_putvalue & 0xffffffff59 mav_putvalue=(mav_putvalue<<1)|160 return mav_putvalue61 if((func7 == "0100000") and (func3 == "100") and (opcode == "0110011")):62 print('--XNOR 3')63 mav_putvalue=mav_putvalue_src1 ^ (~mav_putvalue_src2)64 mav_putvalue=mav_putvalue & 0xffffffff65 mav_putvalue=(mav_putvalue<<1)|166 return mav_putvalue67 if((func7 == "0010000") and (func3 == "001") and (opcode == "0110011")):68 print('--SLO 4')69 shamt1 =mav_putvalue_src2 & (31)70 out=((mav_putvalue_src1)<< shamt1)71 res=out72 min_i=073 max_i=shamt174 if(shamt1==0):75 mav_putvalue = out76 else:77 while (min_i<max_i):78 res=((1 << min_i) | res)79 min_i=min_i+180 mav_putvalue=res & 0xffffffff81 mav_putvalue=(mav_putvalue<<1)|182 return mav_putvalue83 if((func7 == "0010000") and (func3 == "101") and (opcode == "0110011")):84 print('--SRO 5')85 out=((mav_putvalue_src1)>> shamt1)86 res=out87 min_i=32-shamt188 max_i=3289 while (min_i<max_i):90 res=((1 << min_i) | res)91 min_i=min_i+192 mav_putvalue=res & 0xffffffff93 mav_putvalue=(mav_putvalue<<1)|194 return mav_putvalue95 if((func7 == "0110000") and (func3 == "001") and (opcode == "0110011")):96 print('--ROL 6')97 out=(mav_putvalue_src1 << shamt1) | (mav_putvalue_src1 >> ((32-shamt1) & (31)))98 mav_putvalue=out & 0xffffffff99 mav_putvalue=(mav_putvalue<<1)|1100 return mav_putvalue101 if((func7 == "0110000") and (func3 == "101") and (opcode == "0110011")):102 print('--ROR 7')103 out=(mav_putvalue_src1 >> shamt1) | (mav_putvalue_src1 << ((32-shamt1) & (31)))104 mav_putvalue=out & 0xffffffff105 mav_putvalue=(mav_putvalue<<1)|1106 return mav_putvalue107 if((func7 == "0010000") and (func3 == "010") and (opcode == "0110011")):108 print('--SH1ADD 8')109 out=(mav_putvalue_src1 << 1) +mav_putvalue_src2110 mav_putvalue=out & 0xffffffff111 mav_putvalue=(mav_putvalue<<1)|1112 return mav_putvalue113 if((func7 == "0010000") and (func3 == "100") and (opcode == "0110011")):114 print('--SH2ADD 9')115 out=(mav_putvalue_src1 << 2) +mav_putvalue_src2116 mav_putvalue=out & 0xffffffff117 mav_putvalue=(mav_putvalue<<1)|1118 return mav_putvalue119 if((func7 == "0010000") and (func3 == "110") and (opcode == "0110011")):120 print('--SH3ADD 10')121 out=(mav_putvalue_src1 << 3) +mav_putvalue_src2122 mav_putvalue=out & 0xffffffff123 mav_putvalue=(mav_putvalue<<1)|1124 return mav_putvalue125 if((func7 == "0100100") and (func3 == "001") and (opcode == "0110011")):126 print('--SBCLR 11')127 out= mav_putvalue_src1 & (~(1<<shamt1))128 mav_putvalue=out & 0xffffffff129 mav_putvalue=(mav_putvalue<<1)|1130 return mav_putvalue131 if((func7 == "0010100") and (func3 == "001") and (opcode == "0110011")):132 print('--SBSET 12')133 out= mav_putvalue_src1 | (1<<shamt1)134 mav_putvalue=out & 0xffffffff135 mav_putvalue=(mav_putvalue<<1)|1136 return mav_putvalue137 if((func7 == "0110100") and (func3 == "001") and (opcode == "0110011")):138 print('--SBINV 13')139 out= mav_putvalue_src1 ^ (1<<shamt1)140 mav_putvalue=out & 0xffffffff141 mav_putvalue=(mav_putvalue<<1)|1142 return mav_putvandalue143 if((func7 == "0100100") and (func3 == "101") and (opcode == "0110011")):144 print('--SBEXT 14')145 out= 1 & (mav_putvalue_src1 >> shamt1)146 mav_putvalue=out & 0xffffffff147 mav_putvalue=(mav_putvalue<<1)|1148 return mav_putvalue149 if((func7 == "0010100") and (func3 == "101") and (opcode == "0110011")):150 print('--GORC 15 (check)')151 x=mav_putvalue_src1152 mav_putvalue=mav_putvalue_src1153 if (shamt1 & 1):154 x= x | ((x & 0x55555555)<< 1) | (( x & 0xaaaaaaaa) >>1)155 mav_putvalue=x & 0xffffffff156 if (shamt1 & 2):157 x= x | ((x & 0x33333333)<< 2) | ((x & 0xcccccccc) >>2)158 mav_putvalue=x & 0xffffffff159 if (shamt1 & 4):160 x= x | ((x & 0x0f0f0f0f)<< 4) | (( x & 0xf0f0f0f0) >>4)161 mav_putvalue=x & 0xffffffff162 if (shamt1 & 8):163 x= x | ((x & 0x00ff00ff)<< 8) | ((x & 0xff00ff00) >>8)164 mav_putvalue=x & 0xffffffff165 if (shamt1 & 16):166 x= x | ((x & 0x0000ffff)<< 16) | ((x & 0xffff0000) >>16)167 mav_putvalue=x & 0xffffffff168 mav_putvalue=(mav_putvalue<<1)|1169 return mav_putvalue170 if((func7 == "0110100") and (func3 == "101") and (opcode == "0110011")):171 print('--GREV 16 (should check)')172 x=mav_putvalue_src1173 mav_putvalue=mav_putvalue_src1174 if (shamt1 & 1):175 x= ((x & 0x55555555)<< 1) | (( x & 0xaaaaaaaa) >>1)176 mav_putvalue=x & 0xffffffff177 if (shamt1 & 2):178 x= ((x & 0x33333333)<< 2) | (( x & 0xcccccccc) >>2)179 mav_putvalue=x & 0xffffffff180 if (shamt1 & 4):181 x= ((x & 0x0f0f0f0f)<< 4) | (( x & 0xf0f0f0f0) >>4)182 mav_putvalue=x & 0xffffffff183 if (shamt1 & 8):184 x= ((x & 0x00ff00ff)<< 8) | (( x & 0xff00ff00) >>8)185 mav_putvalue=x & 0xffffffff186 if (shamt1 & 16):187 x= ((x & 0x0000ffff)<< 16) | (( x & 0xffff0000) >>16)188 mav_putvalue=x & 0xffffffff189 mav_putvalue=(mav_putvalue<<1)|1190 return mav_putvalue191 if((func7_2bit == "11") and (func3 == "001") and (opcode == "0110011")):192 print('--CMIX 17')193 out= (mav_putvalue_src1 & mav_putvalue_src2) |(mav_putvalue_src3 & (~mav_putvalue_src2))194 mav_putvalue=out & 0xffffffff195 mav_putvalue=(mav_putvalue<<1)|1196 return mav_putvalue197 if((func7_2bit == "11") and (func3 == "101") and (opcode == "0110011")):198 print('--CMOV 18')199 if (mav_putvalue_src2):200 mav_putvalue=mav_putvalue_src1201 else:202 mav_putvalue=mav_putvalue_src3203 mav_putvalue=(mav_putvalue<<1)|1204 return mav_putvalue205 if((func7_2bit == "10") and (func3 == "001") and (opcode == "0110011")):206 print('--FSL 19')207 shamt12= mav_putvalue_src2 & (63)208 A= mav_putvalue_src1209 B= mav_putvalue_src3210 if(shamt12>=32):211 shamt12=shamt12-32212 A= mav_putvalue_src3213 B= mav_putvalue_src1214 if(shamt12):215 mav_putvalue= (A << shamt12) | (B >> (32-shamt12))216 else:217 mav_putvalue=A218 mav_putvalue=mav_putvalue & 0xffffffff219 mav_putvalue=(mav_putvalue<<1)|1220 return mav_putvalue221 if((func7_2bit == "10") and (func3 == "101") and (opcode == "0110011")):222 print('--FSR 20(check)')223 shamt12= mav_putvalue_src2 & (63)224 A= mav_putvalue_src1225 B= mav_putvalue_src3226 if(shamt12>=32):227 shamt12=shamt12-32228 A= mav_putvalue_src3229 B= mav_putvalue_src1230 if(shamt12):231 mav_putvalue= (A >> shamt12) | (B << (32-shamt12))232 else:233 mav_putvalue=A234 mav_putvalue=mav_putvalue & 0xffffffff235 mav_putvalue=(mav_putvalue<<1)|1236 return mav_putvalue237 if((func7 == "0110000") and (imm_value_1 == "00000") and (func3 == "001") and (opcode == "0010011")):238 print('--CLZ 21')239 x=bin(mav_putvalue_src1)[2:]240 x=x.zfill(32)241 mav_putvalue = len(x.split('1', 1)[0])242 mav_putvalue=(mav_putvalue<<1)|1243 return mav_putvalue244 if((func7 == "0110000") and (imm_value_1 == "00001") and (func3 == "001") and (opcode == "0010011")):245 print('--CTZ 22')246 x=bin(mav_putvalue_src1)[2:]247 x=x.zfill(32)248 m = str(x)249 mav_putvalue = len(m)-len(m.rstrip('0'))250 mav_putvalue=(mav_putvalue<<1)|1251 return mav_putvalue252 253 if((func7 == "0110000") and (imm_value_1 == "00010") and (func3 == "001") and (opcode == "0010011")):254 print('--PCNT 23')255 binary = bin(mav_putvalue_src1)256 setBits = [ones for ones in binary[2:] if ones=='1']257 mav_putvalue= len(setBits)258 mav_putvalue=(mav_putvalue<<1)|1259 return mav_putvalue260 if((func7 == "0110000") and (imm_value_1 == "00100") and (func3 == "001") and (opcode == "0010011")):261 print('--SEXT.B 24')262 le=mav_putvalue_src1263 lex=bin(le)[2:]264 lex=lex.zfill(32)265 imm_value = lex[24]266 min_i=8267 max_i=32268 while (min_i<max_i):269 if(imm_value=='1'):270 le=((1 << min_i) | le)271 min_i=min_i+1272 else:273 le=((1 << min_i) | le)274 min_i=min_i+1275 le=le & 0x000000ff276 mav_putvalue=le & 0xffffffff277 mav_putvalue=(mav_putvalue<<1)|1278 return mav_putvalue279 if((func7 == "0110000") and (imm_value_1 == "00101") and (func3 == "001") and (opcode == "0010011")):280 print('--SEXT.H 25')281 le=mav_putvalue_src1282 lex=bin(le)[2:]283 lex=lex.zfill(32)284 imm_value = lex[16]285 min_i=16286 max_i=32287 while (min_i<max_i):288 if(imm_value=='1'):289 le=((1 << min_i) | le)290 min_i=min_i+1291 else:292 le=((1 << min_i) | le)293 min_i=min_i+1294 le=le & 0x0000ffff295 mav_putvalue=le & 0xffffffff296 mav_putvalue=(mav_putvalue<<1)|1297 return mav_putvalue298 if((func7 == "0110000") and (imm_value_1 == "10000") and (func3 == "001") and (opcode == "0010011")):299 print('--CRC32.B 26')300 i=0301 x = mav_putvalue_src1302 while i<8:303 x = (x >> 1) ^ (0xedb88320 & ~((x &1)-1));304 i+=1305 mav_putvalue=x306 mav_putvalue=(mav_putvalue<<1)|1307 return mav_putvalue308 if((func7 == "0110000") and (imm_value_1 == "10001") and (func3 == "001") and (opcode == "0010011")):309 print('--CRC32.H 27')310 i=0311 x = mav_putvalue_src1312 while i<16:313 x = (x >> 1) ^ (0xedb88320 & ~((x &1)-1));314 i+=1315 mav_putvalue=x316 mav_putvalue=(mav_putvalue<<1)|1317 return mav_putvalue318 if((func7 == "0110000") and (imm_value_1 == "10010") and (func3 == "001") and (opcode == "0010011")):319 print('--CRC32.W 28')320 i=0321 x = mav_putvalue_src1322 while i<32:323 x = (x >> 1) ^ (0xedb88320 & ~((x &1)-1));324 i+=1325 mav_putvalue=x326 mav_putvalue=(mav_putvalue<<1)|1327 return mav_putvalue328 if((func7 == "0110000") and (imm_value_1 == "11000") and (func3 == "001") and (opcode == "0010011")):329 print('--CRC32C.B 29')330 i=0331 x = mav_putvalue_src1332 while i<8:333 x = (x >> 1) ^ (0x82F63B78 & ~((x &1)-1));334 i+=1335 mav_putvalue=x336 mav_putvalue=(mav_putvalue<<1)|1337 return mav_putvalue338 if((func7 == "0110000") and (imm_value_1 == "11001") and (func3 == "001") and (opcode == "0010011")):339 print('--CRC32C.H 30')340 i=0341 x = mav_putvalue_src1342 while i<16:343 x = (x >> 1) ^ (0x82F63B78 & ~((x &1)-1));344 i+=1345 mav_putvalue=x346 mav_putvalue=(mav_putvalue<<1)|1347 return mav_putvalue348 if((func7 == "0110000") and (imm_value_1 == "11010") and (func3 == "001") and (opcode == "0010011")):349 print('--CRC32C.W 31')350 i=0351 x = mav_putvalue_src1352 while i<32:353 x = (x >> 1) ^ (0x82F63B78 & ~((x &1)-1));354 i+=1355 mav_putvalue=x356 mav_putvalue=(mav_putvalue<<1)|1357 return mav_putvalue358 if((func7 == "0000101") and (func3 == "001") and (opcode == "0110011")):359 print('--CLMUL 32')360 x=0361 i=0362 while i<32:363 if ((mav_putvalue_src2 >> i) & 1):364 x =x ^ mav_putvalue_src1 << i365 i=i+1366 mav_putvalue=x & 0xffffffff367 mav_putvalue=(mav_putvalue<<1)|1368 return mav_putvalue369 if((func7 == "0000101") and (func3 == "011") and (opcode == "0110011")):370 print('--CLMULH 33')371 x=0372 i=1373 while i<32:374 if ((mav_putvalue_src2 >> i) & 1):375 x =x ^ mav_putvalue_src1 >> (32-i)376 i=i+1377 mav_putvalue=x & 0xffffffff378 mav_putvalue=(mav_putvalue<<1)|1379 return mav_putvalue380 if((func7 == "0000101") and (func3 == "010") and (opcode == "0110011")):381 print('--CLMULR 34')382 x=0383 i=0384 while i<32:385 if ((mav_putvalue_src2 >> i) & 1):386 x =x ^ mav_putvalue_src1 >> (32-i-1)387 i=i+1388 mav_putvalue=x & 0xffffffff389 mav_putvalue=(mav_putvalue<<1)|1390 return mav_putvalue391 if((func7 == "0000101") and (func3 == "100") and (opcode == "0110011")):392 print('--MIN 35')393 le1=mav_putvalue_src1394 lex=bin(le1)[2:]395 lex=lex.zfill(32)396 imm_value1 = lex[0]397 le2=mav_putvalue_src2398 ex=bin(le2)[2:]399 ex=ex.zfill(32)400 imm_value2 = ex[0]401 if(imm_value1=='1') and (imm_value2=='0'):402 mav_putvalue_src1=(mav_putvalue_src1<<1)|1403 return mav_putvalue_src1404 if(imm_value1=='0') and (imm_value2=='1'):405 mav_putvalue_src2=(mav_putvalue_src2<<1)|1406 return mav_putvalue_src2407 if((imm_value1=='0') and (imm_value2=='0')) or ((imm_value1=='1') and (imm_value2=='1')) :408 if (mav_putvalue_src1 < mav_putvalue_src2):409 mav_putvalue_src1=(mav_putvalue_src1<<1)|1410 return mav_putvalue_src1411 else:412 mav_putvalue_src2=(mav_putvalue_src2<<1)|1413 return mav_putvalue_src2414 if((func7 == "0000101") and (func3 == "101") and (opcode == "0110011")):415 print('--MAX 36')416 le1=mav_putvalue_src1417 lex=bin(le1)[2:]418 lex=lex.zfill(32)419 imm_value1 = lex[0]420 le2=mav_putvalue_src2421 ex=bin(le2)[2:]422 ex=ex.zfill(32)423 imm_value2 = ex[0]424 if(imm_value1=='1') and (imm_value2=='0'):425 mav_putvalue_src2=(mav_putvalue_src2<<1)|1426 return mav_putvalue_src2427 if(imm_value1=='0') and (imm_value2=='1'):428 mav_putvalue_src1=(mav_putvalue_src1<<1)|1429 return mav_putvalue_src1430 if((imm_value1=='0') and (imm_value2=='0')) or ((imm_value1=='1') and (imm_value2=='1')) :431 if (mav_putvalue_src1 > mav_putvalue_src2):432 mav_putvalue_src1=(mav_putvalue_src1<<1)|1433 return mav_putvalue_src1434 else:435 mav_putvalue_src2=(mav_putvalue_src2<<1)|1436 return mav_putvalue_src2437 if((func7 == "0000101") and (func3 == "110") and (opcode == "0110011")):438 print('--MINU 37')439 if (mav_putvalue_src1 < mav_putvalue_src2):440 mav_putvalue=mav_putvalue_src1441 else:442 mav_putvalue=mav_putvalue_src2443 mav_putvalue=(mav_putvalue<<1)|1444 return mav_putvalue445 if((func7 == "0000101") and (func3 == "111") and (opcode == "0110011")):446 print('--MAXU 38')447 if (mav_putvalue_src1 > mav_putvalue_src2):448 mav_putvalue=mav_putvalue_src1449 else:450 mav_putvalue=mav_putvalue_src2451 mav_putvalue=(mav_putvalue<<1)|1452 return mav_putvalue453 if((func7 == "0100100") and (func3 == "110") and (opcode == "0110011")):454 print('--BDEP 39')455 r=0456 j=0457 for i in range(32):458 if ((mav_putvalue_src2 >> i) & 1):459 if ((mav_putvalue_src1 >> j) & 1):460 r |= 1 << i461 j=j+1462 mav_putvalue=r463 mav_putvalue=(mav_putvalue<<1)|1464 return mav_putvalue465 if((func7 == "0000100") and (func3 == "110") and (opcode == "0110011")):466 print('--BEXT 40')467 r=0468 j=0469 for i in range(32):470 if ((mav_putvalue_src2 >> i) & 1):471 if ((mav_putvalue_src1 >> i) & 1):472 r |= 1 << j473 j=j+1474 mav_putvalue=r475 mav_putvalue=(mav_putvalue<<1)|1476 return mav_putvalue477 if((func7 == "0000100") and (func3 == "100") and (opcode == "0110011")):478 print('--PACK 41')479 lower = (mav_putvalue_src1 << 16) >> 16480 lower=lower & 0x0000ffff481 upper =mav_putvalue_src2 << 16482 mav_putvalue=lower | upper483 mav_putvalue=mav_putvalue & 0xffffffff484 mav_putvalue=(mav_putvalue<<1)|1485 return mav_putvalue486 if((func7 == "0100100") and (func3 == "100") and (opcode == "0110011")):487 print('--PACKU 42')488 lower = (mav_putvalue_src1 >> 16)489 upper =mav_putvalue_src2 >> 16 << 16490 mav_putvalue=lower | upper491 mav_putvalue=(mav_putvalue<<1)|1492 return mav_putvalue493 if((func7 == "0000100") and (func3 == "111") and (opcode == "0110011")):494 print('--PACKH 45')495 lower = mav_putvalue_src1& 255496 upper = (mav_putvalue_src2 & 255) << 8497 mav_putvalue=lower | upper498 mav_putvalue=(mav_putvalue<<1)|1499 return mav_putvalue500 if((func7_imm == "00100") and (func3 == "001") and (opcode == "0010011")):501 print('--SLOI 46')502 out=((mav_putvalue_src1)<< shamt_imm)503 res=out504 min_i=0505 max_i=shamt_imm506 while (min_i<max_i):507 res=((1 << min_i) | res)508 min_i=min_i+1509 mav_putvalue=res & 0xffffffff510 mav_putvalue=(mav_putvalue<<1)|1511 return mav_putvalue512# uint_xlen_t sro(uint_xlen_t rs1, uint_xlen_t rs2)513# {514# int shamt = rs2 & (XLEN - 1);515# return ~(~rs1 >> shamt);516# }517 if((func7_imm == "00100") and (func7_fsri_1bit != "1") and (func3 == "101") and (opcode == "0010011")):518 print('--SROI 47')519 out=((mav_putvalue_src1)>> shamt_imm)520 res=out521 min_i=32-shamt_imm522 max_i=32523 while (min_i<max_i):524 res=((1 << min_i) | res)525 min_i=min_i+1526 mav_putvalue=res & 0xffffffff527 mav_putvalue=(mav_putvalue<<1)|1528 return mav_putvalue529 if((func7_imm == "01100") and (func7_fsri_1bit != "1") and (func3 == "101") and (opcode == "0010011")):530 print('--RORI 48')531 imm_value = int(le[length-27:length-20],2)532 shamt_imm = imm_value & (31)533 out=(mav_putvalue_src1 >> shamt_imm) | (mav_putvalue_src1 << ((32-shamt_imm) & (31)))534 mav_putvalue=out & 0xffffffff535 mav_putvalue=(mav_putvalue<<1)|1536 return mav_putvalue537 if((func7_imm == "01001") and (func3 == "001") and (opcode == "0010011")):538 print('--SBCLRI 49')539 out= mav_putvalue_src1 & (~(1<<shamt_imm))540 mav_putvalue=out & 0xffffffff541 mav_putvalue=(mav_putvalue<<1)|1542 return mav_putvalue543 if((func7_imm == "00101") and (func3 == "001") and (opcode == "0010011")):544 print('--SBSETI 50')545 out= mav_putvalue_src1 | (1<<shamt_imm)546 mav_putvalue=out & 0xffffffff547 mav_putvalue=(mav_putvalue<<1)|1548 return mav_putvalue549 if((func7_imm == "01101") and (func3 == "001") and (opcode == "0010011")):550 print('--SBINVI 51')551 out= mav_putvalue_src1 ^ (1<<shamt_imm)552 mav_putvalue=out & 0xffffffff553 mav_putvalue=(mav_putvalue<<1)|1554 return mav_putvalue555 if((func7_imm == "01001") and (func3 == "101") and (opcode == "0010011")):556 print('--SBEXTI 52')557 out= 1 & (mav_putvalue_src1 >> shamt_imm)558 mav_putvalue=out & 0xffffffff559 mav_putvalue=(mav_putvalue<<1)|1560 return mav_putvalue561 def suffle32(mav_putvalue_src1,maskl,maskr,n):562 x = mav_putvalue_src1 & ~(maskl | maskr)563 x =x | ((mav_putvalue_src1 << n) & maskl) | ((mav_putvalue_src1 >> n) & maskr)564 return x565 if((func7 == "0000100") and (func3 == "001") and (opcode == "0110011")):566 print('--SHFL 53')567 x= mav_putvalue_src1568 shamt= mav_putvalue_src2 & (15)569 if(shamt & 8):570 x=suffle32(x, 0x00ff0000,0x0000ff00,8)571 if(shamt & 4):572 x=suffle32(x, 0x0f000f00,0x00f000f0,4)573 if(shamt & 2):574 x=suffle32(x, 0x30303030,0x0c0c0c0c,2)575 if(shamt & 1):576 x=suffle32(x, 0x44444444,0x22222222,1)577 x=(x<<1)|1578 return x579 if((func7 == "0000100") and (func3 == "101") and (opcode == "0110011")):580 print('--UNSHFL 54')581 x= mav_putvalue_src1582 shamt= mav_putvalue_src2 & (15)583 mav_putvalue=mav_putvalue_src1584 if(shamt & 1):585 x=suffle32(x, 0x44444444,0x22222222,1)586 mav_putvalue=x & 0xffffffff587 if(shamt & 2):588 x=suffle32(x, 0x30303030,0x0c0c0c0c,2)589 mav_putvalue=x & 0xffffffff590 if(shamt & 4):591 x=suffle32(x, 0x0f000f00,0x00f000f0,4)592 mav_putvalue=x & 0xffffffff593 if(shamt & 8):594 x=suffle32(x, 0x00ff0000,0x0000ff00,8)595 mav_putvalue=x & 0xffffffff596 mav_putvalue=(mav_putvalue<<1)|1597 return mav_putvalue598 if((func7_imm_SHFL == "000010") and (func3 == "001") and (opcode == "0010011")):599 print('--SHFLI 55 (check)')600 imm_value = le[length-26:length-20]601 imm_value=(int(str(imm_value),2))602 x= mav_putvalue_src1603 shamt= imm_value & (15)604 x=mav_putvalue_src1605 if(shamt & 8):606 x=suffle32(x, 0x00ff0000,0x0000ff00,8)607 if(shamt & 4):608 x=suffle32(x, 0x0f000f00,0x00f000f0,4)609 if(shamt & 2):610 x=suffle32(x, 0x30303030,0x0c0c0c0c,2)611 if(shamt & 1):612 x=suffle32(x, 0x44444444,0x22222222,1)613 x=(x<<1)|1614 return x615 if((func7_imm_SHFL == "000010") and (func3 == "101") and (opcode == "0010011")):616 print('--UNSHFLI 56 (check)')617 imm_value = le[length-26:length-20]618 imm_value=(int(str(imm_value),2))619 x= mav_putvalue_src1620 shamt= imm_value & (15)621 mav_putvalue=mav_putvalue_src1622 if(shamt & 1):623 x=suffle32(x, 0x44444444,0x22222222,1)624 mav_putvalue=x & 0xffffffff625 if(shamt & 2):626 x=suffle32(x, 0x30303030,0x0c0c0c0c,2)627 mav_putvalue=x & 0xffffffff628 if(shamt & 4):629 x=suffle32(x, 0x0f000f00,0x00f000f0,4)630 mav_putvalue=x & 0xffffffff631 if(shamt & 8):632 x=suffle32(x, 0x00ff0000,0x0000ff00,8)633 mav_putvalue=x & 0xffffffff634 mav_putvalue=(mav_putvalue<<1)|1635 return mav_putvalue636 if((func7_imm == "00101") and (func7_fsri_1bit != "1") and (func3 == "101") and (opcode == "0010011")):637 print('--GORCI 57')638 x=mav_putvalue_src1639 if (shamt_imm & 1):640 x= x | ((x & 0x55555555)<< 1) | ((x & 0xaaaaaaaa) >>1)641 if (shamt_imm & 2):642 x= x | ((x & 0x33333333)<< 2) | ((x & 0xcccccccc) >>2)643 if (shamt_imm & 4):644 x= x| ((x & 0x0f0f0f0f)<< 4) | ((x & 0xf0f0f0f0) >>4)645 if (shamt_imm & 8):646 x= x | ((x & 0x00ff00ff)<< 8) | ((x & 0xff00ff00) >>8)647 if (shamt_imm & 16):648 x= x| ((x & 0x0000ffff)<< 16) | ((x & 0xffff0000) >>16)649 mav_putvalue=x & 0xffffffff650 mav_putvalue=(mav_putvalue<<1)|1651 return mav_putvalue652 if((func7_imm == "01101")and(func7_fsri_1bit != "1") and (func3 == "101") and (opcode == "0010011")):653 print('--GREVI 58')654 imm_value = le[length-25:length-20]655 imm_value=(int(str(imm_value),2))656 shamt_imm= imm_value & (31)657 x=mav_putvalue_src1658 if (shamt_imm & 1):659 x= ((x & 0x55555555)<< 1) | (( x & 0xaaaaaaaa) >>1)660 if (shamt_imm & 2):661 x= ((x & 0x33333333)<< 2) | (( x & 0xcccccccc) >>2)662 if (shamt_imm & 4):663 x= ((x & 0x0f0f0f0f)<< 4) | (( x & 0xf0f0f0f0) >>4)664 if (shamt_imm & 8):665 x= ((x & 0x00ff00ff)<< 8) | (( x & 0xff00ff00) >>8)666 if (shamt_imm & 16):667 x= ((x & 0x0000ffff)<< 16) | (( x & 0xffff0000) >>16)668 669 mav_putvalue=x & 0xffffffff670 #print("mav_putvalue before adding valid bit",hex(mav_putvalue))671 mav_putvalue=(mav_putvalue<<1)|1672 #print("mav_putvalue after adding valid bit",hex(mav_putvalue))673 return mav_putvalue674 if((func7_fsri_1bit == "1") and (func3 == "101") and (opcode == "0010011")):675 print('--_FSRI 59')676 fsr_imm_value = le[length-26:length-20]677 fsr_imm_value=(int(str(fsr_imm_value),2))678 shamt1= fsr_imm_value & (63)679 #print(shamt1)680 A= mav_putvalue_src1681 B= mav_putvalue_src3682 if(shamt1>=32):683 shamt1=shamt1-32684 A= mav_putvalue_src3685 B= mav_putvalue_src1686 if(shamt1):687 mav_putvalue= (A >> shamt1) | (B << (32-shamt1))688 else:689 mav_putvalue=A690 mav_putvalue=mav_putvalue & 0xffffffff691 #print("mav_putvalue before adding valid bit",hex(mav_putvalue))692 mav_putvalue=(mav_putvalue<<1)|1693 #print("mav_putvalue after adding valid bit",hex(mav_putvalue))694 return mav_putvalue695 def slo(src1,src2):696 print('--SLO function')697 shamt1= src2 & (31)698 out=((src1)<< shamt1)699 res=out700 min_i=0701 max_i=shamt1702 while (min_i<max_i):703 res=((1 << min_i) | res)704 min_i=min_i+1705 mav_putvalue=res & 0xffffffff706 return mav_putvalue707 if((func7 == "0100100") and (func3 == "111") and (opcode == "0110011")):708 print('--BFP 60')709 cfg = mav_putvalue_src2 >> (16)710 leng=0711 off=0712 if((cfg>>30)==2):713 cfg = cfg>>16714 leng= (cfg>>8) & 15715 off= cfg & 31716 if leng:717 leng=leng718 else:719 leng=16720 mask = slo(0, leng) << off721 data = mav_putvalue_src2 << off722 mav_putvalue =(data & mask) | (mav_putvalue_src1 & ~mask)723 mav_putvalue=mav_putvalue & 0xffffffff724 mav_putvalue=(mav_putvalue<<1)|1725 return mav_putvalue726 #print('--INVALID ')...

Full Screen

Full Screen

test_public.py

Source:test_public.py Github

copy

Full Screen

...110 check_func(func2, func2_case_9, False)111 check_func(func2, func2_case_10, False)112 check_func(func2, func2_case_11, True)113def func3_case_1() -> None:114 func3((1, "re", "rt", ["a", "b", "c"])) # success115def func3_case_2() -> None:116 func3((1, "re", "rt", "hello")) # success117def func3_case_3() -> None:118 func3((True, "re", "rt", "hello")) # success119def func3_case_4() -> None:120 func3((True, "re", "rt", "hello")) # success121def func3_case_5() -> None:122 func3((True, "re", "rt", "hello", "hi")) # fail123def func3_case_6() -> None:124 class A(str):125 pass126 func3((True, A(), A(), A())) # success127def func3_case_7() -> None:128 class A(str):129 pass130 func3((True, "re", "rt", "hello", A())) # fail131def func3_case_8() -> None:132 func3((1.1, "", "", "hello")) # success133def func3_case_9() -> None:134 func3((1j, "", "", "hello")) # fail135def test_func3() -> None:136 check_annotations(func3)137 check_func(func3, func3_case_1, True)138 check_func(func3, func3_case_2, True)139 check_func(func3, func3_case_3, True)140 check_func(func3, func3_case_4, True)141 check_func(func3, func3_case_5, False)142 check_func(func3, func3_case_6, True)143 check_func(func3, func3_case_7, False)144 check_func(func3, func3_case_8, True)145 check_func(func3, func3_case_9, False)146def func4_case_1() -> None:147 func4((1, 1, 2, 4)) # success148def func4_case_2() -> None:149 func4((1,)) # success...

Full Screen

Full Screen

riscv_ins.py

Source:riscv_ins.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Created on Tue Jul 19 10:28:14 202245@author: dcr6"""78rv32i_instructions = ['LUI','AUIPC','JAL','JALR','BEQ','BNE','BLT','BGE','BLTU', 9 'BGEU','LB','LH','LW','LBU','LHU','SB','SH','SW','ADDI',10 'SLTI','SLTIU','XORI','ORI','ANDI','SLLI','SRLI','SRAI',11 'ADD','SUB','SLL','SLT','SLTU','XOR','SRL','SRA','OR','AND',12 'FENCE', 'FENCE.I','ECALL','EBREAK','CSRRW','CSRRS','CSRRC',13 'CSRRWI','CSRRSI','CSRRCI']1415rv64i_instructions = ['LWU','LD','SD','ADDIW','SLLIW','SRLIW','SRAIW','ADDW','SUBW','SLLW','SRLW','SRAW']1617rv32m_instructions = ['MUL','MULH','MULHSU','MULHU','DIV','DIVU','REM','REMU'] 18 19def ins_to_str(ins):20 opcode = ins & 0x7F21 func3 = (ins >> 12) & 0x722 func7 = (ins >> 25) & 0x7F23 24 if (opcode == 0x03):25 if (func3 == 0x00):26 return 'LB'27 if (func3 == 0x01):28 return 'LH'29 if (func3 == 0x02):30 return 'LW'31 if (func3 == 0x03):32 return 'LD'33 if (func3 == 0x04):34 return 'LBU'35 if (func3 == 0x05):36 return 'LHU'37 if (func3 == 0x06):38 return 'LWU'39 if (opcode == 0x13):40 if (func3 == 0x00):41 return 'ADDI'42 if (func3 == 0x01):43 if (func7 == 0x00):44 return 'SLLI'45 if (func3 == 0x02):46 return 'SLTI'47 if (func3 == 0x03):48 return 'SLTIU'49 if (func3 == 0x04):50 return 'XORI'51 if (func3 == 0x05):52 if (func7 == 0x00):53 return 'SRLI'54 if (func7 == 0x20):55 return 'SRAI'56 if (func3 == 0x06):57 return 'ORI'58 if (func3 == 0x07):59 return 'ANDI'60 if (opcode == 0x17):61 return 'AUIPC'62 if (opcode == 0x1b):63 if (func3 == 0x00):64 return 'ADDIW'65 if (func3 == 0x01):66 if (func7 == 0x00):67 return 'SLLIW'68 if (func3 == 0x05):69 if (func7 == 0x00):70 return 'SRLIW'71 if (func7 == 0x20):72 return 'SRAIW'73 if (opcode == 0x23):74 if (func3 == 0x00):75 return 'SB'76 if (func3 == 0x01):77 return 'SH'78 if (func3 == 0x02):79 return 'SW'80 if (func3 == 0x03):81 return 'SD'82 if (opcode == 0x33):83 if (func3 == 0x00):84 if (func7 == 0x00):85 return 'ADD'86 if (func7 == 0x01):87 return 'MUL'88 if (func7 == 0x20):89 return 'SUB'90 if (func3 == 0x01):91 if (func7 == 0x00):92 return 'SLL'93 if (func7 == 0x01):94 return 'MULH'95 if (func3 == 0x02):96 if (func7 == 0x00):97 return 'SLT'98 if (func7 == 0x01):99 return 'MULHSU'100 if (func3 == 0x03):101 if (func7 == 0x00):102 return 'SLTU'103 if (func7 == 0x01):104 return 'MULHU'105 if (func3 == 0x04):106 if (func7 == 0x00):107 return 'XOR'108 if (func7 == 0x01):109 return 'DIV'110 if (func3 == 0x05):111 if (func7 == 0x00):112 return 'SRL'113 if (func7 == 0x01):114 return 'DIVU'115 if (func7 == 0x20):116 return 'SRA'117 if (func3 == 0x06):118 if (func7 == 0x00):119 return 'OR'120 if (func7 == 0x01):121 return 'REM'122 if (func3 == 0x07):123 if (func7 == 0x00):124 return 'AND'125 if (func7 == 0x01):126 return 'REMU'127 128 if (opcode == 0x37):129 return 'LUI'130 if (opcode == 0x3b):131 if (func3 == 0x00):132 if (func7 == 0x00):133 return 'ADDW'134 if (func7 == 0x20):135 return 'SUBW'136 if (func3 == 0x01):137 if (func7 == 0x00):138 return 'SLLW'139 if (func3 == 0x05):140 if (func7 == 0x00):141 return 'SRLW'142 if (func7 == 0x20):143 return 'SRAW'144 145 if (opcode == 0x63):146 if (func3 == 0x00):147 return 'BEQ'148 if (func3 == 0x01):149 return 'BNE'150 if (func3 == 0x04):151 return 'BLT'152 if (func3 == 0x05):153 return 'BGE'154 if (func3 == 0x06):155 return 'BLTU'156 if (func3 == 0x07):157 return 'BGEU'158 if (opcode == 0x67):159 if (func3 == 0x00):160 return 'JALR'161 if (opcode == 0x6F):162 return 'JAL'163 if (opcode == 0x73):164 if (func3 == 0x00):165 if (ins == 0x00000073):166 return 'ECALL'167 if (ins == 0x00100073):168 return 'EBREAK'169 170 return 'Unknown opcode {:x} func3 {:x} func7 {:x} full {:08x}'.format(opcode, func3, func7, ins)171 172RTypeIns = ['ADD','SUB','SLL','SLT','SLTU','XOR','SRL','SRA','OR','AND']173ITypeIns = ['JALR','LB','LH','LW','LBU','LHU','ADDI','SLTI','SLTIU','XORI',174 'ORI','ANDI','SLLI','SRLI','SRAI']175STypeIns = ['SB','SH','SW']176BTypeIns = ['BEQ','BNE','BLT','BGE','BLTU','BGEU']177UTypeIns = ['LUI','AUIPC']178JTypeIns = ['JAL']179CSRRIns = ['CSRRW','CSRRS','CSRRC']180CSRIIns = ['CSRRWI','CSRRSI','CSRRCI']181182def ins_to_regs(ins):183 code = ins_to_str(ins)184 185 rd = 'r{}'.format((ins >> 7) & 0x1F)186 rs1 = 'r{}'.format((ins >> 15) & 0x1F)187 rs2 = 'r{}'.format((ins >> 20) & 0x1F)188 189 csr = 'csr{}'.format((ins >> 20) & 0xFFF)190 191 if (code in RTypeIns):192 return [rd, rs1, rs2]193 if (code in RTypeIns):194 return [rd, rs1]195 if (code in STypeIns):196 return [rs1, rs2]197 if (code in BTypeIns):198 return [rs1, rs2]199 if (code in UTypeIns):200 return [rd]201 if (code in JTypeIns):202 return [rd]203 if (code in CSRRIns):204 return [rd, rs1, csr]205 if (code in CSRIIns):206 return [rd, csr]207 208def get_ins(code):209210 size = len(code)211 off = 0 212 213 ret = []214 215 while (off <= (size-4)):216 ins = int.from_bytes(code[off:off+4], byteorder='little')217 218 ret.append(ins_to_str(ins))219 off += 4220221 return ret222223def get_regs(code):224 size = len(code)225 off = 0 226 227 ret = set([])228 229 while (off <= (size-4)):230 ins = int.from_bytes(code[off:off+4], byteorder='little')231 232 regs = ins_to_regs(ins)233234 off += 4235 236 #print('reg {:x}'.format(off))237 238 if (regs is None):239 continue240 241 for r in regs:242 ret.add(r)243 244 #print('Regs so far', ret)245246 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run refurb automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful