예제 #1
0
  def gen_mem_image():

    # text section

    text = """
    # load array pointers
    csrr  x1, mngr2proc < 100
    csrr  x2, mngr2proc < 0x2000
    csrr  x3, mngr2proc < 0x3000
    csrr  x4, mngr2proc < 0x4000
    add   x5, x0, x1

    # main loop
  loop:
    lw    x6,   0(x2)
    lw    x7,   4(x2)
    lw    x8,   8(x2)
    lw    x9,  12(x2)
    lw    x10,  0(x3)
    lw    x11,  4(x3)
    lw    x12,  8(x3)
    lw    x13, 12(x3)
    add   x6, x6, x10
    add   x7, x7, x11
    add   x8, x8, x12
    add   x9, x9, x13
    sw    x6,   0(x4)
    sw    x7,   4(x4)
    sw    x8,   8(x4)
    sw    x9,  12(x4)
    addi  x5, x5, -4
    addi  x2, x2, 16
    addi  x3, x3, 16
    addi  x4, x4, 16
    bne   x5, x0, loop

    # end of the program
    csrw  proc2mngr, x0 > 0
    nop
    nop
    nop
    nop
    nop
    nop
"""

    mem_image = assemble( text )

    # load data by manually create data sections using binutils

    src0_section = mk_section( ".data", c_vvadd_src0_ptr, src0 )

    src1_section = mk_section( ".data", c_vvadd_src1_ptr, src1 )

    # load data

    mem_image.add_section( src0_section )
    mem_image.add_section( src1_section )

    return mem_image
예제 #2
0
def run_test(ProcModel,
             gen_test,
             dump_vcd=None,
             src_delay=0,
             sink_delay=0,
             mem_stall_prob=0,
             mem_latency=0,
             max_cycles=10000,
             print_trace=True,
             ref_output=None,
             num_regs=0):

    # Instantiate and elaborate the model

    model = TestHarness(ProcModel, dump_vcd, src_delay, sink_delay,
                        mem_stall_prob, mem_latency, ref_output, num_regs)

    model.vcd_file = dump_vcd
    model.elaborate()

    # Assemble the test program

    mem_image = assemble(gen_test())

    # Load the program into the model

    model.load(mem_image)

    # Create a simulator using the simulation tool

    sim = SimulationTool(model)

    # Run the simulation

    print()

    sim.reset()
    while not model.done() and sim.ncycles < max_cycles:
        if print_trace:
            sim.print_line_trace()
        sim.cycle()

    # print the very last line trace after the last tick

    if print_trace:
        sim.print_line_trace()

    # Force a test failure if we timed out

    assert sim.ncycles < max_cycles

    # Add a couple extra ticks so that the VCD dump is nicer

    sim.cycle()
    sim.cycle()
    sim.cycle()

    model.cleanup()
예제 #3
0
    def gen_mem_image():

        # text section

        text = """
    # load array pointers
    csrr  x1, mngr2proc < 200
    csrr  x2, mngr2proc < 0x2000
    csrr  x3, mngr2proc < 0x3000
    csrr  x4, mngr2proc < 0x4000
    addi  x5, x0, 0

  loop:
    lw    x6, 0(x2)    # src0_real
    lw    x8, 0(x3)    # src1_real
    lw    x7, 4(x2)    # src0_imag
    lw    x9, 4(x3)    # src1_imag
    mul   x10, x6, x8  # real * real
    mul   x11, x7, x9  # imag * imag
    mul   x12, x7, x8  # imag * real
    mul   x13, x6, x9  # real * imag
    sub   x14, x10,x11 # dest_real
    add   x15, x12,x13 # dest_imag
    addi  x5, x5, 2
    addi  x2, x2, 8
    addi  x3, x3, 8
    sw    x14, 0(x4)
    sw    x15, 4(x4)
    addi  x4, x4, 8
    bne   x5, x1, loop

    # end of the program
    csrw  proc2mngr, x0 > 0
    nop
    nop
    nop
    nop
    nop
    nop
"""

        mem_image = assemble(text)

        # load data by manually create data sections using binutils

        src0_section = mk_section(".data", c_cmplx_mult_src0_ptr, src0)

        mem_image.add_section(src0_section)

        src1_section = mk_section(".data", c_cmplx_mult_src1_ptr, src1)

        mem_image.add_section(src1_section)

        return mem_image
예제 #4
0
  def gen_mem_image():

    # text section

    text = \
           """
           # load array pointers
           csrr  x1, mngr2proc < 100
           csrr  x2, mngr2proc < 0x2000
           csrr  x3, mngr2proc < 0x3000
           csrr  x4, mngr2proc < 0x4000
           add   x5, x0, x1

         loop:
           lw    x6, 0(x2)
           lw    x7, 0(x3)
           add   x8, x6, x7
           sw    x8, 0(x4)
           addi  x2, x2, 4
           addi  x3, x3, 4
           addi  x4, x4, 4
           addi  x5, x5, -1
           bne   x5, x0, loop

           # end of the program
           csrw  proc2mngr, x0 > 0
           nop
           nop
           nop
           nop
           nop
           nop
           """

    mem_image = assemble( text )

    # load data by manually create data sections using binutils

    src0_section = mk_section( ".data", c_vvadd_src0_ptr, src0 )
    src1_section = mk_section( ".data", c_vvadd_src1_ptr, src1 )

    # load data

    mem_image.add_section( src0_section )
    mem_image.add_section( src1_section )

    return mem_image
예제 #5
0
    def gen_mem_image():

        # text section

        text = """

    csrr  x4, mngr2proc < 0x2000
    csrr  x5, mngr2proc < 0x3000
    csrr  x6, mngr2proc < 0x4000
    csrr  x7, mngr2proc < 10
    csrr  x8, mngr2proc < 10

    addi  x24, x0, 64   # coeff0
    addi  x25, x0, 48   # coeff1

    # Assume that nrows and ncols are positive and otherwise well-behaved
    addi  x2, x7, -1    # end condition nrows
    addi  x3, x8, -1    # end condition ncols

    addi  x9, x0, 1     # ridx starts at 1
                        # zero: row loop
  zero:
    addi  x10, x0, 1
    # one: col loop
    # Calculate mask index
  one:
    mul   x11, x8, x9   # ridx*ncols
    add   x11, x11, x10 # ridx*ncols + cidx
    slli  x11, x11, 2   # ridx*ncols + cidx (pointer)
    add   x12, x5, x11  # ridx*ncols + cidx (pointer) for mask
    lw    x12, 0(x12)   # mask[ridx*ncols + cidx]

    # If block
    # if ( !mask[ridx*ncols + cidx] ) goto two:
    beq   x12, x0, two

    add   x12, x6, x11  # ridx*ncols + cidx (pointer) for src
    lw    x13, 0(x12)   # src[ridx*ncols + cidx]
    mul   x13, x13, x24 # src[ridx*ncols + cidx] * coeff0
    add   x23, x13, x0  # out = src[ridx*ncols + cidx] * coeff0

    lw    x13, 4(x12)   # src[ridx*ncols + (cidx+1)]
    mul   x13, x13, x25 # src[ridx*ncols + (cidx+1)] * coeff1
    add   x23, x23, x13 # out += src[ridx*ncols + (cidx+1)] * coeff1

    lw    x13, -4(x12)  # src[ridx*ncols + (cidx-1)]
    mul   x13, x13, x25 # src[ridx*ncols + (cidx-1)] * coeff1
    add   x23, x23, x13 # out += src[ridx*ncols + (cidx-1)] * coeff1

    addi  x22, x9, 1    # ridx+1
    mul   x12, x8, x22  # (ridx+1)*ncols
    add   x12, x12, x10 # (ridx+1)*ncols + cidx
    slli  x12, x12, 2   # (ridx+1)*ncols + cidx (pointer)
    add   x13, x6, x12  # (ridx+1)*ncols + cidx (pointer) for src
    lw    x13, 0(x13)   # src[(ridx+1)*ncols + cidx]
    mul   x14, x13, x25 # src[(ridx+1)*ncols + cidx] * coeff1
    add   x23, x23, x14 # out += src[(ridx+1)*ncols + cidx] * coeff1

    addi  x22, x9, -1   # ridx-1
    mul   x12, x8, x22  # (ridx-1)*ncols
    add   x12, x12, x10 # (ridx-1)*ncols + cidx
    slli  x12, x12, 2   # (ridx-1)*ncols + cidx (pointer)
    add   x13, x6, x12  # (ridx-1)*ncols + cidx (pointer) for src
    lw    x13, 0(x13)   # src[(ridx-1)*ncols + cidx]
    mul   x14, x13, x25 # src[(ridx-1)*ncols + cidx] * coeff1
    add   x23, x23, x14 # out += src[(ridx-1)*ncols + cidx] * coeff1

    add   x12, x4, x11  # ridx*ncols + cidx (pointer) for dest
    srai  x23, x23, 8   # out >>= shamt
    sw    x23, 0(x12)   # dest[ridx*ncols + cidx] = out
    jal   x0, three         # End of if block, goto three:

    # Else block
  two:
    add   x12, x6, x11  # ridx*ncols + cidx (pointer) for src
    lw    x13, 0(x12)   # src[ridx*ncols + cidx]
    add   x14, x4, x11  # ridx*ncols + cidx (pointer) for dest
    sw    x13, 0(x14)   # dest[ridx*ncols + cidx] = src[ridx*ncols + cidx]

  three:
    addi  x10, x10, 1   # cidx++
    bne   x10, x3, one  # if ( cidx != ncols - 1 ) goto one:
    addi  x9, x9, 1     # ridx++
    bne   x9, x2, zero  # if ( ridx != nrows - 1 ) goto zero:

    csrw  proc2mngr, x0 > 0
    nop
    nop
    nop
    nop
    nop
    nop
"""

        mem_image = assemble(text)

        # load data by manually create data sections using binutils

        src_section = mk_section(".data", c_masked_filter_src_ptr, src)

        mem_image.add_section(src_section)

        mask_section = mk_section(".data", c_masked_filter_mask_ptr, mask)

        mem_image.add_section(mask_section)

        return mem_image
    def gen_mem_image():

        # text section

        text = """
    # load array pointers
    csrr  x1, mngr2proc < 0x2000
    csrr  x2, mngr2proc < 0x3000
    csrr  x3, mngr2proc < 20
    csrr  x4, mngr2proc < 0x4000
    csrr  x5, mngr2proc < 0x5000
    csrr  x6, mngr2proc < 50

    addi  x7, x0, 0      # loop counter i is in x7

  zero:
    slli  x25, x7, 2     # multiply by 4 to get i in the index form

    add   x9, x1, x25    # pointer to i in srch_keys
    lw    x9, 0(x9)      # key = srch_keys[i]
    addi  x10, x0, 0     # idx_min
    srai  x11, x6, 1     # idx_mid = dict_sz/2
    addi  x12, x6, -1    # idx_max = (dict_sz-1)
    addi  x13, x0, 0     # done = false

    addi  x14, x0, -1    # -1
    add   x15, x2, x25   # i pointer in srch_values
    sw    x14, 0(x15)    # srch_values[i] = -1

  one:
    slli  x24, x11, 2    # idx_mid in pointer form
    add   x16, x4, x24   # idx_mid pointer in dict_keys
    lw    x17, 0(x16)    # midkey = dict_keys[idx_mid]

    bne   x9, x17, two   #  if ( key == midkey ) goto two:

    # if block starts
    add   x16, x5, x24   # idx_mid pointer in dict_values
    lw    x18, 0(x16)    # dict_values[idx_mid]
    add   x15, x2, x25   # i pointer in srch_values
    sw    x18, 0(x15)    # srch_values[i] = dict_values[idx_mid]
    addi  x13, x0, 1     # done = true
    # if block ends

  two:
    slt   x18, x17, x9   # midkey < key
    beq   x18, x0, three # if ( midkey < key ) goto three

                         # if block for midkey < key
    addi  x10, x11, 1    # idx_min = idx_mid + 1
    jal   x0, four   # if ( midkey > key ) goto four:
    # end of if block

    # else block
  three:
    slt   x18, x9, x17   # if midkey > key
    beq   x18, x0, four  # if ( midkey > key ) goto four:
    # if block for midkey > key
    addi  x12, x11, -1   # idx_max = idx_mid - 1
    # end of if block

  four:
    add   x20, x10, x12  # idx_min + idx_max
    srai  x11, x20, 1    # idx_mid = ( idx_min + idx_max ) / 2

    slt   x21, x12, x10  # idx_max < idx_min
    or    x22, x21, x13  # done || (idx_max < idx_min)
    # while
    # ( !(done || (idx_max < idx_min)) )
    # goto one:
    beq   x22, x0, one

    addi  x7, x7, 1     # i++
    bne   x7, x3, zero   # if (i < srch_sz) goto 0:

    # end of the program
    csrw  proc2mngr, x0 > 0
    nop
    nop
    nop
    nop
    nop
    nop

"""

        mem_image = assemble(text)

        # load data by manually create data sections using binutils

        d_keys_section = mk_section(".data", c_bin_search_d_keys_ptr, d_keys)

        mem_image.add_section(d_keys_section)

        d_values_section = mk_section(".data", c_bin_search_d_values_ptr,
                                      d_values)

        mem_image.add_section(d_values_section)

        s_keys_section = mk_section(".data", c_bin_search_s_keys_ptr, s_keys)

        mem_image.add_section(s_keys_section)

        return mem_image