Blame view

kernel/time/timeconst.bc 2.75 KB
70730bca1   H. Peter Anvin   kernel: Replace t...
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
  scale=0
  
  define gcd(a,b) {
  	auto t;
  	while (b) {
  		t = b;
  		b = a % b;
  		a = t;
  	}
  	return a;
  }
  
  /* Division by reciprocal multiplication. */
  define fmul(b,n,d) {
         return (2^b*n+d-1)/d;
  }
  
  /* Adjustment factor when a ceiling value is used.  Use as:
     (imul * n) + (fmulxx * n + fadjxx) >> xx) */
  define fadj(b,n,d) {
  	auto v;
  	d = d/gcd(n,d);
  	v = 2^b*(d-1)/d;
  	return v;
  }
  
  /* Compute the appropriate mul/adj values as well as a shift count,
     which brings the mul value into the range 2^b-1 <= x < 2^b.  Such
     a shift value will be correct in the signed integer range and off
     by at most one in the upper half of the unsigned range. */
  define fmuls(b,n,d) {
  	auto s, m;
  	for (s = 0; 1; s++) {
  		m = fmul(s,n,d);
  		if (m >= 2^(b-1))
  			return s;
  	}
  	return 0;
  }
  
  define timeconst(hz) {
03f136a20   Jason A. Donenfeld   timeconst: Update...
42
43
  	print "/* Automatically generated by kernel/time/timeconst.bc */
  "
70730bca1   H. Peter Anvin   kernel: Replace t...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  	print "/* Time conversion constants for HZ == ", hz, " */
  "
  	print "
  "
  
  	print "#ifndef KERNEL_TIMECONST_H
  "
  	print "#define KERNEL_TIMECONST_H
  
  "
  
  	print "#include <linux/param.h>
  "
  	print "#include <linux/types.h>
  
  "
  
  	print "#if HZ != ", hz, "
  "
0a227985d   Nicholas Mc Guire   time: Move timeco...
63
64
  	print "#error \qinclude/generated/timeconst.h has the wrong HZ value!\q
  "
70730bca1   H. Peter Anvin   kernel: Replace t...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  	print "#endif
  
  "
  
  	if (hz < 2) {
  		print "#error Totally bogus HZ value!
  "
  	} else {
  		s=fmuls(32,1000,hz)
  		obase=16
  		print "#define HZ_TO_MSEC_MUL32\tU64_C(0x", fmul(s,1000,hz), ")
  "
  		print "#define HZ_TO_MSEC_ADJ32\tU64_C(0x", fadj(s,1000,hz), ")
  "
  		obase=10
  		print "#define HZ_TO_MSEC_SHR32\t", s, "
  "
  
  		s=fmuls(32,hz,1000)
  		obase=16
  		print "#define MSEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000), ")
  "
  		print "#define MSEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000), ")
  "
  		obase=10
  		print "#define MSEC_TO_HZ_SHR32\t", s, "
  "
  
  		obase=10
  		cd=gcd(hz,1000)
  		print "#define HZ_TO_MSEC_NUM\t\t", 1000/cd, "
  "
  		print "#define HZ_TO_MSEC_DEN\t\t", hz/cd, "
  "
  		print "#define MSEC_TO_HZ_NUM\t\t", hz/cd, "
  "
  		print "#define MSEC_TO_HZ_DEN\t\t", 1000/cd, "
  "
  		print "
  "
  
  		s=fmuls(32,1000000,hz)
  		obase=16
  		print "#define HZ_TO_USEC_MUL32\tU64_C(0x", fmul(s,1000000,hz), ")
  "
  		print "#define HZ_TO_USEC_ADJ32\tU64_C(0x", fadj(s,1000000,hz), ")
  "
  		obase=10
  		print "#define HZ_TO_USEC_SHR32\t", s, "
  "
  
  		s=fmuls(32,hz,1000000)
  		obase=16
  		print "#define USEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000000), ")
  "
  		print "#define USEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000000), ")
  "
  		obase=10
  		print "#define USEC_TO_HZ_SHR32\t", s, "
  "
  
  		obase=10
  		cd=gcd(hz,1000000)
  		print "#define HZ_TO_USEC_NUM\t\t", 1000000/cd, "
  "
  		print "#define HZ_TO_USEC_DEN\t\t", hz/cd, "
  "
  		print "#define USEC_TO_HZ_NUM\t\t", hz/cd, "
  "
  		print "#define USEC_TO_HZ_DEN\t\t", 1000000/cd, "
  "
  		print "
  "
  
  		print "#endif /* KERNEL_TIMECONST_H */
  "
  	}
  	halt
  }
0a227985d   Nicholas Mc Guire   time: Move timeco...
144
  hz = read();
70730bca1   H. Peter Anvin   kernel: Replace t...
145
  timeconst(hz)