Skip to content

Instantly share code, notes, and snippets.

@hgomersall
hgomersall / fft_permute.py
Created July 3, 2015 16:18
FFT permutations
from veriutils import (
check_intbv_signal, check_bool_signal)
from myhdl import Signal, intbv, always_comb, always
from math import log
import numpy as np
def FFTPermute(input_siglist, output_siglist, butterfly_index,
clock_enable, clock):
@hgomersall
hgomersall / clmath_test.py
Last active August 29, 2015 14:27
cl math test
import numpy as np
import pyopencl as cl
from pyopencl import tools as cl_tools
from pyopencl import array as cl_array
from pyopencl import clmath
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
@hgomersall
hgomersall / test.c
Last active February 11, 2016 08:40
Problem code with Valgrind on ARM
#include <stdio.h>
#include <stdint.h>
#define N_SUBVALS 4
#define BOUNDARY 4
int main()
{
// The code finds the next boundary alignment for each set of of 4
from myhdl import *
class Interface(object):
def __init__(self):
self.foo = Signal(intbv(0)[20:])
self.bar = Signal(intbv(0)[20:])
@block
def Foo(a, b, c, d, e, clock):
from myhdl import *
import myhdl
class Interface(object):
def __init__(self):
self.bar = Signal(intbv(0)[4:])
@block
def block1(out_interface, foo):
@hgomersall
hgomersall / problem_with_multiple_converts.py
Last active June 15, 2016 16:28
An example of conversion problems when a signal is used in more than one conversion.
from myhdl import *
@block
def block1(clock, input_signal, output_signal):
@always(clock.posedge)
def driver():
output_signal.next = input_signal
return driver
from myhdl import *
class Interface():
def __init__(self):
self.data = Signal(False)
class HDLClass1(object):
@block
@hgomersall
hgomersall / rr_arbiter.py
Created May 16, 2018 17:52
A quick and dirty round robin arbiter in myhdl for demonstrating myhdls meta-programming capability. It's not tested, but shows the principles.
from myhdl import *
@block
def grant_selector(request, grant, request_bit):
if request_bit == 0:
@always_comb
def selector():
grant.next = request[request_bit]
@hgomersall
hgomersall / packet.h
Last active November 23, 2018 13:33
Simple networking
#ifndef CURIOUS_NETWORKING_H
#define CURIOUS_NETWORKING_H
static const size_t packet_len = 1395;
static const char packet[] = {
0x31, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x33, 0x2c, 0x20, 0x34, 0x2c, 0x20,
0x35, 0x2c, 0x20, 0x36, 0x2c, 0x20, 0x37, 0x2c, 0x20, 0x38, 0x2c, 0x20,
0x39, 0x2c, 0x20, 0x31, 0x30, 0x2c, 0x20, 0x31, 0x31, 0x2c, 0x20, 0x31,
0x32, 0x2c, 0x20, 0x31, 0x33, 0x2c, 0x20, 0x31, 0x34, 0x2c, 0x20, 0x31,
0x35, 0x2c, 0x20, 0x31, 0x36, 0x2c, 0x20, 0x31, 0x37, 0x2c, 0x20, 0x31,
@hgomersall
hgomersall / empty_aligned.py
Created January 9, 2020 15:48
Simple pure python function to return an empty n-byte-aligned array.
import numpy as np
def empty_aligned(shape, dtype='float64', order='C', n=None):
'''empty_aligned(shape, dtype='float64', order='C', n=None)
Function that returns an empty numpy array that is n-byte aligned,
where ``n`` is determined by inspecting the CPU if it is not
provided.
The alignment is given by the final optional argument, ``n``. If ``n`` is
not set then the default alignment is used.
The rest of the arguments are as per :func:`numpy.empty`.