| |
| Posted by Tiago Gasiba | PermalinkReply |
|
Tiago Gasiba
| Hi *,
I'm trying to port a C library I have written in C to the D programming
language; This library manages matrixes of bits, in which a single row of a
matrix is represented (in C) by an array of ints. Each int holds 32 bits -
operations are really done at the bit-level - a mess with C.
Therefore, I need to implement a very fast bit-array in D. For this, I try
to use the data structure "bit []", but it is not flexible enough,
according to my experiments. For example, the following code does not
compile, or even worse, the compiler gets crazy :)
------- test.d -------
import std.c.stdio;
const int L = 10;
int main( char [][] argv ){
bit [] X;
bit [] Y;
int ii;
X.length=L;
Y.length=L;
X[] = true;
Y[] = true;
X[] ^= Y[]; (1)
for( ii=0; ii<L; ii++ ) (2)
X[ii] ^= Y[ii]; (3)
for( ii=0; ii<L; ii++ )
printf("%d ",X[ii]);
printf("\n");
return 0;
}
--------------
Internally, a "bit []" is represented with longs (or ints) or whatever;
The expression "X[] ^= Y[]", i.e number 1, should work at bit-level with
the longs; an implementation like number 2 and number 3 would be extremely
slow, specially for very large arrays.
The other problem is that, if you comment out line (1), the compiler gets
crazy: "Internal error: ../ztc/cgcs.c 213".
I'm using "Digital Mars D Compiler v0.127" under Linux SuSE 9.2.
Any comments / solutions?
Can a fast bit-array manipulation routine be implemented in the next
version of D? If this is not the case, I need to have to consider two
cases:
- continue to use the code already in C, and import my functions through a
".o" object - ugly solution
- forget about D, i.e. D does not bring advantage, therefore continue
programming as before in C.
I think that an internal D implementation is very very easy, i.e. just
consider that an bit-array is composed by, for example, N integers, and OR,
XOR or AND each integer as required, and the net effect is that the
individual bits also go through the same operation... This is what I
currently have implemented in C :)
BR,
Tiago
|