summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@unpythonic.net>2013-09-08 08:44:01 -0500
committerAndy Pugh <andy@bodgesoc.org>2013-09-08 21:42:54 +0100
commit6018a79e518efef15adca2c9dd580deaeab75600 (patch)
tree1ea2665a85650896c2688d83626e36325c6defaf
parent125f811007e1f1c3bd2d4bce7b70b999fa659b42 (diff)
downloadlinuxcnc-6018a79e518efef15adca2c9dd580deaeab75600.tar.gz
linuxcnc-6018a79e518efef15adca2c9dd580deaeab75600.zip
rtapi_math64: signed versions. (Seem to work, ap)
-rw-r--r--docs/man/man3/rtapi_div_u64.3rtapi19
-rw-r--r--src/rtapi/rtapi_math64.h11
2 files changed, 24 insertions, 6 deletions
diff --git a/docs/man/man3/rtapi_div_u64.3rtapi b/docs/man/man3/rtapi_div_u64.3rtapi
index 2058e4b92..bbefad27a 100644
--- a/docs/man/man3/rtapi_div_u64.3rtapi
+++ b/docs/man/man3/rtapi_div_u64.3rtapi
@@ -8,6 +8,10 @@ rtapi_div_u64 \- unsigned division of a 64-bit number by a 32-bit number
__u64 rtapi_div_u64_rem(__u64 \fIdividend\fR, __u32 \fIdivisor\fR, __u32 *\fIremainder\fR)
.HP
__u64 rtapi_div_u64(__u64 \fIdividend\fR, __u32 \fIdivisor\fR)
+.HP
+__s64 rtapi_div_s64(__s64 \fIdividend\fR, __s32 \fIdivisor\fR)
+.HP
+__s64 rtapi_div_s64_rem(__s64 \fIdividend\fR, __s32 \fIdivisor\fR, __s32 *\fIremainder\fR)
.SH ARGUMENTS
.IP \fIdividend\fR
@@ -16,19 +20,22 @@ The value to be divided
The value to divide by
.IP \fIremainder\fR
Pointer to the location to store the remainder. This may not be a NULL
-pointer. If the remainder is not desired, call \fBrtapi_div_u64\fR.
+pointer. If the remainder is not desired, call \fBrtapi_div_u64\fR or
+\fBrtapi_div_s64\fR.
.SH DESCRIPTION
-Perform integer division (and optionally compute the remainder) with a 64-bit dividend.
+Perform integer division (and optionally compute the remainder) with a 64-bit dividend and 32-bit divisor.
.SH RETURN VALUE
-The result of integer division of \fIdividend / divisor\fR.
+The result of integer division of \fIdividend / divisor\fR. In versions with the \fIremainder\fR argument, the remainder is stored in the pointed-to location.
.SH NOTES
-If the result of the division does not fit in a \fB__u32\fR, the result is undefined.
+If the result of the division does not fit in the return type, the result is
+undefined.
-This function exists because in kernel space, the use of the division operator
-on a 64-bit type can lead to an undefined symbol when the module is loaded.
+This function exists because in kernel space the use of the division operator
+on a 64-bit type can lead to an undefined symbol such as __umoddi3 when the
+module is loaded.
.SH REALTIME CONSIDERATIONS
May be called from init/cleanup code and from within realtime tasks.
diff --git a/src/rtapi/rtapi_math64.h b/src/rtapi/rtapi_math64.h
index 90c5f99c8..03e5fcc82 100644
--- a/src/rtapi/rtapi_math64.h
+++ b/src/rtapi/rtapi_math64.h
@@ -5,6 +5,8 @@
#include <linux/math64.h>
#define rtapi_div_u64_rem div_u64_rem
#define rtapi_div_u64 div_u64
+#define rtapi_div_s64_rem div_s64_rem
+#define rtapi_div_s64 div_s64
#else
static inline __u64 rtapi_div_u64_rem(__u64 dividend, __u32 divisor, __u32 *remainder)
{
@@ -15,6 +17,15 @@ static inline __u64 rtapi_div_u64_rem(__u64 dividend, __u32 divisor, __u32 *rema
static inline __u64 rtapi_div_u64(__u64 dividend, __u32 divisor) {
return dividend / divisor;
}
+static inline __s64 rtapi_div_s64_rem(__s64 dividend, __s32 divisor, __s32 *remainder)
+{
+ *remainder = dividend % divisor;
+ return dividend / divisor;
+}
+
+static inline __s64 rtapi_div_s64(__s64 dividend, __s32 divisor) {
+ return dividend / divisor;
+}
#endif
#endif