deprecated cow_size_unsafe() and Cow::size_unsafe() as cow_size() and Cow::size() somehow showed better codegen regardless of LTO

cpp
Avril 4 years ago
parent 0c5865e00f
commit 2aaa4247f5
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -24,14 +24,19 @@ cow_t* cow_clone(const cow_t* cow);
int cow_is_fake(const cow_t* cow);
/// Get the size of this cow area.
size_t cow_size(const cow_t* cow);
/// Get the size of this cow area by assuming layout. This should work assuming "cow_t.h"'s build assertions didn't fail and avoids an extra call.
/// XXX: Deprecated function unpon seeing preferable codegen for using `cow_size()` over this. Use `cow_size()` instead.
static inline
#ifdef _COW_NO_ASSUME_ABI
#define cow_size_unsafe(v) cow_size(v)
#define _cow_size_unsafe(v) cow_size(v)
#else
// XXX: This macro is *VERY* ABI sensitive. This shouldn't be used if the ABI has changed since the build of libcow's `cow_t.h` passed its static assertions in *both* the C and C++ implementations.
// The C++ API uses this by default for its `Cow::size()` function.
#define cow_size_unsafe(v) *(((size_t*)(v))+1)
#define _cow_size_unsafe(v) (*(((size_t*)(v))+1))
__attribute__((deprecated))
#endif
size_t cow_size_unsafe(const cow_t* v) { return _cow_size_unsafe(v); }
/// Get the `void*` pointer to the start of the area.
#define cow_ptr(v) (*((void**)(v)))

@ -27,7 +27,9 @@ struct Cow {
///
/// Note: This behaviour can be diabled by building with `-DCOW_NO_ASSUME_ABI`. In this case, this function calls out to the C API to determine the size.
/// There is also likely no benefit using this over `size()` in LTO enabled builds.
inline size_t size_unsafe() const { return cow_size_unsafe(get_raw()); }
///
/// XXX: Deprecated function for now. It seems `size()` offers better codegen on LTO and non-LTO enabled builds.
[[deprecated]] inline size_t size_unsafe() const { return _cow_size_unsafe(get_raw()); }
inline unsigned char* as_bytes() { return (unsigned char*)area(); }
inline const unsigned char* as_bytes() const { return (const unsigned char*)area(); }

@ -6,11 +6,13 @@ int main()
{
Cow real(4096);
printf("Fast size: %lu, slow size: %lu\n", real.size_unsafe(), real.size());
Cow::Fake clone = real;
{
Cow::Fake clone2 = clone;
}
if(0) cow_size_unsafe(NULL);
return 0;
}

Binary file not shown.
Loading…
Cancel
Save