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

Subversion Repositories versatile_library

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 46 to Rev 47
    Reverse comparison

Rev 46 → Rev 47

/versatile_library/trunk/misc/VersatileCounter.php
0,0 → 1,16
#!/usr/bin/php
<?php
 
include (dirname(__FILE__) . '/VersatileCounter.class.php');
 
if(isset($argv[1]) and !isset(VersatileCounter::$masks[$argv[1]])) {
echo "Error: Bitmask not found" . PHP_EOL;
die(1);
}
 
$c = new VersatileCounter(isset($argv[1])?$argv[1]:8);
$c->run(isset($argv[2])?$argv[2]:2,isset($argv[3]));
 
if(!isset($argv[3])) {
echo $c->state() . PHP_EOL;
}
versatile_library/trunk/misc/VersatileCounter.php Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: versatile_library/trunk/misc/VersatileCounter.class.php =================================================================== --- versatile_library/trunk/misc/VersatileCounter.class.php (nonexistent) +++ versatile_library/trunk/misc/VersatileCounter.class.php (revision 47) @@ -0,0 +1,100 @@ + 0x3, + 3 => 0x6, + 4 => 0xC, + 5 => 0x14, + 6 => 0x30, + 7 => 0x60, + 8 => 0xB8, + 9 => 0x110, + 10 => 0x240, + 11 => 0x500, + 12 => 0x829, + 13 => 0x100C, + 14 => 0x2015, + 15 => 0x6000, + 16 => 0xD008, + 17 => 0x12000, + 18 => 0x20400, + 19 => 0x40023, + 20 => 0x90000, + 21 => 0x140000, + 22 => 0x300000, + 23 => 0x420000, + 24 => 0xE10000, + 25 => 0x1200000, + 26 => 0x2000023, + 27 => 0x4000013, + 28 => 0xC800000, + 29 => 0x14000000, + 30 => 0x20000029, + 31 => 0x48000000, + 32 => 0x80200003 + + ); + + private $length, $mask; + + private $state = 0; + + function __construct($length = 8) { + $this->length = $length; + $this->mask = self::$masks[$length]; + } + + function state() { + return sprintf("%0" . $this->length . "b",$this->state); + } + + function tick() { + + $ns = ($this->state * 2) & (pow(2,$this->length) - 1); + + $new = $this->state & pow(2,$this->length - 1); + + for($i = $this->length - 2;$i >= 0;$i--) { + + if($this->mask & pow(2,$i)) { + $new = (int) ($new xor ($this->state & pow(2,$i))); + } + + } + + if($new == 0) { + $ns++; + } + + $this->state = $ns; + + } + + function run($ticks,$output = false) { + + if($output) { + printf("%" . strlen($ticks) . "u: %0" . $this->length . "b\n",0,$this->state); + } + + for($i=0;$i<$ticks;$i++) { + $this->tick(); + if($output) { + printf("%" . strlen($ticks) . "u: %0" . $this->length . "b\n",$i+1,$this->state); + } + } + + } + + static function GetState($length,$ticks) { + + $VC = new self($length); + $VC->run($ticks); + + return $VC->state; + + } + +}

powered by: WebSVN 2.1.0

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