OpenCores
URL https://opencores.org/ocsvn/mcs-4/mcs-4/trunk

Subversion Repositories mcs-4

[/] [mcs-4/] [trunk/] [rtl/] [verilog/] [common/] [functions.vh] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 rrpollack
////////////////////////////////////////////////////////////////////////
2
//
3
// MCS-4 common useful functions
4
//
5
// This file contains a set of useful functions used by other
6
// MCS-4 emulation modules.
7
//
8
// This file is part of the MCS-4 project hosted at OpenCores:
9
//      http://www.opencores.org/cores/mcs-4/
10
//
11
// Copyright © 2021 by Reece Pollack <rrpollack@opencores.org>
12
//
13
// These materials are provided under the Creative Commons
14
// "Attribution-NonCommercial-ShareAlike" (CC BY-NC-SA) Public License.
15
// They are NOT "public domain", and are protected by copyright.
16
//
17
// This work based on materials provided by Intel Corporation and
18
// others under the same license. See the file doc/License for
19
// details of this license.
20
//
21
////////////////////////////////////////////////////////////////////////
22
 
23
    //
24
    // Calculate integer ceil(log2(value))
25
    //
26
    // This is useful for determining the width of a register
27
    // required to hold the specified value.
28
    //
29
    // The implementation of $clog2() in iSim is FUBAR. This
30
    // performs the same function, except it actually works.
31
    //
32
    function integer clog2 (
33
        input integer value
34
    );
35
        integer bits;
36
        begin
37
            value = value - 1;
38
            for (bits = 0; value > 0; bits = bits + 1)
39
                value = value >> 1;
40
            clog2 = bits;
41
        end
42
    endfunction
43
 
44
    //
45
    // Convert Nanoseconds to Cycles
46
    //
47
    // This converts nanoseconds to cycles, rounded up. This
48
    // implementation assumes SYSCLK_TCY is already defined.
49
    //
50
    function integer nstocy (
51
        input integer ns
52
    );
53
        begin
54
            nstocy = (ns + (SYSCLK_TCY - 1)) / SYSCLK_TCY;
55
        end
56
    endfunction
57
 
58
    //
59
    // Calculate a Base-2 ceiling
60
    //
61
    function integer ceil2 (
62
        input integer value,
63
        input integer step
64
    );
65
        begin
66
            ceil2 = (value + (step - 1)) & ~(step - 1);
67
        end
68
    endfunction

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.