At 10:38 PM 7/10/2002, William A. Rowe, Jr. wrote:
At 10:03 PM 7/10/2002, Brian Pane wrote:
Bill Stoddard wrote:

I've not looked at the generated code, but profiling indicates that an
additional division is happening, adding an extra 231 instructions.
(xlc_r -O2)

If you redefine the macro as a shift, does the profile look better?

Ok, attached is the code redone as binary math. I'm tired, could be any number of major blunders in it, but on first pass, it looked right.

Bill
Index: include/apr_time.h
===================================================================
RCS file: /home/cvs/apr/include/apr_time.h,v
retrieving revision 1.54
diff -u -r1.54 apr_time.h
--- include/apr_time.h  2 Jul 2002 15:47:12 -0000       1.54
+++ include/apr_time.h  11 Jul 2002 05:32:17 -0000
@@ -92,19 +92,23 @@
 /** short interval for I/O timeouts, in microseconds */
 typedef apr_int32_t apr_short_interval_time_t;
 
-/** number of microseconds per second */
-#define APR_USEC_PER_SEC APR_TIME_C(1000000)
+/** number of binary microseconds per second (2^20) */
+#define APR_USEC_PER_SEC APR_TIME_C(1048576)
+#define APR_USEC_BITS 20
 
-#define apr_time_usec(time) ((apr_int32_t)((time) % APR_USEC_PER_SEC))
+#define apr_time_usec(time) ((apr_int32_t)((((time) & (APR_USEC_PER_SEC - 1)) \
+                             * APR_TIME_C(1000000)) >> APR_USEC_BITS))
 
-#define apr_time_nsec(time) ((apr_int32_t)((time) % APR_USEC_PER_SEC) * 
(apr_int32_t)1000)
+#define apr_time_nsec(time) ((apr_int32_t)((((time) & (APR_USEC_PER_SEC - 1)) \
+                          * APR_TIME_C(1000000000)) >> APR_USEC_BITS))
 
-#define apr_time_sec(time) ((apr_int64_t)((time) / APR_USEC_PER_SEC))
+#define apr_time_sec(time) ((apr_int64_t)((time) >> APR_USEC_BITS))
 
-#define apr_time_from_sec(sec) ((apr_time_t)(sec) * APR_USEC_PER_SEC)
+#define apr_time_from_sec(sec) ((apr_time_t)(sec) << APR_USEC_BITS)
+
+#define apr_time_make(sec, usec) ((apr_time_t)(sec) << APR_USEC_BITS \
+          + ((apr_time_t)(usec) * APR_TIME_C(1000000)) >> APR_USEC_BITS)
 
-#define apr_time_make(sec, usec) ((apr_time_t)(sec) * APR_USEC_PER_SEC \
-                                + (apr_time_t)(usec))
 
 /**
  * return the current time

Reply via email to