top of page

Lab6 PartA: Questions and Answers

In this blog we are going to answer the Questions asked in the new code provided to us which helped optimized the existing problem with Assembly Language.


QUESTION 1:

// these variables will be used in our assembler code, so we're going

// to hand-allocate which register they are placed in

// Q: what is an alternate approach?

register int16_t* in_cursor asm("r20"); // input cursor

register int16_t* out_cursor asm("r21"); // output cursor

register int16_t vol_int asm("r22"); // volume as int16_t


ANSWER 1:

Put the registers we are going to use inside the clobber of the ASM function call.

So when we use the ASM function it will look like this


ASM ( "command" : in : out: clobber );


The clobber can be used to define registers we want to reserve or plan to use during the program execution.


QUESTION 2:

// set vol_int to fixed-point representation of 0.75

// Q: should we use 32767 or 32768 in next line? why?

vol_int = (int16_t) (0.75 * 32767.0);


ANSWER 2:

We should use 32767, because we get the value by executing the command 2 ^ 16 which is 65,536 we need to divide this by 2 because we are using a signed integer so half the value will be negative, this gives us 32,768 which one would think is the correct answer however because our index starts at 0 and NOT at 1 we need to subtract -1 from that value which gives us 32,767



QUESTION 3:

// Q: what does it mean to "duplicate" values in the next line?

__asm__ ("dup v1.8h,%w0"::"r"(vol_int)); // duplicate vol_int into v1.8h


ANSWER 3:

To duplicate, to copy a register into a scalar or vector.

Copy the value of the %w0 register into the v1.8h vector

The 8H symbolizes a vector split into 8 rows with 16 bits a row from a 128 bit vector.


QUESTION 4:

// Q: what happens if we remove the following

// two lines? Why?

: [in]"+r"(in_cursor)

: "0"(in_cursor),[out]"r"(out_cursor)


ANSWER 4:

We will lose our "in" and "out" operators. Basically the ASM function will not know where to get the values from , and where to put the values once the operation has been completed.


Most likely because it would be a pointless operation the compiler would skip over this part without those 2 lines.

QUESTION 5:

// Q: are the results usable? are they correct?

printf("Result: %d\n", ttl);


ANSWER 5:

Our results are different here, -574 versus the original output of 416. Which means the results must be incorrect. What I believe is happening here is that the registers are being used by the compiler twice or values are being overwritten by us or the compiler when using the ASM command.

Even though we have reserved special registers to use that does not mean that those registers did not have values inside of them already which the compiler was gong to use later in the program.

7 views0 comments

Recent Posts

See All

Closing Thoughts

For my final blog post I would like to discuss what I have learned and plan to utilize in the future from this course. So although I was not able to successfully improve my package to operate function

Stage 3 Optimization(COMPUTER ARCHITECTURE ENDIANESS)

Seeing as how the compiler flags did not provide any optimization I will on to my next attempt which is converting big endian to small endian. The aarch64 architecture uses the little endian byte orde

Stage 3 Optimization(Compiler Flags)

My first attempt to optimize the project will be to work with the compiler flag options. By default the compiler is set to compile in this manner "gcc -E -g -o2" The -E option represents preprocesses

bottom of page