[PATCH] D46925: Remaining Binary Operations on Primary Fixed Point Types

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 15 19:50:47 PDT 2018


leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr, jakehehrlich.
leonardchan added a project: clang.

This patch implements the remaining arithmetic and logical operations on the primary fixed point types.

The operations are `+`, `-`, `*`, `/`, `<<`, and `>>`.

  // Addition
   s_accum = 3.0hk;
   short _Accum s_accum_sum = s_accum + s_accum2;
   assert(s_accum_sum == 5);
   assert(s_fract + s_fract2 == 0);
  
   // Subtraction
   short _Accum s_accum_diff = s_accum - s_accum2;
   assert(s_accum_diff == 1);
   assert(s_accum2 - s_accum == -1);
  
   // Multiplication
   short _Accum s_accum_mul = s_accum * s_accum2;
   assert(s_accum_mul == 6);
   assert(2.0hk * 3.0hk == 6);
   assert(2.0hk * 3 == 6);
   assert(2.5hk * 3 == 7.5k);
   assert(-2.5hk * 3 == -7.5lk);
   assert(3 * -2.5hk == -7.5hk);
   assert(-2.5hk * 0 == 0);
  
   // Division
   const short _Accum s_accum3 = 2.5hk;
   short _Accum s_accum_div = s_accum3 / s_accum2;
   assert(s_accum_div == 1.25hk);
   assert(5.0hk / s_accum3 == 2);
   assert(-5.0hk / s_accum3 == -2);
   assert(9.9k / 3.3k == 3);
   assert(9.9hk / 3.3k != 3);  // We lose precision when converting between types of different
                               // fractional width.
   assert(6.75hk / 2.25k == 3);  // Unless the fractional part can be evenly represented with
                                 // sums of powers of 2.
   assert(0 / 2.0hk == 0);

`%` is not a valod operation on fixed point types.

This is the parent of https://reviews.llvm.org/D46917


Repository:
  rC Clang

https://reviews.llvm.org/D46925

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/OperationKinds.def
  include/clang/AST/Type.h
  lib/AST/ASTContext.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Edit/RewriteObjCFoundationAPI.cpp
  lib/Sema/SemaExpr.cpp
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Frontend/fixed_point_validation.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46925.146984.patch
Type: text/x-patch
Size: 32639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180516/663933af/attachment-0001.bin>


More information about the cfe-commits mailing list