64bits alignment

Technical questions regarding the XTC tools and programming with XMOS.
malo
Active Member
Posts: 33
Joined: Fri Sep 16, 2016 9:03 pm

64bits alignment

Post by malo »

Hello,

would like to have filter coefs in the structure, have found that they need to be 64bits aligned for dsp_filters_biquads/ldd.
trying with following structure

Code: Select all

typedef struct
{
    long long       padding_to_64b;
    int             filter_coefs [COEFS_PER_BIQUAD * CROSSOVER_BIQUADS_MAX];
} coefs_t;
and checking with

Code: Select all

    coefs_t coefs;
    printf (">> 0x%X, 0x%X\n", &(coefs.padding_to_64b), coefs.filter_coefs);
While on tile 0 I'm getting proper alignment

Code: Select all

>> 0x7D7F8, 0x7D800
On tile 1 Im getting

Code: Select all

>> 0x7F42C, 0x7F434
Which is 32bits alignment.

What is the trick to make it work on tile 1 as well?

wbr
malo


robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

That's odd!
Could you upload a working example please.
(p.s. aligned attribute is on its way)
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Initial most unlikely thought, on xs1 targets the alignment of long long is 32bit (but there is no lld instruction either), could the compiler somehow be thinking the wrong target?
Use '-v' to see what target xcc is sending to the compiler...
malo
Active Member
Posts: 33
Joined: Fri Sep 16, 2016 9:03 pm

Post by malo »

Hello,

the problem seems not to be in tile 0/1 but in combined combinable functions:)

here is the example compiled with -O3 for XCORE-200-EXPLORER target

Code: Select all

/*
 * alignment-test.xc
 *
 *  Created on: 1 Mar 2017
 *      Author: malo
 */

#include <platform.h>
#include <xs1.h>
#include <stdint.h>
#include <stdio.h>

typedef struct
{
    long long       padding_to_64b;
    int32_t         filter_coefs [16];
} coefs_t;

typedef interface sink_if
{
    void process_sample (unsigned int fs_, int left_, int right_);
} sink_if;

typedef interface dummy_if
{
    void nop ();
} dummy_if;

[[combinable]]
void dummy (server interface dummy_if i_dummy_)
{
    coefs_t coefs;
    printf (">>dummy: 0x%X, 0x%X\n", &(coefs.padding_to_64b), coefs.filter_coefs);

    while (1)
    {
        select
        {
            case i_dummy_.nop ():
                printf ("dummy: nop\n");
            break;
        }
    }
}

[[combinable]]
void sink (server interface sink_if i_sink_)
{
    coefs_t coefs;
    printf (">>sink: 0x%X, 0x%X\n", &(coefs.padding_to_64b), coefs.filter_coefs);

    while (1)
    {
        select
        {
            case i_sink_.process_sample (unsigned int fs_, int left_, int right_):
                printf ("sink: process_sample\n");
                break;
        }
    }
}

void source (client interface sink_if i_sink_, client interface dummy_if i_dummy_)
{
    coefs_t coefs;
    printf (">>source: 0x%X, 0x%X\n", &(coefs.padding_to_64b), coefs.filter_coefs);

    i_sink_.process_sample (0, 0, 0);
    i_dummy_.nop ();
}

int main()
{
    interface sink_if i_sink;
    interface dummy_if i_dummy;

    par
    {
        on tile [0]: source (i_sink, i_dummy);
        on tile [1] : [[combine, ordered]] par
        {
            dummy (i_dummy);
            sink (i_sink);
        }
    }

    return 0;
}
Here is my output

Code: Select all

>>source: 0x7FF20, 0x7FF28
>>dummy: 0x7FEF8, 0x7FF00
>>sink: 0x7FE9C, 0x7FEA4
sink: process_sample
dummy: nop
Bug or feature?

wbr
malo
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi Malo,
I can confirm that it is a bug during the creation of a frame of data to hold a set of combinable stack variables - the lump is not 8byte aligned, even though one of its elements must be.
Thank you for reporting it.
It has been fixed in the 14.3 release - shortly available.
A work around would be to use global data - sorry.
Robert
malo
Active Member
Posts: 33
Joined: Fri Sep 16, 2016 9:03 pm

Post by malo »

Hello Robert,

thanks for the quick response. btw what does it mean "shortly available"?

wbr
malo
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

another good question.
It is pending a feature completion - but this is being delayed due to other pressures.
We have plans to make available 'engineering builds' (our nightly builds) as non releases, I'll see if I can progress this alternative.