1 /* SPDX-License-Identifier: GPL-2.0 */ << 2 << 3 scale=0 1 scale=0 4 2 5 define gcd(a,b) { 3 define gcd(a,b) { 6 auto t; 4 auto t; 7 while (b) { 5 while (b) { 8 t = b; 6 t = b; 9 b = a % b; 7 b = a % b; 10 a = t; 8 a = t; 11 } 9 } 12 return a; 10 return a; 13 } 11 } 14 12 15 /* Division by reciprocal multiplication. */ 13 /* Division by reciprocal multiplication. */ 16 define fmul(b,n,d) { 14 define fmul(b,n,d) { 17 return (2^b*n+d-1)/d; 15 return (2^b*n+d-1)/d; 18 } 16 } 19 17 20 /* Adjustment factor when a ceiling value is u 18 /* Adjustment factor when a ceiling value is used. Use as: 21 (imul * n) + (fmulxx * n + fadjxx) >> xx) * 19 (imul * n) + (fmulxx * n + fadjxx) >> xx) */ 22 define fadj(b,n,d) { 20 define fadj(b,n,d) { 23 auto v; 21 auto v; 24 d = d/gcd(n,d); 22 d = d/gcd(n,d); 25 v = 2^b*(d-1)/d; 23 v = 2^b*(d-1)/d; 26 return v; 24 return v; 27 } 25 } 28 26 29 /* Compute the appropriate mul/adj values as w 27 /* Compute the appropriate mul/adj values as well as a shift count, 30 which brings the mul value into the range 2 28 which brings the mul value into the range 2^b-1 <= x < 2^b. Such 31 a shift value will be correct in the signed 29 a shift value will be correct in the signed integer range and off 32 by at most one in the upper half of the uns 30 by at most one in the upper half of the unsigned range. */ 33 define fmuls(b,n,d) { 31 define fmuls(b,n,d) { 34 auto s, m; 32 auto s, m; 35 for (s = 0; 1; s++) { 33 for (s = 0; 1; s++) { 36 m = fmul(s,n,d); 34 m = fmul(s,n,d); 37 if (m >= 2^(b-1)) 35 if (m >= 2^(b-1)) 38 return s; 36 return s; 39 } 37 } 40 return 0; 38 return 0; 41 } 39 } 42 40 43 define timeconst(hz) { 41 define timeconst(hz) { 44 print "/* Automatically generated by k 42 print "/* Automatically generated by kernel/time/timeconst.bc */\n" 45 print "/* Time conversion constants fo 43 print "/* Time conversion constants for HZ == ", hz, " */\n" 46 print "\n" 44 print "\n" 47 45 48 print "#ifndef KERNEL_TIMECONST_H\n" 46 print "#ifndef KERNEL_TIMECONST_H\n" 49 print "#define KERNEL_TIMECONST_H\n\n" 47 print "#define KERNEL_TIMECONST_H\n\n" 50 48 51 print "#include <linux/param.h>\n" 49 print "#include <linux/param.h>\n" 52 print "#include <linux/types.h>\n\n" 50 print "#include <linux/types.h>\n\n" 53 51 54 print "#if HZ != ", hz, "\n" 52 print "#if HZ != ", hz, "\n" 55 print "#error \qinclude/generated/time 53 print "#error \qinclude/generated/timeconst.h has the wrong HZ value!\q\n" 56 print "#endif\n\n" 54 print "#endif\n\n" 57 55 58 if (hz < 2) { 56 if (hz < 2) { 59 print "#error Totally bogus HZ 57 print "#error Totally bogus HZ value!\n" 60 } else { 58 } else { 61 s=fmuls(32,1000,hz) 59 s=fmuls(32,1000,hz) 62 obase=16 60 obase=16 63 print "#define HZ_TO_MSEC_MUL3 61 print "#define HZ_TO_MSEC_MUL32\tU64_C(0x", fmul(s,1000,hz), ")\n" 64 print "#define HZ_TO_MSEC_ADJ3 62 print "#define HZ_TO_MSEC_ADJ32\tU64_C(0x", fadj(s,1000,hz), ")\n" 65 obase=10 63 obase=10 66 print "#define HZ_TO_MSEC_SHR3 64 print "#define HZ_TO_MSEC_SHR32\t", s, "\n" 67 65 68 s=fmuls(32,hz,1000) 66 s=fmuls(32,hz,1000) 69 obase=16 67 obase=16 70 print "#define MSEC_TO_HZ_MUL3 68 print "#define MSEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000), ")\n" 71 print "#define MSEC_TO_HZ_ADJ3 69 print "#define MSEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000), ")\n" 72 obase=10 70 obase=10 73 print "#define MSEC_TO_HZ_SHR3 71 print "#define MSEC_TO_HZ_SHR32\t", s, "\n" 74 72 75 obase=10 73 obase=10 76 cd=gcd(hz,1000) 74 cd=gcd(hz,1000) 77 print "#define HZ_TO_MSEC_NUM\ 75 print "#define HZ_TO_MSEC_NUM\t\t", 1000/cd, "\n" 78 print "#define HZ_TO_MSEC_DEN\ 76 print "#define HZ_TO_MSEC_DEN\t\t", hz/cd, "\n" 79 print "#define MSEC_TO_HZ_NUM\ 77 print "#define MSEC_TO_HZ_NUM\t\t", hz/cd, "\n" 80 print "#define MSEC_TO_HZ_DEN\ 78 print "#define MSEC_TO_HZ_DEN\t\t", 1000/cd, "\n" 81 print "\n" 79 print "\n" 82 80 83 s=fmuls(32,1000000,hz) 81 s=fmuls(32,1000000,hz) 84 obase=16 82 obase=16 85 print "#define HZ_TO_USEC_MUL3 83 print "#define HZ_TO_USEC_MUL32\tU64_C(0x", fmul(s,1000000,hz), ")\n" 86 print "#define HZ_TO_USEC_ADJ3 84 print "#define HZ_TO_USEC_ADJ32\tU64_C(0x", fadj(s,1000000,hz), ")\n" 87 obase=10 85 obase=10 88 print "#define HZ_TO_USEC_SHR3 86 print "#define HZ_TO_USEC_SHR32\t", s, "\n" 89 87 90 s=fmuls(32,hz,1000000) 88 s=fmuls(32,hz,1000000) 91 obase=16 89 obase=16 92 print "#define USEC_TO_HZ_MUL3 90 print "#define USEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000000), ")\n" 93 print "#define USEC_TO_HZ_ADJ3 91 print "#define USEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000000), ")\n" 94 obase=10 92 obase=10 95 print "#define USEC_TO_HZ_SHR3 93 print "#define USEC_TO_HZ_SHR32\t", s, "\n" 96 94 97 obase=10 95 obase=10 98 cd=gcd(hz,1000000) 96 cd=gcd(hz,1000000) 99 print "#define HZ_TO_USEC_NUM\ 97 print "#define HZ_TO_USEC_NUM\t\t", 1000000/cd, "\n" 100 print "#define HZ_TO_USEC_DEN\ 98 print "#define HZ_TO_USEC_DEN\t\t", hz/cd, "\n" 101 print "#define USEC_TO_HZ_NUM\ 99 print "#define USEC_TO_HZ_NUM\t\t", hz/cd, "\n" 102 print "#define USEC_TO_HZ_DEN\ 100 print "#define USEC_TO_HZ_DEN\t\t", 1000000/cd, "\n" 103 101 104 cd=gcd(hz,1000000000) 102 cd=gcd(hz,1000000000) 105 print "#define HZ_TO_NSEC_NUM\ 103 print "#define HZ_TO_NSEC_NUM\t\t", 1000000000/cd, "\n" 106 print "#define HZ_TO_NSEC_DEN\ 104 print "#define HZ_TO_NSEC_DEN\t\t", hz/cd, "\n" 107 print "#define NSEC_TO_HZ_NUM\ 105 print "#define NSEC_TO_HZ_NUM\t\t", hz/cd, "\n" 108 print "#define NSEC_TO_HZ_DEN\ 106 print "#define NSEC_TO_HZ_DEN\t\t", 1000000000/cd, "\n" 109 print "\n" 107 print "\n" 110 108 111 print "#endif /* KERNEL_TIMECO 109 print "#endif /* KERNEL_TIMECONST_H */\n" 112 } 110 } 113 halt 111 halt 114 } 112 } 115 113 116 hz = read(); 114 hz = read(); 117 timeconst(hz) 115 timeconst(hz)
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.