Compiler Support
[Utility Library]

Collaboration diagram for Compiler Support:

Bit Operations

These functions are not meant to be called directly. Please see Bit Operations instead.



static int_fast8_t compiler_priv_ctz8 (uint8_t x)
static int_fast8_t compiler_priv_ctz16 (uint16_t x)
static int_fast8_t compiler_priv_ctz32 (uint32_t x)
static int_fast8_t compiler_priv_clz8 (uint8_t x)
static int_fast8_t compiler_priv_clz16 (uint16_t x)
static int_fast8_t compiler_priv_clz32 (uint32_t x)
static uint8_t compiler_priv_brev8 (uint8_t x)
static uint16_t compiler_priv_brev16 (uint16_t x)
static uint32_t compiler_priv_brev32 (uint32_t x)
static int8_t compiler_min_s8 (int8_t a, int8_t b)
static int16_t compiler_min_s16 (int16_t a, int16_t b)
static int32_t compiler_min_s32 (int32_t a, int32_t b)
static int64_t compiler_min_s64 (int64_t a, int64_t b)
static uint8_t compiler_min_u8 (uint8_t a, uint8_t b)
static uint16_t compiler_min_u16 (uint16_t a, uint16_t b)
static uint32_t compiler_min_u32 (uint32_t a, uint32_t b)
static uint64_t compiler_min_u64 (uint64_t a, uint64_t b)
static int8_t compiler_max_s8 (int8_t a, int8_t b)
static int16_t compiler_max_s16 (int16_t a, int16_t b)
static int32_t compiler_max_s32 (int32_t a, int32_t b)
static int64_t compiler_max_s64 (int64_t a, int64_t b)
static uint8_t compiler_max_u8 (uint8_t a, uint8_t b)
static uint16_t compiler_max_u16 (uint16_t a, uint16_t b)
static uint32_t compiler_max_u32 (uint32_t a, uint32_t b)
static uint64_t compiler_max_u64 (uint64_t a, uint64_t b)
#define compiler_ctz(x)   compiler_priv_demux_size(sizeof(x), compiler_priv_ctz, (x))
 Count Trailing Zeroes.
#define compiler_clz(x)   compiler_priv_demux_size(sizeof(x), compiler_priv_clz, (x))
 Count Leading Zeroes.
#define compiler_brev(x)   compiler_priv_demux_size(sizeof(x), compiler_priv_brev, (x))
 Reverse the order of the bits in x.

Extended type checking



#define __bitwise   __attribute__((bitwise))
 Make a type incompatible with all other types.
#define __virtual
 Mark a pointer as virtual.
#define __physical   __attribute__((noderef, address_space(1)))
 Mark a pointer as physical.
#define __force   __attribute__((force))
 Force a type cast.

Function and Data Attributes



#define __noreturn
 The function does not return.
#define __must_check
 The return value must be checked.
#define __used
 Mark a function or data object as being used.
#define __always_inline   inline __attribute__((always_inline))
 The function should always be inlined.
#define __nonnull(...)
 Define non-null function attributes.
#define __printf_format(fmt_index, first_arg_index)
 The function takes a printf-like format string.
#define compiler_align_data(byte_alignment)
 Align data variables to a give byte value.

Optimization Control



#define likely(exp)   (exp)
 The expression exp is likely to be true.
#define unlikely(exp)   (exp)
 The expression exp is unlikely to be true.
#define barrier()   do { } while (0)
 Optimization barrier.
#define is_constant(exp)   (0)
 Determine if an expression evaluates to a constant value.

Top-level Directives



#define COMPILER_PRAGMA(arg)   _Pragma(#arg)
 Emit the compiler pragma arg.
#define COMPILER_PACK_SET(alignment)   COMPILER_PRAGMA(pack(alignment))
 Set maximum alignment for subsequent struct and union definitions to alignment.
#define COMPILER_PACK_RESET()   COMPILER_PRAGMA(pack())
 Set default alignment for subsequent struct and union definitions.
#define ERROR_FUNC(name, msg)   extern int name(void)
 Fail compilation if function call isn't eliminated.

Interrupt Control



#define cpu_irq_enable()   asm volatile("sei" ::: "memory")
 Enable interrupts globally.
#define cpu_irq_disable()   asm volatile("cli" ::: "memory")
 Disable interrupts globally.

Detailed Description

This group provides various mechanisms which are not defined by the C standard, but supported by most compilers anyway. Each compiler typically defines its own set of extensions for providing these mechanisms, so we need a common abstraction layer to use them in applications and drivers.


Define Documentation

#define __always_inline   inline __attribute__((always_inline))

The function should always be inlined.

This annotation instructs the compiler to ignore its inlining heuristics and inline the function no matter how big it thinks it becomes.

#define __bitwise   __attribute__((bitwise))

Make a type incompatible with all other types.

This is a sparse attribute which has no effect on other compilers. Declaring a type as __bitwise will cause sparse to complain if it is implicitly or explicitly cast to a different type. This is useful when dealing with foreign-endian types, for example, since it is always a bug if they are accessed without proper byte swapping.

#define __force   __attribute__((force))

Force a type cast.

This modifier can be used to silence any warnings from sparse with regards to casting of bitwise types or casting from one address space to another. This is typically used by the functions that provides the mappings between those types, e.g. byte swapping functions.

Referenced by be16_to_cpu(), be32_to_cpu(), cpu_to_be16(), cpu_to_be32(), cpu_to_le16(), cpu_to_le32(), le16_to_cpu(), and le32_to_cpu().

#define __must_check

The return value must be checked.

This annotation may cause the compiler to warn if someone calls the annotated function without checking its return value.

Definition at line 145 of file compiler.h.

#define __nonnull ( ...   ) 

Define non-null function attributes.

This function attribute specifies that some function parameters must be non-null pointers.

Definition at line 182 of file compiler.h.

#define __noreturn

The function does not return.

This function annotation gives a hint to the compiler that the function being annotated does not return. This may give the compiler some more room for optimizations.

Definition at line 134 of file compiler.h.

#define __physical   __attribute__((noderef, address_space(1)))

Mark a pointer as physical.

A pointer marked with this annotation cannot be dereferenced since it belongs to an address space which cannot be accessed directly on all platforms. It must be mapped to a virtual address by calling an appropriate mapping function.

#define __printf_format ( fmt_index,
first_arg_index   ) 

The function takes a printf-like format string.

This annotation may cause the compiler to emit a warning if the format string doesn't match the parameters given.

Definition at line 193 of file compiler.h.

#define __used

Mark a function or data object as being used.

The compiler will normally warn about functions or variables defined as static but not referenced anywhere. By annotating them with __used, the compiler will shut up and emit the symbol. This is useful when a symbol is only referenced by inline assembly code, for example.

Definition at line 159 of file compiler.h.

#define __virtual

Mark a pointer as virtual.

This annotation does nothing on any compiler, since the virtual address space is the default one.

 
#define barrier (  )     do { } while (0)

Optimization barrier.

This macro forces the compiler to reload any variables from memory. Local variables are left alone, unless they had their address taken at some point.

Definition at line 246 of file compiler.h.

Referenced by at90usb_ep_enable(), at90usb_udc_kill_last_in_bank(), at90usb_udc_submit_in_queue(), at90usb_udc_submit_out_queue(), atomic_read(), atomic_write(), clk_enable_at90usb(), cpu_irq_restore(), ring_extract_entries(), ring_insert_entries(), softirq_disable(), and softirq_enable().

#define compiler_align_data ( byte_alignment   ) 

Align data variables to a give byte value.

Parameters:
byte_alignment Data alignment given in bytes

This function will align a data variable in memory to the supplied number of bytes. The number of bytes must be a power of two, e.g., 1, 2, 4, 8, 16, etc.

The compiler_align_data attribute must be placed at the very beginning of the declaration of the variable.

Example:
compiler_align_data(4) static uint32_t dma_buffer[64];

Definition at line 213 of file compiler.h.

#define compiler_brev (  )     compiler_priv_demux_size(sizeof(x), compiler_priv_brev, (x))

Reverse the order of the bits in x.

See also:
bit_word_reverse()

Definition at line 480 of file compiler.h.

#define compiler_clz (  )     compiler_priv_demux_size(sizeof(x), compiler_priv_clz, (x))

Count Leading Zeroes.

See also:
bit_word_find_last_one_bit()

Definition at line 428 of file compiler.h.

Referenced by ilog2().

#define compiler_ctz (  )     compiler_priv_demux_size(sizeof(x), compiler_priv_ctz, (x))

Count Trailing Zeroes.

See also:
bit_word_find_first_one_bit()

Definition at line 374 of file compiler.h.

 
#define COMPILER_PACK_RESET (  )     COMPILER_PRAGMA(pack())

Set default alignment for subsequent struct and union definitions.

Definition at line 290 of file compiler.h.

#define COMPILER_PACK_SET ( alignment   )     COMPILER_PRAGMA(pack(alignment))

Set maximum alignment for subsequent struct and union definitions to alignment.

Definition at line 281 of file compiler.h.

#define COMPILER_PRAGMA ( arg   )     _Pragma(#arg)

Emit the compiler pragma arg.

Parameters:
arg The pragma directive as it would appear after #pragma (i.e. not stringified).

Definition at line 273 of file compiler.h.

 
#define cpu_irq_disable (  )     asm volatile("cli" ::: "memory")

Disable interrupts globally.

This implies a barrier to ensure that memory operations don't "leak" out of the critical section.

Definition at line 41 of file compiler-gcc.h.

Referenced by at90usb_udc_ep0_worker(), at90usb_udc_submit_in_queue(), at90usb_udc_submit_out_queue(), cpu_irq_save(), mainloop_run(), msc_read_worker(), msc_write_worker(), and softirq_poll().

 
#define cpu_irq_enable (  )     asm volatile("sei" ::: "memory")

Enable interrupts globally.

This implies a barrier to ensure that memory operations don't "leak" out of the critical section.

Definition at line 42 of file compiler-gcc.h.

Referenced by at90usb_udc_ep0_worker(), at90usb_udc_submit_in_queue(), at90usb_udc_submit_out_queue(), cpu_enter_sleep(), main(), mainloop_run(), msc_read_worker(), msc_write_worker(), and softirq_poll().

#define ERROR_FUNC ( name,
msg   )     extern int name(void)

Fail compilation if function call isn't eliminated.

If the compiler fails to optimize away all calls to the function name, terminate compilation and display msg to the user.

Note that not all compilers support this, so this is best-effort only. Sometimes, there may be a linker error instead, and when optimization is disabled, this mechanism will be completely disabled.

Definition at line 305 of file compiler.h.

#define is_constant ( exp   )     (0)

Determine if an expression evaluates to a constant value.

Parameters:
exp Any expression
Returns:
true if exp is constant, false otherwise.

Definition at line 259 of file compiler.h.

Referenced by dma_alloc(), dma_free(), and ilog2().

#define likely ( exp   )     (exp)

The expression exp is likely to be true.

Definition at line 226 of file compiler.h.

Referenced by block_alloc_request().

#define unlikely ( exp   )     (exp)

The expression exp is unlikely to be true.

Definition at line 234 of file compiler.h.

Referenced by msc_do_read(), msc_submit_read_buffers(), and msc_submit_write_data_req().

Generated on Thu Apr 29 14:10:34 2010 for xplain-bc by  doxygen 1.6.3