<commit_before>'Undocumented strange behavior of storing data to r0'

import numpy as np
from textwrap import dedent

from videocore.assembler import qpu
from videocore.driver import Driver, DriverError

@qpu
def case1(asm):
    ldi(r0, 0)
    exit()

@qpu
def case2(asm):
    mov(r0, 1)
    exit()

@qpu
def case3(asm):
    mov(r1, 0)
    exit()

@qpu
def case4(asm):
    ldi(r0, [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])
    exit()

@qpu
def case5(asm):
    ldi(r0, [1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1])
    exit()

@qpu
def case6(asm):
    ldi(r1, 1)
    ldi(r2, 1)
    isub(r0, r1, r2)
    exit()

def test(prog):
    print '{} ... '.format(prog.__name__), 
    ok = True
    try:
        drv.execute(1, drv.program(prog), timeout=1)
    except:
        ok = False
    print ['\033[31mfailed.\033[39m', '\033[32mok.\033[39m'][ok]

with Driver() as drv:

    print('QPU halts when r0 of SIMD element 0 become 0')

    test(case1)
    test(case2)
    test(case3)
    test(case4)
    test(case5)
    test(case6)

    print('#### REBOOT Raspberry Pi after you run this program ####')
<commit_msg>Add comments and removed unnecessary module imports.<commit_after>'Undocumented strange behavior of storing data to r0'

from videocore.assembler import qpu
from videocore.driver import Driver

@qpu
def case1(asm)
    ldi(r0, 0)  # halt
    exit()

@qpu
def case2(asm):
    mov(r0, 1)  # does not halt
    exit()

@qpu
def case3(asm):
    mov(r1, 0)  # does not halt
    exit()

@qpu
def case4(asm):
    ldi(r0, [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])  # halt
    exit()

@qpu
def case5(asm):
    ldi(r0, [1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1])  # does not halt
    exit()

@qpu
def case6(asm):
    ldi(r1, 1)
    ldi(r2, 1)
    isub(r0, r1, r2)    # halt
    exit()

def test(prog):
    print '{} ... '.format(prog.__name__), 
    ok = True
    try:
        drv.execute(1, drv.program(prog), timeout=1)
    except:
        ok = False
    print ['\033[31mfailed.\033[39m', '\033[32mok.\033[39m'][ok]

with Driver() as drv:

    print('QPU halts when r0 of SIMD element 0 become 0')

    test(case1)
    test(case2)
    test(case3)
    test(case4)
    test(case5)
    test(case6)

    print('#### REBOOT Raspberry Pi after you run this program ####')

{'fraction_non_alphanumeric': 0.16486972147349505, 'fraction_numerical': 0.07637017070979335, 'mean_word_length': 2.9626334519572954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3494081', 'n_tokens_mistral': 1023, 'n_tokens_neox': 968, 'n_words': 231}