Skip to content

postgres指令选择问题 #31

@lfeng14

Description

@lfeng14
  • 描述
    postgres里面有涉及nan与0.0比较,毕昇生成的指令fmaxnm,应该使用fcmp指令。当前通过修改代码后规避。在 C 语言标准中,‌任何浮点数与 NaN 的比较(包括 ==、!=、>、<、>=、<=)均返回 false
    // postgresql geo_ops.c
    Datum
    dist_pc(FunctionCallInfo fcinfo)
    {
     Point *point = ((Point *) ((Pointer) ((fcinfo->args[0].value))));
     CIRCLE *circle = ((CIRCLE *) ((Pointer) ((fcinfo->args[1].value))));
     float8 result;
    
     result = float8_mi(point_dt(point, &circle->center),
            circle->radius);
    
            if (__builtin_isnan (result)) {
              return Float8GetDatum(result);
            }
    
     if (result < 0.0)
      result = 0.0;
    
     return Float8GetDatum(result);
    }
    
  • demo: 如何d是-1 返回0.0;如果d是nan,返回nan;
    double f(double d) {
      if (d < 0.0) {
         return 0.0;
       }
      return d;
    }
    
  • 构建命令:
    clang -S geo_ops-proce.c  -o geo_ops.s -O2; cat  geo_ops.s | grep -a1 fmaxnm
    /home/luofeng/BiSheng/BiSheng-Compiler-4.2.0/bin//clang -Wno-error=unused-command-line-argument -Wno-error=strict-prototypes -Wno-error=unused-but-set-variable -Wno-error=backend-plugin -O3 -mcpu=tsv110  -fuse-ld=lld  -mllvm -inline-threshold=2000 -Wl,-mllvm,-inline-threshold=2000 -fprofile-use=/media/bisheng.profdata -Wall -Wmissing-prototypes -Wpointer-arith -Wno-error=unused-command-line-argument -Wno-error=strict-prototypes -Wno-error=unused-but-set-variable -Wno-error=backend-plugin -I. -I. -I../../../../src/include  -D_GNU_SOURCE -I/usr/include/libxml2   -S -o geo_ops-bs17.s geo_ops.c
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions