OpenCores
URL https://opencores.org/ocsvn/versatile_library/versatile_library/trunk

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [misc/] [VersatileCounter.class.php] - Blame information for rev 86

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 47 unneback
<?php
2
 
3
class VersatileCounter {
4
 
5
    static $masks = array(
6
 
7
         => 0x3,
8
         => 0x6,
9
         => 0xC,
10
         => 0x14,
11
         => 0x30,
12
         => 0x60,
13
         => 0xB8,
14
         => 0x110,
15
        10 => 0x240,
16
        11 => 0x500,
17
        12 => 0x829,
18
        13 => 0x100C,
19
        14 => 0x2015,
20
        15 => 0x6000,
21
        16 => 0xD008,
22
        17 => 0x12000,
23
        18 => 0x20400,
24
        19 => 0x40023,
25
        20 => 0x90000,
26
        21 => 0x140000,
27
        22 => 0x300000,
28
        23 => 0x420000,
29
        24 => 0xE10000,
30
        25 => 0x1200000,
31
        26 => 0x2000023,
32
        27 => 0x4000013,
33
        28 => 0xC800000,
34
        29 => 0x14000000,
35
        30 => 0x20000029,
36
        31 => 0x48000000,
37
        32 => 0x80200003
38
 
39
    );
40
 
41
    private $length$mask;
42
 
43
    private $state 0;
44
 
45
    function __construct($length 8) {
46
        $this->length $length;
47
        $this->mask self::$masks[$length];
48
    }
49
 
50
    function state() {
51
        return sprintf("%0" $this->length "b",$this->state);
52
    }
53
 
54
    function tick() {
55
 
56
        $ns = ($this->state 2) & (pow(2,$this->length) - 1);
57
 
58
        $new $this->state pow(2,$this->length 1);
59
 
60
        for($i $this->length 2;$i >= 0;$i--) {
61
 
62
            if($this->mask pow(2,$i)) {
63
                $new = (int) ($new xor ($this->state pow(2,$i)));
64
            }
65
 
66
        }
67
 
68
        if($new == 0) {
69
            $ns++;
70
        }
71
 
72
        $this->state $ns;
73
 
74
    }
75
 
76
    function run($ticks,$output false) {
77
 
78
        if($output) {
79
            printf("%" strlen($ticks) . "u: %0" $this->length "b\n",0,$this->state);
80
        }
81
 
82
        for($i=0;$i<$ticks;$i++) {
83
            $this->tick();
84
            if($output) {
85
                printf("%" strlen($ticks) . "u: %0" $this->length "b\n",$i+1,$this->state);
86
            }
87
        }
88
 
89
    }
90
 
91
    static function GetState($length,$ticks) {
92
 
93
        $VC = new self($length);
94
        $VC->run($ticks);
95
 
96
        return $VC->state;
97
 
98
    }
99
 
100
}

powered by: WebSVN 2.1.0

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