Modelsim (XE III/Starter 6.4b) not allowing me to define a macro function
- by montooner
I'm working on a Xiling FPGA for a course project. Normally we use the lab computers, but I'm trying to install on my own computer.
So, I'm trying to include a macro file using line:
`include "Const.v"
But the following macro function doesn't work. Any ideas why?
`ifdef synthesis // if Synplify
`define SYNPLIFY
`define SYNTHESIS
`define MACROSAFE
`else // if not Synplify
`ifdef MODELSIM
`define SIMULATION
`define MACROSAFE
`else
`define XST
// synthesis translate_off // if XST then stop compiling
`undef XST
`define SIMULATION
`define MODELSIM
// synthesis translate_on // if XST then resume compiling
`ifdef XST
`define SYNTHESIS
`define MACROSAFE
`endif
`endif
`endif
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Section: Log2 Macro
// Desc: A macro to take the log base 2 of any number. Useful for
// calculating bitwidths. Warning, this actually calculates
// log2(x-1), not log2(x).
//------------------------------------------------------------------------------
`ifdef MACROSAFE
`define log2(x) ((((x) > 1) ? 1 : 0) + \
(((x) > 2) ? 1 : 0) + \
(((x) > 4) ? 1 : 0) + \
(((x) > 8) ? 1 : 0) + \
(((x) > 16) ? 1 : 0) + \
(((x) > 32) ? 1 : 0) + \
(((x) > 64) ? 1 : 0) + \
(((x) > 128) ? 1 : 0) + \
(((x) > 256) ? 1 : 0) + \
(((x) > 512) ? 1 : 0) + \
(((x) > 1024) ? 1 : 0) + \
(((x) > 2048) ? 1 : 0) + \
(((x) > 4096) ? 1 : 0) + \
(((x) > 8192) ? 1 : 0) + \
(((x) > 16384) ? 1 : 0) + \
(((x) > 32768) ? 1 : 0) + \
(((x) > 65536) ? 1 : 0) + \
(((x) > 131072) ? 1 : 0) + \
(((x) > 262144) ? 1 : 0) + \
(((x) > 524288) ? 1 : 0) + \
(((x) > 1048576) ? 1 : 0) + \
(((x) > 2097152) ? 1 : 0) + \
(((x) > 4194304) ? 1 : 0) + \
(((x) > 8388608) ? 1 : 0) + \
(((x) > 16777216) ? 1 : 0) + \
(((x) > 33554432) ? 1 : 0) + \
(((x) > 67108864) ? 1 : 0) + \
(((x) > 134217728) ? 1 : 0) + \
(((x) > 268435456) ? 1 : 0) + \
(((x) > 536870912) ? 1 : 0) + \
(((x) > 1073741824) ? 1 : 0))
`endif