Preface

This document contains useful information for embedded software developers who wish to migrate their code from Renesas tools to CyberTHOR Studios GNU tools (and vice versa) for RX target. At present, this guide contains the following:


   Compiler Options
   Compiler Macros
   Compiler Directives
   Assembler Directives.
   Intrinsic Functions.
   Built-in Functions
   Linker Section Mapping
   C/Math Library Functions.
   Inline Assembly

Revision History:

Version Number

Date

Overview of changes

1.0 01-July-2010 Document created.
2.0 17-September-2014 Updated to GNURX v14.03
3.0 20-October-2016 Added new responsive template
3.1 19-April-2021 Added support for the latest extensions.

Please note that this is an intermediate guide, which will be improved and enhanced periodically.

Please do not hesitate to send any of your suggestions or ideas. You may log in your suggestions on our web site https://llvm-gcc-renesas.com/.

You will need to register first, after which you can either add a new support query at the following link: https://llvm-gcc-renesas.com/my-support-requests/tickettrackingsystem/addticket, or ask a question here: https://llvm-gcc-renesas.com/forum/ask/.

Please note that in order to be able to add a new support query or ask a question you must be logged in.

Compiler Options


Renesas Compiler Options

Equivalent GCC compiler options
 

-include = <path name>[,…]
Include paths.

-I<path>
 

-preinclude = <file name>[,...]
Includes the specified files at the head of compiled files.

-include <file>
 

-define = <sub> [,…]
<sub>: <macro name> [ = <string literal>]

Defines <string literal> as <macro name>

-D<macro>
 

-undefine = <sub>[,…]
<sub>:< macro name >

Disables the predefined macro of <macro name>

-U <macro>

-nomessage [ = <error number> [- <error number>] [,…] ]
Specifies whether to output information-level messages.

-w
 

-preprocessor [= <file name>]
Preprocessor to named file.

-E -o filename
 

-output={prep | src | obj | abs | hex | sty }[=filename]
Specifies the output file type and output filename
prep = Outputs a source file after preprocessed.
src = Outputs an assembly language file.
obj = Outputs a relocatable file.
abs = Outputs an absolute file.
hex = Outputs an Intel hex type file.
sty = Outputs a Motorola S type file.

filename = Name of output file

-o filename
filename = Name of output file

Use following compiler options for specifying the output file type.
-E = Outputs a source file after preprocessed.
-S = Outputs an assembly language file.
-c = Outputs a relocatable file
no option = Outputs an absolute file

Use following linker options for specifying the output file type.
--oformat=hex : Outputs an Intel hex type file.
--oformat=srec : Outputs a Motorola S type file.

-debug
Outputs debugging information.

-g[level]
 

-listfile[=<file name>]
Outputs a source list file
-nolistfile
Does not output a source list file.

-Wa,-al=file
Outputs a source list file
No Option
Does not output a source list file.
show = <sub>[,…]
<sub>: {source | conditionals | definitions | expansions }

Specifies the contents of the source list file.
source = Outputs the C/C++ source file.
conditionals = Outputs the statements unsatisfied in conditional assembly.
definitions = Outputs the information before .DEFINE replacement.
expansions = Outputs the assembler macro
expansion statements.

-a[sub-option...]

Sub-options [default hls]:
c  = omit false conditionals
d  = omit debugging directives
h  = include high-level source
l  = include assembly
m = include macro expansions
n = omit forms processing
s  = include symbols
=FILE list to FILE (must be last sub-option)
 

-optimize = { 0 | 1 | 2 | max }

Specifies the optimization level.

optimize=0: the compiler does not optimize the program
optimize=1: the compiler partially optimizes the program for code size
optimize=2: the compiler performs overall optimization
optimize=max: the compiler performs optimization as much as possible; the optimization scope is expanded to its maximum extent, and if the speed option is specified, loop expansion is possible on a large scale.

-O0 : the compiler does not optimize the program
-O1: the compiler partially optimizes the program for code size
-O2: the compiler performs overall optimization
-Os or -O3: the compiler performs optimization as much as possible; the optimization scope is expanded to its maximum extent, and if the speed option is specified, loop expansion is possible on a large scale.
-speed

Optimizes with emphasis on execution performance

-O3
-size

Optimizes with emphasis on code size.

-Os
-loop[=<numeric value>]

Expands a loop under the condition of loop expansion maximum number =
<numeric value>.

-funroll-loops
-inline[=<numeric value>]

Performs inline expansion automatically.

-finline-functions
-finline-small-functions
-finline-functions-called-once
-finline-limit=n
-volatile

Handles external variables as if they are volatile qualified.
Not supported.

However, keyword volatile is supported

-const_copy

Enables constant propagation of const qualified external variables.
-fgcse
-schedule

Schedules instructions
-fschedule-insns
-fschedule-insns2
-fpu
Outputs an object that uses floating-point operation instructions.

-nofpu
Outputs an object that does not use floating-point operation instructions.
-fpu
Outputs an object that uses floating-point operation instructions.

-nofpu
Outputs an object that does not use floating-point operation instructions.
-cpu = { rx600 }

Generates an instruction code for RX600 Series.

-mcpu={ rx600 }
-endian = { big | little }

Specifies the endian type for data.

-mbig-endian-data
 
-mlittle-endian-data
-dbl_size = { 4 | 8 }

4: Handles the double type and long double  type in single precision.
8: Handles the double type and long double type in double precision.

-m32bit-doubles : Handles the double type and long double

-m64bit-doubles : Handles the double type and long double type in double precision.

-pack

Assumes the boundary alignment value for structure members is 1.
-fpack-struct
-fint_register = { 0 | 1 | 2 | 3 | 4 }

0: No registers are used only for fast interrupts.
1: R13 is used only for fast interrupts.
2: R13 and R12 are used only for fast interrupts.
3: R13 to R11 are used only for fast interrupts.
4: R13 to R10 are used only for fast interrupts.

-mint-register=N

N=1 : Register r13 will be reserved for the exclusive use of fast interrupt handlers
N=2 : Reserves registers r13 and r12
N=3 : Reserves r13, r12 and r11
N=4 : Reserves r13 through r10
N=0 : Default option. This does not reserve any registers

-patch = { rx610 }

Avoids a problem specific to the CPU type.
The MVTIPL instruction should not be generated (for RX610 Group).
-patch={ rx610 }
Alias for option "-mcpu"

-comment = { nest | nonest }
Enables nested comments to be written.

By default enabled. To generate warning for nested comments use option.
-Wcomment

-rtti = { on | off }

Enables dynamic_cast and typeid.

-fno-rtti
 

-exception
Enables the C++ exception processing (try, catch, throw).

-fexceptions
 

-lang = { c | cpp | ecpp | c99 }
Specifies the language of the source program.

-x <language>
 

-asmcmd=<file name>

Specifies the asrx options with a subcommand file.
No direct support.

However, -Wa option can be used to pass assembler options.

-lnkcmd=<file name>

Specifies the optlnk options with a subcommand file.
@file

Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed.

-asmopt=["]<assembler option> [?<assembler option>…]["]

Specifies the asrx options.
-Wa,<assembler option> can be used to pass assembler options.
-lnkopt=["]<linkage option> [?<linkage option>…]["]

Specifies the optlnk options
-Wl,<linker option> can be used to pass assembler options.

For more information on the above compiler command line options, please refer to the gcc manual.

Compiler Macros


Renesas macro

Equivalent GCC macro

_DATE_, _FILE_, _LINE_, _STDC_, _STDC_HOSTED_, _STDC_VERSION_, _cplusplus, _TIME_

__DATE__, __FILE__, __LINE__, __STDC__, __STDC_HOSTED__, __STDC_VERSION__, __cplusplus, __TIME__

__RX600, __RX200

__RX600__, __RX200__

__BIG, __LIT

__RX_BIG_ENDIAN__, __RX_LITTLE_ENDIAN__

__DBL4, __DBL8

__RX_32BIT_DOUBLES__, __RX_64BIT_DOUBLES__

__INT_SHORT

No corresponding GCC macro

__SCHAR, __UCHAR

No corresponding GCC macro

__SBIT, __UBIT

No corresponding GCC macro

__ROZ, __RON

No corresponding GCC macro

__DOFF, __DON

No corresponding GCC macro

__BITLEFT, __BITRIGHT

No corresponding GCC macro

__AUTO_ENUM

No corresponding GCC macro

__FUNCTION_LIB, __INTRINSIC_LIB

No corresponding GCC macro

__FPU

__RX_FPU_INSNS__

__RENESAS__

No corresponding GCC macro

__RENESAS_VERSION__

No corresponding GCC macro, should be defined inside the file

__RX

__RX__

__PIC

No corresponding GCC macro

__PID

No corresponding GCC macro


For more information on the above compiler predefined macros, please refer to the gcc manual.

Compiler directives


Renesas Directives Equivalent GNU directive or method
#pragma interrupt [(]<function name>
[(<interrupt specification>[,...])][,...][)]
This extension declares an interrupt function.
#pragma interrupt func
void func(){ .... }
void __attribute__ ((interrupt)) func ();
 
#pragma interrupt function_name(fint)

Fast interrupt
void function_name(void) __attribute__ ((fast_interrupt));
#pragma section [<section type>] [<new section name>]

This extension changes the section name to be output by the compiler.

Pragma is not available but the functionality can be achieved using __attribute__ ((section(“<section name>”)))
For e.g:
extern void foobar (void) __attribute__ ((section ("bar")));

Alternatively, this can be achieved using the linker script. In section definition, the contents of an output section can be specified by listing particular input files, listing particular input-file sections, or combination of the two.
#pragma stacksize {si=<constant> | su=<constant>}

When si=<constant> is specified, a data section is created to be used as the stack
of size <constant> with section name SI.
When su=<constant> is specified, a data section is created to be used as the stack
of size <constant> with section name SU.

char stack[100] __attribute__ ((section ("STACK"))) = { 0 };
 
main()
{
      /* Initialize stack pointer */
      init_sp (stack + sizeof (stack));
}
#pragma inline [(]<function name>[,...][)]
#pragma noinline [(]<function name>[,...][)]

#pragma inline declares a function for which inline expansion is performed.

inline void foo (const char) __attribute__((always_inline));

#pragma inline_asm[(]<function name>[,...][)]

This extension declares an assembly-language function for which inline expansion is performed

Asm(<assembly-language instruction string>);

#pragma entry[(]<function name>[)]

This specifies that the function specified as <function name> is handled as an entry function.

#pragma stacksize su=100
#pragma entry INIT
void INIT() {
:
}

Achieved through linker script.

#pragma option [<option string>]

This extension applies the options specified in <option string>.

#pragma option speed
void func1(){ ... } /* Default + -speed are applied

#pragma GCC optimize ("string"...)

OR

attribute optimize can be used as below,

void  func1 () __attribute__((optimize("-O3")));

#pragma pack
#pragma unpack
#pragma packoption

#pragma pack specifies the boundary alignment value for structure members and class members after the #pragma pack written in the source program.

__attribute__ ((packed));

struct foo
{
char a;
int x[2] __attribute__ ((packed));
};

 

#pragma endian [{big | little}]

This extension specifies the endian for the area that stores static objects.

This is not supported in GNU toolchains.

In GNU toolchains, command line options should be used to specify the endianness.

#pragma bit_order [{left | right}]

Switches the order of bit assignment.

This is not supported in GNU toolchains.
#pragma instalign4

#pragma instalign8

#pragma noinstalign

Specifies the function in which instructions at branch destinations are aligned for execution.

This is not supported in GNU toolchains.

For more information on the above compiler directives, please refer to the gcc manual.

Assembler Directives


Renesas Assembler Directives GNU Assembler Directives
.ORG

Declares the start address. The section including this directive becomes an absolute-addressing section.

.org
.ENDIAN

Specifies the endian for the section.

Following command line options for GNU assembler can be used;

-mbig-endian
-mlittle-endian

.BYTE

Stores 1-byte data in a ROM area.

.byte
.WORD

Stores 2-byte data in a ROM area.

.word
.LWORD

Stores 4-byte data in a ROM area.

.long
.FLOAT

Stores floating-point data represented by four bytes in a ROM area.

.float
.DOUBLE

Stores floating-point data represented by eight bytes in a ROM area.

.double
.ALIGN
Corrects a location counter to a multiple of the boundary alignment value.

.align <boundary alignment value>
(for details on more options of aligning like filling specific values,etc, please see link below)

.END .end
.INCLUDE .include
.SECTION name, attribute .section “ name” , “attributes”

(for details on the possible attributes, please refer the GNU linker manual)

.GLB .global
.EQU value .equ sym_name , value
.IF .if
.ELSE .else
.ELIF .elseif
.ENDIF .endif
.MACRO .macro
.ENDM .endm
.OFFSET .align
.BLKB .fill
.BLKW .fill
.BLKL .fill
.BLKD .fill
.EXITM .exitm
.MREPEAT .rept
.ENDR .endr
.LIST .list/.nolist
.LINE .line/.file
.DEFINE .set

For more information on the above assembler directives, please refer to the as manual.

Intrinsic Functions


Renesas Intrinsic functions Equivalent GCC inline code
unsigned long get_psw(void);
unsigned long get_usp(void);
unsigned long get_fpsw(void);
unsigned long get_isp(void);
unsigned long get_intb(void);
unsigned long get_bpsw(void);
unsigned long get_bpc(void);
unsigned long get_fintv(void);
 
int __builtin_rx_mvfc (int)
Generates the mvfc machine instruction which reads the control register specified in its argument and returns its value. The integer parameter corresponds to control registers as follows:
`0x0 psw'
`0x2 usp'
`0x3 fpsw'
`0x4 cpen'
`0x8 bpsw'
`0x9 bpc'
`0xA isp'
`0xB fintv'
`0xc intb'
Any other values will result in a warning message from the compiler. 

As an example, in order to read the contents of the fpsw register the following code can be used:

int a = __builtin_rx_mvfc (3);

void set_psw(unsigned long data) void __builtin_rx_setpsw (int)
Generates the setpsw machine instruction to set the specified bit in the processor status word.
signed long max(signed long data1, signed long data2) N/A
signed long min(signed long data1, signed long data2) N/A
unsigned long revl(unsigned long data) uint32_t __builtin_bswap32(uint32_t x)
Returns x with the order of the bytes reversed
unsigned long revw(unsigned long data) int __builtin_rx_revw(int)
Generates the revw machine instruction which swaps the bytes in the argument so that bits 0--7 now occupy bits 8--15 and vice versa, and also bits 16--23 occupy bits 24--31 and vice versa.
void xchg(signed long *data1, signed long *data2) void __builtin_rx_xchg (int *, int *)
Generates the xchg machine instruction.
long long rmpab(long long init, unsigned long count, signed char *addr1, signed char *addr2) long long __builtin_rx_rmpa8(long long init, signed char *addr1, signed char *addr2, unsigned int count)
Generates the rmpa.B machine instruction, performing a repeated multiply and accumulate sequence with the initial value specified by init, the start addresses of values to be multiplied specified by addr1 and addr2 and the number of multiply-and-accumulate operations specified by count.
long long rmpaw(long long init, unsigned long count, short *addr1, short *addr2) long long __builtin_rx_rmpa16(long long init, signed short *addr1, signed short *addr2, unsigned int count)
Generates the rmpa.W machine instruction, performing a repeated multiply and accumulate sequence with the initial value specified by init, the start addresses of values to be multiplied specified by addr1 and addr2 and the number of multiply-and-accumulate operations specified by count.
long long rmpal(long long init, unsigned long count, long *addr1, long *addr2) long long __builtin_rx_rmpa32(long long init, signed long *addr1, signed long *addr2, unsigned int count)
Generates the rmpa.L machine instruction, performing a repeated multiply and accumulate sequence with the initial value specified by init, the start addresses of values to be multiplied specified by addr1 and addr2 and the number of multiply-and-accumulate operations specified by count.
unsigned long rolc(unsigned long data) N/A
unsigned long rorc(unsigned long data) N/A
unsigned long rotl(unsigned long data, unsigned long num) N/A
unsigned long rotr(unsigned long data, unsigned long num) N/A
void brk(void) void __builtin_rx_brk (void) Generates the brk machine instruction.
void int_exception(signed long num) void __builtin_rx_int (int) Generates the int machine instruction to generate an interrupt with the specified value.
void wait(void) void __builtin_rx_wait (void) Generates the wait machine instruction.
void nop(void) __asm("nop")
void set_ipl(signed long level) void __builtin_rx_mvtipl (int)
Generates the mvtipl machine instruction to set the interrupt priority level.
unsigned char get_ipl(void) N/A
void set_fpsw(unsigned long data) void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
void set_usp(void * data) void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
void set_isp(void * data) void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
void set_intb(void * data) void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
void set_bpsw(unsigned long data) void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
void set_bpc(void * data) void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
void set_fintv(void * data) void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
signed long long emul(signed long data1, signed long data2) N/A
unsigned long long emulu(unsigned long data1, unsigned long data2) N/A
void chg_pmusr(void) N/A
void set_acc(signed long long data) void __builtin_rx_mvtachi (int)
Generates the mvtachi machine instruction to set the top 32 bits of the accumulator A0.
void __builtin_rx_mvtaclo (int)
Generates the mvtaclo machine instruction to set the bottom 32 bits of the accumulator A0.
signed long long get_acc(void) int __builtin_rx_mvfachi (void)
Generates the mvfachi machine instruction to read the top 32 bits of the accumulator.
int __builtin_rx_mvfacmi (void)
Generates the mvfacmi machine instruction to read the middle 32 bits of the accumulator.
void setpsw_i(void) N/A
void clrpsw_i(void) N/A
long macl(short* data1, short* data2, unsigned long count) N/A
short macw1(short* data1, short* data2, unsigned long count) N/A
short macw2(short* data1, short* data2, unsigned long count) N/A
void _CALL_INIT(void); N/A
void _CALL_END(void); N/A
void _INITSCT(void); N/A

Built-in Functions


GNU RX Built-in Functions Description Version
void __builtin_rx_brk (void) Generates the brk machine instruction.
void __builtin_rx_clrpsw (int) Generates the clrpsw machine instruction to clear the specified bit in the processor status word.
void __builtin_rx_int (int) Generates the int machine instruction to generate an interrupt with the specified value.
void __builtin_rx_machi (int, int) Generates the machi machine instruction to add the result of multiplying the top 16 bits of the two arguments into the accumulator A0.
void __builtin_rx_machi_A1 (int, int) Generates the machi machine instruction to add the result of multiplying the top 16 bits of the two arguments into the accumulator A1.
void __builtin_rx_maclo (int, int) Generates the maclo machine instruction to add the result of multiplying the bottom 16 bits of the two arguments into the accumulator A0.
void __builtin_rx_maclo_A1 (int, int) Generates the maclo machine instruction to add the result of multiplying the bottom 16 bits of the two arguments into the accumulator A1.
void __builtin_rx_mulhi (int, int) Generates the mulhi machine instruction to place the result of multiplying the top 16 bits of the two arguments into the accumulator A0.
void __builtin_rx_mulhi_A1 (int, int) Generates the mulhi machine instruction to place the result of multiplying the top 16 bits of the two arguments into the accumulator A1.
void __builtin_rx_mullo (int, int) Generates the mullo machine instruction to place the result of multiplying the bottom 16 bits of the two arguments into the accumulator A0.
void __builtin_rx_mullo_A1 (int, int) Generates the mullo machine instruction to place the result of multiplying the bottom 16 bits of the two arguments into the accumulator A1.
int __builtin_rx_mvfachi (void) Generates the mvfachi machine instruction to read the top 32 bits of the accumulator.
int __builtin_rx_mvfacmi (void) Generates the mvfacmi machine instruction to read the middle 32 bits of the accumulator.
int __builtin_rx_mvfc (int) Generates the mvfc machine instruction which reads the control register specified in its argument and returns its value.
void __builtin_rx_mvtachi (int) Generates the mvtachi machine instruction to set the top 32 bits of the accumulator A0.
void __builtin_rx_mvtachi_A1 (int) Generates the mvtachi machine instruction to set the top 32 bits of the accumulator A1.
void __builtin_rx_mvtaclo (int) Generates the mvtaclo machine instruction to set the bottom 32 bits of the accumulator A0.
void __builtin_rx_mvtaclo_A1 (int) Generates the mvtaclo machine instruction to set the bottom 32 bits of the accumulator A1.
void __builtin_rx_mvtc (int reg, int val) Generates the mvtc machine instruction which sets control register number reg to val.
void __builtin_rx_mvtipl (int) Generates the mvtipl machine instruction set the interrupt priority level.
void __builtin_rx_racw (int) Generates the racw machine instruction to round the accumulator A0 according to the specified mode.
void __builtin_rx_racw_A1 (int) Generates the racw machine instruction to round the accumulator A1 according to the specified mode.
int __builtin_rx_revw (int) Generates the revw machine instruction which swaps the bytes in the argument so that bits 0–7 now occupy bits 8–15 and vice versa, and also bits 16–23 occupy bits 24–31 and vice versa.
long long __builtin_rx_rmpa8 (long long init, signed char *addr1, signed char *addr2, unsigned int count) Generates the rmpa.B machine instruction, performing a repeated multiply and accumulate sequence with the initial value specified by init, the start addresses of values to be multiplied specified by addr1 and addr2 and the number of multiply-and-accumulate operations specified by count. GCC 4.8.4.201902-GNURX or newer
long long __builtin_rx_rmpa16 (long long init, signed char *addr1, signed char *addr2, unsigned int count) Generates the rmpa.W machine instruction, performing a repeated multiply and accumulate sequence with the initial value specified by init, the start addresses of values to be multiplied specified by addr1 and addr2 and the number of multiply-and-accumulate operations specified by count. GCC 4.8.4.201902-GNURX or newer
long long __builtin_rx_rmpa32 (long long init, signed char *addr1, signed char *addr2, unsigned int count) Generates the rmpa.L machine instruction, performing a repeated multiply and accumulate sequence with the initial value specified by init, the start addresses of values to be multiplied specified by addr1 and addr2 and the number of multiply-and-accumulate operations specified by count. GCC 4.8.4.201902-GNURX or newer
void __builtin_rx_round (float) Generates the round machine instruction which returns the floating-point argument rounded according to the current rounding mode set in the floating-point status word register.
void __builtin_rx_dround (double float) Generates the dround machine instruction which returns the double-precision floating-point argument rounded according to the current rounding mode set in the double-precision floating-point status word register. Available for RXv3 and for -mdfpu option enabled. GCC 4.8.4.201803-GNURX or newer
void __builtin_rx_setpsw (int) Generates the setpsw machine instruction to set the specified bit in the processor status word.
void __builtin_rx_wait (void) Generates the wait machine instruction.
void __builtin_rx_xchg (int *, int *) Generates the xchg machine instruction.
int __builtin_rx_bset (int, int) Generates the bset machine instruction.
int __builtin_rx_bclr (int, int) Generates the bclr machine instruction.
int __builtin_rx_bnot (int, int) Generates the bnot machine instruction.
void __builtin_rx_bset_mem (char *, char) Generates the bset machine instruction. GCC 4.8.0.201603-GNURX or newer
void __builtin_rx_bclr_mem (char *, char) Generates the bclr machine instruction. GCC 4.8.0.201603-GNURX or newer
void __builtin_rx_bnot_mem (char *, char) Generates the bnot machine instruction. GCC 4.8.0.201603-GNURX or newer
void __builtin_rx_emula_A0 (int, int) Generates the emula machine instruction, which multiplies the arguments and places the result in the accumulator A0.
void __builtin_rx_emula_A1 (int, int) Generates the emula machine instruction, which multiplies the arguments and places the result in the accumulator A1.
void __builtin_rx_emaca_A0 (int, int) Generates the emaca machine instruction, which multiplies the arguments and adds the result to the value saved in the accumulator A0.
void __builtin_rx_emaca_A1 (int, int) Generates the emaca machine instruction, which multiplies the arguments and adds the result to the value saved in the accumulator A1.
void __builtin_rx_emsba_A0 (int, int) Generates the emsba machine instruction, which multiplies the arguments and subtracts the result from the value saved in the accumulator (ACC) A0. The result of subtraction is stored in ACC.
void __builtin_rx_emsba_A1 (int, int) Generates the emsba machine instruction, which multiplies the arguments and adds the result to the value saved in the accumulator (ACC) A1. The result of subtraction is stored in ACC.
void __builtin_rx_mullh_A0 (int, int) enerates the mullh machine instruction, which multiplies the lower 16 bits of the first argument by the upper 16 bits of the second argument. The result is stored in the accumulator (ACC) A0.
void __builtin_rx_mullh_A1 (int, int) Generates the mullh machine instruction, which multiplies the lower 16 bits of the first argument by the upper 16 bits of the second argument. The result is stored in the accumulator (ACC) A1.
void __builtin_rx_maclh_A0 (int, int) Generates the maclh machine instruction, which multiplies the lower 16 bits of the first argument by the upper 16 bits of the second argument. The result is added to the stored value of the accumulator (ACC) A0.
void __builtin_rx_maclh_A1 (int, int) Generates the maclh machine instruction, which multiplies the lower 16 bits of the first argument by the upper 16 bits of the second argument. The result is added to the stored value of the accumulator (ACC) A1.
void __builtin_rx_msblh_A0 (int, int) Generates the msblh machine instruction, which multiplies the lower 16 bits of the first argument by the upper 16 bits of the second argument, and subtracts the result from the value of the accumulator (ACC) A0. The result of subtraction is stored in ACC.
void __builtin_rx_msblh_A1 (int, int) Generates the msblh machine instruction, which multiplies the lower 16 bits of the first argument by the upper 16 bits of the second argument, and subtracts the result from the value of the accumulator (ACC) A1. The result of subtraction is stored in ACC.
void __builtin_rx_msbhi_A0 (int, int) Generates the msbhi machine instruction, which multiplies the upper 16 bits of the first argument by the upper 16 bits of the second argument, and subtracts the result from the value in the accumulator (ACC) A0. The result of subtraction is stored in ACC.
void __builtin_rx_msbhi_A1 (int, int) Generates the msbhi machine instruction, which multiplies the upper 16 bits of the first argument by the upper 16 bits of the second argument, and subtracts the result from the value in the accumulator (ACC) A1. The result of subtraction is stored in ACC.
void __builtin_rx_msblo_A0 (int, int) Generates the msblo machine instruction, which multiplies the lower 16 bits of the first argument by the lower 16 bits of the second argument, and subtracts the result from the value in the accumulator (ACC) A0. The result of subtraction is stored in ACC.
void __builtin_rx_msblo_A1 (int, int) Generates the msblo machine instruction, which multiplies the lower 16 bits of the first argument by the lower 16 bits of the second argument, and subtracts the result from the value in the accumulator (ACC) A1. The result of subtraction is stored in ACC.
void __builtin_rx_rdacw_A0 (int) Generates the rdacw machine instruction, which rounds the value of the accumulator A0 into a word and stores the result in the accumulator.
void __builtin_rx_rdacw_A1 (int) Generates the rdacw machine instruction, which rounds the value of the accumulator A1 into a word and stores the result in the accumulator.
void __builtin_rx_rdacl_A0 (int) Generates the rdacl machine instruction, which rounds the value of the accumulator A0 into a longword and stores the result in the accumulator.
void __builtin_rx_rdacl_A1 (int) Generates the rdacl machine instruction, which rounds the value of the accumulator A1 into a longword and stores the result in the accumulator.
void __builtin_rx_racl_A0 (int) Generates the racl machine instruction, which rounds the value of the accumulator A0 into a longword and stores the result in the accumulator.
void __builtin_rx_racl_A1 (int) Generates the racl machine instruction, which rounds the value of the accumulator A1 into a longword and stores the result in the accumulator.
int __builtin_rx_mvfachi_A0 (int) Generates the mvfachi machine instruction to read the top 32 bits of the accumulator A0.
int __builtin_rx_mvfachi_A1 (int) Generates the mvfachi machine instruction to read the top 32 bits of the accumulator A1.
int __builtin_rx_mvfacmi_A0 (int) Generates the mvfacmi machine instruction to read the middle 32 bits of the accumulator A0.
int __builtin_rx_mvfacmi_A1 (int) Generates the mvfacmi machine instruction to read the middle 32 bits of the accumulator A1.
int __builtin_rx_mvfaclo_A0 (int) Generates the mvfaclo machine instruction to read the lower 32 bits of the accumulator A0.
int __builtin_rx_mvfacgu_A0 (int) Generates the mvfacgu machine instruction to read the most significant 32 bits of the accumulator A0, after being shifted to the left by zero to two bits as specified by the function argument
int __builtin_rx_mvfacgu_A1 (int) Generates the mvfacgu machine instruction to read the most significant 32 bits of the accumulator A1, after being shifted to the left by zero to two bits as specified by the function argument
void __builtin_rx_mvtacgu_A0 (int) Generates the mvtacgu machine instruction to move the contents of the argument to the most significant 32 bits (bits 95 to 64) of the accumulator A0.
void __builtin_rx_mvtacgu_A1 (int) Generates the mvtacgu machine instruction to move the contents of the argument to the most significant 32 bits (bits 95 to 64) of the accumulator A1.
void __builtin_rx_save (int) Generates the save machine instruction which collectively saves the values of CPU register (R1 to R15, USP, FPSW, ACC1 and ACC1) in a save register bank. The bank number of the destination for saving is specified by the argument. Available for RXv3. GCC 4.8.4.201902-SP1-GNURX or newer
void __builtin_rx_rstr (int) Generates the rstr machine instruction which collectively restores the values from a save register bank to CPU registers (R1 to R15, USP, FPSW, ACC1 and ACC1). The bank number of the source for restoration is specified by the argument. Available for RXv3. GCC 4.8.4.201902-SP1-GNURX or newer
int __builtin_rx_mvfdc (int) Generates the mvfdc machine instruction which transfers from double-precision floating-point control register. Available for RXv3 and for -mdfpu option enabled. GCC 4.8.4.201803-GNURX or newer
void __builtin_rx_mvtdc (int, int) Generates the mvtdc machine instruction which transfers the first argument, to the second, double-precision floating-point control register argument. Available for RXv3 and for -mdfpu option enabled. GCC 4.8.4.201803-GNURX or newer
void __builtin_rx_mvfdr Generates the mvfdr machine instruction which transfers from double-precision floating-point comparison result register. Available for RXv3 and for -mdfpu option enabled. GCC 4.8.4.201803-GNURX or newer
int __builtin_rx_bfmov(int dest, int src, int slsb, int dlsb, int width) Generates the bfmov machine instruction:bit-field move. Available for RXv3. GCC 4.8.4.201803-GNURX or newer
int __builtin_rx_bfmovz(int dest, int src, int slsb, int dlsb, int width) Generates the bfmov machine instruction:bit-field move to zero. Available for RXv3. GCC 4.8.4.201803-GNURX or newer
void __init_tfu (void) Initialize TFU when the -mtfu= option is used. Available for RXv3. GCC 4.8.4.201902-GNURX or newer
void __builtin_rx_sincosf (float value, float *sin, float *cos) Calculates sine and cosine at the same time. The value variable represents the radian. The sine and cosine variables represent the addresses to store the arithmetic results. This builtin function is used with the -mtfu=intrinsic option. Available for RXv3. GCC 4.8.4.201902-GNURX or newer
void __builtin_rx_atan2hypotf (float y, float x, float *atan2, float *hypot) Calculates arctangent and hypotenuse at the same time. The y variable represents the dividend (y coordinate), the x variable represents the divisor (x coordinate). The atan2 and hypot variables represent the addresses to store the arithmetic results. This builtin function is used with the -mtfu=intrinsic option. Available for RXv3. GCC 4.8.4.201902-GNURX or newer
float __builtin_rx_sinf (float value) Return the arithmetic result of sine. The value variable represents the radian. This builtin function is used with the -mtfu=intrinsic,mathlib option. Available for RXv3. GCC 4.8.4.201902-GNURX or newer
float __builtin_rx_cosf (float value) Return the arithmetic result of cosine. The value variable represents the radian. This builtin function is used with the -mtfu=intrinsic,mathlib option. Available for RXv3. GCC 4.8.4.201902-GNURX or newer
float __builtin_rx_atan2f (float y, float x) Return the arithmetic result of arctangent. The y variable represents the dividend (y coordinate) and the x variable represents the divisor (x coordinate). This builtin function is used with the -mtfu=intrinsic,mathlib option. Available for RXv3. GCC 4.8.4.201902-GNURX or newer
float __builtin_rx_hypotf (float x, float y) Return the arithmetic result of hypotenuse. The y variable represents the dividend (y coordinate) and the x variable represents the divisor (x coordinate). This builtin function is used with the -mtfu=intrinsic,mathlib option. Available for RXv3. GCC 4.8.4.201902-GNURX or newer

Linker Section Mapping


Renesas Section Equivalent GCC Section
CCRX Section GNURX Section
D .data
D_2 .data
D_1 .data
SI Istack
SU .ustack
B .bss
B_2 .bss
B_1 .bss
R .bss
R_2 .bss
R_1 .bss
P .text
FIXEDVECT .fvectors
C, C_2, C_1, C*,C$*,L,W* .rodata

For more information on assembler constraints, please refer to the gcc manual.

For more information on assembler command line options, please refer to the as manual.

C/Math Library Functions


GNU C library namely Newlib is under free software license. The Newlib supports various processors and architectures.

1.    Complete set of Standard input/output functions.
2.    Float parameters support for Math library.
3.    The library can be built with integer only support. This in turn reduces the load.
4.    Option is available to build the libraries with floating point support.
5.    A customizable math error handler matherr() is available.
6.    All the functions are reentrant.

Drawbacks Involved:

1.   malloc() is used in every stdio routine.
2.   There is no support for low-level routines to connect to the target.

C library Math Functions only in Renesas:

No. Function
General Utilities (stddef.h)
1 offsetof

C library Math Functions only in GNU:

No. Function Description

Character type handling routines (ctype.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC35 for more information on these routines.

1 Isascii ASCII character predicate
2 Toascii Control character predicate
3 Iswalnum Alphanumeric wide character test
4 Iswalpha Alphabetic wide character test
5 Iswcntrla Wide character cntrl test
6 Iswdigit Decimal digit wide character test
7 Iswgraph Graphic wide character test
8 Iswlower Lowercase wide character test
9 Iswprint Printable wide character test
10 Iswpunct Punctuation wide character test
11 Iswspace Wide character space test
12 Iswupper Uppercase wide character test
13 Iswxdigit Hexadecimal digit wide character test
14 Iswctype Extensible wide character test
15 Wctype Get wide character classification type
16 *Towlower Translate wide characters to lower case
17 *Towupper Translate wide characters to upper case
18 Towctrans Extensible wide character case mapping
19 Wctrans Get wide character translation type

No. Function Description

Mathematics Functions (math.h)

Please refer the http://sources.redhat.com/newlib/libm.html#SEC1 for more information on these routines.

1 acosh, acoshf Inverse hyperbolic cosine
2 asinh, asinhf Inverse hyperbolic sine
3 atanh, atanhf Inverse hyperbolic tangent
4 jN,jNf,yN,yNf Bessel functions
5 erf, erff, erfc, erfcf Error function
6 gamma, gammaf, lgamma, lgammaf, gamma_r, hypot, hypotf Distance from origin
7 isnan, isnanf, isinf, isinff, finite, finitef Test for exceptional numbers
8 remainder, remainderf Round and remainder
9 cbrt, cbrtf Cube root
10 copysign, copysignf Sign of y, magnitude of x
11 expm, expmf Exponential minus 1
12 ilogb, ilogbf Get exponent of floating point number
13 infinity, infinityf Representation of infinity
14 logp, logpf Log of 1 + x
15 Matherr Modifiable math error handler
16 nan, nanf Representation of infinity
17 nextafter, nextafterf Get next number
18 scalbn, scalbnf Scale by integer

No. Function Description

General Utilities (stdlib.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC1 for more information on these routines.

1 Atexit Request execution of functions at program exit
2 Atoff String to double or float
3 Ecvt, ecvtf, fcvt, fcvtf Double or float to string
4 Gvcvt, gcvtf Format double or float as string
5 Ecvtbuf, fcvtbuf Double or float to string
6 __env_lock, __env_unlock Lock environ variable
7 Getenv Look up environment variable
8 Mallinfo, malloc_stats, mallopt Malloc support
9 __malloc_lock, __malloc_unlock Lock malloc pool
10 Mblen Minimal multibyte length function
11 Mbstowcs Minimal multibyte string to wide char converter
12 Mbtowc Minimal multibyte to wide char converter
13 Rand48, drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48 Pseudo random number generators and initialization routines
14 Strtof String to double or float
15 System Execute command string
16 Wcstombs Minimal wide char string to multibyte string converter
17 Wctomb Minimal wide char to multibyte converter

No. Function Description

String and Memory routines (string.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC109 for more information on these routines.

1 Bcmp Compare two memory areas
2 Bcopy Copy memory regions
3 Bzero Initialize memory to zero
4 Index Search for character in string
5 Memccpy Copy memory regions with end token check
6 Mempcpy Copy memory regions and return end pointer
7 Rindex Reverse search for character in string
8 Strcasecmp Case insensitive character string compare
9 Strlwr Force string to lower case
10 Strncasecmp Case insensitive character string compare
11 strtok_r,strsep Get next token from a string
12 Strupr Force string to uppercase
13 Swab Swap adjacent bytes

No. Function Description

Input/output routines (stdio.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC67 for more information on these routines.

1 Fgetpos Record position in a stream or file
2 Fiprintf Format output to file (integer only)
3 Fdopen Turn open file into a stream
4 Freopen Open a file using an existing file descriptor
5 fseeko Set file position
6 Fsetpos Restore position of a stream or file
7 ftello Return position in a stream or file
8 Getw Read a word (int)
9 Iprintf Write formatted output (integer only)
10 mktemp, mkstemp Generate unused file name
11 Putw Write a word (int)
12 Remove Delete a file's name
13 Rename Rename a file
14 Setbuf Specify full buffering for a file or stream
15 Siprintf Write formatted output (integer only)
16 asprintf, snprintf Format output
17 Tmpfile Create a temporary file
18 Tmpnam, Name for a temporary file
Large file input / output:
19 Fopen64 Open a large file
20 Freopen64 Open a large file using an existing file descriptor
21 Ftello64 Return position in a stream or file
22 Fseeko64 Set file position for large file
23 Fgetpos64 Record position in a large stream or file
24 Fsetpos64 Restore position of a large stream or file
25 Tmpfile64 Create a large temporary file

 

Along with all the above, following set of routines are provided in the newlib library:

1.    Wide character strings (wchar.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC144

2.    Signal handling (signal.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC169

3.    Time functions (time.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC172

4.    Locale specific routines (locale.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC183

Useful Links:

http://sources.redhat.com/newlib/libc.html
http://sources.redhat.com/newlib/libm.html

Inline Assembly


We can instruct the compiler to insert the code of a function into the code of its callers, to the point where actually the call is to be made. Such functions are inline functions. This method of inlining reduces the function-call overhead. And if any of the actual argument values are constant, their known values may permit simplifications at compile time so that not all of the inline function’s code needs to be included. The effect on code size is less predictable, it depends on the particular case. To declare an inline function, we’ve to use the keyword inline in its declaration. Inline assembly is important primarily because of its ability to operate and make its output visible on C variables. Because of this capability, "asm" works as an interface between the assembly instructions and the "C" program that contains it.

 

Syntax

GCC, the GNU C Compiler for Linux, uses AT&T UNIX assembly syntax.

a) Source-Destination Ordering

The first operand is the source and the second operand is the destination. ie, "Op-code src dst".

This is similar to the syntax followed in Renesas.

b) Register Naming

Register names are prefixed by % i.e., if r0 is to be used, write %r0.

c) Immediate Operand

Immediate operands are preceded by ’#’. For hexadecimal constants a ’0x’ is suffixed to the constant.

d) Operand Size

Size of memory operands is determined from the last character of the op-code name.

Op-code suffixes of ’b’, ’w’, and ’l’ specify byte(8-bit), word(16-bit), and long (32-bit) memory references.

e) Memory Operands

Base register is enclosed in ‘(’ and ’)’ and indirect memory reference is like

“section&colon;disp(base, index, scale)”. When a constant is used for disp and sol; scale, ’#’ shouldn’t be prefixed