組み込みCPUって小数の計算ができないの!?

  • このエントリーをはてなブックマークに追加

という話題について。

INTELやAMDやARMだとか、パソコンやスマホに入っているCPUは計算能力に特化しているので、整数も小数も超高速に計算できます。

 

が、組み込み用途で使うようなCPU(マイコン・MPU)なんていうのは非常に貧弱なため、全然違います。

組み込みマイコンでも高い部類(千円に近い値段)のものは浮動小数点のハードウェアを持っているのでそれなりな速度で計算できますが、

普通の安いマイコンではそもそも浮動小数点のハードウェアを持っていません。

つまり、整数計算しかできません!

それもスマホやPCみたいに64bitなんてのではなく、16bitや下手したら8bitだったりします。

 

要は、小数の計算が出来ないどころではなく、整数の計算すらしょぼいのです。

8bitのマイコンでも32bitなどの大きな数値を計算することは出来ますが、「8bitごとに足し算して繰り上げて上の桁の計算に使用して……」なんてことをするので4倍以上の時間がかかります。

浮動小数点も同様です。

浮動小数点数の仮数部だけを個別に計算して、指数部もまた個別に計算して……

要はプログラムでビット操作を延々として浮動小数点数の計算を行うのです。

考えてみればわかると思いますが、浮動小数点数の計算をビット操作でやるなんてめっちゃ大変です。

普通に整数計算の数十倍とかかかります。(下手したらもっと?)

 

さらに「浮動小数点同士の足し算・引き算・掛け算・割り算」をソフトウェアで行う必要があるので、そのためのライブラリをプログラム内に入れる必要が出てきます。

容量が数十kBしかないCPUだとけっこうな負担になります。

 

……ということで、浮動小数点数のハードウェアを持っていないCPUでは基本的には

・計算がありえないほど遅い

・ROMの容量が足りなくなる

ということで使わないという判断をすることが普通です。

 

以上、小田切でした。

  • このエントリーをはてなブックマークに追加

Warning: extract() expects parameter 1 to be array, string given in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 314

Warning: Illegal string offset 'title' in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 318

Warning: Cannot assign an empty string to a string offset in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 318

Warning: Illegal string offset 'content' in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 320

Warning: Cannot assign an empty string to a string offset in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 320

Warning: Illegal string offset 'button_text' in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 322

Warning: Cannot assign an empty string to a string offset in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 322

Warning: Illegal string offset 'button_url' in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 323

Warning: Cannot assign an empty string to a string offset in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 323

Warning: Illegal string offset 'button_cvtag' in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 324

Warning: Cannot assign an empty string to a string offset in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 324

Warning: Illegal string offset 'image' in /home/kisukunanato/kairo-consulting.com/public_html/blog/wp-content/themes/xeory_base/lib/functions/bzb-functions.php on line 332

SNSでもご購読できます。