summaryrefslogtreecommitdiff
path: root/TAO/tao/align.h
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-07-02 05:14:19 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-07-02 05:14:19 +0000
commit05834cf795347886b4daf40d2497a4efae91aec3 (patch)
tree342202567424d86b13f973916f58c0511331046f /TAO/tao/align.h
parent1a9acde7970222a4434ccf485d0895090960da7b (diff)
downloadATCD-05834cf795347886b4daf40d2497a4efae91aec3.tar.gz
*** empty log message ***
Diffstat (limited to 'TAO/tao/align.h')
-rw-r--r--TAO/tao/align.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/TAO/tao/align.h b/TAO/tao/align.h
new file mode 100644
index 00000000000..cf11ac0447e
--- /dev/null
+++ b/TAO/tao/align.h
@@ -0,0 +1,80 @@
+// This may look like C, but it's really -*- C++ -*-
+// @(#) $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO
+//
+// = FILENAME
+// align.h
+//
+// = DESCRIPTION
+// Pointer alignment utilities
+//
+// A "ptr_arith_t" type is defined for doing numerical operations
+// on pointers, such as aligning them. Pointer sizes vary from 2
+// to 8 bytes in today's environments; a portable data type is much
+// needed.
+//
+// = AUTHOR
+// Copyright 1994-1995 by Sun Microsystems, Inc.
+//
+// ============================================================================
+
+#if !defined (TAO_ALIGN_H)
+#define TAO_ALIGN_H
+
+// Type for doing arithmetic on pointers ... as elsewhere, we assume
+// that "unsigned" versions of a type are the same size as the
+// "signed" version of the same type.
+
+#if SIZEOF_VOID_P == SIZEOF_INT
+typedef u_int ptr_arith_t;
+
+#elif SIZEOF_VOID_P == SIZEOF_LONG
+typedef u_long ptr_arith_t;
+
+#elif SIZEOF_VOID_P == SIZEOF_LONG_LONG
+typedef u_long long ptr_arith_t;
+
+#else
+# error "Can't find a suitable type for doing pointer arithmetic."
+#endif
+
+// Efficiently align "value" up to "alignment", knowing that all such
+// boundaries are binary powers and that we're using two's complement
+// arithmetic.
+
+#if 0
+static inline ptr_arith_t
+align_binary (const ptr_arith_t value,
+ size_t alignment)
+{
+ ptr_arith_t temp = alignment - 1;
+
+ return (value + temp) & ~temp;
+}
+#endif
+#define align_binary(ptr, align_sub_1) \
+ ((ptr + (align_sub_1)) & (~(align_sub_1)))
+
+// Efficiently round "ptr" up to an "alignment" boundary, knowing that
+// all such boundaries are binary powers and that we're using two's
+// complement arithmetic.
+//
+// XXX Returned as "byte pointer" -- CDR module would change to be
+// seen as a "void *". May want to change this to add XDR cleanly.
+
+#if 0
+static inline u_char *
+ptr_align_binary (const u_char *ptr,
+ size_t alignment)
+{
+ return (u_char *) align_binary ((ptr_arith_t) ptr, alignment);
+}
+#endif
+#define ptr_align_binary(ptr, alignment) \
+ ((u_char *) align_binary(((ptr_arith_t) (ptr)), ((alignment)-1)))
+
+#endif /* TAO_ALIGN_H */