Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abc
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
abc
Commits
c7bc6b63
Commit
c7bc6b63
authored
Mar 22, 2020
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experiments with simulation-based engines.
parent
a4518e6f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
379 additions
and
62 deletions
+379
-62
src/aig/gia/gia.h
+2
-0
src/aig/gia/giaMan.c
+1
-0
src/aig/gia/giaSimBase.c
+310
-2
src/misc/extra/extraUtilFile.c
+7
-24
src/misc/extra/extraUtilMisc.c
+49
-36
src/misc/util/utilTruth.h
+10
-0
No files found.
src/aig/gia/gia.h
View file @
c7bc6b63
...
...
@@ -205,9 +205,11 @@ struct Gia_Man_t_
int
fBuiltInSim
;
int
iPatsPi
;
int
nSimWords
;
int
nSimWordsT
;
int
iPastPiMax
;
int
nSimWordsMax
;
Vec_Wrd_t
*
vSims
;
Vec_Wrd_t
*
vSimsT
;
Vec_Wrd_t
*
vSimsPi
;
Vec_Wrd_t
*
vSimsPo
;
Vec_Int_t
*
vClassOld
;
...
...
src/aig/gia/giaMan.c
View file @
c7bc6b63
...
...
@@ -96,6 +96,7 @@ void Gia_ManStop( Gia_Man_t * p )
Vec_IntFreeP
(
&
p
->
vClassNew
);
Vec_IntFreeP
(
&
p
->
vClassOld
);
Vec_WrdFreeP
(
&
p
->
vSims
);
Vec_WrdFreeP
(
&
p
->
vSimsT
);
Vec_WrdFreeP
(
&
p
->
vSimsPi
);
Vec_WrdFreeP
(
&
p
->
vSimsPo
);
Vec_IntFreeP
(
&
p
->
vTimeStamps
);
...
...
src/aig/gia/giaSimBase.c
View file @
c7bc6b63
...
...
@@ -20,6 +20,7 @@
#include "gia.h"
#include "misc/util/utilTruth.h"
#include "misc/extra/extra.h"
ABC_NAMESPACE_IMPL_START
...
...
@@ -768,7 +769,7 @@ int Gia_ManSimRelCompare( Gia_Man_t * p, int nWords, Vec_Wrd_t * vSims, int nWor
}
return
1
;
}
void
Gia_ManSimRelCollectOutputs
(
Gia_Man_t
*
p
,
int
nWords
,
Vec_Wrd_t
*
vSims
,
int
nWordsOut
,
Vec_Wrd_t
*
vSimsOut
,
Vec_Wrd_t
*
vRel
)
int
Gia_ManSimRelCollectOutputs
(
Gia_Man_t
*
p
,
int
nWords
,
Vec_Wrd_t
*
vSims
,
int
nWordsOut
,
Vec_Wrd_t
*
vSimsOut
,
Vec_Wrd_t
*
vRel
)
{
int
i
,
m
,
nMints
=
nWords
/
nWordsOut
,
Count
=
0
;
assert
(
Vec_WrdSize
(
vSims
)
==
nWords
*
Gia_ManObjNum
(
p
)
);
...
...
@@ -784,6 +785,7 @@ void Gia_ManSimRelCollectOutputs( Gia_Man_t * p, int nWords, Vec_Wrd_t * vSims,
}
if
(
Count
)
printf
(
"The relation is not well-defined for %d (out of %d) patterns.
\n
"
,
Count
,
64
*
nWordsOut
);
return
Count
;
}
Vec_Wrd_t
*
Gia_ManSimRel
(
Gia_Man_t
*
p
,
Vec_Int_t
*
vObjs
,
Vec_Wrd_t
*
vVals
)
{
...
...
@@ -810,7 +812,8 @@ Vec_Wrd_t * Gia_ManSimRel( Gia_Man_t * p, Vec_Int_t * vObjs, Vec_Wrd_t * vVals )
Gia_ManSimPatSimPo
(
p
,
Gia_ObjId
(
p
,
pObj
),
pObj
,
nWords
*
nMints
,
vSims
);
Gia_ManForEachObjVec
(
vObjs
,
p
,
pObj
,
i
)
pObj
->
fPhase
=
0
;
Gia_ManSimRelCollectOutputs
(
p
,
nWords
*
nMints
,
vSims
,
nWords
,
vVals
,
vRel
);
if
(
Gia_ManSimRelCollectOutputs
(
p
,
nWords
*
nMints
,
vSims
,
nWords
,
vVals
,
vRel
)
)
Vec_WrdFreeP
(
&
vRel
);
Vec_WrdFree
(
vSims
);
return
vRel
;
}
...
...
@@ -1330,6 +1333,311 @@ Vec_Int_t * Gia_SimAbsPerformOne( Gia_Man_t * pGia, word * pOffSet, word * pOnSe
return
vResub
;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
typedef
struct
Gia_RsbMan_t_
Gia_RsbMan_t
;
struct
Gia_RsbMan_t_
{
Gia_Man_t
*
pGia
;
word
*
pOffSet
;
word
*
pOnSet
;
int
nWords
;
int
nWordsT
;
Vec_Wrd_t
*
vSims
;
Vec_Wrd_t
*
vSimsT
;
Vec_Int_t
*
vCands
;
Vec_Int_t
*
vObjs
;
Vec_Int_t
*
vObjs2
;
Vec_Wec_t
*
vSets
[
2
];
word
*
pSet
[
3
];
Vec_Int_t
*
vActive
;
};
Gia_RsbMan_t
*
Gia_RsbAlloc
(
Gia_Man_t
*
pGia
,
word
*
pOffSet
,
word
*
pOnSet
,
Vec_Wrd_t
*
vSims
,
int
nWords
,
Vec_Wrd_t
*
vSimsT
,
int
nWordsT
,
Vec_Int_t
*
vCands
)
{
int
i
,
iObj
;
Gia_RsbMan_t
*
p
=
ABC_CALLOC
(
Gia_RsbMan_t
,
1
);
assert
(
nWords
<=
1024
);
assert
(
Vec_WrdSize
(
vSims
)
==
64
*
nWords
*
nWordsT
);
assert
(
Vec_WrdSize
(
vSims
)
==
Vec_WrdSize
(
vSimsT
)
);
p
->
pGia
=
pGia
;
p
->
pOffSet
=
pOffSet
;
p
->
pOnSet
=
pOnSet
;
p
->
nWords
=
nWords
;
p
->
nWordsT
=
nWordsT
;
p
->
vSims
=
vSims
;
p
->
vSimsT
=
vSimsT
;
p
->
vCands
=
vCands
;
p
->
vObjs
=
Vec_IntAlloc
(
100
);
p
->
vObjs2
=
Vec_IntAlloc
(
100
);
p
->
vSets
[
0
]
=
Vec_WecAlloc
(
1024
);
p
->
vSets
[
1
]
=
Vec_WecAlloc
(
1024
);
p
->
pSet
[
0
]
=
ABC_CALLOC
(
word
,
nWordsT
);
p
->
pSet
[
1
]
=
ABC_CALLOC
(
word
,
nWordsT
);
p
->
pSet
[
2
]
=
ABC_CALLOC
(
word
,
nWordsT
);
p
->
vActive
=
Vec_IntAlloc
(
100
);
Vec_IntForEachEntry
(
vCands
,
iObj
,
i
)
{
assert
(
iObj
<
nWordsT
*
64
);
Abc_TtSetBit
(
p
->
pSet
[
0
],
iObj
);
}
Vec_WecPushLevel
(
p
->
vSets
[
0
]
);
Vec_WecPushLevel
(
p
->
vSets
[
1
]
);
for
(
i
=
0
;
i
<
64
*
nWords
;
i
++
)
{
int
Value0
=
Abc_TtGetBit
(
pOffSet
,
i
);
int
Value1
=
Abc_TtGetBit
(
pOnSet
,
i
);
if
(
Value0
&&
!
Value1
)
Vec_WecPush
(
p
->
vSets
[
0
],
0
,
i
);
else
if
(
!
Value0
&&
Value1
)
Vec_WecPush
(
p
->
vSets
[
1
],
0
,
i
);
else
assert
(
!
Value0
||
!
Value1
);
}
assert
(
Vec_WecSize
(
p
->
vSets
[
0
])
==
1
);
assert
(
Vec_WecSize
(
p
->
vSets
[
1
])
==
1
);
Abc_Random
(
1
);
//Extra_PrintBinary2( stdout, (unsigned*)pOffSet, 64*nWords ); printf( "\n" );
//Extra_PrintBinary2( stdout, (unsigned*)pOnSet, 64*nWords ); printf( "\n" );
return
p
;
}
void
Gia_RsbFree
(
Gia_RsbMan_t
*
p
)
{
Vec_IntFree
(
p
->
vActive
);
Vec_IntFree
(
p
->
vObjs
);
Vec_IntFree
(
p
->
vObjs2
);
Vec_WecFree
(
p
->
vSets
[
0
]
);
Vec_WecFree
(
p
->
vSets
[
1
]
);
ABC_FREE
(
p
->
pSet
[
0
]
);
ABC_FREE
(
p
->
pSet
[
1
]
);
ABC_FREE
(
p
->
pSet
[
2
]
);
ABC_FREE
(
p
);
}
int
Gia_RsbCost
(
Gia_RsbMan_t
*
p
)
{
Vec_Int_t
*
vLevel
[
2
];
int
i
,
Cost
=
0
;
Vec_WecForEachLevelTwo
(
p
->
vSets
[
0
],
p
->
vSets
[
1
],
vLevel
[
0
],
vLevel
[
1
],
i
)
Cost
+=
Vec_IntSize
(
vLevel
[
0
])
*
Vec_IntSize
(
vLevel
[
1
]);
return
Cost
;
}
void
Gia_RsbPrint
(
Gia_RsbMan_t
*
p
)
{
Vec_Int_t
*
vLevel
[
2
];
int
n
,
i
,
nLeaves
=
1
<<
Vec_IntSize
(
p
->
vObjs
);
assert
(
Vec_WecSize
(
p
->
vSets
[
0
])
==
nLeaves
);
assert
(
Vec_WecSize
(
p
->
vSets
[
1
])
==
nLeaves
);
printf
(
"Database for %d objects and cost %d:
\n
"
,
Vec_IntSize
(
p
->
vObjs
),
Gia_RsbCost
(
p
)
);
Vec_WecForEachLevelTwo
(
p
->
vSets
[
0
],
p
->
vSets
[
1
],
vLevel
[
0
],
vLevel
[
1
],
i
)
{
for
(
n
=
0
;
n
<
2
;
n
++
)
{
printf
(
"%5d : "
,
i
);
Extra_PrintBinary2
(
stdout
,
(
unsigned
*
)
&
i
,
Vec_IntSize
(
p
->
vObjs
)
);
printf
(
" %d "
,
n
);
Vec_IntPrint
(
vLevel
[
n
]
);
}
}
}
void
Gia_RsbUpdateAdd
(
Gia_RsbMan_t
*
p
,
int
iObj
)
{
int
n
,
i
,
nLeaves
=
1
<<
Vec_IntSize
(
p
->
vObjs
);
assert
(
Vec_WecSize
(
p
->
vSets
[
0
])
==
nLeaves
);
assert
(
Vec_WecSize
(
p
->
vSets
[
1
])
==
nLeaves
);
for
(
i
=
0
;
i
<
nLeaves
;
i
++
)
{
for
(
n
=
0
;
n
<
2
;
n
++
)
{
Vec_Int_t
*
vLevelN
=
Vec_WecPushLevel
(
p
->
vSets
[
n
]);
Vec_Int_t
*
vLevel
=
Vec_WecEntry
(
p
->
vSets
[
n
],
i
);
int
iMint
,
j
,
k
=
0
;
Vec_IntForEachEntry
(
vLevel
,
iMint
,
j
)
{
if
(
Abc_TtGetBit
(
Vec_WrdEntryP
(
p
->
vSims
,
p
->
nWords
*
iObj
),
iMint
)
)
Vec_IntPush
(
vLevelN
,
iMint
);
else
Vec_IntWriteEntry
(
vLevel
,
k
++
,
iMint
);
}
Vec_IntShrink
(
vLevel
,
k
);
}
}
Vec_IntPush
(
p
->
vObjs
,
iObj
);
assert
(
Vec_WecSize
(
p
->
vSets
[
0
])
==
2
*
nLeaves
);
assert
(
Vec_WecSize
(
p
->
vSets
[
1
])
==
2
*
nLeaves
);
}
void
Gia_RsbUpdateRemove
(
Gia_RsbMan_t
*
p
,
int
Index
)
{
Vec_Int_t
*
vLevel
[
2
],
*
vTemp
[
2
][
2
];
int
k
=
0
,
m
,
m2
,
nLeaves
=
1
<<
Vec_IntSize
(
p
->
vObjs
);
assert
(
Index
<
Vec_IntSize
(
p
->
vObjs
)
);
assert
(
Vec_WecSize
(
p
->
vSets
[
0
])
==
nLeaves
);
assert
(
Vec_WecSize
(
p
->
vSets
[
1
])
==
nLeaves
);
for
(
m
=
0
;
m
<
nLeaves
;
m
++
)
{
if
(
m
&
(
1
<<
Index
)
)
continue
;
m2
=
m
^
(
1
<<
Index
);
vTemp
[
0
][
0
]
=
Vec_WecEntry
(
p
->
vSets
[
0
],
m
);
vTemp
[
0
][
1
]
=
Vec_WecEntry
(
p
->
vSets
[
1
],
m
);
vTemp
[
1
][
0
]
=
Vec_WecEntry
(
p
->
vSets
[
0
],
m2
);
vTemp
[
1
][
1
]
=
Vec_WecEntry
(
p
->
vSets
[
1
],
m2
);
Vec_IntAppend
(
vTemp
[
0
][
0
],
vTemp
[
1
][
0
]
);
Vec_IntAppend
(
vTemp
[
0
][
1
],
vTemp
[
1
][
1
]
);
Vec_IntClear
(
vTemp
[
1
][
0
]
);
Vec_IntClear
(
vTemp
[
1
][
1
]
);
}
Vec_IntDrop
(
p
->
vObjs
,
Index
);
Vec_WecForEachLevelTwo
(
p
->
vSets
[
0
],
p
->
vSets
[
1
],
vLevel
[
0
],
vLevel
[
1
],
m
)
{
if
(
m
&
(
1
<<
Index
)
)
continue
;
ABC_SWAP
(
Vec_Int_t
,
Vec_WecArray
(
p
->
vSets
[
0
])[
k
],
Vec_WecArray
(
p
->
vSets
[
0
])[
m
]
);
ABC_SWAP
(
Vec_Int_t
,
Vec_WecArray
(
p
->
vSets
[
1
])[
k
],
Vec_WecArray
(
p
->
vSets
[
1
])[
m
]
);
k
++
;
}
assert
(
k
==
nLeaves
/
2
);
Vec_WecShrink
(
p
->
vSets
[
0
],
k
);
Vec_WecShrink
(
p
->
vSets
[
1
],
k
);
}
int
Gia_RsbRemovalCost
(
Gia_RsbMan_t
*
p
,
int
Index
)
{
Vec_Int_t
*
vTemp
[
2
][
2
];
unsigned
Mask
=
Abc_InfoMask
(
Index
);
int
m
,
m2
,
Cost
=
0
,
nLeaves
=
1
<<
Vec_IntSize
(
p
->
vObjs
);
assert
(
Vec_WecSize
(
p
->
vSets
[
0
])
==
(
1
<<
Vec_IntSize
(
p
->
vObjs
))
);
assert
(
Vec_WecSize
(
p
->
vSets
[
1
])
==
(
1
<<
Vec_IntSize
(
p
->
vObjs
))
);
for
(
m
=
0
;
m
<
nLeaves
;
m
++
)
{
if
(
m
&
(
1
<<
Index
)
)
continue
;
m2
=
m
^
(
1
<<
Index
);
vTemp
[
0
][
0
]
=
Vec_WecEntry
(
p
->
vSets
[
0
],
m
);
vTemp
[
0
][
1
]
=
Vec_WecEntry
(
p
->
vSets
[
1
],
m
);
vTemp
[
1
][
0
]
=
Vec_WecEntry
(
p
->
vSets
[
0
],
m2
);
vTemp
[
1
][
1
]
=
Vec_WecEntry
(
p
->
vSets
[
1
],
m2
);
Cost
+=
(
Vec_IntSize
(
vTemp
[
0
][
0
])
+
Vec_IntSize
(
vTemp
[
1
][
0
]))
*
(
Vec_IntSize
(
vTemp
[
0
][
1
])
+
Vec_IntSize
(
vTemp
[
1
][
1
]));
}
return
Cost
;
}
int
Gia_RsbFindNodeToRemove
(
Gia_RsbMan_t
*
p
,
int
*
pMinCost
)
{
int
i
,
iObj
,
iMin
=
-
1
,
CostMin
=
ABC_INFINITY
;
Vec_IntForEachEntry
(
p
->
vObjs
,
iObj
,
i
)
{
int
Cost
=
Gia_RsbRemovalCost
(
p
,
i
);
if
(
CostMin
>
Cost
)
{
CostMin
=
Cost
;
iMin
=
i
;
}
}
if
(
pMinCost
)
*
pMinCost
=
CostMin
;
return
iMin
;
}
void
Gia_RsbFindMints
(
Gia_RsbMan_t
*
p
,
int
*
pMint0
,
int
*
pMint1
)
{
int
iSetI
=
Abc_Random
(
0
)
%
Vec_IntSize
(
p
->
vActive
);
int
iSet
=
Vec_IntEntry
(
p
->
vActive
,
iSetI
);
Vec_Int_t
*
vArray0
=
Vec_WecEntry
(
p
->
vSets
[
0
],
iSet
);
Vec_Int_t
*
vArray1
=
Vec_WecEntry
(
p
->
vSets
[
1
],
iSet
);
int
iMint0i
=
Abc_Random
(
0
)
%
Vec_IntSize
(
vArray0
);
int
iMint1i
=
Abc_Random
(
0
)
%
Vec_IntSize
(
vArray1
);
int
iMint0
=
Vec_IntEntry
(
vArray0
,
iMint0i
);
int
iMint1
=
Vec_IntEntry
(
vArray1
,
iMint1i
);
*
pMint0
=
iMint0
;
*
pMint1
=
iMint1
;
}
int
Gia_RsbFindNode
(
Gia_RsbMan_t
*
p
)
{
int
i
,
iObj
,
nNodes
,
nNodesNew
=
-
1
,
nNodesOld
=
-
1
,
Mint0
,
Mint1
,
Shift
;
Abc_TtCopy
(
p
->
pSet
[
1
],
p
->
pSet
[
0
],
p
->
nWordsT
,
0
);
Vec_IntForEachEntry
(
p
->
vObjs
,
iObj
,
i
)
{
assert
(
Abc_TtGetBit
(
p
->
pSet
[
1
],
iObj
)
);
Abc_TtXorBit
(
p
->
pSet
[
1
],
iObj
);
}
Abc_TtCopy
(
p
->
pSet
[
2
],
p
->
pSet
[
1
],
p
->
nWordsT
,
0
);
Gia_RsbFindMints
(
p
,
&
Mint0
,
&
Mint1
);
nNodes
=
Abc_TtAndXorSum
(
p
->
pSet
[
1
],
Vec_WrdEntryP
(
p
->
vSimsT
,
p
->
nWordsT
*
Mint0
),
Vec_WrdEntryP
(
p
->
vSimsT
,
p
->
nWordsT
*
Mint1
),
p
->
nWordsT
);
for
(
i
=
0
;
i
<
5
&&
nNodes
>
1
;
i
++
)
{
nNodesOld
=
nNodes
;
Abc_TtCopy
(
p
->
pSet
[
2
],
p
->
pSet
[
1
],
p
->
nWordsT
,
0
);
Gia_RsbFindMints
(
p
,
&
Mint0
,
&
Mint1
);
nNodesNew
=
Abc_TtAndXorSum
(
p
->
pSet
[
1
],
Vec_WrdEntryP
(
p
->
vSimsT
,
p
->
nWordsT
*
Mint0
),
Vec_WrdEntryP
(
p
->
vSimsT
,
p
->
nWordsT
*
Mint1
),
p
->
nWordsT
);
assert
(
nNodesNew
<=
nNodes
);
if
(
nNodesNew
<
nNodes
)
i
=
0
;
nNodes
=
nNodesNew
;
}
Shift
=
Abc_Random
(
0
)
%
(
64
*
p
->
nWordsT
);
for
(
i
=
0
;
i
<
64
*
p
->
nWordsT
;
i
++
)
{
int
Index
=
(
i
+
Shift
)
%
(
64
*
p
->
nWordsT
);
if
(
Abc_TtGetBit
(
p
->
pSet
[
2
],
Index
)
)
return
Index
;
}
assert
(
0
);
return
-
1
;
}
int
Gia_RsbCollectValid
(
Gia_RsbMan_t
*
p
)
{
Vec_Int_t
*
vLevel
[
2
];
int
i
;
Vec_IntClear
(
p
->
vActive
);
assert
(
Vec_WecSize
(
p
->
vSets
[
0
])
==
Vec_WecSize
(
p
->
vSets
[
1
])
);
Vec_WecForEachLevelTwo
(
p
->
vSets
[
0
],
p
->
vSets
[
1
],
vLevel
[
0
],
vLevel
[
1
],
i
)
if
(
Vec_IntSize
(
vLevel
[
0
])
&&
Vec_IntSize
(
vLevel
[
1
])
)
Vec_IntPush
(
p
->
vActive
,
i
);
if
(
Vec_IntSize
(
p
->
vActive
)
==
0
)
return
0
;
return
1
;
}
Vec_Int_t
*
Gia_RsbSolve
(
Gia_RsbMan_t
*
p
)
{
int
i
,
iMin
;
Vec_IntClear
(
p
->
vObjs
);
while
(
Gia_RsbCollectValid
(
p
)
)
Gia_RsbUpdateAdd
(
p
,
Gia_RsbFindNode
(
p
)
);
for
(
i
=
0
;
i
<
100
;
i
++
)
{
int
k
,
nUndo
=
1
+
Abc_Random
(
0
)
%
Vec_IntSize
(
p
->
vObjs
);
for
(
k
=
0
;
k
<
nUndo
;
k
++
)
{
iMin
=
Gia_RsbFindNodeToRemove
(
p
,
NULL
);
// &MinCost );
Gia_RsbUpdateRemove
(
p
,
iMin
);
}
while
(
Gia_RsbCollectValid
(
p
)
)
Gia_RsbUpdateAdd
(
p
,
Gia_RsbFindNode
(
p
)
);
if
(
Vec_IntSize
(
p
->
vObjs2
)
==
0
||
Vec_IntSize
(
p
->
vObjs2
)
>
Vec_IntSize
(
p
->
vObjs
)
)
{
Vec_IntClear
(
p
->
vObjs2
);
Vec_IntAppend
(
p
->
vObjs2
,
p
->
vObjs
);
}
}
//Gia_RsbPrint( p );
return
Vec_IntDup
(
p
->
vObjs2
);
}
Vec_Int_t
*
Gia_RsbSetFind
(
word
*
pOffSet
,
word
*
pOnSet
,
Vec_Wrd_t
*
vSims
,
int
nWords
,
Vec_Wrd_t
*
vSimsT
,
int
nWordsT
,
Vec_Int_t
*
vCands
)
{
Gia_RsbMan_t
*
p
=
Gia_RsbAlloc
(
NULL
,
pOffSet
,
pOnSet
,
vSims
,
nWords
,
vSimsT
,
nWordsT
,
vCands
);
Vec_Int_t
*
vObjs
=
Gia_RsbSolve
(
p
);
Gia_RsbFree
(
p
);
Vec_IntSort
(
vObjs
,
0
);
return
vObjs
;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
...
...
src/misc/extra/extraUtilFile.c
View file @
c7bc6b63
...
...
@@ -496,33 +496,16 @@ unsigned Extra_ReadBinary( char * Buffer )
***********************************************************************/
void
Extra_PrintBinary
(
FILE
*
pFile
,
unsigned
Sign
[],
int
nBits
)
{
int
Remainder
,
nWords
;
int
w
,
i
;
Remainder
=
(
nBits
%
(
sizeof
(
unsigned
)
*
8
));
nWords
=
(
nBits
/
(
sizeof
(
unsigned
)
*
8
))
+
(
Remainder
>
0
);
for
(
w
=
nWords
-
1
;
w
>=
0
;
w
--
)
for
(
i
=
((
w
==
nWords
-
1
&&
Remainder
)
?
Remainder
-
1
:
31
);
i
>=
0
;
i
--
)
fprintf
(
pFile
,
"%c"
,
'0'
+
(
int
)((
Sign
[
w
]
&
(
1
<<
i
))
>
0
)
);
// fprintf( pFile, "\n" );
int
i
;
for
(
i
=
nBits
-
1
;
i
>=
0
;
i
--
)
fprintf
(
pFile
,
"%c"
,
'0'
+
Abc_InfoHasBit
(
Sign
,
i
)
);
// fprintf( pFile, "\n" );
}
void
Extra_PrintBinary2
(
FILE
*
pFile
,
unsigned
Sign
[],
int
nBits
)
{
int
Remainder
,
nWords
;
int
w
,
i
;
Remainder
=
(
nBits
%
(
sizeof
(
unsigned
)
*
8
));
nWords
=
(
nBits
/
(
sizeof
(
unsigned
)
*
8
))
+
(
Remainder
>
0
);
for
(
w
=
0
;
w
<
nWords
;
w
++
)
{
int
Limit
=
w
==
nWords
-
1
?
Remainder
:
32
;
for
(
i
=
0
;
i
<
Limit
;
i
++
)
fprintf
(
pFile
,
"%c"
,
'0'
+
(
int
)((
Sign
[
w
]
&
(
1
<<
i
))
>
0
)
);
}
int
i
;
for
(
i
=
0
;
i
<
nBits
;
i
++
)
fprintf
(
pFile
,
"%c"
,
'0'
+
Abc_InfoHasBit
(
Sign
,
i
)
);
// fprintf( pFile, "\n" );
}
...
...
src/misc/extra/extraUtilMisc.c
View file @
c7bc6b63
...
...
@@ -2594,6 +2594,19 @@ static inline void Extra_Transpose64Simple( word A[64], word B[64] )
if
(
(
A
[
i
]
>>
k
)
&
1
)
B
[
k
]
|=
((
word
)
1
<<
(
63
-
i
));
}
static
inline
void
Extra_BitMatrixTransposeSimple
(
Vec_Wrd_t
*
vSimsIn
,
int
nWordsIn
,
Vec_Wrd_t
*
vSimsOut
,
int
nWordsOut
)
{
int
i
,
k
;
assert
(
Vec_WrdSize
(
vSimsIn
)
==
nWordsIn
*
nWordsOut
*
64
);
assert
(
Vec_WrdSize
(
vSimsIn
)
==
Vec_WrdSize
(
vSimsOut
)
);
assert
(
Vec_WrdSize
(
vSimsIn
)
%
nWordsIn
==
0
);
assert
(
Vec_WrdSize
(
vSimsOut
)
%
nWordsOut
==
0
);
Vec_WrdFill
(
vSimsOut
,
Vec_WrdSize
(
vSimsOut
),
0
);
for
(
i
=
0
;
i
<
64
*
nWordsOut
;
i
++
)
for
(
k
=
0
;
k
<
64
*
nWordsIn
;
k
++
)
if
(
Abc_InfoHasBit
(
(
unsigned
*
)
Vec_WrdEntryP
(
vSimsIn
,
i
*
nWordsIn
),
k
)
)
Abc_InfoSetBit
(
(
unsigned
*
)
Vec_WrdEntryP
(
vSimsOut
,
k
*
nWordsOut
),
i
);
}
void
Extra_Transpose32
(
unsigned
a
[
32
]
)
{
int
j
,
k
;
...
...
@@ -2642,13 +2655,13 @@ void Extra_BitMatrixTransposeP( Vec_Wrd_t * vSimsIn, int nWordsIn, Vec_Wrd_t * v
assert
(
Vec_WrdSize
(
vSimsIn
)
==
Vec_WrdSize
(
vSimsOut
)
);
assert
(
Vec_WrdSize
(
vSimsIn
)
/
nWordsIn
==
64
*
nWordsOut
);
assert
(
Vec_WrdSize
(
vSimsOut
)
/
nWordsOut
==
64
*
nWordsIn
);
for
(
y
=
0
;
y
<
nWordsIn
;
y
++
)
for
(
x
=
0
;
x
<
nWordsOut
;
x
++
)
for
(
y
=
0
;
y
<
nWordsIn
;
y
++
)
{
for
(
i
=
0
;
i
<
64
;
i
++
)
{
pM
[
i
]
=
Vec_WrdEntryP
(
vSimsOut
,
(
64
*
y
+
i
)
*
nWordsOut
+
x
);
pM
[
i
][
0
]
=
Vec_WrdEntry
(
vSimsIn
,
(
64
*
x
+
i
)
*
nWordsIn
+
y
);
pM
[
i
]
=
Vec_WrdEntryP
(
vSimsOut
,
(
64
*
y
+
63
-
i
)
*
nWordsOut
+
x
);
pM
[
i
][
0
]
=
Vec_WrdEntry
(
vSimsIn
,
(
64
*
x
+
63
-
i
)
*
nWordsIn
+
y
);
}
Extra_Transpose64p
(
pM
);
}
...
...
@@ -2657,8 +2670,8 @@ void Extra_BitMatrixTransposePP( Vec_Ptr_t * vSimsIn, int nWordsIn, Vec_Wrd_t *
{
word
*
pM
[
64
];
int
i
,
y
,
x
;
assert
(
Vec_WrdSize
(
vSimsOut
)
/
nWordsOut
==
64
*
nWordsIn
);
for
(
y
=
0
;
y
<
nWordsIn
;
y
++
)
for
(
x
=
0
;
x
<
nWordsOut
;
x
++
)
for
(
y
=
0
;
y
<
nWordsIn
;
y
++
)
{
for
(
i
=
0
;
i
<
64
;
i
++
)
{
...
...
@@ -2668,51 +2681,51 @@ void Extra_BitMatrixTransposePP( Vec_Ptr_t * vSimsIn, int nWordsIn, Vec_Wrd_t *
Extra_Transpose64p
(
pM
);
}
}
void
Extra_BitMatrixTransposeTest
()
{
int
nWordsIn
=
1
;
int
nWordsOut
=
2
;
int
i
,
k
,
nItems
=
64
*
nWordsIn
*
nWordsOut
;
Vec_Wrd_t
*
vSimsIn
=
Vec_WrdStart
(
nItems
);
Vec_Wrd_t
*
vSimsOut
=
Vec_WrdStart
(
nItems
);
Abc_RandomW
(
1
);
for
(
i
=
0
;
i
<
nItems
;
i
++
)
Vec_WrdWriteEntry
(
vSimsIn
,
i
,
Abc_RandomW
(
0
)
);
Extra_BitMatrixTransposeP
(
vSimsIn
,
nWordsIn
,
vSimsOut
,
nWordsOut
);
nItems
=
Vec_WrdSize
(
vSimsIn
)
/
nWordsIn
;
for
(
i
=
0
;
i
<
nItems
;
i
++
)
void
Extra_BitMatrixShow
(
Vec_Wrd_t
*
vSims
,
int
nWords
)
{
int
i
,
k
,
nBits
=
Vec_WrdSize
(
vSims
)
/
nWords
;
for
(
i
=
0
;
i
<
nBits
;
i
++
)
{
if
(
i
%
64
==
0
)
Abc_Print
(
1
,
"
\n
"
);
for
(
k
=
0
;
k
<
nWords
In
;
k
++
)
for
(
k
=
0
;
k
<
nWords
;
k
++
)
{
Extra_PrintBinary
(
stdout
,
(
unsigned
*
)
Vec_WrdEntryP
(
vSimsIn
,
i
*
nWordsIn
+
k
),
64
);
Extra_PrintBinary
2
(
stdout
,
(
unsigned
*
)
Vec_WrdEntryP
(
vSims
,
i
*
nWords
+
k
),
64
);
Abc_Print
(
1
,
" "
);
}
Abc_Print
(
1
,
"
\n
"
);
}
Abc_Print
(
1
,
"
\n
"
);
}
void
Extra_BitMatrixTransposeTest
()
{
abctime
clk
=
Abc_Clock
();
nItems
=
Vec_WrdSize
(
vSimsOut
)
/
nWordsOut
;
for
(
i
=
0
;
i
<
nItems
;
i
++
)
{
if
(
i
%
64
==
0
)
Abc_Print
(
1
,
"
\n
"
);
for
(
k
=
0
;
k
<
nWordsOut
;
k
++
)
{
Extra_PrintBinary
(
stdout
,
(
unsigned
*
)
Vec_WrdEntryP
(
vSimsOut
,
i
*
nWordsOut
+
k
),
64
);
Abc_Print
(
1
,
" "
);
}
Abc_Print
(
1
,
"
\n
"
);
}
Abc_Print
(
1
,
"
\n
"
);
int
nWordsIn
=
100
;
int
nWordsOut
=
200
;
int
nItems
=
64
*
nWordsIn
*
nWordsOut
;
Vec_Wrd_t
*
vSimsIn
=
Vec_WrdStartRandom
(
nItems
);
Vec_Wrd_t
*
vSimsOut
=
Vec_WrdStart
(
nItems
);
Vec_Wrd_t
*
vSimsOut2
=
Vec_WrdStart
(
nItems
);
Extra_BitMatrixTransposeP
(
vSimsIn
,
nWordsIn
,
vSimsOut
,
nWordsOut
);
Extra_BitMatrixTransposeSimple
(
vSimsIn
,
nWordsIn
,
vSimsOut2
,
nWordsOut
);
if
(
memcmp
(
Vec_WrdArray
(
vSimsOut
),
Vec_WrdArray
(
vSimsOut2
),
sizeof
(
word
)
*
Vec_WrdSize
(
vSimsOut
)
)
)
printf
(
"Verification failed.
\n
"
);
else
printf
(
"Verification succeeded.
\n
"
);
//Extra_BitMatrixShow( vSimsIn, nWordsIn );
//Extra_BitMatrixShow( vSimsOut, nWordsOut );
//Extra_BitMatrixShow( vSimsOut2, nWordsOut );
Vec_WrdFree
(
vSimsIn
);
Vec_WrdFree
(
vSimsOut
);
Vec_WrdFree
(
vSimsOut2
);
Abc_PrintTime
(
1
,
"Time"
,
Abc_Clock
()
-
clk
);
}
////////////////////////////////////////////////////////////////////////
...
...
src/misc/util/utilTruth.h
View file @
c7bc6b63
...
...
@@ -1842,6 +1842,16 @@ static inline int Abc_TtCountOnesVecXor( word * x, word * y, int nWords )
Count
+=
Abc_TtCountOnes
(
x
[
w
]
^
y
[
w
]
);
return
Count
;
}
static
inline
int
Abc_TtAndXorSum
(
word
*
pOut
,
word
*
pIn1
,
word
*
pIn2
,
int
nWords
)
{
int
w
,
Count
=
0
;
for
(
w
=
0
;
w
<
nWords
;
w
++
)
{
pOut
[
w
]
&=
pIn1
[
w
]
^
pIn2
[
w
];
Count
+=
Abc_TtCountOnes
(
pOut
[
w
]
);
}
return
Count
;
}
/**Function*************************************************************
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment