1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/lm32_functions.v Sun Apr 04 20:40:03 2010 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +// ============================================================================= 1.5 +// COPYRIGHT NOTICE 1.6 +// Copyright 2006 (c) Lattice Semiconductor Corporation 1.7 +// ALL RIGHTS RESERVED 1.8 +// This confidential and proprietary software may be used only as authorised by 1.9 +// a licensing agreement from Lattice Semiconductor Corporation. 1.10 +// The entire notice above must be reproduced on all authorized copies and 1.11 +// copies may only be made to the extent permitted by a licensing agreement from 1.12 +// Lattice Semiconductor Corporation. 1.13 +// 1.14 +// Lattice Semiconductor Corporation TEL : 1-800-Lattice (USA and Canada) 1.15 +// 5555 NE Moore Court 408-826-6000 (other locations) 1.16 +// Hillsboro, OR 97124 web : http://www.latticesemi.com/ 1.17 +// U.S.A email: techsupport@latticesemi.com 1.18 +// =============================================================================/ 1.19 +// FILE DETAILS 1.20 +// Project : LatticeMico32 1.21 +// File : lm32_functions.v 1.22 +// Title : Common functions 1.23 +// Version : 6.1.17 1.24 +// : Initial Release 1.25 +// Version : 7.0SP2, 3.0 1.26 +// : No Change 1.27 +// Version : 3.5 1.28 +// : Added function to generate log-of-two that rounds-up to 1.29 +// : power-of-two 1.30 +// ============================================================================= 1.31 + 1.32 +function integer clogb2; 1.33 +input [31:0] value; 1.34 +begin 1.35 + for (clogb2 = 0; value > 0; clogb2 = clogb2 + 1) 1.36 + value = value >> 1; 1.37 +end 1.38 +endfunction 1.39 + 1.40 +function integer clogb2_v1; 1.41 +input [31:0] value; 1.42 +reg [31:0] i; 1.43 +reg [31:0] temp; 1.44 +begin 1.45 + temp = 0; 1.46 + i = 0; 1.47 + for (i = 0; temp < value; i = i + 1) 1.48 + temp = 1<<i; 1.49 + clogb2_v1 = i-1; 1.50 +end 1.51 +endfunction 1.52 +