guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `SCM_MAKE_CHAR ()' signedness issue


From: carlo\.bramix
Subject: Re: `SCM_MAKE_CHAR ()' signedness issue
Date: Mon, 17 Aug 2009 20:52:59 +0200

Hello,
if I understood the problem, I think it can be easily fixed without using an 
inline function.

For example:

#ifdef __GNUC__

#define SCM_MAKE_CHAR(__x)                                            \
({ scm_t_int32 __t = (scm_t_int32)(__x);                              \
  (__t < 0)                                                           \
  ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (__x), scm_tc8_char) \
  : SCM_MAKE_ITAG8 ((scm_t_bits) (__x), scm_tc8_char);                \
  __t;                                                                \
})

#else

#define SCM_MAKE_CHAR(x)                                              \
  ((scm_t_int32) (x) < 0                                              \
  ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (x), scm_tc8_char)   \
  : SCM_MAKE_ITAG8 ((scm_t_bits) (x), scm_tc8_char))

#endif

solves the problem.
Actually a much more efficient solution specifically designed for GCC may use 
__builtin_types_compatible_p() and __builtin_choose_expr() intrinsic functions, 
but this will force you to support GCC 3.x or newer.

Something like:
#if defined __GNUC__ && __GNUC__ >= 3
...
#elif ...

will need to be written.

Sincerely,

Carlo Bramini.

---------- Initial Header -----------

>From      : address@hidden
To          : address@hidden
Cc          :
Date      : Mon, 17 Aug 2009 17:33:03 +0200
Subject : Re: `SCM_MAKE_CHAR ()' signedness issue

> Mike Gran <address@hidden> writes:
>
> > On my system I ran a test with SCM_MAKE_CHAR as a macro, an an inline,
> > and as a never inlined function.  I ran ./check-guile twice for each.
>
> You're cheating!  ;-)
>
> The test suite does lots of things besides calling `SCM_MAKE_CHAR ()',
> so I'm not sure if it's a good benchmark.
>
> I'm fairly confident that for such a small piece of code inlining is
> always a good idea.
>
> Thanks,
> Ludo'.
>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]