Based on patches from H.J. Lu <hjl@nynexst.com>: