Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow on moderately deep ternary expression #37

Closed
rudy-6-4 opened this issue Aug 22, 2024 · 4 comments
Closed

Stack overflow on moderately deep ternary expression #37

rudy-6-4 opened this issue Aug 22, 2024 · 4 comments

Comments

@rudy-6-4
Copy link

When generating code deep ternary, a stack overflow happens for moderate sequence of ternary.
Is there a way to have bigger/unlimited stacks for yowasp-yosys ?

Using from python:
yowasp-runtime==1.53
yowasp-yosys==0.44.0.0.post760

Code example:

module main(a, result);
    input[0:8] a;
    output  [0:8] result;
    assign result = (
    (a[0:8] == 0) ? 0:
    (a[0:8] == 1) ? 1:
    (a[0:8] == 2) ? 2:
    (a[0:8] == 3) ? 3:
    (a[0:8] == 4) ? 4:
    (a[0:8] == 5) ? 5:
    (a[0:8] == 6) ? 6:
    (a[0:8] == 7) ? 7:
    (a[0:8] == 8) ? 8:
    (a[0:8] == 9) ? 9:
    (a[0:8] == 10) ? 10:
    (a[0:8] == 11) ? 11:
    (a[0:8] == 12) ? 12:
    (a[0:8] == 13) ? 13:
    (a[0:8] == 14) ? 14:
    (a[0:8] == 15) ? 15:
    (a[0:8] == 16) ? 16:
    (a[0:8] == 17) ? 17:
    (a[0:8] == 18) ? 18:
    (a[0:8] == 19) ? 19:
    (a[0:8] == 20) ? 20:
    (a[0:8] == 21) ? 21:
    (a[0:8] == 22) ? 22:
    (a[0:8] == 23) ? 23:
    (a[0:8] == 24) ? 24:
    (a[0:8] == 25) ? 25:
    (a[0:8] == 26) ? 26:
    (a[0:8] == 27) ? 27:
    (a[0:8] == 28) ? 28:
    (a[0:8] == 29) ? 29:
    (a[0:8] == 30) ? 30:
    (a[0:8] == 31) ? 31:
    (a[0:8] == 32) ? 32:
    (a[0:8] == 33) ? 33:
    (a[0:8] == 34) ? 34:
    (a[0:8] == 35) ? 35:
    (a[0:8] == 36) ? 36:
    (a[0:8] == 37) ? 37:
    (a[0:8] == 38) ? 38:
    (a[0:8] == 39) ? 39:
    (a[0:8] == 40) ? 40:
    (a[0:8] == 41) ? 41:
    (a[0:8] == 42) ? 42:
    (a[0:8] == 43) ? 43:
    (a[0:8] == 44) ? 44:
    (a[0:8] == 45) ? 45:
    (a[0:8] == 46) ? 46:
    (a[0:8] == 47) ? 47:
    (a[0:8] == 48) ? 48:
    (a[0:8] == 49) ? 49:
    (a[0:8] == 50) ? 50:
    (a[0:8] == 51) ? 51:
    (a[0:8] == 52) ? 52:
    (a[0:8] == 53) ? 53:
    (a[0:8] == 54) ? 54:
    (a[0:8] == 55) ? 55:
    (a[0:8] == 56) ? 56:
    (a[0:8] == 57) ? 57:
    (a[0:8] == 58) ? 58:
    (a[0:8] == 59) ? 59:
    (a[0:8] == 60) ? 60:
    (a[0:8] == 61) ? 61:
    (a[0:8] == 62) ? 62:
    (a[0:8] == 63) ? 63:
    (a[0:8] == 64) ? 64:
    (a[0:8] == 65) ? 65:
    (a[0:8] == 66) ? 66:
    (a[0:8] == 67) ? 67:
    (a[0:8] == 68) ? 68:
    (a[0:8] == 69) ? 69:
    (a[0:8] == 70) ? 70:
    (a[0:8] == 71) ? 71:
    (a[0:8] == 72) ? 72:
    (a[0:8] == 73) ? 73:
    (a[0:8] == 74) ? 74:
    (a[0:8] == 75) ? 75:
    (a[0:8] == 76) ? 76:
    (a[0:8] == 77) ? 77:
    (a[0:8] == 78) ? 78:
    (a[0:8] == 79) ? 79:
    (a[0:8] == 80) ? 80:
    (a[0:8] == 81) ? 81:
    (a[0:8] == 82) ? 82:
    (a[0:8] == 83) ? 83:
    (a[0:8] == 84) ? 84:
    (a[0:8] == 85) ? 85:
    (a[0:8] == 86) ? 86:
    (a[0:8] == 87) ? 87:
    (a[0:8] == 88) ? 88:
    (a[0:8] == 89) ? 89:
    (a[0:8] == 90) ? 90:
    (a[0:8] == 91) ? 91:
    (a[0:8] == 92) ? 92:
    (a[0:8] == 93) ? 93:
    (a[0:8] == 94) ? 94:
    (a[0:8] == 95) ? 95:
    (a[0:8] == 96) ? 96:
    (a[0:8] == 97) ? 97:
    (a[0:8] == 98) ? 98:
    (a[0:8] == 99) ? 99:
    (a[0:8] == 100) ? 100:
    (a[0:8] == 101) ? 101:
    (a[0:8] == 102) ? 102:
    (a[0:8] == 103) ? 103:
    (a[0:8] == 104) ? 104:
    (a[0:8] == 105) ? 105:
    (a[0:8] == 106) ? 106:
    (a[0:8] == 107) ? 107:
    (a[0:8] == 108) ? 108:
    (a[0:8] == 109) ? 109:
    (a[0:8] == 110) ? 110:
    (a[0:8] == 111) ? 111:
    (a[0:8] == 112) ? 112:
    (a[0:8] == 113) ? 113:
    (a[0:8] == 114) ? 114:
    (a[0:8] == 115) ? 115:
    (a[0:8] == 116) ? 116:
    (a[0:8] == 117) ? 117:
    (a[0:8] == 118) ? 118:
    (a[0:8] == 119) ? 119:
    (a[0:8] == 120) ? 120:
    (a[0:8] == 121) ? 121:
    (a[0:8] == 122) ? 122:
    (a[0:8] == 123) ? 123:
    (a[0:8] == 124) ? 124:
    (a[0:8] == 125) ? 125:
    (a[0:8] == 126) ? 126:
    (a[0:8] == 127) ? 127:
    (a[0:8] == 128) ? 128:
    (a[0:8] == 129) ? 129:
    (a[0:8] == 130) ? 130:
    (a[0:8] == 131) ? 131:
    (a[0:8] == 132) ? 132:
    (a[0:8] == 133) ? 133:
    (a[0:8] == 134) ? 134:
    (a[0:8] == 135) ? 135:
    (a[0:8] == 136) ? 136:
    (a[0:8] == 137) ? 137:
    (a[0:8] == 138) ? 138:
    (a[0:8] == 139) ? 139:
    (a[0:8] == 140) ? 140:
    (a[0:8] == 141) ? 141:
    (a[0:8] == 142) ? 142:
    (a[0:8] == 143) ? 143:
    (a[0:8] == 144) ? 144:
    (a[0:8] == 145) ? 145:
    (a[0:8] == 146) ? 146:
    (a[0:8] == 147) ? 147:
    (a[0:8] == 148) ? 148:
    (a[0:8] == 149) ? 149:
    (a[0:8] == 150) ? 150:
    (a[0:8] == 151) ? 151:
    (a[0:8] == 152) ? 152:
    (a[0:8] == 153) ? 153:
    (a[0:8] == 154) ? 154:
    (a[0:8] == 155) ? 155:
    (a[0:8] == 156) ? 156:
    (a[0:8] == 157) ? 157:
    (a[0:8] == 158) ? 158:
    (a[0:8] == 159) ? 159:
    (a[0:8] == 160) ? 160:
    (a[0:8] == 161) ? 161:
    (a[0:8] == 162) ? 162:
    (a[0:8] == 163) ? 163:
    (a[0:8] == 164) ? 164:
    (a[0:8] == 165) ? 165:
    (a[0:8] == 166) ? 166:
    (a[0:8] == 167) ? 167:
    (a[0:8] == 168) ? 168:
    (a[0:8] == 169) ? 169:
    (a[0:8] == 170) ? 170:
    (a[0:8] == 171) ? 171:
    (a[0:8] == 172) ? 172:
    (a[0:8] == 173) ? 173:
    (a[0:8] == 174) ? 174:
    (a[0:8] == 175) ? 175:
    (a[0:8] == 176) ? 176:
    (a[0:8] == 177) ? 177:
    (a[0:8] == 178) ? 178:
    (a[0:8] == 179) ? 179:
    (a[0:8] == 180) ? 180:
    (a[0:8] == 181) ? 181:
    (a[0:8] == 182) ? 182:
    (a[0:8] == 183) ? 183:
    (a[0:8] == 184) ? 184:
    (a[0:8] == 185) ? 185:
    (a[0:8] == 186) ? 186:
    (a[0:8] == 187) ? 187:
    (a[0:8] == 188) ? 188:
    (a[0:8] == 189) ? 189:
    (a[0:8] == 190) ? 190:
    (a[0:8] == 191) ? 191:
    (a[0:8] == 192) ? 192:
    (a[0:8] == 193) ? 193:
    (a[0:8] == 194) ? 194:
    (a[0:8] == 195) ? 195:
    (a[0:8] == 196) ? 196:
    (a[0:8] == 197) ? 197:
    (a[0:8] == 198) ? 198:
    (a[0:8] == 199) ? 199:
    (a[0:8] == 200) ? 200:
    (a[0:8] == 201) ? 201:
    (a[0:8] == 202) ? 202:
    (a[0:8] == 203) ? 203:
    (a[0:8] == 204) ? 204:
    (a[0:8] == 205) ? 205:
    (a[0:8] == 206) ? 206:
    (a[0:8] == 207) ? 207:
    (a[0:8] == 208) ? 208:
    (a[0:8] == 209) ? 209:
    (a[0:8] == 210) ? 210:
    (a[0:8] == 211) ? 211:
    (a[0:8] == 212) ? 212:
    (a[0:8] == 213) ? 213:
    (a[0:8] == 214) ? 214:
    (a[0:8] == 215) ? 215:
    (a[0:8] == 216) ? 216:
    (a[0:8] == 217) ? 217:
    (a[0:8] == 218) ? 218:
    (a[0:8] == 219) ? 219:
    (a[0:8] == 220) ? 220:
    (a[0:8] == 221) ? 221:
    (a[0:8] == 222) ? 222:
    (a[0:8] == 223) ? 223:
    (a[0:8] == 224) ? 224:
    (a[0:8] == 225) ? 225:
    (a[0:8] == 226) ? 226:
    (a[0:8] == 227) ? 227:
    (a[0:8] == 228) ? 228:
    (a[0:8] == 229) ? 229:
    (a[0:8] == 230) ? 230:
    (a[0:8] == 231) ? 231:
    (a[0:8] == 232) ? 232:
    (a[0:8] == 233) ? 233:
    (a[0:8] == 234) ? 234:
    (a[0:8] == 235) ? 235:
    (a[0:8] == 236) ? 236:
    (a[0:8] == 237) ? 237:
    (a[0:8] == 238) ? 238:
    (a[0:8] == 239) ? 239:
    (a[0:8] == 240) ? 240:
    (a[0:8] == 241) ? 241:
    (a[0:8] == 242) ? 242:
    (a[0:8] == 243) ? 243:
    (a[0:8] == 244) ? 244:
    (a[0:8] == 245) ? 245:
    (a[0:8] == 246) ? 246:
    (a[0:8] == 247) ? 247:
    (a[0:8] == 248) ? 248:
    (a[0:8] == 249) ? 249:
    (a[0:8] == 250) ? 250:
    (a[0:8] == 251) ? 251:
    (a[0:8] == 252) ? 252:
    (a[0:8] == 253) ? 253:
    (a[0:8] == 254) ? 254:
    (a[0:8] == 255) ? 255:
    (a[0:8] == 256) ? 256:
    (a[0:8] == 257) ? 257:
    (a[0:8] == 258) ? 258:
    (a[0:8] == 259) ? 259:
    (a[0:8] == 260) ? 260:
    (a[0:8] == 261) ? 261:
    (a[0:8] == 262) ? 262:
    (a[0:8] == 263) ? 263:
    (a[0:8] == 264) ? 264:
    (a[0:8] == 265) ? 265:
    (a[0:8] == 266) ? 266:
    (a[0:8] == 267) ? 267:
    (a[0:8] == 268) ? 268:
    (a[0:8] == 269) ? 269:
    (a[0:8] == 270) ? 270:
    (a[0:8] == 271) ? 271:
    (a[0:8] == 272) ? 272:
    (a[0:8] == 273) ? 273:
    (a[0:8] == 274) ? 274:
    (a[0:8] == 275) ? 275:
    (a[0:8] == 276) ? 276:
    (a[0:8] == 277) ? 277:
    (a[0:8] == 278) ? 278:
    (a[0:8] == 279) ? 279:
    (a[0:8] == 280) ? 280:
    (a[0:8] == 281) ? 281:
    (a[0:8] == 282) ? 282:
    (a[0:8] == 283) ? 283:
    (a[0:8] == 284) ? 284:
    (a[0:8] == 285) ? 285:
    (a[0:8] == 286) ? 286:
    (a[0:8] == 287) ? 287:
    (a[0:8] == 288) ? 288:
    (a[0:8] == 289) ? 289:
    (a[0:8] == 290) ? 290:
    (a[0:8] == 291) ? 291:
    (a[0:8] == 292) ? 292:
    (a[0:8] == 293) ? 293:
    (a[0:8] == 294) ? 294:
    (a[0:8] == 295) ? 295:
    (a[0:8] == 296) ? 296:
    (a[0:8] == 297) ? 297:
    (a[0:8] == 298) ? 298:
    (a[0:8] == 299) ? 299:
    (a[0:8] == 300) ? 300:
    (a[0:8] == 301) ? 301:
    (a[0:8] == 302) ? 302:
    (a[0:8] == 303) ? 303:
    (a[0:8] == 304) ? 304:
    (a[0:8] == 305) ? 305:
    (a[0:8] == 306) ? 306:
    (a[0:8] == 307) ? 307:
    (a[0:8] == 308) ? 308:
    (a[0:8] == 309) ? 309:
    (a[0:8] == 310) ? 310:
    (a[0:8] == 311) ? 311:
    (a[0:8] == 312) ? 312:
    (a[0:8] == 313) ? 313:
    (a[0:8] == 314) ? 314:
    (a[0:8] == 315) ? 315:
    (a[0:8] == 316) ? 316:
    (a[0:8] == 317) ? 317:
    (a[0:8] == 318) ? 318:
    (a[0:8] == 319) ? 319:
    (a[0:8] == 320) ? 320:
    (a[0:8] == 321) ? 321:
    (a[0:8] == 322) ? 322:
    (a[0:8] == 323) ? 323:
    (a[0:8] == 324) ? 324:
    (a[0:8] == 325) ? 325:
    (a[0:8] == 326) ? 326:
    (a[0:8] == 327) ? 327:
    (a[0:8] == 328) ? 328:
    (a[0:8] == 329) ? 329:
    (a[0:8] == 330) ? 330:
    (a[0:8] == 331) ? 331:
    (a[0:8] == 332) ? 332:
    (a[0:8] == 333) ? 333:
    (a[0:8] == 334) ? 334:
    (a[0:8] == 335) ? 335:
    (a[0:8] == 336) ? 336:
    (a[0:8] == 337) ? 337:
    (a[0:8] == 338) ? 338:
    (a[0:8] == 339) ? 339:
    (a[0:8] == 340) ? 340:
    (a[0:8] == 341) ? 341:
    (a[0:8] == 342) ? 342:
    (a[0:8] == 343) ? 343:
    (a[0:8] == 344) ? 344:
    (a[0:8] == 345) ? 345:
    (a[0:8] == 346) ? 346:
    (a[0:8] == 347) ? 347:
    (a[0:8] == 348) ? 348:
    (a[0:8] == 349) ? 349:
    (a[0:8] == 350) ? 350:
    (a[0:8] == 351) ? 351:
    (a[0:8] == 352) ? 352:
    (a[0:8] == 353) ? 353:
    (a[0:8] == 354) ? 354:
    (a[0:8] == 355) ? 355:
    (a[0:8] == 356) ? 356:
    (a[0:8] == 357) ? 357:
    (a[0:8] == 358) ? 358:
    (a[0:8] == 359) ? 359:
    (a[0:8] == 360) ? 360:
    (a[0:8] == 361) ? 361:
    (a[0:8] == 362) ? 362:
    (a[0:8] == 363) ? 363:
    (a[0:8] == 364) ? 364:
    (a[0:8] == 365) ? 365:
    (a[0:8] == 366) ? 366:
    (a[0:8] == 367) ? 367:
    (a[0:8] == 368) ? 368:
    (a[0:8] == 369) ? 369:
    (a[0:8] == 370) ? 370:
    (a[0:8] == 371) ? 371:
    (a[0:8] == 372) ? 372:
    (a[0:8] == 373) ? 373:
    (a[0:8] == 374) ? 374:
    (a[0:8] == 375) ? 375:
    (a[0:8] == 376) ? 376:
    (a[0:8] == 377) ? 377:
    (a[0:8] == 378) ? 378:
    (a[0:8] == 379) ? 379:
    (a[0:8] == 380) ? 380:
    (a[0:8] == 381) ? 381:
    (a[0:8] == 382) ? 382:
    (a[0:8] == 383) ? 383:
    (a[0:8] == 384) ? 384:
    (a[0:8] == 385) ? 385:
    (a[0:8] == 386) ? 386:
    (a[0:8] == 387) ? 387:
    (a[0:8] == 388) ? 388:
    (a[0:8] == 389) ? 389:
    (a[0:8] == 390) ? 390:
    (a[0:8] == 391) ? 391:
    (a[0:8] == 392) ? 392:
    (a[0:8] == 393) ? 393:
    (a[0:8] == 394) ? 394:
    (a[0:8] == 395) ? 395:
    (a[0:8] == 396) ? 396:
    (a[0:8] == 397) ? 397:
    (a[0:8] == 398) ? 398:
    (a[0:8] == 399) ? 399:
    (a[0:8] == 400) ? 400:
    (a[0:8] == 401) ? 401:
    (a[0:8] == 402) ? 402:
    (a[0:8] == 403) ? 403:
    (a[0:8] == 404) ? 404:
    (a[0:8] == 405) ? 405:
    (a[0:8] == 406) ? 406:
    (a[0:8] == 407) ? 407:
    (a[0:8] == 408) ? 408:
    (a[0:8] == 409) ? 409:
    (a[0:8] == 410) ? 410:
    (a[0:8] == 411) ? 411:
    (a[0:8] == 412) ? 412:
    (a[0:8] == 413) ? 413:
    (a[0:8] == 414) ? 414:
    (a[0:8] == 415) ? 415:
    (a[0:8] == 416) ? 416:
    (a[0:8] == 417) ? 417:
    (a[0:8] == 418) ? 418:
    (a[0:8] == 419) ? 419:
    (a[0:8] == 420) ? 420:
    (a[0:8] == 421) ? 421:
    (a[0:8] == 422) ? 422:
    (a[0:8] == 423) ? 423:
    (a[0:8] == 424) ? 424:
    (a[0:8] == 425) ? 425:
    (a[0:8] == 426) ? 426:
    (a[0:8] == 427) ? 427:
    (a[0:8] == 428) ? 428:
    (a[0:8] == 429) ? 429:
    (a[0:8] == 430) ? 430:
    (a[0:8] == 431) ? 431:
    (a[0:8] == 432) ? 432:
    (a[0:8] == 433) ? 433:
    (a[0:8] == 434) ? 434:
    (a[0:8] == 435) ? 435:
    (a[0:8] == 436) ? 436:
    (a[0:8] == 437) ? 437:
    (a[0:8] == 438) ? 438:
    (a[0:8] == 439) ? 439:
    (a[0:8] == 440) ? 440:
    (a[0:8] == 441) ? 441:
    (a[0:8] == 442) ? 442:
    (a[0:8] == 443) ? 443:
    (a[0:8] == 444) ? 444:
    (a[0:8] == 445) ? 445:
    (a[0:8] == 446) ? 446:
    (a[0:8] == 447) ? 447:
    (a[0:8] == 448) ? 448:
    (a[0:8] == 449) ? 449:
    (a[0:8] == 450) ? 450:
    (a[0:8] == 451) ? 451:
    (a[0:8] == 452) ? 452:
    (a[0:8] == 453) ? 453:
    (a[0:8] == 454) ? 454:
    (a[0:8] == 455) ? 455:
    (a[0:8] == 456) ? 456:
    (a[0:8] == 457) ? 457:
    (a[0:8] == 458) ? 458:
    (a[0:8] == 459) ? 459:
    (a[0:8] == 460) ? 460:
    (a[0:8] == 461) ? 461:
    (a[0:8] == 462) ? 462:
    (a[0:8] == 463) ? 463:
    (a[0:8] == 464) ? 464:
    (a[0:8] == 465) ? 465:
    (a[0:8] == 466) ? 466:
    (a[0:8] == 467) ? 467:
    (a[0:8] == 468) ? 468:
    (a[0:8] == 469) ? 469:
    (a[0:8] == 470) ? 470:
    (a[0:8] == 471) ? 471:
    (a[0:8] == 472) ? 472:
    (a[0:8] == 473) ? 473:
    (a[0:8] == 474) ? 474:
    (a[0:8] == 475) ? 475:
    (a[0:8] == 476) ? 476:
    (a[0:8] == 477) ? 477:
    (a[0:8] == 478) ? 478:
    (a[0:8] == 479) ? 479:
    (a[0:8] == 480) ? 480:
    (a[0:8] == 481) ? 481:
    (a[0:8] == 482) ? 482:
    (a[0:8] == 483) ? 483:
    (a[0:8] == 484) ? 484:
    (a[0:8] == 485) ? 485:
    (a[0:8] == 486) ? 486:
    (a[0:8] == 487) ? 487:
    (a[0:8] == 488) ? 488:
    (a[0:8] == 489) ? 489:
    (a[0:8] == 490) ? 490:
    (a[0:8] == 491) ? 491:
    (a[0:8] == 492) ? 492:
    (a[0:8] == 493) ? 493:
    (a[0:8] == 494) ? 494:
    (a[0:8] == 495) ? 495:
    (a[0:8] == 496) ? 496:
    (a[0:8] == 497) ? 497:
    (a[0:8] == 498) ? 498:
    (a[0:8] == 499) ? 499:
    (a[0:8] == 500) ? 500:
    (a[0:8] == 501) ? 501:
    (a[0:8] == 502) ? 502:
    (a[0:8] == 503) ? 503:
    (a[0:8] == 504) ? 504:
    (a[0:8] == 505) ? 505:
    (a[0:8] == 506) ? 506:
    (a[0:8] == 507) ? 507:
    (a[0:8] == 508) ? 508:
    (a[0:8] == 509) ? 509:
    (a[0:8] == 510) ? 510:
    511
    );
endmodule
 /----------------------------------------------------------------------------\
 |  yosys -- Yosys Open SYnthesis Suite                                       |
 |  Copyright (C) 2012 - 2024  Claire Xenia Wolf <[email protected]>         |
 |  Distributed under an ISC-like license, type "license" to see terms        |
 \----------------------------------------------------------------------------/
 Yosys 0.44 (git sha1 80ba43d26, ccache clang 14.0.0-1ubuntu1.1 -O3 -flto -flto)

-- Executing script file `/home/rudy/.cache/concrete-python/synthesis/tmp4nj5qxj_-yosys.script' --
echo on

yosys> read -sv /home/rudy/.cache/concrete-python/synthesis/tmpxafilov_-source.verilog

yosys> read_verilog -defer -sv /home/rudy/.cache/concrete-python/synthesis/tmpxafilov_-source.verilog

1. Executing Verilog-2005 frontend: /home/rudy/.cache/concrete-python/synthesis/tmpxafilov_-source.verilog
Parsing SystemVerilog input from `/home/rudy/.cache/concrete-python/synthesis/tmpxafilov_-source.verilog' to AST representation.
Storing AST representation for module `$abstract\main'.
Successfully finished Verilog frontend.

yosys> prep

2. Executing PREP pass.

yosys> hierarchy -check

2.1. Executing HIERARCHY pass (managing design hierarchy).

2.1.1. Executing AST frontend in derive mode using pre-parsed AST for module `\main'.

Traceback (most recent call last):
  File "/home/rudy/zama/concrete/frontends/concrete-python/.venv/bin/yowasp-yosys", line 8, in <module>
    sys.exit(_run_yosys_argv())
             ^^^^^^^^^^^^^^^^^
  File "/home/rudy/zama/concrete/frontends/concrete-python/.venv/lib/python3.11/site-packages/yowasp_yosys/__init__.py", line 16, in _run_yosys_argv
    sys.exit(run_yosys(sys.argv[1:]))
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rudy/zama/concrete/frontends/concrete-python/.venv/lib/python3.11/site-packages/yowasp_yosys/__init__.py", line 11, in run_yosys
    return yowasp_runtime.run_wasm(__package__, "yosys.wasm", resources=["share"],
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rudy/zama/concrete/frontends/concrete-python/.venv/lib/python3.11/site-packages/yowasp_runtime/__init__.py", line 133, in run_wasm
    raise exception # re-raise to preserve backtrace
    ^^^^^^^^^^^^^^^
  File "/home/rudy/zama/concrete/frontends/concrete-python/.venv/lib/python3.11/site-packages/yowasp_runtime/__init__.py", line 120, in run
    app.exports(store)["_start"](store)
  File "/home/rudy/zama/concrete/frontends/concrete-python/.venv/lib/python3.11/site-packages/wasmtime/_func.py", line 91, in __call__
    with enter_wasm(store) as trap:
  File "/usr/lib/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/rudy/zama/concrete/frontends/concrete-python/.venv/lib/python3.11/site-packages/wasmtime/_func.py", line 272, in enter_wasm
    raise trap_obj
wasmtime._trap.Trap: error while executing at wasm backtrace:
    0: 0x86ffdb - <unknown>!<wasm function 13584>
    1: 0x86fa83 - <unknown>!<wasm function 13583>
    2: 0x86e118 - <unknown>!<wasm function 13577>
    3: 0xa981dd - <unknown>!<wasm function 17556>
    4: 0xa981bd - <unknown>!<wasm function 17556>
    5: 0xab6236 - <unknown>!<wasm function 17583>
    6: 0xa9fb3e - <unknown>!<wasm function 17583>
    7: 0xab7c5d - <unknown>!<wasm function 17594>
    8: 0xac47c7 - <unknown>!<wasm function 17600>
    9: 0xd6fbea - <unknown>!<wasm function 20100>
   10: 0x8c44da - <unknown>!<wasm function 14156>
   11: 0x8c3eb6 - <unknown>!<wasm function 14154>
   12: 0x8c83df - <unknown>!<wasm function 14189>
   13: 0x159f753 - <unknown>!<wasm function 26453>
   14: 0x8c8654 - <unknown>!<wasm function 14191>
   15: 0x159f3af - <unknown>!<wasm function 26452>
   16: 0x8c44da - <unknown>!<wasm function 14156>
   17: 0x8c3eb6 - <unknown>!<wasm function 14154>
   18: 0x8a3ec1 - <unknown>!<wasm function 13934>
   19: 0x889f6f - <unknown>!<wasm function 13914>
   20: 0x870f92 - <unknown>!<wasm function 13595>
   21: 0xd769 - <unknown>!<wasm function 23>

Caused by:
    0: memory fault at wasm address 0x10000000b in linear memory of size 0x9b0000
    1: wasm trap: out of bounds memory access
@whitequark
Copy link
Member

whitequark commented Aug 22, 2024

Unlimited: no.

Bigger: yes, I'll bump the stack size.

@whitequark
Copy link
Member

whitequark commented Aug 22, 2024

I want to point out that a 512 level deep unbalanced ternary expression is not "moderately deep", but rather "so deep that it will only appear in generated code, and even then rarely".

In any case, I've been looking at the Yosys stack usage and under Valgrind's DRD it appears to be 24K per nesting level, or about 2.4M per 100 levels. On Linux you have about 8M of stack total and it seems that stack use is somewhat more conservative, at about 1.5M per 100 levels. On Linux the initial 8M of stack seems to be more of an advisory than anything (it looks like you can exceed it) and the 24K per nesting level figure seems to hold.

I'll increase stack size to 8M, which should bring it roughly on par with Linux will allow you to use roughly 560 nesting levels. I think on macOS you only get 1M of stack, which is less than 100 levels deep. I'm not sure what happens on Windows.

@whitequark
Copy link
Member

I filed YosysHQ/yosys#4562 to track the rather poor performance of Yosys on such expressions.

whitequark added a commit that referenced this issue Aug 22, 2024
@whitequark
Copy link
Member

whitequark commented Aug 22, 2024

The next build of YoWASP Yosys on Test PyPI should have a stack size of 8M. Let me know if you need a backport of this change to the latest release branch (which would be Yosys 0.44).

Also, code generators typically must split expressions into multiple chunks to avoid this kind of issue. For example, Verilator does this to avoid nesting issues in C++ compilers. You will probably need to implement the same behavior, even if only to avoid the quadratic slowdown I've demonstrated in YosysHQ/yosys#4562.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants