cosmopolitan/libc/intrin/segmentation.h
Justine Tunney fa20edc44d
Reduce header complexity
- Remove most __ASSEMBLER__ __LINKER__ ifdefs
- Rename libc/intrin/bits.h to libc/serialize.h
- Block pthread cancelation in fchmodat() polyfill
- Remove `clang-format off` statements in third_party
2023-11-28 14:39:42 -08:00

25 lines
818 B
C

#ifndef COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
#define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#ifdef _COSMO_SOURCE
/**
* Reads scalar from memory, offset by segment.
*
* @return *(MEM) relative to segment
* @see pushpop()
*/
#define fs(MEM) __peek("fs", MEM)
#define gs(MEM) __peek("gs", MEM)
#define __peek(SEGMENT, ADDRESS) \
({ \
typeof(*(ADDRESS)) Pk; \
asm("mov\t%%" SEGMENT ":%1,%0" : "=r"(Pk) : "m"(*(ADDRESS))); \
Pk; \
})
#endif /* _COSMO_SOURCE */
#endif /* __GNUC__ && !__STRICT_ANSI__ */
#endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */