[LLVMdev] Architecture Dependency of LLVM bitcode (was Re: compile linux kernel)

Sherief N. Farouk sherief at mganin.com
Mon Sep 29 12:03:43 PDT 2008


> hton and ntoh intrinsics.  These are needed to allow target code to
> deal with endianness in a target independent way.  (Ok, you could
> potentially write code that detected endiannes at runtime and chose
> multiversioned code based on that, but that is ugly and optimization
> prohibiting).
> 

Why not add types with explicit endianess? A trick I use for reading binary
files across platforms is to define the types int32, int32_le and int32_be :
int32 is platform-native, _le and _be are little and big endian,
respectively. I use and #ifdef in my types.hpp to determine which of _le and
_be is a typedef for the standard uint32, and the other is implemented as a
class with operator int32(). "add i32_be %X, 8" looks elegant to me, and
quite easy (for someone writing the ir output to a text file, like me :) to
bolt on to existing code.

- Sherief






More information about the llvm-dev mailing list