如何在MIPS中将浮点寄存器设置为0(或清除其值). [英] How to set a floating point register to 0 in MIPS (or clear its value).

查看:528
本文介绍了如何在MIPS中将浮点寄存器设置为0(或清除其值).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在MIPS流水线代码中实现一个包含单个浮点数的方阵乘法器.

I'm currently implementing a square matrix multiplier containing single floating point numbers in MIPS assembly line code.

我的问题是,完成对相应行和列的乘积求和以便计算我的点积后,我想清除该浮点寄存器,以便可以为乘积矩阵中的下一个条目计算点积现在,我继续将当前的点产品与所有以前的点产品相加.

My problem is that once I am done summing the multiplications of the corresponding rows and columns in order to calculate my dot product I want to clear that floating point register so I can calculate the dot product for the next entry in the product matrix.Right now I keep adding the current dot product with all the previous dot products.

我尝试将浮点寄存器设置为零的事情:

Things I've tried to set the floating point register as zero:

l.s $f3,$0 #loading zero into the register

addi $t0,$t0,$zero #setting a temp register as zero
l.s $f3,($t0)

我一直收到指示运行时异常和地址超出范围的错误.

I keep getting an error indicating a runtime exception and an address out of range.

推荐答案

您正在做的是从地址0加载浮点数,因此是错误的.您想改为加载值0.您可以通过mtc1 $zero, $f3进行操作.之所以可行,是因为所有零位在浮点中也意味着零.对于其他值,您之后必须执行cvt.s.w才能将整数转换为浮点数.或者,您可以通过sub.s $f3, $f3, $f3从其自身减去寄存器.不知道这是否适用于所有可能的值(我正在考虑NaNInf等),或者它是否比从整数零寄存器传输更快.

What you are doing is loading a float from address 0, hence the fault. You want to load the value 0 instead. You can do that by mtc1 $zero, $f3. This works because all zero bits mean zero in floating point too. For other values, you'd have to do a cvt.s.w afterwards to convert the integer to floating point. Alternatively you can subtract the register from itself by sub.s $f3, $f3, $f3. Don't know if this works for all possible values (I am thinking of NaN, Inf and such) or if it is faster than transferring from the integer zero register.

这篇关于如何在MIPS中将浮点寄存器设置为0(或清除其值).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆