aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/anlogic/arith_map.v
blob: 1186543daed0d37972184933eccda919b2f795d6 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2018  Miodrag Milanovic <miodrag@symbioticeda.com>
 *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

(* techmap_celltype = "$alu" *)
module _80_anlogic_alu (A, B, CI, BI, X, Y, CO);
	parameter A_SIGNED = 0;
	parameter B_SIGNED = 0;
	parameter A_WIDTH  = 1;
	parameter B_WIDTH  = 1;
	parameter Y_WIDTH  = 1;

	input [A_WIDTH-1:0] A;
	input [B_WIDTH-1:0] B;
	output [Y_WIDTH-1:0] X, Y;

	input CI, BI;
	output [Y_WIDTH-1:0] CO;
   
	wire CIx;
	wire [Y_WIDTH-1:0] COx;

	wire _TECHMAP_FAIL_ = Y_WIDTH <= 2;

	wire [Y_WIDTH-1:0] A_buf, B_buf;
	\$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
	\$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));

	wire [Y_WIDTH-1:0] AA = A_buf;
	wire [Y_WIDTH-1:0] BB = BI ? ~B_buf : B_buf;
	wire [Y_WIDTH-1:0] C = { COx, CIx };

    wire dummy;
    AL_MAP_ADDER #(
    	.ALUTYPE("ADD_CARRY"))
    adder_cin  (
        .a(CI),
		.b(1'b0),
		.c(1'b0),
        .o({CIx, dummy})
	);

	genvar i;
	generate for (i = 0; i < Y_WIDTH; i = i + 1) begin: slice
	    AL_MAP_ADDER #(
            .ALUTYPE("ADD")
        ) adder_i (
            .a(AA[i]),
            .b(BB[i]),
            .c(C[i]),
            .o({COx[i],Y[i]})
        );

		wire cout;
		AL_MAP_ADDER #(
			.ALUTYPE("ADD"))
		adder_cout  (
			.a(1'b0),
			.b(1'b0),
			.c(COx[i]),
			.o({cout, CO[i]})
		);
	  end: slice	  
	endgenerate

   /* End implementation */
   assign X = AA ^ BB;
endmodule
----------------------------------------------------*/ /* Constant declarations */ /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* Stucture declarations */ /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* Type declarations */ /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* Variable declarations */ /*---------------------------------------------------------------------------*/ #ifndef lint static char rcsid[] DD_UNUSED = "$Id: cuddInit.c,v 1.33 2007/07/01 05:10:50 fabio Exp $"; #endif /*---------------------------------------------------------------------------*/ /* Macro declarations */ /*---------------------------------------------------------------------------*/ /**AutomaticStart*************************************************************/ /*---------------------------------------------------------------------------*/ /* Static function prototypes */ /*---------------------------------------------------------------------------*/ /**AutomaticEnd***************************************************************/ /*---------------------------------------------------------------------------*/ /* Definition of exported functions */ /*---------------------------------------------------------------------------*/ /**Function******************************************************************** Synopsis [Creates a new DD manager.] Description [Creates a new DD manager, initializes the table, the basic constants and the projection functions. If maxMemory is 0, Cudd_Init decides suitable values for the maximum size of the cache and for the limit for fast unique table growth based on the available memory. Returns a pointer to the manager if successful; NULL otherwise.] SideEffects [None] SeeAlso [Cudd_Quit] ******************************************************************************/ DdManager * Cudd_Init( unsigned int numVars /* initial number of BDD variables (i.e., subtables) */, unsigned int numVarsZ /* initial number of ZDD variables (i.e., subtables) */, unsigned int numSlots /* initial size of the unique tables */, unsigned int cacheSize /* initial size of the cache */, unsigned long maxMemory /* target maximum memory occupation */) { DdManager *unique; int i,result; DdNode *one, *zero; unsigned int maxCacheSize; unsigned int looseUpTo; extern DD_OOMFP MMoutOfMemory; DD_OOMFP saveHandler; if (maxMemory == 0) { maxMemory = getSoftDataLimit(); } looseUpTo = (unsigned int) ((maxMemory / sizeof(DdNode)) / DD_MAX_LOOSE_FRACTION); unique = cuddInitTable(numVars,numVarsZ,numSlots,looseUpTo); if (unique == NULL) return(NULL); unique->maxmem = (unsigned long) maxMemory / 10 * 9; maxCacheSize = (unsigned int) ((maxMemory / sizeof(DdCache)) / DD_MAX_CACHE_FRACTION); result = cuddInitCache(unique,cacheSize,maxCacheSize); if (result == 0) return(NULL); saveHandler = MMoutOfMemory; MMoutOfMemory = Cudd_OutOfMem; unique->stash = ABC_ALLOC(char,(maxMemory / DD_STASH_FRACTION) + 4); MMoutOfMemory = saveHandler; if (unique->stash == NULL) { (void) fprintf(unique->err,"Unable to set aside memory\n"); } /* Initialize constants. */ unique->one = cuddUniqueConst(unique,1.0); if (unique->one == NULL) return(0); cuddRef(unique->one); unique->zero = cuddUniqueConst(unique,0.0); if (unique->zero == NULL) return(0); cuddRef(unique->zero); #ifdef HAVE_IEEE_754 if (DD_PLUS_INF_VAL != DD_PLUS_INF_VAL * 3 || DD_PLUS_INF_VAL != DD_PLUS_INF_VAL / 3) { (void) fprintf(unique->err,"Warning: Crippled infinite values\n"); (void) fprintf(unique->err,"Recompile without -DHAVE_IEEE_754\n"); } #endif unique->plusinfinity = cuddUniqueConst(unique,DD_PLUS_INF_VAL); if (unique->plusinfinity == NULL) return(0); cuddRef(unique->plusinfinity); unique->minusinfinity = cuddUniqueConst(unique,DD_MINUS_INF_VAL); if (unique->minusinfinity == NULL) return(0); cuddRef(unique->minusinfinity); unique->background = unique->zero; /* The logical zero is different from the CUDD_VALUE_TYPE zero! */ one = unique->one; zero = Cudd_Not(one); /* Create the projection functions. */ unique->vars = ABC_ALLOC(DdNodePtr,unique->maxSize); if (unique->vars == NULL) { unique->errorCode = CUDD_MEMORY_OUT; return(NULL); } for (i = 0; i < unique->size; i++) { unique->vars[i] = cuddUniqueInter(unique,i,one,zero); if (unique->vars[i] == NULL) return(0); cuddRef(unique->vars[i]); } if (unique->sizeZ) cuddZddInitUniv(unique); unique->memused += sizeof(DdNode *) * unique->maxSize; unique->bFunc = NULL; unique->bFunc2 = NULL; unique->TimeStop = 0; return(unique); } /* end of Cudd_Init */ /**Function******************************************************************** Synopsis [Deletes resources associated with a DD manager.] Description [Deletes resources associated with a DD manager and resets the global statistical counters. (Otherwise, another manaqger subsequently created would inherit the stats of this one.)] SideEffects [None] SeeAlso [Cudd_Init] ******************************************************************************/ void Cudd_Quit( DdManager * unique) { if (unique->stash != NULL) ABC_FREE(unique->stash); cuddFreeTable(unique); } /* end of Cudd_Quit */ /*---------------------------------------------------------------------------*/ /* Definition of internal functions */ /*---------------------------------------------------------------------------*/ /**Function******************************************************************** Synopsis [Initializes the ZDD universe.] Description [Initializes the ZDD universe. Returns 1 if successful; 0 otherwise.] SideEffects [None] SeeAlso [cuddZddFreeUniv] ******************************************************************************/ int cuddZddInitUniv( DdManager * zdd) { DdNode *p, *res; int i; zdd->univ = ABC_ALLOC(DdNodePtr, zdd->sizeZ); if (zdd->univ == NULL) { zdd->errorCode = CUDD_MEMORY_OUT; return(0); } res = DD_ONE(zdd); cuddRef(res); for (i = zdd->sizeZ - 1; i >= 0; i--) { unsigned int index = zdd->invpermZ[i]; p = res; res = cuddUniqueInterZdd(zdd, index, p, p); if (res == NULL) { Cudd_RecursiveDerefZdd(zdd,p); ABC_FREE(zdd->univ); return(0); } cuddRef(res); cuddDeref(p); zdd->univ[i] = res; } #ifdef DD_VERBOSE cuddZddP(zdd, zdd->univ[0]); #endif return(1); } /* end of cuddZddInitUniv */ /**Function******************************************************************** Synopsis [Frees the ZDD universe.] Description [Frees the ZDD universe.] SideEffects [None] SeeAlso [cuddZddInitUniv] ******************************************************************************/ void cuddZddFreeUniv( DdManager * zdd) { if (zdd->univ) { Cudd_RecursiveDerefZdd(zdd, zdd->univ[0]); ABC_FREE(zdd->univ); } } /* end of cuddZddFreeUniv */ /*---------------------------------------------------------------------------*/ /* Definition of static functions */ /*---------------------------------------------------------------------------*/ ABC_NAMESPACE_IMPL_END