mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 08:48:29 +00:00
Fix printvideo regression and minor improvements
This commit is contained in:
parent
eb4bb43275
commit
e86cff8ba0
25 changed files with 240 additions and 207 deletions
154
libc/bits/bits.h
154
libc/bits/bits.h
|
@ -50,78 +50,104 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
|
|||
((uint16_t)kReverseBits[(X)&0xff] << 010 | \
|
||||
kReverseBits[((uint16_t)(X) >> 010) & 0xff])
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define READ16LE(P) ((unsigned)(P)[1] << 010 | (unsigned)(P)[0])
|
||||
#define READ32LE(P) \
|
||||
((unsigned long)(P)[3] << 030 | (unsigned long)(P)[2] << 020 | \
|
||||
(unsigned long)(P)[1] << 010 | (unsigned long)(P)[0])
|
||||
#define READ64LE(P) \
|
||||
((unsigned long long)(P)[3] << 030 | (unsigned long)(P)[2] << 020 | \
|
||||
(unsigned long long)(P)[1] << 010 | (unsigned long)(P)[0])
|
||||
#else
|
||||
#define READ16LE(P) read16le(P)
|
||||
#define READ32LE(P) read32le(P)
|
||||
#define READ64LE(P) read64le(P)
|
||||
#define read16le(P) \
|
||||
({ \
|
||||
const unsigned char *Pu = (const unsigned char *)(P); \
|
||||
(uint16_t) Pu[1] << 010 | (uint16_t)Pu[0]; \
|
||||
#define READ16LE(S) \
|
||||
((uint16_t)((unsigned char *)(S))[1] << 010 | \
|
||||
(uint16_t)((unsigned char *)(S))[0] << 000)
|
||||
#define READ32LE(S) \
|
||||
((uint32_t)((unsigned char *)(S))[3] << 030 | \
|
||||
(uint32_t)((unsigned char *)(S))[2] << 020 | \
|
||||
(uint32_t)((unsigned char *)(S))[1] << 010 | \
|
||||
(uint32_t)((unsigned char *)(S))[0] << 000)
|
||||
#define READ64LE(S) \
|
||||
((uint64_t)((unsigned char *)(S))[7] << 070 | \
|
||||
(uint64_t)((unsigned char *)(S))[6] << 060 | \
|
||||
(uint64_t)((unsigned char *)(S))[5] << 050 | \
|
||||
(uint64_t)((unsigned char *)(S))[4] << 040 | \
|
||||
(uint64_t)((unsigned char *)(S))[3] << 030 | \
|
||||
(uint64_t)((unsigned char *)(S))[2] << 020 | \
|
||||
(uint64_t)((unsigned char *)(S))[1] << 010 | \
|
||||
(uint64_t)((unsigned char *)(S))[0] << 000)
|
||||
|
||||
#define READ16BE(S) \
|
||||
((uint16_t)((unsigned char *)(S))[0] << 010 | \
|
||||
(uint16_t)((unsigned char *)(S))[1] << 000)
|
||||
#define READ32BE(S) \
|
||||
((uint32_t)((unsigned char *)(S))[0] << 030 | \
|
||||
(uint32_t)((unsigned char *)(S))[1] << 020 | \
|
||||
(uint32_t)((unsigned char *)(S))[2] << 010 | \
|
||||
(uint32_t)((unsigned char *)(S))[3] << 000)
|
||||
#define READ64BE(S) \
|
||||
((uint64_t)((unsigned char *)(S))[0] << 070 | \
|
||||
(uint64_t)((unsigned char *)(S))[1] << 060 | \
|
||||
(uint64_t)((unsigned char *)(S))[2] << 050 | \
|
||||
(uint64_t)((unsigned char *)(S))[3] << 040 | \
|
||||
(uint64_t)((unsigned char *)(S))[4] << 030 | \
|
||||
(uint64_t)((unsigned char *)(S))[5] << 020 | \
|
||||
(uint64_t)((unsigned char *)(S))[6] << 010 | \
|
||||
(uint64_t)((unsigned char *)(S))[7] << 000)
|
||||
|
||||
#define read16le(S) \
|
||||
({ \
|
||||
unsigned char *Str = (unsigned char *)(S); \
|
||||
READ16LE(Str); \
|
||||
})
|
||||
#define read32le(P) \
|
||||
({ \
|
||||
const unsigned char *Pu = (const unsigned char *)(P); \
|
||||
((uint32_t)Pu[3] << 030 | (uint32_t)Pu[2] << 020 | \
|
||||
(uint32_t)Pu[1] << 010 | (uint32_t)Pu[0] << 000); \
|
||||
#define read32le(S) \
|
||||
({ \
|
||||
unsigned char *Str = (unsigned char *)(S); \
|
||||
READ32LE(Str); \
|
||||
})
|
||||
#define read64le(P) \
|
||||
({ \
|
||||
const unsigned char *Pu = (const unsigned char *)(P); \
|
||||
((uint64_t)Pu[7] << 070 | (uint64_t)Pu[6] << 060 | \
|
||||
(uint64_t)Pu[5] << 050 | (uint64_t)Pu[4] << 040 | \
|
||||
(uint64_t)Pu[3] << 030 | (uint64_t)Pu[2] << 020 | \
|
||||
(uint64_t)Pu[1] << 010 | (uint64_t)Pu[0] << 000); \
|
||||
#define read64le(S) \
|
||||
({ \
|
||||
unsigned char *Str = (unsigned char *)(S); \
|
||||
READ64LE(Str); \
|
||||
})
|
||||
#endif
|
||||
|
||||
#define WRITE16LE(P, V) \
|
||||
do { \
|
||||
uint8_t *Ple = (unsigned char *)(P); \
|
||||
uint16_t Vle = (V); \
|
||||
Ple[0] = (uint8_t)(Vle >> 000); \
|
||||
Ple[1] = (uint8_t)(Vle >> 010); \
|
||||
#define read16be(S) \
|
||||
({ \
|
||||
unsigned char *Str = (unsigned char *)(S); \
|
||||
READ16BE(Str); \
|
||||
})
|
||||
#define read32be(S) \
|
||||
({ \
|
||||
unsigned char *Str = (unsigned char *)(S); \
|
||||
READ32BE(Str); \
|
||||
})
|
||||
#define read64be(S) \
|
||||
({ \
|
||||
unsigned char *Str = (unsigned char *)(S); \
|
||||
READ64BE(Str); \
|
||||
})
|
||||
|
||||
#define WRITE16LE(P, V) \
|
||||
do { \
|
||||
uint8_t *Ple = (uint8_t *)(P); \
|
||||
uint16_t Vle = (V); \
|
||||
Ple[0] = (uint8_t)(Vle >> 000); \
|
||||
Ple[1] = (uint8_t)(Vle >> 010); \
|
||||
} while (0)
|
||||
|
||||
#define WRITE32LE(P, V) \
|
||||
do { \
|
||||
uint8_t *Ple = (unsigned char *)(P); \
|
||||
uint32_t Vle = (V); \
|
||||
Ple[0] = (uint8_t)(Vle >> 000); \
|
||||
Ple[1] = (uint8_t)(Vle >> 010); \
|
||||
Ple[2] = (uint8_t)(Vle >> 020); \
|
||||
Ple[3] = (uint8_t)(Vle >> 030); \
|
||||
#define WRITE32LE(P, V) \
|
||||
do { \
|
||||
uint8_t *Ple = (uint8_t *)(P); \
|
||||
uint32_t Vle = (V); \
|
||||
Ple[0] = (uint8_t)(Vle >> 000); \
|
||||
Ple[1] = (uint8_t)(Vle >> 010); \
|
||||
Ple[2] = (uint8_t)(Vle >> 020); \
|
||||
Ple[3] = (uint8_t)(Vle >> 030); \
|
||||
} while (0)
|
||||
|
||||
#define WRITE64LE(P, V) \
|
||||
do { \
|
||||
uint8_t *Ple = (unsigned char *)(P); \
|
||||
uint64_t Vle = (V); \
|
||||
Ple[0] = (uint8_t)(Vle >> 000); \
|
||||
Ple[1] = (uint8_t)(Vle >> 010); \
|
||||
Ple[2] = (uint8_t)(Vle >> 020); \
|
||||
Ple[3] = (uint8_t)(Vle >> 030); \
|
||||
Ple[4] = (uint8_t)(Vle >> 040); \
|
||||
Ple[5] = (uint8_t)(Vle >> 050); \
|
||||
Ple[6] = (uint8_t)(Vle >> 060); \
|
||||
Ple[7] = (uint8_t)(Vle >> 070); \
|
||||
#define WRITE64LE(P, V) \
|
||||
do { \
|
||||
uint8_t *Ple = (uint8_t *)(P); \
|
||||
uint64_t Vle = (V); \
|
||||
Ple[0] = (uint8_t)(Vle >> 000); \
|
||||
Ple[1] = (uint8_t)(Vle >> 010); \
|
||||
Ple[2] = (uint8_t)(Vle >> 020); \
|
||||
Ple[3] = (uint8_t)(Vle >> 030); \
|
||||
Ple[4] = (uint8_t)(Vle >> 040); \
|
||||
Ple[5] = (uint8_t)(Vle >> 050); \
|
||||
Ple[6] = (uint8_t)(Vle >> 060); \
|
||||
Ple[7] = (uint8_t)(Vle >> 070); \
|
||||
} while (0)
|
||||
|
||||
/* TODO(jart): these ones aren't coded correctly */
|
||||
#define read128le(P) ((uint128_t)read64le((P) + 8) << 0100 | read64le(P))
|
||||
#define read16be(P) ((uint16_t)(*(P) << 010) | (uint16_t)(*((P) + 1)))
|
||||
#define read32be(P) ((uint32_t)read16be(P) << 020 | (uint32_t)read16be((P) + 2))
|
||||
#define read64be(P) ((uint64_t)read32be(P) << 040 | read32be((P) + 4))
|
||||
#define read128be(P) ((uint128_t)read64be(P) << 0100 | read64be((P) + 8))
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § bits » some assembly required ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
|
|
@ -148,7 +148,7 @@ float atanf(float);
|
|||
float atanhf(float);
|
||||
float cbrtf(float);
|
||||
float ceilf(float);
|
||||
float copysignf(float, float y);
|
||||
float copysignf(float, float);
|
||||
float cosf(float);
|
||||
float coshf(float);
|
||||
float dremf(float, float);
|
||||
|
|
|
@ -38,7 +38,7 @@ memrchr:.leafprologue
|
|||
jz 5f
|
||||
vmovd %esi,%xmm0
|
||||
vpbroadcastb %xmm0,%ymm0
|
||||
3: vmovups -32(%rdi,%rdx),%ymm1
|
||||
3: vmovdqu -32(%rdi,%rdx),%ymm1
|
||||
vpcmpeqb %ymm1,%ymm0,%ymm1
|
||||
vpmovmskb %ymm1,%eax
|
||||
lzcnt %eax,%eax
|
||||
|
|
|
@ -38,7 +38,7 @@ memrchr16:
|
|||
jz 5f
|
||||
vmovd %esi,%xmm0
|
||||
vpbroadcastw %xmm0,%ymm0
|
||||
3: vmovups -32(%rdi,%rdx,2),%ymm1
|
||||
3: vmovdqu -32(%rdi,%rdx,2),%ymm1
|
||||
vpcmpeqw %ymm1,%ymm0,%ymm1
|
||||
vpmovmskb %ymm1,%eax
|
||||
lzcnt %eax,%eax
|
||||
|
|
|
@ -38,7 +38,7 @@ wmemrchr:
|
|||
jz 5f
|
||||
vmovd %esi,%xmm0
|
||||
vpbroadcastd %xmm0,%ymm0
|
||||
3: vmovups -32(%rdi,%rdx,4),%ymm1
|
||||
3: vmovdqu -32(%rdi,%rdx,4),%ymm1
|
||||
vpcmpeqd %ymm1,%ymm0,%ymm1
|
||||
vpmovmskb %ymm1,%eax
|
||||
lzcnt %eax,%eax
|
||||
|
|
|
@ -7,9 +7,9 @@ COSMOPOLITAN_C_START_
|
|||
│ cosmopolitan § characters » unicode ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
extern const uint64_t kEastAsianWidth[];
|
||||
extern const uint8_t kEastAsianWidth[];
|
||||
extern const uint32_t kEastAsianWidthBits;
|
||||
extern const uint64_t kCombiningChars[];
|
||||
extern const uint8_t kCombiningChars[];
|
||||
extern const uint32_t kCombiningCharsBits;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/unicode/unicode.h"
|
||||
|
||||
/**
|
||||
|
@ -28,10 +27,10 @@ int wcwidth(wchar_t ucs) {
|
|||
if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) {
|
||||
return -1;
|
||||
} else if (0 <= ucs && ucs < kCombiningCharsBits &&
|
||||
bt(kCombiningChars, ucs)) {
|
||||
!!(kCombiningChars[ucs >> 3] & (1 << (ucs & 7)))) {
|
||||
return 0;
|
||||
} else if (0 <= ucs && ucs < kEastAsianWidthBits) {
|
||||
return 1 + bt(kEastAsianWidth, ucs);
|
||||
return 1 + !!(kEastAsianWidth[ucs >> 3] & (1 << (ucs & 7)));
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue