tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] Implementing gcc intrinsics


From: Vladimir Vissoultchev
Subject: [Tinycc-devel] Implementing gcc intrinsics
Date: Fri, 8 Apr 2016 12:35:44 +0300

Hi,

How would you implement intrinsic functions in tcc? Currently I'm using this
in a header file:

#define __builtin_expect(X, C) (X)

#if defined(__i386__) || defined(__x86_64__)
static inline unsigned long __builtin_clz(unsigned long x)
{
  unsigned long r; __asm__("bsr %1, %0" : "=r" (r) : "rm" (x) : "cc");
return r^31;
}

static inline unsigned long __builtin_ctz(unsigned long x)
{
  unsigned long r; __asm__("bsf %1, %0" : "=r" (r) : "rm" (x) : "cc");
return r;
}

static inline unsigned long __builtin_bswap32(unsigned long x)
{
  unsigned long r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
}

static inline unsigned long long __builtin_bswap64(unsigned long long x)
{
  unsigned long long r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
}
#endif

Most of these are single instructions on x86/x64 but for other targets I
suppose these have to be impl in libtcc as full blown functions
until someone impl codegen part for the target.

Also, clz/ctz have clzl and clzll variants (for long and long long args) but
I suppose the base clz intrinsic will be better to work with whatever 
integral type is thrown at it, so to be easier to alias l/ll variants to it
with no type conv.

Actually, is there support for inlines in tcc?

cheers,
</wqw>




reply via email to

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