Add 0b prefixed binary numbers

This commit is contained in:
Nigel Tao committed 2021-01-28 21:54:06 +11:00
1 parent 1a63b53e13
commit 8c4c714ad1
4 files changed
+21 -8

No files matched your search

+1
View File
@@ -3,6 +3,7 @@
## Work In Progress
- Added `0b` prefixed binary numbers.
- Added `WUFFS_BASE__PIXEL_BLEND__SRC_OVER`.
- Added `WUFFS_BASE__PIXEL_FORMAT__BGR_565`.
- Added `WUFFS_CONFIG__MODULE__BASE__ETC` sub-modules.
+10 -4
View File
@@ -250,10 +250,16 @@ func appendComment(buf []byte, comments []string, line uint32, indent int, other
func appendNum(buf []byte, s string) []byte {
groupLen := uint32(6)
if (len(s) >= 2) && (s[0] == '0') && ((s[1] == 'X') || (s[1] == 'x')) {
buf = append(buf, "0x"...)
s = s[2:]
groupLen = 4
if (len(s) >= 2) && (s[0] == '0') {
if (s[1] == 'X') || (s[1] == 'x') {
buf = append(buf, "0x"...)
s = s[2:]
groupLen = 4
} else if (s[1] == 'B') || (s[1] == 'b') {
buf = append(buf, "0b"...)
s = s[2:]
groupLen = 4
}
}
nonUnderscores := uint32(0)
+6
View File
@@ -210,6 +210,10 @@ func hexaNumericUnderscore(c byte) bool {
return ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f') || (c == '_') || ('0' <= c && c <= '9')
}
func zeroOneUnderscore(c byte) bool {
return (c == '_') || ('0' <= c && c <= '1')
}
func numeric(c byte) bool {
return ('0' <= c && c <= '9')
}
@@ -336,6 +340,8 @@ loop:
if c == '0' && j < len(src) {
if next := src[j]; next == 'x' || next == 'X' {
j, isDigit = j+1, hexaNumericUnderscore
} else if next == 'b' || next == 'B' {
j, isDigit = j+1, zeroOneUnderscore
} else if numeric(next) {
return nil, nil, fmt.Errorf("token: legacy octal syntax at %s:%d", filename, line)
}
+4 -4
View File
@@ -198,8 +198,8 @@ pri func hasher.up_sse42!(x: slice base.u8),
// - shuffling with 0b0100_1110 gives [x2+x3, x2+x3, x0+x1, x0+x1].
// - adding gives [x0+x1+x2+x3, ditto, ditto, ditto].
// The truncate_u32 call extracts the first u32: x0+x1+x2+x3.
v1 = v1._mm_add_epi32(b: v1._mm_shuffle_epi32(imm8: 0xB1)) // 0b1011_0001
v1 = v1._mm_add_epi32(b: v1._mm_shuffle_epi32(imm8: 0x4E)) // 0b0100_1110
v1 = v1._mm_add_epi32(b: v1._mm_shuffle_epi32(imm8: 0b1011_0001))
v1 = v1._mm_add_epi32(b: v1._mm_shuffle_epi32(imm8: 0b0100_1110))
s1 ~mod+= v1.truncate_u32()
// Combine v2j and v2k. The slli (shift logical left immediate) by 5
@@ -207,8 +207,8 @@ pri func hasher.up_sse42!(x: slice base.u8),
v2 = v2k._mm_add_epi32(b: v2j._mm_slli_epi32(imm8: 5))
// Similarly merge v2 (a 4×u32 vector) into s2 (a scalar u32 scalar).
v2 = v2._mm_add_epi32(b: v2._mm_shuffle_epi32(imm8: 0xB1)) // 0b1011_0001
v2 = v2._mm_add_epi32(b: v2._mm_shuffle_epi32(imm8: 0x4E)) // 0b0100_1110
v2 = v2._mm_add_epi32(b: v2._mm_shuffle_epi32(imm8: 0b1011_0001))
v2 = v2._mm_add_epi32(b: v2._mm_shuffle_epi32(imm8: 0b0100_1110))
s2 ~mod+= v2.truncate_u32()
// Handle the tail of args.x that wasn't a complete 32-byte chunk.