SPO600 Lab 6

#include <stdio.h>
#include <stdbool.h>
#include <arm_sve.h>
#include "vol.h"

int main()
{
    int x;
    int ttl = 0;

    // ---- Create in[] and out[] arrays
    int64_t *in;
    int64_t *out;
    in = (int64_t *)calloc(SAMPLES, sizeof(int64_t));
    out = (int64_t *)calloc(SAMPLES, sizeof(int64_t));

    // ---- Create dummy samples in in[]
    vol_createsample(in, SAMPLES);

    // ---- This is the part we're interested in!
    // ---- Scale the samples from in[], placing results in out[]

    /*for (x = 0; x < SAMPLES; x++) {
        out[x]=(int64_t) ((float) (VOLUME/100.0) * (float) in[x]);
    }*/

    svbool_t pg; // [1]
    svint64_t svin; // [1]
    svfloat64_t svv;// [1]
    const float64_t division = (float)(VOLUME / 100.0); // [2]
    for (int i = 0; i < SAMPLES; i += svcntd()) // [3]
    {
        pg = svwhilelt_b64(i, SAMPLES); // [4]
        svin = svld1(pg, &in[i]); // [5]
        svv = svld1(pg, &division); // [6]
        svst1(pg, &out[i], svcvt_s64_z(pg, svmul_f64_z(pg, svv, svcvt_f64_z(pg, svin)))); // [7]
    }

    // ---- This part sums the samples. (Why is this needed?)
    for (x = 0; x < SAMPLES; x++)
    {
        ttl = (ttl + out[x]) % 1000;
    }

    // ---- Print the sum of the samples. (Why is this needed?)
    printf("Result: %d\n", ttl);

    return 0;
}

The above code is my SVE2 implementation for the vol0.c program, specially for the scale volume function:

[1]: Declarations of vectors and guarded predicate for the loop.

[2]: Scale rate defined by VOLUME in vol.h

[3]: The loop with i increase by  the number of double-precision lanes in the vector.

[4]: Verify loop predicate after each loop.

[5]: Load a vector with data of samples.

[6]: Load another vector with the scale volume rate

[7]: Do multiply between 2 vectors and some conversions to mimic the original algorithm.

The hard part in the lab is that it is hard to find public discussions about SVE2 code, and I have to look at the instruction references.

Comments

Popular posts from this blog

SPO600 Lab 2

SPO600 Lab 1

SPO600 Lab 3