summaryrefslogtreecommitdiff
path: root/nios2sim-ng.h
blob: 7a3d711cc6b826b077e71816cfa185387b8a303f (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
/*
 *
 */

#ifndef _NIOS2SIM_NG_H_
#define _NIOS2SIM_NG_H_

#include <stdlib.h>
#include <stdint.h>

#include "compiler.h"

#define __round_mask(x, y)	((__typeof__(x))((y) - 1))
#define round_up(x, y)		((((x) - 1) | __round_mask(x, y)) + 1)

#define err(fmt, args...)	fprintf(stderr, "Error: " fmt, ##args)
#define warn(fmt, args...)	fprintf(stderr, "Warning: " fmt, ##args)
#define info(fmt, args...)	fprintf(stdout, fmt, ##args)
#ifdef DEBUG
# define dbg(fmt, args...)	fprintf(stdout, fmt, ##args)
#else
# define dbg(fmt, args...)
#endif

static inline size_t size_scale(size_t size)
{
	if (size > 1024 * 1024)
		size /= 1024 * 1024;
	else if (size > 1024)
		size /= 1024;

	return size;
}

static inline char *size_postfix(size_t size)
{
	char *ret = "";

	if (size > 1024 * 1024)
		ret = "M";
	else if (size > 1024)
		ret = "K";

	return ret;
}

#endif /* _NIOS2SIM_NG_H_ */