Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • c7b1687
  • /
  • perl
  • /
  • mul.pl
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:611a7606259fe278eb38e20084dd141aaa2fc0db
directory badge Iframe embedding
swh:1:dir:6fe9f7ebaafee609a988be3a56ecc53319a65256
mul.pl
#!/usr/bin/perl

use ExtUtils::testlib;

use SSLeay;


sub mul
	{
	my($ab,$cd,$num)=@_;

	if ($num <= 4096)
		{
		return($ab*$cd);
		}
	else
		{
		my($a,$b,$c,$d,$n,$ac,$bd,$m,$t1,$t2);

		$n=$num/2;

		$a=$ab->mask_bits($n);
		$b=$ab->rshift($n);
		$c=$cd->mask_bits($n);
		$d=$cd->rshift($n);

		$t1=($b-$a);
		$t2=($c-$d);
		$m= &mul($t1,$t2,$n);
		$ac=&mul($a,$c,$n);
		$bd=&mul($b,$d,$n);
		$m=$m+$ac+$bd;
		$m=$m->lshift($n);
		$bd=$bd->lshift($num);

		$r=$ac+$m+$bd;
		return($r);
		}
	}

$num=4096*32;
$a=SSLeay::BN::rand($num);
$b=SSLeay::BN::rand($num);

#for (1 .. 10)
	{
	$r=&mul($a,$b,$num);
	}

#for (1 .. 10)
	{
	$rr=$a*$b;
	}

$res=$rr-$r;
print $res->bn2hex()."\n";

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top