forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit6b9bba2
committed
Marginal performance hacking in erand48.c.
Get rid of the multiplier and addend variables in favor of hard-wiredconstants. Do the multiply-and-add using uint64 arithmetic, ratherthan manually combining several narrower multiplications and additions.Make _dorand48 return the full-width new random value, and have itscallers use that directly (after suitable masking) rather thanreconstructing what they need from the unsigned short[] representation.On my machine, this is good for a nearly factor-of-2 speedup ofpg_erand48(), probably mostly from needing just one call of ldexp()rather than three. The wins for the other functions are smallerbut measurable. While none of the existing call sites are reallyperformance-critical, a cycle saved is a cycle earned; and besidesthe machine code is smaller this way (at least on x86_64).Patch by me, but the original idea to optimize this by switchingto int64 arithmetic is from Fabien Coelho.Discussion:https://postgr.es/m/1551.1546018192@sss.pgh.pa.us1 parente090466 commit6b9bba2
1 file changed
+33
-38
lines changedLines changed: 33 additions & 38 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
37 | 37 |
| |
38 | 38 |
| |
39 | 39 |
| |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 |
| |
41 | 46 |
| |
42 | 47 |
| |
43 |
| - | |
44 |
| - | |
45 |
| - | |
46 |
| - | |
47 | 48 |
| |
48 | 49 |
| |
49 | 50 |
| |
50 | 51 |
| |
51 | 52 |
| |
52 | 53 |
| |
53 |
| - | |
54 |
| - | |
55 |
| - | |
56 |
| - | |
57 |
| - | |
58 |
| - | |
59 | 54 |
| |
60 | 55 |
| |
61 | 56 |
| |
62 | 57 |
| |
| 58 | + | |
| 59 | + | |
| 60 | + | |
63 | 61 |
| |
64 |
| - | |
| 62 | + | |
65 | 63 |
| |
66 | 64 |
| |
67 |
| - | |
68 |
| - | |
69 |
| - | |
70 |
| - | |
71 |
| - | |
72 |
| - | |
73 |
| - | |
74 |
| - | |
75 |
| - | |
76 |
| - | |
77 |
| - | |
78 |
| - | |
79 |
| - | |
80 |
| - | |
81 |
| - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
82 | 80 |
| |
83 | 81 |
| |
84 | 82 |
| |
| |||
89 | 87 |
| |
90 | 88 |
| |
91 | 89 |
| |
92 |
| - | |
93 |
| - | |
94 |
| - | |
95 |
| - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
96 | 93 |
| |
97 | 94 |
| |
98 | 95 |
| |
| |||
102 | 99 |
| |
103 | 100 |
| |
104 | 101 |
| |
105 |
| - | |
106 |
| - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
107 | 105 |
| |
108 | 106 |
| |
109 | 107 |
| |
| |||
113 | 111 |
| |
114 | 112 |
| |
115 | 113 |
| |
116 |
| - | |
117 |
| - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
118 | 117 |
| |
119 | 118 |
| |
120 | 119 |
| |
| |||
134 | 133 |
| |
135 | 134 |
| |
136 | 135 |
| |
137 |
| - | |
138 |
| - | |
139 |
| - | |
140 |
| - | |
141 | 136 |
|
0 commit comments
Comments
(0)