promotional, or sales literature without prior written consent from
MIT in each case. */
-/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.32 1987/08/06 19:58:57 jinx Exp $
+/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.33 1987/08/17 19:31:42 jinx Exp $
Bit string primitives.
\f
#define read_bits_initialize() \
long end, end_mod, offset; \
+ Pointer *start; \
Primitive_3_Args (); \
\
CHECK_ARG (3, BIT_STRING_P); \
end = (bit_string_length (Arg3)); \
end_mod = (end % POINTER_LENGTH); \
- offset = (arg_nonnegative_integer (2))
+ offset = (arg_nonnegative_integer (2)); \
+ start = read_bits_ptr(Arg1, offset, end); \
+ compute_read_bits_offset(offset, end)
+
/* (READ-BITS! pointer offset bit-string)
Read the contents of memory at the address (POINTER,OFFSET)
{
read_bits_initialize();
- copy_bits ((object_msw_ptr(Arg1, (offset + end))),
+ copy_bits (start,
offset,
(Nth_Vector_Loc (Arg3, (index_to_word (Arg3, (end - 1))))),
((end_mod == 0) ? 0 : (POINTER_LENGTH - end_mod)),
copy_bits ((Nth_Vector_Loc (Arg3, (index_to_word (Arg3, (end - 1))))),
((end_mod == 0) ? 0 : (POINTER_LENGTH - end_mod)),
- (object_msw_ptr(Arg1, (offset + end))),
+ start,
offset,
end);
PRIMITIVE_RETURN( NIL);
/* -*-C-*-
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.h,v 1.3 1987/08/06 05:03:44 jinx Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.h,v 1.4 1987/08/17 19:32:28 jinx Rel $
Copyright (c) 1987 Massachusetts Institute of Technology
#define BIT_STRING_LENGTH_OFFSET 1
#define BIT_STRING_FIRST_WORD 2
-#define bits_to_pointers(bits) \
+#define bits_to_pointers(bits) \
(((bits) + (POINTER_LENGTH - 1)) / POINTER_LENGTH)
#define low_mask(nbits) ((1 << (nbits)) - 1)
#define any_mask(nbits, offset) ((low_mask (nbits)) << (offset))
-#define bit_string_length(bit_string) \
+#define bit_string_length(bit_string) \
(Fast_Vector_Ref (bit_string, BIT_STRING_LENGTH_OFFSET))
-#define bit_string_start_ptr(bit_string) \
+#define bit_string_start_ptr(bit_string) \
(Nth_Vector_Loc (bit_string, BIT_STRING_FIRST_WORD))
-#define bit_string_end_ptr(bit_string) \
+#define bit_string_end_ptr(bit_string) \
(Nth_Vector_Loc (bit_string, ((Vector_Length (bit_string)) + 1)))
-#define bit_string_msw(bit_string) \
+#define bit_string_msw(bit_string) \
(bit_string_word(bit_string_high_ptr(bit_string)))
-#define bit_string_lsw(bit_string) \
+#define bit_string_lsw(bit_string) \
(bit_string_word(Nth_Vector_Loc(bit_string, index_to_word(bit_string, 0))))
-#define index_pair_to_bit_fixnum(string, word, bit) \
+#define index_pair_to_bit_fixnum(string, word, bit) \
(Make_Unsigned_Fixnum (index_pair_to_bit_number (string, word, bit)))
\f
/* Byte order dependencies. */
#define inc_bit_string_ptr(ptr) ((ptr)++)
-#define object_msw_ptr(object, length) \
-(Get_Pointer(object) + bits_to_pointers(length - 1))
-
/* This is off by one so bit_string_word will get the correct word. */
-#define index_to_word(bit_string, index) \
+#define index_to_word(bit_string, index) \
((BIT_STRING_FIRST_WORD + 1) + (index / POINTER_LENGTH))
-#define index_pair_to_bit_number(string, word, bit) \
+#define index_pair_to_bit_number(string, word, bit) \
(((word) * POINTER_LENGTH) + (bit))
+#define read_bits_ptr(object, offset, end) \
+(Nth_Vector_Loc(object, bits_to_pointers((offset + end) - 1)))
+
+#define compute_read_bits_offset(offset, end) \
+{ \
+ offset = ((offset + end) % POINTER_LENGTH); \
+ if (offset != 0) \
+ offset = (POINTER_LENGTH - offset); \
+}
+
\f
#else /* not VAX_BYTE_ORDER */
#define inc_bit_string_ptr(ptr) (--(ptr))
-#define object_msw_ptr(object, length) (Get_Pointer(object))
-
/* This is especially clever. To understand it, note that the index
of the last pointer of a vector is also the GC length of the
vector, so that all we need do is subtract the zero-based word
index from the GC length. */
-#define index_to_word(bit_string, index) \
+#define index_to_word(bit_string, index) \
((Vector_Length (bit_string)) - (index / POINTER_LENGTH))
-#define index_pair_to_bit_number(string, word, bit) \
+#define index_pair_to_bit_number(string, word, bit) \
((((Vector_Length (string)) - (word)) * POINTER_LENGTH) + (bit))
+#define read_bits_ptr(object, offset, end) \
+(Nth_Vector_Loc((object), ((offset) / POINTER_LENGTH)))
+
+#define compute_read_bits_offset(offset, end) \
+{ \
+ offset = (offset % POINTER_LENGTH); \
+}
+
#endif /* VAX_BYTE_ORDER */