Description of the Project
Your processor does not have a floating point hardware. But, your application requires floating point arithmetic. Your task is to implement an efficient function to realize floating point addition and floating point addition. You will assume the bfloat16 representation. This representation is identical to the IEEE-784 standard discussed in the class and the book, except that the mantissa is only 7 bits, so the entire representation fits in 16 bits.
What you need to do?
• Write RISC-V assembly code and verify using the Venus RISC-V simulator.
• You are given a skeleton file that consists declarations for inputs x and y and output z, and operation to be performed. If (operation = 0) z = x + y else z = x – y
• z should be a valid bfloat16 representation of the answer, which means it should be normalized. Inputs x and y are also normalized bfloat16 representations.
• Input and output is done in decimal integer representation. So, the bfloat16 representations of x and y are input to your program as decimal integers and your output should also be a decimal integer corresponding to the bfloat16 representation of z.
• You can ignore rounding, overflow, and underflow, but make sure test cases where one of the operand is a zero.
• TA will provide additional test cases.
Useful Resources on the Web
https://en.wikipedia.org/wiki/Bfloat16_floating-point_format
https://oletus.github.io/float16-simulator.js/
https://www.rapidtables.com/convert/number/binary-to-decimal.html
https://www.binaryhexconverter.com/decimal-to-binary-converter
Skeleton File and Sample Results
.data
x: .word 16192 # 0.75= 16192
y: .word 16544 # 5 = 16544
z: .word 0 # expected result 0.75-5= -4.25 which is 49312 if operation is 1
operation: .word 1 #0 is add, 1 is subtract
.text
la t0, operation
lw t0, 0(t0) # t0 contains the flag whether to add or subtract
la t1, x
la t2, y
lw t1, 0(t1) # t1 has x in bfloat16 representation
lw t2, 0(t2) # t2 has y in bfloat16 represenation
#your program starts here
#store the final result in z
#print the result as z as decimal integer and exit
print:
#exit
addi a0, x0, 10
ecall