| 1 | // | 
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo | 
|---|
| 3 | // | 
|---|
| 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
| 5 | // file "LICENCE" distributed with Cforall. | 
|---|
| 6 | // | 
|---|
| 7 | // align.h -- | 
|---|
| 8 | // | 
|---|
| 9 | // Author           : Thierry Delisle | 
|---|
| 10 | // Created On       : Mon Feb 12 18:06:59 2018 | 
|---|
| 11 | // Last Modified By : | 
|---|
| 12 | // Last Modified On : | 
|---|
| 13 | // Update Count     : 0 | 
|---|
| 14 | // | 
|---|
| 15 | // This  library is free  software; you  can redistribute  it and/or  modify it | 
|---|
| 16 | // under the terms of the GNU Lesser General Public License as published by the | 
|---|
| 17 | // Free Software  Foundation; either  version 2.1 of  the License, or  (at your | 
|---|
| 18 | // option) any later version. | 
|---|
| 19 | // | 
|---|
| 20 | // This library is distributed in the  hope that it will be useful, but WITHOUT | 
|---|
| 21 | // ANY  WARRANTY;  without even  the  implied  warranty  of MERCHANTABILITY  or | 
|---|
| 22 | // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License | 
|---|
| 23 | // for more details. | 
|---|
| 24 | // | 
|---|
| 25 | // You should  have received a  copy of the  GNU Lesser General  Public License | 
|---|
| 26 | // along  with this library. | 
|---|
| 27 | // | 
|---|
| 28 |  | 
|---|
| 29 | #pragma once | 
|---|
| 30 |  | 
|---|
| 31 | extern "C" { | 
|---|
| 32 | #include <time.h> | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | #include "bits/defs.h" | 
|---|
| 36 |  | 
|---|
| 37 | struct timespec; | 
|---|
| 38 | struct itimerval; | 
|---|
| 39 |  | 
|---|
| 40 | //============================================================================================= | 
|---|
| 41 | // time type | 
|---|
| 42 | //============================================================================================= | 
|---|
| 43 |  | 
|---|
| 44 | struct __cfa_time_t { | 
|---|
| 45 | uint64_t val; | 
|---|
| 46 | }; | 
|---|
| 47 |  | 
|---|
| 48 | // ctors | 
|---|
| 49 | static inline void ?{}( __cfa_time_t & this ) { this.val = 0; } | 
|---|
| 50 | static inline void ?{}( __cfa_time_t & this, const __cfa_time_t & rhs ) { this.val = rhs.val; } | 
|---|
| 51 | static inline void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; } | 
|---|
| 52 |  | 
|---|
| 53 | static inline __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) { | 
|---|
| 54 | this.val = 0; | 
|---|
| 55 | return this; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | // logical ops | 
|---|
| 59 | static inline bool ?==?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val == rhs.val; } | 
|---|
| 60 | static inline bool ?!=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val != rhs.val; } | 
|---|
| 61 | static inline bool ?>? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >  rhs.val; } | 
|---|
| 62 | static inline bool ?<? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <  rhs.val; } | 
|---|
| 63 | static inline bool ?>=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >= rhs.val; } | 
|---|
| 64 | static inline bool ?<=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <= rhs.val; } | 
|---|
| 65 |  | 
|---|
| 66 | static inline bool ?==?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val == rhs; } | 
|---|
| 67 | static inline bool ?!=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val != rhs; } | 
|---|
| 68 | static inline bool ?>? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >  rhs; } | 
|---|
| 69 | static inline bool ?<? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <  rhs; } | 
|---|
| 70 | static inline bool ?>=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >= rhs; } | 
|---|
| 71 | static inline bool ?<=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <= rhs; } | 
|---|
| 72 |  | 
|---|
| 73 | // addition/substract | 
|---|
| 74 | static inline __cfa_time_t ?+?( __cfa_time_t lhs, __cfa_time_t rhs ) { | 
|---|
| 75 | __cfa_time_t ret; | 
|---|
| 76 | ret.val = lhs.val + rhs.val; | 
|---|
| 77 | return ret; | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | static inline __cfa_time_t ?-?( __cfa_time_t lhs, __cfa_time_t rhs ) { | 
|---|
| 81 | __cfa_time_t ret; | 
|---|
| 82 | ret.val = lhs.val - rhs.val; | 
|---|
| 83 | return ret; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | static inline __cfa_time_t ?`cfa_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; } | 
|---|
| 87 | static inline __cfa_time_t ?`cfa_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; } | 
|---|
| 88 | static inline __cfa_time_t ?`cfa_us( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; } | 
|---|
| 89 | static inline __cfa_time_t ?`cfa_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; } | 
|---|
| 90 |  | 
|---|
| 91 | static inline __cfa_time_t from_s  ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; } | 
|---|
| 92 | static inline __cfa_time_t from_ms ( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; } | 
|---|
| 93 | static inline __cfa_time_t from_us ( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; } | 
|---|
| 94 | static inline __cfa_time_t from_ns ( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; } | 
|---|
| 95 |  | 
|---|
| 96 | static inline uint64_t to_s  ( __cfa_time_t t ) { return t.val / 1_000_000_000ul; } | 
|---|
| 97 | static inline uint64_t to_ms ( __cfa_time_t t ) { return t.val /     1_000_000ul; } | 
|---|
| 98 | static inline uint64_t to_us ( __cfa_time_t t ) { return t.val /         1_000ul; } | 
|---|
| 99 | static inline uint64_t to_ns ( __cfa_time_t t ) { return t.val /             1ul; } | 
|---|