【问题标题】:Why do those two high(64bx64b) functions give different results?为什么这两个高(64bx64b)函数会给出不同的结果?
【发布时间】:2015-07-01 09:44:19
【问题描述】:
static __inline__ uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t* hip) {
        __uint128_t product = ((__uint128_t)a)*((__uint128_t)b);
        *hip = product>>64;
        return (uint64_t)product;
}

我正在尝试在 AVX2 上使用 MULX 内在函数编写以下内容(更具体地说,BMI2)。但他们没有给出相同的结果。

static __inline__ uint64_t mulhilo64(uint64_t  a, uint64_t b, uint64_t *c){
     return _mulx_u64(a, b, &c);
}

【问题讨论】:

  • 你能提供一个简单的测试用例和每个实现的结果吗?
  • 第一个函数是一段很长的代码的一部分。我只是用第二个功能替换它,没有别的。你认为它们也应该是一样的吗?
  • 我在第二个函数中发现了一个可能的错误(见下面的答案)——我只是想把一个简单的测试用例放在一起,看看我是否可以复制这个问题。

标签: c++ hpc intrinsics avx2 bmi


【解决方案1】:

看起来这个函数可能是错误的:

static __inline__ uint64_t mulhilo64(uint64_t  a, uint64_t b, uint64_t *c){
     return _mulx_u64(a, b, &c);
}

应该是这样的:

static __inline__ uint64_t mulhilo64(uint64_t  a, uint64_t b, uint64_t *c){
     return _mulx_u64(a, b, c);
}                        // ^

请注意,编译时启用警告(例如gcc -Wall ...)有助于捕捉此类简单错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-11
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多