Jan van Oosterwijk wrote:
> Once upun a time (in the 1960's) there existed a Dutch computer,
> called "Electrologica X8", that implemented Booleans as single bits.
> I'm not sure there has ever been a Fortran compiler for this system.
>
> >The reason seems to be cost: a bit address is a new _class_ of
> >address for the compiler to know about. Anyway, type bit_logical
> >always seems to get shot down. It's been brought up over the
> >years. I believe it is impossible to do via the type mechanism
> >(and have something you can use = to assign to or from).
> >
> ><snip sig>
>
> ---
Shouldn't it be possible to write a bit_vector type, though? If all you
need is one flag, then you might as well use logical and be done with
it. But when you really want single bit booleans is when you need a lot
of them, such as for masks. I haven't sat down and tried to work it out
very carefully, but it should be possible to encapsulate a bit vector
type made up of reallocatable arrays of default integer. Then when you
ask for a bit_vector of size n, it is implemented as an integer array of
size n/(#bits in standard integer) + 1. You would implement the class
methods with the bit manipulation routines already in the language.
In fact, you could mke it even simpler by just having a scalar type with
one integer, and using some parameters supplied by the class to
calculate the size of the array, like this:
module bit_vector_class
public :: bit_vector
type :: bit_vector
private
integer :: bits
end type bit_vector
integer,public,parameter :: NoBitsInteger = ####
! Methods using bit arithmetic intrinsics follow...
....
use bit_vector_class
type(bit_vector),dimension(NoBitsInteger/n + 1) :: bv
! Processing follows...
This has the advantage that we can use allocatable arrays, automatic
arrays, etc.
Alvaro Fernandez
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|