Main Content

addComplexTypeAlignment

Specify alignment boundary of a complex type

Description

example

addComplexTypeAlignment(hDataAlign,baseType,alignment) specifies the alignment boundary of real and complex data members of a complex type.

The starting memory address of the real and imaginary part of complex variables produced by the code generator with the specified type are a multiple of the specified alignment boundary. The code generator replaces operations in generated code when both of these conditions are true:

  • A code replacement table entry has a complex argument with a data alignment requirement that is less than or equal to the alignment boundary value

  • The entry satisfies all other code replacement match criteria.

To use this function, your code replacement library registration file must include additional compiler data alignment information, such as alignment syntax.

Examples

collapse all

This example shows how to specify a 16-byte alignment boundary for complex int8 types by adding the addComplexTypeAlignment line to your code replacement library registration file.

function rtwTargetInfo(cm)
% rtwTargetInfo function to register a code replacement library (CRL)
% for use with  code generation

  % Register the CRL defined in local function locCrlRegFcn
  cm.registerTargetInfo(@locCrlRegFcn);

end % End of RTWTARGETINFO

% Local function to define a CRL containing crl_table_mmul_4x4_single_align
function thisCrl = locCrlRegFcn

  % create an alignment specification object, assume gcc
  as = RTW.AlignmentSpecification;
  as.AlignmentType = {'DATA_ALIGNMENT_LOCAL_VAR', ...
                      'DATA_ALIGNMENT_GLOBAL_VAR', ...
                      'DATA_ALIGNMENT_STRUCT_FIELD'};
  as.AlignmentSyntaxTemplate = '__attribute__((aligned(%n)))';
  as.SupportedLanguages={'c', 'c++'};

  % add the alignment specification object
  da = RTW.DataAlignment;
  da.addAlignmentSpecification(as);
  da.addComplexTypeAlignment('int8', 16);

  % add the data alignment object to target characteristics
  tc = RTW.TargetCharacteristics;
  tc.DataAlignment = da;

  % Instantiate a CRL registry entry
  thisCrl = RTW.TflRegistry;

  % Define the CRL properties
  thisCrl.Name = 'Data Alignment Example';
  thisCrl.Description = 'Example of replacement with data alignment';
  thisCrl.TableList = {'crl_table_mmul_4x4_single_align'};
    thisCrl.TargetCharacteristics = tc;

end % End of LOCCRLREGFCN

Input Arguments

collapse all

The hDataAlign is a handle to a data alignment object, previously returned by hDataAlign = RTW.DataAlignment.

Example: da

The baseType is a character vector or string scalar that specifies a built-in data type such as int8 or long.

Example: 'int8'

The alignment is a positive integer that is a power of 2. This value specifies the alignment boundary.

Example: 16

Version History

Introduced in R2014a