1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: tomcl
#
# Created: 11/12/2015
# Copyright: (c) tomcl 2015
# Licence: <your licence>
#-------------------------------------------------------------------------------
import random
def rand64():
bits = random.getrandbits(64) # 64 random bits, us unsigned
if bits >= (1<<63): # convert from unsigned to signed representation
return bits - (1<<64)
else:
return bits
def twosComp(x,width=128): # comvert from signed int to two's comp representation
# choose large default width, when extracting lower bits
# too large a value of width does not matter
if x < 0:
return (1 << width) + x
else:
return x
def pw(x):
return "0X%X" % (x % (1<<32))
def pw0(x):
return pw(twosComp(x))
def pw1(x):
return pw (twosComp(x) >> 32)
def pw2(x):
return pw (twosComp(x) >> 64)
def pw3(x):
return pw (twosComp(x) >> 96)
def makeData(name, num, dat, s=""):
return ("%s%s%d DCD %s\n"% (("\n ; " + s + "\n" if s else ""), name, num, ",".join(dat)))
def genTest(num, a,b, s):
p = a*b # this is the correct 128 bit product of a and b
s = makeData("INA",num, [pw0(a), pw1(a)], s)
s += makeData("INB", num, [pw0(b),pw1(b)])
s += makeData("OUTAxB", num, [pw0(p),pw1(p),pw2(p),pw3(p)])
return s
def makeTestData():
s = genTest(0, 0x200000030, 0x50000007000, "Test 0: simple diagnostic")
s += genTest(1,0x7FFFFFFF, 0x7FFFFFFF, "Test 1: carries" )
s += genTest(2, 0, 0, "Test 2: all zeros")
s += genTest(3, -1, -1, "Test 3: both negative")
s += genTest(4, -1, 1, "Test 4: A negative")
s += genTest(5, 1, -1, "Test 5: B negative")
s += genTest(6, rand64(), rand64(), "Test 6: Random bits")
s += genTest(7, rand64(), rand64(), "Test 7: Random bits")
return s
print makeTestData()
|