This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Uniform "floats"


Hi Everybody,

I'm working on a small hack that involves interfacing guile to some
routines that use lots of arrays of floats (not doubles).  It appears
that there is a nice mapping between uniform vectors of floats, and C
arrays of floats so it would be nice to just pass the address of a
uniform array to the C function.  Since some of the arrays are
quite large I will save overhead and make the glue code much easier to
understand by not having to convert.  I've tested this out and it
seems to work well enough.

BUT, I work on 32 bit suns and 64 bit alphas.  On the 64bit alpha,
uniform vectors of floats are not enabled (SCM_SINGLES is undefined
since sizeof(float) != sizeof(long)).  The best option seems to be
using an uniform vectors of doubles and converting.  I've looked over
the source code (971123 and 971215) and I don't see any technical
reason to not define SCM_SINGLES on a 64 bit machine, but it's likely
I've missed something.  I have defined SCM_SINGLES by hand letting the
interpreter decide whether to use a single or a double depending on
the precision of the number.  This seems to work.

It would be very convenient if uniform vectors of floats were
available on 64bit machines.  This seems to be possible by simply
changing configure.in from

**********
AC_TRY_RUN(main () { exit (sizeof(float) != sizeof(long)); },
           AC_DEFINE(SCM_SINGLES),,AC_DEFINE(SCM_SINGLES)
           AC_MSG_WARN(Guessing that sizeof(long) == sizeof(float) -- see scmcon
fig.h.in))
**********

to
**********
AC_TRY_RUN(main () { exit (sizeof(float) > sizeof(long)); },
           AC_DEFINE(SCM_SINGLES),,AC_DEFINE(SCM_SINGLES)
           AC_MSG_WARN(Guessing that sizeof(long) < sizeof(float) -- see scmcon
fig.h.in))
**********
and 

libguile/init.c from

**********
#ifdef SCM_SINGLES
  if (sizeof (float) != sizeof (long))
      fixconfig (remsg, "SCM_SINGLES", 0);
#endif /* def SCM_SINGLES */
**********

to
**********
#ifdef SCM_SINGLES
  if (sizeof (float) > sizeof (long))
      fixconfig (remsg, "SCM_SINGLES", 0);
#endif /* def SCM_SINGLES */
**********

It's not very "schemeish" to worry about the storage class of a
variable, but it would make interfaces to other code easier if guile
has this sort of low level support.  

On a similar note, I would really appreciate a gh_uniform_vector
interface to generate uniform vectors in C code.  I currently call
scm_make_uve which is a not extremely easy to use in C.  It would be
ideal if gh_uniform_vector was prototyped something like this "SCM
gh_uniform_vector(int len, int type)" where type was SCM_BOOL,
SCM_BYTE, SCM_CHAR, SCM_LONG, SCM_ULONG, &c, but this involves hacking
scm_make_uve or duplicating code.

I have hacks that do most of what I describe, and I'd be more than
happy to send them to the right person, but if the wizards decide to
implement something like they could probably do a much better job.

Thank you,

Clark