lm32_functions.v

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