In the CCRX, some of the assembler instructions can be described in C source as "Intrinsic Functions". However, it is not described "as assembler instruction", but as a function format set in the CCRX. When an intrinsic function is used, the compiler inserts the corresponding code into the program.
* Indicates whether the function is limited when the RX processor mode is user mode. |
signed long max(signed long data1, signed long data2) signed long __max(signed long data1, signed long data2) [V2.05.00 or later] |
Selects the greater of two input values (this function is expanded into a MAX instruction).
The greater value of data1 and data2
#include <machine.h> extern signed long ret,in1,in2; void main(void) { ret = max(in1,in2);// Stores the greater value of in1 and in2 in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
signed long min(signed long data1, signed long data2) signed long __min(signed long data1, signed long data2) [V2.05.00 or later] |
Selects the smaller of two input values (this function is expanded into a MIN instruction).
The smaller value of data1 and data2
#include <machine.h> extern signed long ret,in1,in2; void main(void) { ret = min(in1,in2);// Stores the smaller value of in1 and in2 in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
Reverses the byte order in 4-byte data (this function is expanded into a REVL instruction).
data Data for which byte order is to be reversed
Value of data with the byte order reversed
#include <machine.h> extern unsigned long ret,indata=0x12345678; void main(void) { ret = revl(indata);// ret = 0x78563412 } |
The header does not have to be included when using an intrinsic function whose name starts with __.
Reverses the byte order within each of the upper and lower two bytes of 4-byte data (this function is expanded into a REVW instruction).
data Data for which byte order is to be reversed
Value of data with the byte order reversed within the upper and lower two bytes
#include <machine.h> extern unsigned long ret;indata=0x12345678; void main(void) { ret = revw(indata);// ret = 0x34127856 } |
The header does not have to be included when using an intrinsic function whose name starts with __.
void xchg(signed long *data1, signed long *data2) void __xchg(signed long *data1, signed long *data2) [V2.05.00 or later] |
Exchanges the contents of the areas indicated by parameters (this function is expanded into an XCHG instruction).
#include <machine.h> extern signed long *in1,*in2; void main(void) { xchg (in1,in2);// Exchanges data at address in1 and address in2. } |
The XCHG instruction to be generated has a memory operand with a location indicated by data2.
The header does not have to be included when using an intrinsic function whose name starts with __.
Performs a multiply-and-accumulate operation with the initial value specified by init, the number of multiply-and-accumulate operations specified by count, and the start addresses of values to be multiplied specified by addr1 and addr2 (this function is expanded into a RMPA.B instruction).
count Count of multiply-and-accumulate operations
*addr1 Start address of values 1 to be multiplied
*addr2 Start address of values 2 to be multiplied
Lower 64 bits of the init + Σ(data1[n] * data2[n]) result (n = 0, 1, ..., const - 1)
The RMPA instruction obtains a result in a maximum of 80 bits, but this intrinsic function handles only 64 bits.
The header does not have to be included when using an intrinsic function whose name starts with __.
long long rmpaw(long long init, unsigned long count, short *addr1, short *addr2) long long __rmpaw(long long init, unsigned long count, short *addr1, short *addr2) [V2.05.00 or later] |
Performs a multiply-and-accumulate operation with the initial value specified by init, the number of multiply-and-accumulate operations specified by count, and the start addresses of values to be multiplied specified by addr1 and addr2 (this function is expanded into a RMPA.W instruction).
count Count of multiply-and-accumulate operations
*addr1 Start address of values 1 to be multiplied
*addr2 Start address of values 2 to be multiplied
Lower 64 bits of the init + Σ(data1[n] * data2[n]) result (n = 0, 1, ..., const - 1)
The RMPA instruction obtains a result in a maximum of 80 bits, but this intrinsic function handles only 64 bits.
The header does not have to be included when using an intrinsic function whose name starts with __.
long long rmpal(long long init, unsigned long count, long *addr1, long *addr2) long long __rmpal(long long init, unsigned long count, long *addr1, long *addr2) [V2.05.00 or later] |
Performs a multiply-and-accumulate operation with the initial value specified by init, the number of multiply-and-accumulate operations specified by count, and the start addresses of values to be multiplied specified by addr1 and addr2 (this function is expanded into a RMPA.L instruction).
count Count of multiply-and-accumulate operations
*addr1 Start address of values 1 to be multiplied
*addr2 Start address of values 2 to be multiplied
Lower 64 bits of the init + Σ(data1[n] * data2[n]) result (n = 0, 1, ..., const - 1)
The RMPA instruction obtains a result in a maximum of 80 bits, but this intrinsic function handles only 64 bits.
The header does not have to be included when using an intrinsic function whose name starts with __.
Rotates data including the C flag to left by one bit (this function is expanded into a ROLC instruction).
The bit pushed out of the operand is set to the C flag.
data Data to be rotated to left
Result of 1-bit left rotation of data including the C flag
#include <machine.h> extern unsigned long ret, indata; void main(void) { ret = rolc(indata);// Rotates indata including the C flag // to left by one bit and stores the result // in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
Rotates data including the C flag to right by one bit (this function is expanded into a RORC instruction).
The bit pushed out of the operand is set to the C flag.
data Data to be rotated to right
Result of 1-bit right rotation of data including the C flag
#include <machine.h> extern unsigned long ret, indata; void main(void) { ret = rorc(indata);// Rotates indata including the C flag // to right by one bit and stores the result // in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
unsigned long rotl(unsigned long data, unsigned long num) unsigned long __rotl(unsigned long data, unsigned long num) [V2.05.00 or later] |
Rotates data to left by the specified number of bits (this function is expanded into a ROTL instruction).
The bit pushed out of the operand is set to the C flag.
data Data to be rotated to left
num Number of bits to be rotated
Result of num-bit left rotation of data
#include <machine.h> extern unsigned long ret, indata; void main(void) { ret = rotl(indata, 31); // Rotates indata to left by 31 bits // and stores the result in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
unsigned long rotr(unsigned long data, unsigned long num) unsigned long __rotr(unsigned long data, unsigned long num) [V2.05.00 or later] |
Rotates data to right by the specified number of bits (this function is expanded into a ROTR instruction).
The bit pushed out of the operand is set to the C flag.
data Data to be rotated to right
num Number of bits to be rotated
Result of num-bit right rotation of data
#include <machine.h> extern unsigned long ret, indata; void main(void) { ret = rotr(indata, 31); // Rotates indata to right by 31 bits // and stores the result in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
This function is expanded into a BRK instruction.
The header does not have to be included when using an intrinsic function whose name starts with __.
This function is expanded into an INT num instruction.
Only an integer from 0 to 255 can be specified as num.
The header does not have to be included when using an intrinsic function whose name starts with __.
This function is expanded into a WAIT instruction.
This function must not be executed when the RX processor mode is user mode. If executed, a privileged instruction exception of the RX occurs due to the specifications of the WAIT instruction.
The header does not have to be included when using an intrinsic function whose name starts with __.
This function is expanded into a NOP instruction.
The header does not have to be included when using an intrinsic function whose name starts with __.
Changes the interrupt mask level.
level Interrupt mask level to be set
A value from 0 to 15 can be specified for level by default, and a value from 0 to 7 can be specified when -patch=rx610 is specified.
If a value outside the above range is specified when level is a constant, an error will be output.
This function must not be executed when the RX processor mode is user mode. If executed, a privileged instruction exception of the RX occurs due to the specifications of the MVTIPL instruction.
The header does not have to be included when using an intrinsic function whose name starts with __.
Refers to the interrupt mask level.
#include <machine.h> extern unsigned char level; void main(void) { level=get_ipl();// Obtains the PSW.IPL value and // stores it in level. } |
If a value smaller than 0 or greater than 7 is specified as level, an error will be output.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern unsigned long data; void main(void) { set_psw(data);// Sets PSW to the value specified by data. } |
Due to the specifications of the RX instruction set, a write to the PM bit of PSW is ignored. In addition, a write to PSW is ignored when the RX processor mode is user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern unsigned long ret; void main(void) { ret=get_psw();// Obtains the PSW value and stores it in ret. } |
In some cases, the timing at which the PSW value is obtained differs from the timing at which get_psw was called, due to the effect of optimization. Therefore when a code using the C, Z, S, or O flag included in the return value of this function is written after some sort of operation, correct operation will not be guaranteed.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern unsigned long data; void main(void) { set_fpsw(data);// Sets FPSW to the value specified by data. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern unsigned long ret; void main(void) { ret=get_fpsw();// Obtains the FPSW value and stores it // in ret. } |
In some cases, the timing at which the FPSW value is obtained differs from the timing at which get_fpsw was called, due to the effect of optimization. Therefore when a code using the CV, CO, CZ, CU, CX, CE, FV, FO, FZ, FU, FX, or FS flag included in the return value of this function is written after some sort of operation, correct operation will not be guaranteed.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * data; void main(void) { set_usp(data);// Sets USP to the value specified by data. } |
A 4-byte boundary address should be specified as data.
Program operation is not guaranteed when a 1-byte boundary address or 2-byte boundary address is specified.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * ret; void main(void) { ret=get_usp();// Obtains the USP value and stores it in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * data; void main(void) { set_isp(data);// Sets ISP to the value specified by data. } |
Due to the specifications of the MVTC instruction used in this function, a write to ISP is ignored when the RX processor mode is user mode.
A 4-byte boundary address should be specified as data.
Program operation is not guaranteed when a 1-byte boundary address or 2-byte boundary address is specified.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * ret; void main(void) { ret=get_isp();// Obtains the ISP value and stores it in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * data; void main(void) { set_intb (data);// Sets INTB to the value specified by data. } |
Due to the specifications of the MVTC instruction used in this function, a write to INTB is ignored when the RX processor mode is user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * ret; void main(void) { ret=get_intb();// Obtains the INTB value and stores it in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern unsigned long data; void main(void) { set_bpsw (data);// Sets BPSW to the value specified by data. } |
Due to the specifications of the MVTC instruction used in this function, a write to BPSW is ignored when the RX processor mode is user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern unsigned long ret; void main(void) { ret=get_bpsw ();// Obtains the BPSW value and stores it // in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * data; void main(void) { set_bpc(data);// Sets BPC to the value specified by data. } |
Due to the specifications of the MVTC instruction used in this function, a write to BPC is ignored when the RX processor mode is user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * ret; void main(void) { ret=get_bpc();// Obtains the BPC value and stores it in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * data; void main(void) { set_fintv(data);// Sets FINTV to the value specified by data. } |
Due to the specifications of the MVTC instruction used in this function, a write to FINTV is ignored when the RX processor mode is user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * ret; void main(void) { ret=get_fintv();// Obtains the FINTV value and stores it // in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
signed long long emul(signed long data1, signed long data2) signed long long __emul(signed long data1, signed long data2) [V2.05.00 or later] |
Performs signed multiplication of significant 64 bits.
Result of signed multiplication (signed 64-bit value)
#include <machine.h> extern signed long long ret; extern signed long data1, data2; void main(void) { ret=emul(data1, data2);// Calculates the value of // "data1 * data2" and stores it in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
unsigned long long emulu(unsigned long data1, unsigned long data2) unsigned long long __emulu(unsigned long data1, unsigned long data2) [V2.05.00 or later] |
Performs unsigned multiplication of significant 64 bits.
Result of unsigned multiplication (unsigned 64-bit value)
#include <machine.h> extern unsigned long long ret; extern unsigned long data1, data2; void main(void) { ret=emulu(data1, data2);// Calculates the value of // "data1 * data2" and stores it in ret. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
Switches the RX processor mode to user mode.
#include <machine.h> void main(void); void Do_Main_on_UserMode(void) { chg_pmusr();// Switches the RX processor mode to user mode. main();// Executes the main function. } |
This function is provided for a reset processing function or interrupt function. Usage in any other function is not recommended.
The processor mode is not switched when the RX processor mode is user mode.
Since the stack is switched from the interrupt stack to the user stack when this function is executed, the following conditions must be met in a function that is calling this function. If the conditions are not met, code does not operate correctly because the stack is not the same before and after this function has been executed.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> void main(void) { signed long long data = 0x123456789ab0000LL; set_acc(data);// Sets ACC to the value specified by data. } |
The header does not have to be included when using an intrinsic function whose name starts with __.
Due to the specifications of the RX instruction set, contents in the lower 16 bits of ACC cannot be obtained. This function returns the value of 0 for these bits.
The header does not have to be included when using an intrinsic function whose name starts with __.
Sets the interrupt enable bit (I bit) in PSW to 1.
Due to the specifications of the SETPSW instruction used by this function, writing to the interrupt enable bit is ignored when the RX processor mode is set to user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
Clears the interrupt enable bit (I bit) in PSW to 0.
Due to the specifications of the CLRPSW instruction used by this function, writing to the interrupt enable bit is ignored when the RX processor mode is set to user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
long macl(short *data1, short *data2, unsigned long count) long __macl(short *data1, short *data2, unsigned long count) [V2.05.00 or later] |
Performs a multiply-and-accumulate operation between data of two bytes each and returns the result as four bytes.
The multiply-and-accumulate operation is executed with DSP functional instructions (MULLO, MACLO, and MACHI).
Data in the middle of the multiply-and-accumulate operation is retained in ACC as 48-bit data.
After all multiply-and-accumulate operations have finished, the contents of ACC are fetched by the MVFACMI instruction and used as the return value of the intrinsic function.
Usage of this intrinsic function enables fast multiply-and-accumulate operations to be expected compared to as when writing multiply-and-accumulate operations without using this intrinsic function.
This intrinsic function can be used for multiply-and-accumulate operations of 2-byte integer data. Saturation and rounding are not performed to the results of multiply-and-accumulate operations.
data1 Start address of values 1 to be multiplied
data2 Start address of values 2 to be multiplied
count Count of multiply-and-accumulate operations
#include <machine.h> short data1[3] = {a1, b1, c1}; short data2[3] = {a2, b2, c2}; void mac_calc() { result = macl(data1, data2, 3); /* Obtains the result of "a1*a2+b1*b2+c1*c2". */ } |
Refer to the programming manual to confirm the detailed contents of the various DSP functional instructions used in multiply-and-accumulate operations.
When the multiplication count is 0, the return value of the intrinsic function is 0.
When using this intrinsic function, save and restore ACC in an interrupt processing in which the ACC value is rewritten.
For the function to save and restore ACC, refer to the compiler option save_acc or the extended language specifications #pragma interrupt.
The header does not have to be included when using an intrinsic function whose name starts with __.
Performs a multiply-and-accumulate operation between data of two bytes each and returns the result as two bytes.
The multiply-and-accumulate operation is executed with DSP functional instructions (MULLO, MACLO, and MACHI).
Data in the middle of the multiply-and-accumulate operation is retained in ACC as 48-bit data.
After all multiply-and-accumulate operations have finished, rounding is applied to the multiply-and-accumulate operation result of ACC.
The macw1 function performs rounding with the "RACW #1" instruction while the macw2 function performs rounding with the "RACW #2" instruction.
Rounding is performed with the following procedure.
The contents of ACC are left-shifted by one bit with the macw1 function and by two bits with the macw2 function. |
The upper 32 bits of ACC are saturated with the upper limit as 0x00007FFF and the lower limit as 0xFFFF8000. |
Finally, the contents of ACC are fetched by the MVFACHI instruction and used as the return value of these intrinsic functions.
Normally, the decimal point position of the multiplication result needs to be adjusted when fixed-point data is multiplied with each other. For example, in a case of multiplication of two Q15-format fixed-point data items, the multiplication result has to be left-shifted by one bit to make the multiplication result have the Q15 format. This left-shifting to adjust the decimal point position is achieved by the left-shift operation of the RACW instruction. Accordingly, in a case of multiply-and-accumulate operation of 2-byte fixed-point data, using these intrinsic functions facilitate multiply-and-accumulate processing. Note however that since the rounding mode of the operation result differs in macw1 and macw2, the intrinsic function to be used should be selected according to the desired accuracy for the operation result.
data1 Start address of values 1 to be multiplied
data2 Start address of values 2 to be multiplied
count Count of multiply-and-accumulate operations
Value obtained by rounding the multiply-and-accumulate operation result with the RACW instruction
Refer to the programming manual to confirm the detailed contents of the various DSP functional instructions used in multiply-and-accumulate operations.
When the multiplication count is 0, the return value of the intrinsic function is 0.
When using this intrinsic function, save and restore ACC in an interrupt processing in which the ACC value is rewritten.
For the function to save and restore ACC, refer to the compiler option save_acc or the extended language specifications #pragma interrupt.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * data; void main(void) { set_extb (data);// Sets EXTB to the value specified by data. } |
This function is only usable when a value other than RXv1 is specified for the isa option or the environment variable ISA_RX. In other cases, this option will lead to an error at compilation.
Due to the specifications of the MVTC instruction used in this function, a write to EXTB is ignored when the RX processor mode is user mode.
The header does not have to be included when using an intrinsic function whose name starts with __.
#include <machine.h> extern void * ret; void main(void) { ret=get_extb();// Obtains the EXTB value and stores it in ret. } |
This function is only usable when a value other than RXv1 is specified for the isa option or the environment variable ISA_RX. In other cases, this option will lead to an error at compilation.
The header does not have to be included when using an intrinsic function whose name starts with __.
Sets the specified one bit in the specified 1-byte area to 0 (this function is expanded into a BCLR instruction).
data Address of the target 1-byte area
bit Position of the bit to be manipulated
unsigned char *data; void main(void) { __bclr(data, 0); // Sets the least significant bit in the 1-byte area indicated // by address data to 0. } |
Only an integer constant from 0 to 7 can be specified as parameter bit.
This function is expanded into a BCLR instruction which directly modifies the bit specified by the parameter to 0 in memory.
Sets the specified one bit in the specified 1-byte area to 1 (this function is expanded into a BSET instruction).
data Address of the target 1-byte area
bit Position of the bit to be manipulated
unsigned char *data; void main(void) { __bset(data, 0); // Sets the least significant bit in the 1-byte area indicated // by address data to 1. } |
Only an integer constant from 0 to 7 can be specified as parameter bit.
This function is expanded into a BSET instruction which directly modifies the bit specified by the parameter to 1 in memory.
Reverses the value of the specified one bit in the specified 1-byte area (this function is expanded into a BNOT instruction).
data Address of the target 1-byte area
bit Position of the bit to be manipulated
unsigned char *data; void main(void) { __bnot(data, 0); // Sets the least significant bit in the 1-byte area indicated // by address data to 0 if the value is 1 or to 1 if the value // is 0. } |
Only an integer constant from 0 to 7 can be specified as parameter bit.
This function is expanded into a BNOT instruction which directly reverses the bit specified by the parameter in memory.
unsigned long data; void main(void) { __set_dpsw(data);// Sets DPSW to the value specified by data. } |
This function is only usable when the dpfpu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.
unsigned long ret; void main(void) { ret=__get_dpsw();// Obtains the DPSW value and stores it in ret. } |
This function is only usable when the dpfpu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.
unsigned long data; void main(void) { __set_decnt(data);// Sets DECNT to the value specified by data. } |
This function is only usable when the dpfpu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.
unsigned long ret; void main(void) { ret=__get_decnt();// Obtains the DECNT value and stores it in ret. } |
This function is only usable when the dpfpu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.
This function is only usable when the dpfpu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.
Initializes the trigonometric function unit.
Before using the trigonometric function unit, initialize the unit from the startup program by calling this function. If you do not do so, correct operation is not guaranteed.
This function is only available when the tfu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.
Uses the trigonometric function unit to calculate the sine and cosine of an angle at the same time (single precision).
f Value in radians from which to calculate the sine and cosine
sin Address for storing the result of the sine operation
cos Address for storing the result of the cosine operation
float f, *sin, *cos; void main(void) { __init_tfu(); // The trigonometric function unit must be initialized in advance. __sincosf(f, sin, cos); } |
Before calling this function, be sure to initialize the trigonometric function unit by calling the __init_tfu() intrinsic function.
This function is not reentrant.
This function is only available when the tfu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.
Uses the trigonometric function unit to calculate the arc tangent of x and y and the square root of the sum of squares
of these values (
) at the same time (single precision).
y Coordinate y (the numerator of the tangent)
x Coordinate x (the denominator of the tangent)
atan2 Address for storing the result of the arc tangent operation for y/x
hypot Address for storing the result of the square root of the sum of squares of x and y (
)
float y, x, *atan2, *hypot; void main(void) { __init_tfu(); // The trigonometric function unit must be initialized in advance. __atan2hypotf(y, x, atan2, hypot); } |
Before calling this function, be sure to initialize the trigonometric function unit by calling the __init_tfu() intrinsic function.
This function is not reentrant.
The result of the arc tangent operation is returned as a value in radians in the range from (-π to π)
This function is only available when the tfu option is specified. If this call is attempted with the option not specified, an error will occur at the time of compilation.