Example #1
0
  /**
   *
   *
   * <pre>
   * always @(posedge clk)
   * begin
   *   if (hangTimer > 150) begin
   *    $fwrite(resultFile, "FAIL: Hang Timer Expired\n");
   *    $finish;
   * end
   *
   * if (foo_go || foo_done || bar_go || bar_done) hangTimer <= 0;
   * else hangTimer <= hangTimer + 1;
   * </pre>
   */
  private void stateTimer(Module module, SimFileHandle resFile, StateMachine mach) {
    Option op = EngineThread.getGenericJob().getOption(OptionRegistry.HANG_TIMER);
    int HANGTIMER = Integer.parseInt(op.getValue(CodeLabel.UNSCOPED).toString(), 10);

    SequentialBlock trueBlock = new SequentialBlock();

    // Hang timer expiry

    FStatement.FWrite write =
        new FStatement.FWrite(
            resFile.getHandle(), new StringStatement("FAIL: Hang Timer Expired\\n"));
    trueBlock.add(write);
    trueBlock.add(new FStatement.Finish());

    ConditionalStatement cs =
        new ConditionalStatement(
            new Compare.GT(getHangTimer(), new Constant(HANGTIMER, getHangTimer().getWidth())),
            trueBlock);

    SequentialBlock block = new SequentialBlock(cs);

    // Hang timer increment
    // List goDone = new ArrayList();
    // for (Iterator iter = this.taskHandles.iterator(); iter.hasNext();)
    // {
    // TaskHandle th = (TaskHandle)iter.next();
    // goDone.add(th.getGoWire());
    // goDone.add(th.getDoneWire());
    // }

    Assign htReset =
        new Assign.NonBlocking(getHangTimer(), new Constant(0, getHangTimer().getWidth()));
    Assign htInc =
        new Assign.NonBlocking(
            getHangTimer(),
            new org.xronos.openforge.verilog.model.Math.Add(
                getHangTimer(), new Constant(1, getHangTimer().getWidth())));
    // ConditionalStatement htCond = new ConditionalStatement(
    // new OrMany(goDone), htReset, htInc);
    ConditionalStatement htCond =
        new ConditionalStatement(
            new Logical.Or(mach.getAllGoWire(), mach.getAllDoneWire()), htReset, htInc);
    block.add(htCond);

    ProceduralTimingBlock ptb =
        new ProceduralTimingBlock(
            new EventControl(new EventExpression.PosEdge(mach.getClock())), block);

    module.state(new Always(ptb));
  }
Example #2
0
  public void stateLogic(Module module, StateMachine mach, Design design) {
    /*
     * if(allGos) begin <statements> end
     */
    SequentialBlock AllGos = new SequentialBlock();
    ConditionalStatement ifAllGos = new ConditionalStatement(mach.getAllGoWire(), AllGos);

    // benchNumReads = benchNumReads + 1; //
    AllGos.add(
        new Assign.Blocking(
            benchNumReads,
            new org.xronos.openforge.verilog.model.Math.Add(
                benchNumReads, new Constant(1, benchNumReads.getWidth()))));
    // benchInReadZone = 1; //
    AllGos.add(new Assign.Blocking(benchInReadZone, new Constant(1, benchInReadZone.getWidth())));

    /*
     * if(benchWorkInProgress === 0) begin benchWorkInProgress = 1;
     * benchFirstReadCycle = benchClockCount ; end
     */
    SequentialBlock bwp = new SequentialBlock();
    bwp.add(new Assign.Blocking(benchWorkInProgress, new Constant(1, benchInReadZone.getWidth())));
    bwp.add(new Assign.Blocking(benchFirstReadCycle, benchClockCount));

    Compare.EQ eq1 =
        new Compare.EQ(benchWorkInProgress, new Constant(0, benchWorkInProgress.getWidth()));
    ConditionalStatement ifbwp = new ConditionalStatement(eq1, bwp);
    AllGos.add(ifbwp);

    // benchReadZoneCyclesCounterSave = benchReadZoneCyclesCounter;
    AllGos.add(new Assign.Blocking(benchReadZoneCyclesCounterSave, benchReadZoneCyclesCounter));
    // benchCoreCyclesCounter = 0;
    AllGos.add(
        new Assign.Blocking(
            benchCoreCyclesCounter, new Constant(0, benchCoreCyclesCounter.getWidth())));

    /*
     * if(benchInWriteZone === 1) begin benchWriteZoneCycles =
     * benchWriteZoneCycles + benchWrietZoneCyclesCounterSave + 1;
     * benchWriteZoneCYlcesCounter = 0; benchInWriteZone = 0; end
     */
    SequentialBlock bwz = new SequentialBlock();
    bwz.add(
        new Assign.Blocking(
            benchWriteZoneCycles,
            new Math.Add(
                new Math.Add(benchWriteZoneCycles, benchWriteZoneCyclesCounterSave),
                new Constant(1, 32))));
    bwz.add(
        new Assign.Blocking(
            benchWriteZoneCyclesCounter, new Constant(0, benchWriteZoneCyclesCounter.getWidth())));
    bwz.add(new Assign.Blocking(benchInWriteZone, new Constant(0, benchInWriteZone.getWidth())));
    Compare.EQ eq2 = new Compare.EQ(benchInWriteZone, new Constant(1, benchInWriteZone.getWidth()));
    ConditionalStatement ifbwz = new ConditionalStatement(eq2, bwz);
    AllGos.add(ifbwz);

    /*
     * if(benchIdleFlag == 1) begin benchIdleCycles = benchIdleCycles +
     * benchIdleCyclesCounter - 1; benchIdleFlag = 0; end
     */
    SequentialBlock bif = new SequentialBlock();
    bif.add(
        new Assign.Blocking(
            benchIdleCycles,
            new Math.Subtract(
                new Math.Add(benchIdleCycles, benchIdleCyclesCounter),
                new Constant(1, benchIdleCycles.getWidth()))));
    bif.add(new Assign.Blocking(benchIdleFlag, new Constant(0, benchIdleFlag.getWidth())));
    Compare.EQ eq3 = new Compare.EQ(benchIdleFlag, new Constant(1, benchIdleFlag.getWidth()));
    ConditionalStatement ifbif = new ConditionalStatement(eq3, bif);
    AllGos.add(ifbif);

    /*
     * if(allDones) begin <statements> end
     */
    SequentialBlock AllDones = new SequentialBlock();
    ConditionalStatement ifAllDones = new ConditionalStatement(mach.getAllDoneWire(), AllDones);

    // benchNumWrites = benchNumWrites + 1; //
    AllDones.add(
        new Assign.Blocking(
            benchNumWrites,
            new Math.Add(benchNumWrites, new Constant(1, benchNumWrites.getWidth()))));
    // benchInWriteZone = 1; //
    AllDones.add(
        new Assign.Blocking(benchInWriteZone, new Constant(1, benchInWriteZone.getWidth())));

    /*
     * if(benchInReadZone === 1) begin benchReadZoneCycles =
     * benchReadZoneCycles + benchReadZoneCyclesCounterSave + 1;
     * benchReadZoneCyclesCounter = 0; benchInReadZone = 0;
     * benchWriteZoneCyclesCounter = 0; benchCoreCycles = benchCoreCycles +
     * benchCoreCyclesCounetr end
     */
    SequentialBlock brz = new SequentialBlock();
    brz.add(
        new Assign.Blocking(
            benchReadZoneCycles,
            new Math.Add(
                new Math.Add(benchReadZoneCycles, benchReadZoneCyclesCounterSave),
                new Constant(1, benchReadZoneCycles.getWidth()))));
    brz.add(
        new Assign.Blocking(
            benchReadZoneCyclesCounter, new Constant(0, benchReadZoneCyclesCounter.getWidth())));
    brz.add(new Assign.Blocking(benchInReadZone, new Constant(0, benchInReadZone.getWidth())));
    brz.add(
        new Assign.Blocking(
            benchWriteZoneCyclesCounter, new Constant(0, benchWriteZoneCyclesCounter.getWidth())));
    brz.add(
        new Assign.Blocking(
            benchCoreCycles, new Math.Add(benchCoreCycles, benchCoreCyclesCounter)));
    Compare.EQ eq4 = new Compare.EQ(benchInReadZone, new Constant(1, benchInReadZone.getWidth()));
    ConditionalStatement ifbrz = new ConditionalStatement(eq4, brz);
    AllDones.add(ifbrz);

    /*
     * if(allGos==1) begin benchCoreCycles = benchCoreCycles + 1; end
     */
    AllDones.add(
        new ConditionalStatement(
            new Compare.EQ(mach.getAllGoWire(), new Constant(1, 1)),
            new Assign.Blocking(
                benchCoreCycles,
                new Math.Add(benchCoreCycles, new Constant(1, benchCoreCycles.getWidth())))));

    // benchWriteZoneCyclesCounterSave = benchWriteZoneCyclesCounter;
    AllDones.add(new Assign.Blocking(benchWriteZoneCyclesCounterSave, benchWriteZoneCyclesCounter));
    // benchLastWriteCycle = benchClockCount + 1;
    AllDones.add(
        new Assign.Blocking(
            benchLastWriteCycle,
            new Math.Add(benchClockCount, new Constant(1, benchClockCount.getWidth()))));
    // benchIdleFlag = 1;
    AllDones.add(new Assign.Blocking(benchIdleFlag, new Constant(1, benchIdleFlag.getWidth())));
    // benchIdleCyclesCounter = 0;
    AllDones.add(
        new Assign.Blocking(
            benchIdleCyclesCounter, new Constant(0, benchIdleCyclesCounter.getWidth())));

    /*
     * if(done) begin <statements> end
     */
    SequentialBlock done = new SequentialBlock();
    ConditionalStatement ifdone = new ConditionalStatement(mach.getDone(), done);

    // benchWriteZoneCycles = benchWriteZoneCycles +
    // benchWriteZoneCyclesCounterSave + 1;
    done.add(
        new Assign.Blocking(
            benchWriteZoneCycles,
            new Math.Add(
                new Math.Add(benchWriteZoneCycles, benchWriteZoneCyclesCounterSave),
                new Constant(1, benchWriteZoneCycles.getWidth()))));
    // benchTotalCycles = benchLastWriteCycle - benchFirstReadCycle;
    done.add(
        new Assign.Blocking(
            benchTotalCycles, new Math.Subtract(benchLastWriteCycle, benchFirstReadCycle)));

    // Find the number of input bytes and number of outputbytes //
    Collection<Task> tasks = design.getTasks();
    // System.out.println("Number of tasks = " + tasks.size());
    int inputsize = 0, outputsize = 0;
    Iterator<Task> iter = tasks.iterator();
    while (iter.hasNext()) {
      Task task = iter.next();
      Call call = task.getCall();

      for (Port port : call.getDataPorts()) {
        inputsize += port.getSize();
      }

      // System.out.println("Input Size Bits = " + inputsize);

      for (Bus bus : call.getExit(Exit.DONE).getDataBuses()) {
        outputsize += bus.getSize();
      }

      // System.out.println("Output Size Bits = " + outputsize);
    }
    Constant benchArgSizeBytes = new Constant(inputsize / 8, 32);
    Constant benchResSizeBytes = new Constant(outputsize / 8, 32);

    Constant hunderd = new Constant(100, 32);

    // benchThroughput = (benchNumReads *
    // benchArgSizeBits/8.0)/(benchTotalCycles);
    done.add(
        new Assign.Blocking(
            benchThroughput,
            new Math.Divide(
                new Math.Multiply(benchNumReads, benchArgSizeBytes), benchTotalCycles)));
    // benchOverallInputUtil = (benchNumReads / benchTotalCycles) * 100.0;
    done.add(
        new Assign.Blocking(
            benchOverallInputUtil,
            new Math.Multiply(new Math.Divide(benchNumReads, benchTotalCycles), hunderd)));

    // benchOverallOutputUtil = (benchNumWrites / benchTotalCycles) * 100.0;
    done.add(
        new Assign.Blocking(
            benchOverallOutputUtil,
            new Math.Multiply(new Math.Divide(benchNumWrites, benchTotalCycles), hunderd)));

    // benchOverallCoreUtil = (benchCoreCycles / benchTotalCycles) * 100.0;
    done.add(
        new Assign.Blocking(
            benchOverallCoreUtil,
            new Math.Multiply(new Math.Divide(benchCoreCycles, benchTotalCycles), hunderd)));

    // benchIdlePercentage = (benchIdleCycles / benchTotalCycles) * 100.0;
    done.add(
        new Assign.Blocking(
            benchIdlePercentage,
            new Math.Multiply(new Math.Divide(benchIdleCycles, benchTotalCycles), hunderd)));

    // benchZoneInputUtil = (benchNumReads/benchReadZoneCycles) * 100.0;
    done.add(
        new Assign.Blocking(
            benchZoneInputUtil,
            new Math.Multiply(new Math.Divide(benchNumReads, benchReadZoneCycles), hunderd)));

    // benchZoneOutputUtil = (benchNumWrites/benchWriteZoneCycles) * 100.0;
    done.add(
        new Assign.Blocking(
            benchZoneOutputUtil,
            new Math.Multiply(new Math.Divide(benchNumWrites, benchWriteZoneCycles), hunderd)));

    // benchZoneCoreUtil = (benchCoreCycles/benchCoreCycles) * 100.0;
    done.add(
        new Assign.Blocking(
            benchZoneCoreUtil,
            new Math.Multiply(new Math.Divide(benchCoreCycles, benchCoreCycles), hunderd)));

    // WUSIWUG ! //
    CommaDelimitedStatement cds = new CommaDelimitedStatement();
    cds.append(
        new StringStatement("**********************************************************\\n"));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    cds = new CommaDelimitedStatement();
    cds.append(
        new StringStatement("******************** BENCHMARK REPORT ********************\\n"));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    cds = new CommaDelimitedStatement();
    cds.append(
        new StringStatement("**********************************************************\\n"));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Total Number of Cycles               : %0d\n", benchClockCount);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Total Number of Cycles               : %0d\\n"));
    cds.append(benchClockCount);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Data Crunching Cycles                : %0d\n", benchTotalCycles);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Data Crunching Cycles                : %0d\\n"));
    cds.append(benchTotalCycles);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Number of Idle Cycles                : %0d\n", benchIdleCycles);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Number of Idle Cycles                : %0d\\n"));
    cds.append(benchIdleCycles);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Number of Reads                      : %0d\n", benchNumReads);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Number of Reads                      : %0d\\n"));
    cds.append(benchNumReads);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Bytes Consumed                       : %0g\n", benchNumReads *
    // benchArgSizeBits/8.0);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Bytes Consumed                       : %0d\\n"));
    cds.append(new Math.Multiply(benchNumReads, benchArgSizeBytes));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Number of Writes                     : %0d\n", benchNumWrites);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Number of Writes                     : %0d\\n"));
    cds.append(benchNumWrites);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Bytes Produced                       : %0g\n", benchNumWrites *
    // benchResSizeBits/8.0);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Bytes Produced                       : %0d\\n"));
    cds.append(new Math.Multiply(benchNumWrites, benchResSizeBytes));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "First Read Cycle                     : %0d\n", benchFirstReadCycle);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("First Read Cycle                     : %0d\\n"));
    cds.append(benchFirstReadCycle);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Last Write Cycle                     : %0d\n", benchLastWriteCycle);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Last Write Cycle                     : %0d\\n"));
    cds.append(benchLastWriteCycle);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Throughput(Bytes Consumed/Cycle)     : %0g\n", benchThroughput);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Throughput(Bytes Consumed/Cycle)     : %0g\\n"));
    cds.append(benchThroughput);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "****** Overall *******************************************\n");
    cds = new CommaDelimitedStatement();
    cds.append(
        new StringStatement("****** Overall *******************************************\\n"));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    // $fwrite (benchmarkReportFile,
    // "Overall Input Link Utilization       : %0g\n",
    // benchOverallInputUtil);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Overall Input Link Utilization       : %0g\\n"));
    cds.append(benchOverallInputUtil);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "Overall Core Utilization             : %0g\n",
    // benchOverallCoreUtil);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Overall Core Utilization             : %0g\\n"));
    cds.append(benchOverallCoreUtil);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "Overall Output Link Utilization      : %0g\n",
    // benchOverallOutputUtil);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Overall Output Link Utilization      : %0g\\n"));
    cds.append(benchOverallOutputUtil);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "Percentage of Idle Cycles            : %0g\n", benchIdlePercentage);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Percentage of Idle Cycles            : %0g\\n"));
    cds.append(benchIdlePercentage);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "******** Zonal *******************************************\n");
    cds = new CommaDelimitedStatement();
    cds.append(
        new StringStatement("******** Zonal *******************************************\\n"));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "Zone Input Link Utilization          : %0g\n", benchZoneInputUtil);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Zone Input Link Utilization          : %0g\\n"));
    cds.append(benchZoneInputUtil);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "Zone Core Utilization                : %0g\n", benchZoneCoreUtil);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Zone Core Utilization                : %0g\\n"));
    cds.append(benchZoneCoreUtil);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "Zone Output Link Utilization         : %0g\n", benchZoneOutputUtil);
    cds = new CommaDelimitedStatement();
    cds.append(new StringStatement("Zone Output Link Utilization         : %0g\\n"));
    cds.append(benchZoneOutputUtil);
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));
    // $fwrite (benchmarkReportFile,
    // "**********************************************************\n");
    cds = new CommaDelimitedStatement();
    cds.append(
        new StringStatement("**********************************************************\\n"));
    done.add(new FStatement.FWrite(reportFile.getHandle(), cds));

    SequentialBlock sblock = new SequentialBlock();
    sblock.add(ifAllGos);
    sblock.add(ifAllDones);
    sblock.add(ifdone);

    // benchClockCount = benchClockCount + 1;
    sblock.add(
        new Assign.Blocking(
            benchClockCount,
            new Math.Add(benchClockCount, new Constant(1, benchClockCount.getWidth()))));
    // benchIdleCyclesCounter = benchIdleFlag == 1 ? benchIdleCyclesCounter
    // + 1 : benchIdleCyclesCounter;
    sblock.add(
        new ConditionalStatement(
            new Compare.EQ(benchIdleFlag, new Constant(1, benchIdleFlag.getWidth())),
            new Assign.Blocking(
                benchIdleCyclesCounter,
                new Math.Add(
                    benchIdleCyclesCounter, new Constant(1, benchIdleCyclesCounter.getWidth()))),
            new Assign.Blocking(benchIdleCyclesCounter, benchIdleCyclesCounter)));
    // benchCoreCyclesCounter = benchCoreCyclesCounter + 1;
    sblock.add(
        new Assign.Blocking(
            benchCoreCyclesCounter,
            new Math.Add(
                benchCoreCyclesCounter, new Constant(1, benchCoreCyclesCounter.getWidth()))));
    // benchReadZoneCyclesCounter = benchInReadZone == 1 ?
    // benchReadZoneCyclesCounter + 1 : benchReadZoneCyclesCounter;
    sblock.add(
        new ConditionalStatement(
            new Compare.EQ(benchInReadZone, new Constant(1, benchInReadZone.getWidth())),
            new Assign.Blocking(
                benchReadZoneCyclesCounter,
                new Math.Add(
                    benchReadZoneCyclesCounter,
                    new Constant(1, benchReadZoneCyclesCounter.getWidth()))),
            new Assign.Blocking(benchReadZoneCyclesCounter, benchReadZoneCyclesCounter)));
    // benchWriteZoneCyclesCounter = benchInWriteZone == 1 ?
    // benchWriteZoneCyclesCounter + 1 : benchWriteZoneCyclesCounter;
    sblock.add(
        new ConditionalStatement(
            new Compare.EQ(benchInWriteZone, new Constant(1, benchInWriteZone.getWidth())),
            new Assign.Blocking(
                benchWriteZoneCyclesCounter,
                new Math.Add(
                    benchWriteZoneCyclesCounter,
                    new Constant(1, benchWriteZoneCyclesCounter.getWidth()))),
            new Assign.Blocking(benchWriteZoneCyclesCounter, benchWriteZoneCyclesCounter)));

    ProceduralTimingBlock ptb =
        new ProceduralTimingBlock(
            new EventControl(new EventExpression.PosEdge(mach.getClock())), sblock);

    module.state(new Always(ptb));
  }