Predefined Types and Functions

A set of core types and functions are available in LCM. They are available in the Pervasives library. See information about the General tab, accessed from Tools > Options > Automation.

Types are classified in a hierarchy of types classes (also called polymorphic types). A number of predefined functions accompany the types. Most of them are attached to a type class: they can be used with any type that belongs to the class.

Types and Type Classes

The LCM types are classified in a hierarchy of types and type classes.

pure
Pure type can take only one value called void (). In fact, when you work with the pure type, the meaningful data is the status of the signal (presence/absence).
bool
Boolean can take 2 values true or false.
Class Integer
Notation:
  • in decimal notation: 1,2,...
  • in hexadecimal notation: 0x12F0, 0xffab1234
  • in binary notation: 1b011001100
In big numbers, digits can be separated by "_": 1000_000_000 is equivalent to 1000000000.
uint8 8-bit unsigned integer number
uint16 16-bit unsigned integer number
uint32 32-bit unsigned integer number
uint64 64-bit unsigned integer number
int8 8-bit signed integer number
int16 16-bit signed integer number
int32 32-bit signed integer number
int64 64-bit signed integer number
Class Floating
Notation:
  • in floating notation: 1.0,3.14,...
  • in exponential notation: 1e14
float32 32-bit single precision floating point
float64 64-bit double precision floating point
Class word
word8 8-bit word : 0wFF
word16 16-bit word : 0w00FF
word32 32-bit word : 0w00FF00FF
word64 64-bit word : 0w00FF00FF00FF00FF
char8
ASCII 8-bit character : Any alphanumerical character 'a','1',...
string8
128 max char8 string : any list of characters starting and ending with a double quote (e.g. "test"). Strings can contain any character (even a new line). A double quote inside a string must be written \".

Typing Mechanism

You can constrain the type of any ports/signals with core types or user-defined types. However, constraining a type is not mandatory.

The LCM inference mechanism determines the port/signal type from its usage. For instance, if the value 1 is assigned to a non-typed signal A, the computed type of A will be 'any ::Number. The computed type can be seen in the tool type of the port/signal.

When the LCM program is built, all the remaining type classes are replaced by core types according to the default settings.

See information about the Build tab, accessed from Tools > Options > Automation.

Predefined Functions

A set of predefined functions are available. Each function works on specific types or a set of types.

Global Functions and Instructions

<- Assignment operator A <- B : The value of B is assigned to A and the status of A is set to emitted.
= Equality operator A=B : returns true if the value of A and B are equal. Note: Always true if A and B are pure.
<> Inequality operator A<>B : returns true if the value of A and B are different.
? Presence operator ?A : Return true if the signal is emitted.
pre Pre operator pre A: Returns the value and the status of the signal at the previous cycle.

Boolean Functions

not not A : returns true if the value A is false, returns false if A is true.
and A and B: returns true if A and B are true, false otherwise.
or A or B : returns true if the value A or the value of B are true, false otherwise.
xor A xor B: returns true if A and B have 2 distinct values, false otherwise.

Orderable Class Functions (all classes but pure and bool)

< A < B : returns true if the value A is less than B
> A > B: returns true if the value A is greater than B
<= A <= B : returns true if the value A is less or equal to B
>= A >= B: returns true if the value A is greater or equal to B
max max(x,y): returns x if x is greater than y
min min(x,y) : returns x if x is less than y

Bitwise Functions (class Word)

NOT Bitwise not : NOT(0w00)
AND Bitwise and : AND (0w00,0wFF)
OR Bitwise or : OR (0wFF,0wFF)
XOR Bitwise XOR: XOR(0wFF,0wFF)
ROR(x,n) Right-rotate x by n bits (n : int16)
ROL(x,n) Left-rotate x by n bits (n : int16)
SHR(x,n) Right-shift by N bits, zero-filled on right (n : int16)
SHL(x,n) Left-shift by N bits, zero-filled on left (n : int16)

Numerical functions (Class Number)

+ Addition : x+y
- Subtraction : x-y
* Multiplication :x * y
/ Division : x / y
** Raising to power (exponentiation): x**y
abs Absolute value of x : abs(x)

Mathematical functions (Class Integer)

mod(x,y) Modulo
lnot(x) bitwise NOT : lnot( 0b11110000)
land(x,y) bitwise AND : land(0b11110000,0b11110000)
lor(x,y) bitwise OR : lor(0b11110000,0b11110000)
lxor(x,y) bitwise Exclusive OR :lxor( 0b11110000,0b11110000)
lsl(x,n) right-shift by N bits, zero-filled on right (n : int16) : lsl(0b11110000,2)
lsr(x,n) left-shift by N bits, zero-filled on left (n : int16) : lsr(0b11111111,2)

Mathematical functions (Class Floating)

sin(x) Sine of input in radian
cos(x) Cosine of input in radian
tan(x) Tangent of input in radian
asin(x) Principal arc sine in the interval [-pi/2, +pi/2]
acos(x) Principal arc cosine in the interval [0, pi]
atan(x) Principal arc tangent in the interval [-pi/2, +pi/2]
atan2(x, y) Principal arc tangent in the interval [-pi, +pi]
sinh(x) Hyperbolic sine of input in radian
cosh(x) Hyperbolic cosine of input in radian
tanh(x) Hyperbolic tangent of input in radian
exp(x) Exponential (ex)
log(x) Natural logarithm
log10(x) Logarithm base 10
sqrt(x) Square root

Other functions

if expr1 then expr2 else expr3 if expr1 is true returns expr2, otherwise returns expr3

Type Conversion Function

Type conversion functions have the form typSrc_TO_typDst. They all have the data to convert as the unique argument and they return the converted data. Type conversion functions are offered for cases that make sense:


  • Between two types belonging to the same class among the classes Word, Integer and Real exam

    Type conversion functions have the form typSrc_TO_typDst. They all have the data to convert as the unique argument and they return the converted data. Type conversion functions are offered for cases that make sense:

    example: word16_TO_word32(), uint32_TO_int16(), float32_TO_float64()
  • Between unsigned integer number and word (identical size only) example: uint16_TO_word16(), word32_TO_uint32() (but not word16_TO_uint32())
  • Between signed integer number and real number example: int32_TO_float64(), float32_TO_int32() (but not uint16_TO_float64())

Conversion Src type size < Dst type size Src type size > Dst type size
Word > Word Extra highest-order ("leftmost") bits are set to 0 Only lowest-order ("rightmost") bits are kept. Extra highest-order ("leftmost") bits are discarded.
Integer > signed Integer Value is unchanged. Value is unchanged till it can be represented by the destination type. Otherwise, the result is implementation dependant! (should be avoided)
Integer > unsigned Integer The source integer is first extended to the size of the destination type. Sign keeps unchanged. Next, the extended source integer is mapped to the destination integer. If the source is signed, the sign bit becomes the highest-order bit of the positive value (negative values become large positive values). The source integer is first mapped to an unsigned integer of same size. If the source is signed, the sign bit becomes the highest-order bit of the positive value (negative values become large positive values). Next, the unsigned integer is reduced to the size of the destination type: only lowest-order ("rightmost") bits are kept. Extra highest-order ("leftmost") bits are discarded.
Floating > Floating See IEEE 754
Floating > Signed Integer The fractional part is discarded. Result is undefined in the case of real value that doesn't fit into the representation domain of the destination integer format.
Signed Integer > Floating The integer value is converted into the nearest real value that can be represented into the destination floating-point type. Result is undefined if the integer value doesn't fit into the representation domain of the destination type.

Default Values for Simulation

When you launch a simulation, values of signals are assigned to default values depending of their type.

BOOL WORD INTEGER FLOATING STRING CHAR
false 0w00 0 0 "" ''