gcc: AVR Built-in Functions
1
1 6.59.10 AVR Built-in Functions
1 ------------------------------
1
1 For each built-in function for AVR, there is an equally named, uppercase
1 built-in macro defined. That way users can easily query if or if not a
1 specific built-in is implemented or not. For example, if
1 '__builtin_avr_nop' is available the macro '__BUILTIN_AVR_NOP' is
1 defined to '1' and undefined otherwise.
1
1 'void __builtin_avr_nop (void)'
1 'void __builtin_avr_sei (void)'
1 'void __builtin_avr_cli (void)'
1 'void __builtin_avr_sleep (void)'
1 'void __builtin_avr_wdr (void)'
1 'unsigned char __builtin_avr_swap (unsigned char)'
1 'unsigned int __builtin_avr_fmul (unsigned char, unsigned char)'
1 'int __builtin_avr_fmuls (char, char)'
1 'int __builtin_avr_fmulsu (char, unsigned char)'
1 These built-in functions map to the respective machine instruction,
1 i.e. 'nop', 'sei', 'cli', 'sleep', 'wdr', 'swap', 'fmul', 'fmuls'
1 resp. 'fmulsu'. The three 'fmul*' built-ins are implemented as
1 library call if no hardware multiplier is available.
1
1 'void __builtin_avr_delay_cycles (unsigned long ticks)'
1 Delay execution for TICKS cycles. Note that this built-in does not
1 take into account the effect of interrupts that might increase
1 delay time. TICKS must be a compile-time integer constant; delays
1 with a variable number of cycles are not supported.
1
1 'char __builtin_avr_flash_segment (const __memx void*)'
11 This built-in takes a byte address to the 24-bit ⇒address
space AVR Named Address Spaces. '__memx' and returns the number of
1 the flash segment (the 64 KiB chunk) where the address points to.
1 Counting starts at '0'. If the address does not point to flash
1 memory, return '-1'.
1
1 'uint8_t __builtin_avr_insert_bits (uint32_t map, uint8_t bits, uint8_t val)'
1 Insert bits from BITS into VAL and return the resulting value. The
1 nibbles of MAP determine how the insertion is performed: Let X be
1 the N-th nibble of MAP
1 1. If X is '0xf', then the N-th bit of VAL is returned unaltered.
1
1 2. If X is in the range 0...7, then the N-th result bit is set to
1 the X-th bit of BITS
1
1 3. If X is in the range 8...'0xe', then the N-th result bit is
1 undefined.
1
1 One typical use case for this built-in is adjusting input and
1 output values to non-contiguous port layouts. Some examples:
1
1 // same as val, bits is unused
1 __builtin_avr_insert_bits (0xffffffff, bits, val)
1
1 // same as bits, val is unused
1 __builtin_avr_insert_bits (0x76543210, bits, val)
1
1 // same as rotating bits by 4
1 __builtin_avr_insert_bits (0x32107654, bits, 0)
1
1 // high nibble of result is the high nibble of val
1 // low nibble of result is the low nibble of bits
1 __builtin_avr_insert_bits (0xffff3210, bits, val)
1
1 // reverse the bit order of bits
1 __builtin_avr_insert_bits (0x01234567, bits, 0)
1
1 'void __builtin_avr_nops (unsigned count)'
1 Insert COUNT 'NOP' instructions. The number of instructions must
1 be a compile-time integer constant.
1
1 There are many more AVR-specific built-in functions that are used to
1 implement the ISO/IEC TR 18037 "Embedded C" fixed-point functions of
1 section 7.18a.6. You don't need to use these built-ins directly.
1 Instead, use the declarations as supplied by the 'stdfix.h' header with
1 GNU-C99:
1
1 #include <stdfix.h>
1
1 // Re-interpret the bit representation of unsigned 16-bit
1 // integer UVAL as Q-format 0.16 value.
1 unsigned fract get_bits (uint_ur_t uval)
1 {
1 return urbits (uval);
1 }
1