LCOV - code coverage report
Current view: top level - gfx/skia/skia/src/jumper - SkJumper_misc.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 12 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2017 Google Inc.
       3             :  *
       4             :  * Use of this source code is governed by a BSD-style license that can be
       5             :  * found in the LICENSE file.
       6             :  */
       7             : 
       8             : #ifndef SkJumper_misc_DEFINED
       9             : #define SkJumper_misc_DEFINED
      10             : 
      11             : #include "SkJumper.h"  // for memcpy()
      12             : 
      13             : // Miscellany used by SkJumper_stages.cpp and SkJumper_vectors.h.
      14             : 
      15             : // Every function in this file should be marked static and inline using SI.
      16             : #define SI static inline
      17             : 
      18             : template <typename T, typename P>
      19           0 : SI T unaligned_load(const P* p) {  // const void* would work too, but const P* helps ARMv7 codegen.
      20             :     T v;
      21           0 :     memcpy(&v, p, sizeof(v));
      22           0 :     return v;
      23             : }
      24             : 
      25             : template <typename Dst, typename Src>
      26           0 : SI Dst bit_cast(const Src& src) {
      27             :     static_assert(sizeof(Dst) == sizeof(Src), "");
      28           0 :     return unaligned_load<Dst>(&src);
      29             : }
      30             : 
      31             : template <typename Dst, typename Src>
      32             : SI Dst widen_cast(const Src& src) {
      33             :     static_assert(sizeof(Dst) > sizeof(Src), "");
      34             :     Dst dst;
      35             :     memcpy(&dst, &src, sizeof(Src));
      36             :     return dst;
      37             : }
      38             : 
      39             : // A couple functions for embedding constants directly into code,
      40             : // so that no .const or .literal4 section is created.
      41           0 : SI int C(int x) {
      42             : #if defined(JUMPER) && defined(__x86_64__)
      43             :     // Move x-the-compile-time-constant as a literal into x-the-register.
      44             :     asm("mov %1, %0" : "=r"(x) : "i"(x));
      45             : #endif
      46           0 :     return x;
      47             : }
      48           0 : SI float C(float f) {
      49           0 :     int x = C(unaligned_load<int>(&f));
      50           0 :     return unaligned_load<float>(&x);
      51             : }
      52             : 
      53             : // Syntax sugar to make C() easy to use for constant literals.
      54           0 : SI int   operator "" _i(unsigned long long int i) { return C(  (int)i); }
      55           0 : SI float operator "" _f(           long double f) { return C((float)f); }
      56             : 
      57             : #endif//SkJumper_misc_DEFINED

Generated by: LCOV version 1.13