mirror of
				https://github.com/riscv-software-src/opensbi
				synced 2025-11-04 05:50:22 +00:00 
			
		
		
		
	There may be few common mathematics helper functions which can be used anywhere in OpenSBI project. Add a separate math helper function file to add these functions. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
		
			
				
	
	
		
			24 lines
		
	
	
		
			397 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			397 B
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * SPDX-License-Identifier: BSD-2-Clause
 | 
						|
 *
 | 
						|
 * Copyright (c) 2020 Western Digital Corporation or its affiliates.
 | 
						|
 *
 | 
						|
 * Common helper functions used across OpenSBI project.
 | 
						|
 *
 | 
						|
 * Authors:
 | 
						|
 *   Atish Patra <atish.patra@wdc.com>
 | 
						|
 */
 | 
						|
 | 
						|
unsigned long log2roundup(unsigned long x)
 | 
						|
{
 | 
						|
	unsigned long ret = 0;
 | 
						|
 | 
						|
	while (ret < __riscv_xlen) {
 | 
						|
		if (x <= (1UL << ret))
 | 
						|
			break;
 | 
						|
		ret++;
 | 
						|
	}
 | 
						|
 | 
						|
	return ret;
 | 
						|
}
 |