V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
northisland
V2EX  ›  问与答

请问, float32 和 int 普通运算计算速度差不多么?

  •  
  •   northisland · Oct 16, 2015 · 2833 views
    This topic created in 3850 days ago, the information mentioned may be changed or developed.
    楼主很懒没有研究过,也没测试。

    以前在学校觉得浮点数计算方法略麻烦,在某些精简指令集(把浮点数指令简化了=_=我在瞎猜)的 CPU 上,可能会慢。
    把我的瞎猜实例化,就像int1+int2可能花1个处理器周期,但float1+float2可能就花>1个处理器周期。

    但事实上是不是这样呢?当然楼主说的肯定是PC处理器,撑死讨论一下ARM。


    请和我探讨一下,验证一下,多谢
    1 replies    2015-10-16 13:23:19 +08:00
    msg7086
        1
    msg7086  
       Oct 16, 2015   ❤️ 1
    https://software.intel.com/sites/landingpage/IntrinsicsGuide/#techs=AVX,AVX2&cats=Arithmetic&expand=73,112

    就拿现在主流的 AVX 系指令集来说。

    32 位整数相加 __m256i _mm256_add_epi32 (__m256i a, __m256i b)
    Architecture Latency Throughput
    Haswell 1 0.5

    32 位浮点相加 __m256 _mm256_add_ps (__m256 a, __m256 b)
    Architecture Latency Throughput
    Haswell 3 1

    延迟是 3 倍,吞吐量占用是 2 倍。(吞吐量占用是越小越快)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   824 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:07 · PVG 06:07 · LAX 15:07 · JFK 18:07
    ♥ Do have faith in what you're doing.