0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

10の割り算 割られる数が1000ぐらいまで正しい(おまけ2)

Last updated at Posted at 2023-11-30

作成中 10の割り算 割られる数が1000ぐらいまで正しい(おまけ2)

目的
M0/M0+でいろいろな変換を高速化
する。
親切な人に頂いたプログラムを解析する

①最初と最後のシフトダウンは、誤差の丸め?
②xをxの上位16ビットと下位16ビットに分ける
③下位16ビット同士を掛ける
④下位、上位のたすき掛けをする
⑤上位16ビット同士を掛ける
⑥1回シフトする
⑦xの入力時に1回、定数で1回、リターンで1回、
合計3回シフトしている

10進化する定数
3435973837(10進)
0xcccccccd(16進)
1100 1100 1100 1100 1100 1100 1100 1101(二進)

yhの値 1回シフトした値
0x6666
0110 0110 0110 0110

ylの値
0x6667
0110 0110 0110 0111

xが19の時の値
 定数3435973837(10進)
65283502903(10進)
1111 0011 0011 0011 0011 0011 0011 0011 0111(二進)

xが19(1/2の時9.5)の時の値 定数66666667(16進) 1717986919(10進)
15461882271(10進)
0011 1001 1001 1001 1001 1001 1001 1001 1111(二進)

o_cop823.jpg

o_cop825.jpg


#include <stdint.h>
uint32_t piyo(uint32_t x)
{
    x >>= 1;
    uint32_t xh = x >> 16;
    uint32_t xl = x & 0xffff;
    uint32_t yh = 0x6666;
    uint32_t yl = 0x6667;
    uint32_t z = xl * yl;
    z >>= 16;
    z += xh * yl + xl * yh;
    z >>= 16;
    z += xh * yh;
    return z >> 1;
}


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?