PostgreSQL Source Code  git master
d2s_intrinsics.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static uint64 umul128 (const uint64 a, const uint64 b, uint64 *const productHi)
 
static uint64 shiftright128 (const uint64 lo, const uint64 hi, const uint32 dist)
 
static uint64 div5 (const uint64 x)
 
static uint64 div10 (const uint64 x)
 
static uint64 div100 (const uint64 x)
 
static uint64 div1e8 (const uint64 x)
 

Function Documentation

◆ div10()

static uint64 div10 ( const uint64  x)
inlinestatic

Definition at line 183 of file d2s_intrinsics.h.

Referenced by d2d(), shiftright128(), and to_chars().

184 {
185  return x / 10;
186 }

◆ div100()

static uint64 div100 ( const uint64  x)
inlinestatic

Definition at line 189 of file d2s_intrinsics.h.

Referenced by d2d(), and shiftright128().

190 {
191  return x / 100;
192 }

◆ div1e8()

static uint64 div1e8 ( const uint64  x)
inlinestatic

Definition at line 195 of file d2s_intrinsics.h.

Referenced by shiftright128(), to_chars(), and to_chars_df().

196 {
197  return x / 100000000;
198 }

◆ div5()

static uint64 div5 ( const uint64  x)
inlinestatic

Definition at line 177 of file d2s_intrinsics.h.

Referenced by d2d(), pow5Factor(), and shiftright128().

178 {
179  return x / 5;
180 }

◆ shiftright128()

static uint64 shiftright128 ( const uint64  lo,
const uint64  hi,
const uint32  dist 
)
inlinestatic

Definition at line 100 of file d2s_intrinsics.h.

References Assert, div10(), div100(), div1e8(), div5(), and umul128().

Referenced by mulShiftAll(), and multipleOfPowerOf2().

101 {
102  /* We don't need to handle the case dist >= 64 here (see above). */
103  Assert(dist < 64);
104 #if !defined(RYU_32_BIT_PLATFORM)
105  Assert(dist > 0);
106  return (hi << (64 - dist)) | (lo >> dist);
107 #else
108  /* Avoid a 64-bit shift by taking advantage of the range of shift values. */
109  Assert(dist >= 32);
110  return (hi << (64 - dist)) | ((uint32) (lo >> 32) >> (dist - 32));
111 #endif
112 }
unsigned int uint32
Definition: c.h:367
#define Assert(condition)
Definition: c.h:738

◆ umul128()

static uint64 umul128 ( const uint64  a,
const uint64  b,
uint64 *const  productHi 
)
inlinestatic

Definition at line 65 of file d2s_intrinsics.h.

Referenced by mulShiftAll(), multipleOfPowerOf2(), and shiftright128().

66 {
67  /*
68  * The casts here help MSVC to avoid calls to the __allmul library
69  * function.
70  */
71  const uint32 aLo = (uint32) a;
72  const uint32 aHi = (uint32) (a >> 32);
73  const uint32 bLo = (uint32) b;
74  const uint32 bHi = (uint32) (b >> 32);
75 
76  const uint64 b00 = (uint64) aLo * bLo;
77  const uint64 b01 = (uint64) aLo * bHi;
78  const uint64 b10 = (uint64) aHi * bLo;
79  const uint64 b11 = (uint64) aHi * bHi;
80 
81  const uint32 b00Lo = (uint32) b00;
82  const uint32 b00Hi = (uint32) (b00 >> 32);
83 
84  const uint64 mid1 = b10 + b00Hi;
85  const uint32 mid1Lo = (uint32) (mid1);
86  const uint32 mid1Hi = (uint32) (mid1 >> 32);
87 
88  const uint64 mid2 = b01 + mid1Lo;
89  const uint32 mid2Lo = (uint32) (mid2);
90  const uint32 mid2Hi = (uint32) (mid2 >> 32);
91 
92  const uint64 pHi = b11 + mid1Hi + mid2Hi;
93  const uint64 pLo = ((uint64) mid2Lo << 32) + b00Lo;
94 
95  *productHi = pHi;
96  return pLo;
97 }
unsigned int uint32
Definition: c.h:367