aboutsummaryrefslogtreecommitdiff
path: root/sys/nmemio/coerce.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/nmemio/coerce.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/nmemio/coerce.x')
-rw-r--r--sys/nmemio/coerce.x25
1 files changed, 25 insertions, 0 deletions
diff --git a/sys/nmemio/coerce.x b/sys/nmemio/coerce.x
new file mode 100644
index 00000000..36f762b2
--- /dev/null
+++ b/sys/nmemio/coerce.x
@@ -0,0 +1,25 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+# COERCE -- Coerce a pointer from one datatype to another, choosing the
+# next larger element for t2 in the event that t1 is not aligned with t2.
+
+pointer procedure coerce (ptr, type1, type2)
+
+pointer ptr # input pointer
+int type1, type2 # from, to data types
+int n
+pointer p
+include <szdtype.inc>
+
+begin
+ p = ptr - 1
+ if (type1 == TY_CHAR) {
+ return (p / ty_size[type2] + 1)
+ } else if (type2 == TY_CHAR) {
+ return (p * ty_size[type1] + 1)
+ } else {
+ p = p * ty_size[type1] # ptr to char
+ n = ty_size[type2]
+ return (((p + n-1) / n) + 1)
+ }
+end