std/jpeg: re-format generated IDCT code

This commit is contained in:
Nigel Tao committed 2023-06-28 13:49:55 +10:00
1 parent 97c4e85e0e
commit dd29401137
2 files changed
+329 -450

No files matched your search

+49 -58
View File
@@ -38,31 +38,31 @@ func main1() error {
fmt.Printf("// -------- BEGIN generated by script/print-jpeg-idct-code.go\n")
fmt.Println()
fmt.Printf("// p0_298631336 = 0x%04X = %5d\n", round(p0_298631336), round(p0_298631336))
fmt.Printf("// p0_390180644 = 0x%04X = %5d\n", round(p0_390180644), round(p0_390180644))
fmt.Printf("// p0_509795579 = 0x%04X = %5d\n", round(p0_509795579), round(p0_509795579))
fmt.Printf("// p0_541196100 = 0x%04X = %5d\n", round(p0_541196100), round(p0_541196100))
fmt.Printf("// p0_601344887 = 0x%04X = %5d\n", round(p0_601344887), round(p0_601344887))
fmt.Printf("// p0_765366865 = 0x%04X = %5d\n", round(p0_765366865), round(p0_765366865))
fmt.Printf("// p0_785694958 = 0x%04X = %5d\n", round(p0_785694958), round(p0_785694958))
fmt.Printf("// p0_899976223 = 0x%04X = %5d\n", round(p0_899976223), round(p0_899976223))
fmt.Printf("// p1_175875602 = 0x%04X = %5d\n", round(p1_175875602), round(p1_175875602))
fmt.Printf("// p1_306562965 = 0x%04X = %5d\n", round(p1_306562965), round(p1_306562965))
fmt.Printf("// p1_501321110 = 0x%04X = %5d\n", round(p1_501321110), round(p1_501321110))
fmt.Printf("// p1_847759065 = 0x%04X = %5d\n", round(p1_847759065), round(p1_847759065))
fmt.Printf("// p1_961570560 = 0x%04X = %5d\n", round(p1_961570560), round(p1_961570560))
fmt.Printf("// p2_053119869 = 0x%04X = %5d\n", round(p2_053119869), round(p2_053119869))
fmt.Printf("// p2_562915447 = 0x%04X = %5d\n", round(p2_562915447), round(p2_562915447))
fmt.Printf("// p3_072711026 = 0x%04X = %5d\n", round(p3_072711026), round(p3_072711026))
fmt.Printf("// p0_298631336 = %s = %10d\n", format8X(p0_298631336), round(p0_298631336))
fmt.Printf("// p0_390180644 = %s = %10d\n", format8X(p0_390180644), round(p0_390180644))
fmt.Printf("// p0_509795579 = %s = %10d\n", format8X(p0_509795579), round(p0_509795579))
fmt.Printf("// p0_541196100 = %s = %10d\n", format8X(p0_541196100), round(p0_541196100))
fmt.Printf("// p0_601344887 = %s = %10d\n", format8X(p0_601344887), round(p0_601344887))
fmt.Printf("// p0_765366865 = %s = %10d\n", format8X(p0_765366865), round(p0_765366865))
fmt.Printf("// p0_785694958 = %s = %10d\n", format8X(p0_785694958), round(p0_785694958))
fmt.Printf("// p0_899976223 = %s = %10d\n", format8X(p0_899976223), round(p0_899976223))
fmt.Printf("// p1_175875602 = %s = %10d\n", format8X(p1_175875602), round(p1_175875602))
fmt.Printf("// p1_306562965 = %s = %10d\n", format8X(p1_306562965), round(p1_306562965))
fmt.Printf("// p1_501321110 = %s = %10d\n", format8X(p1_501321110), round(p1_501321110))
fmt.Printf("// p1_847759065 = %s = %10d\n", format8X(p1_847759065), round(p1_847759065))
fmt.Printf("// p1_961570560 = %s = %10d\n", format8X(p1_961570560), round(p1_961570560))
fmt.Printf("// p2_053119869 = %s = %10d\n", format8X(p2_053119869), round(p2_053119869))
fmt.Printf("// p2_562915447 = %s = %10d\n", format8X(p2_562915447), round(p2_562915447))
fmt.Printf("// p3_072711026 = %s = %10d\n", format8X(p3_072711026), round(p3_072711026))
fmt.Printf("//\n")
fmt.Printf("// m0_390180644 = 0x%08X = %10d\n", round(m0_390180644), round(m0_390180644))
fmt.Printf("// m0_509795579 = 0x%08X = %10d\n", round(m0_509795579), round(m0_509795579))
fmt.Printf("// m0_601344887 = 0x%08X = %10d\n", round(m0_601344887), round(m0_601344887))
fmt.Printf("// m0_785694958 = 0x%08X = %10d\n", round(m0_785694958), round(m0_785694958))
fmt.Printf("// m0_899976223 = 0x%08X = %10d\n", round(m0_899976223), round(m0_899976223))
fmt.Printf("// m1_306562965 = 0x%08X = %10d\n", round(m1_306562965), round(m1_306562965))
fmt.Printf("// m1_961570560 = 0x%08X = %10d\n", round(m1_961570560), round(m1_961570560))
fmt.Printf("// m2_562915447 = 0x%08X = %10d\n", round(m2_562915447), round(m2_562915447))
fmt.Printf("// m0_390180644 = %s = %10d\n", format8X(m0_390180644), round(m0_390180644))
fmt.Printf("// m0_509795579 = %s = %10d\n", format8X(m0_509795579), round(m0_509795579))
fmt.Printf("// m0_601344887 = %s = %10d\n", format8X(m0_601344887), round(m0_601344887))
fmt.Printf("// m0_785694958 = %s = %10d\n", format8X(m0_785694958), round(m0_785694958))
fmt.Printf("// m0_899976223 = %s = %10d\n", format8X(m0_899976223), round(m0_899976223))
fmt.Printf("// m1_306562965 = %s = %10d\n", format8X(m1_306562965), round(m1_306562965))
fmt.Printf("// m1_961570560 = %s = %10d\n", format8X(m1_961570560), round(m1_961570560))
fmt.Printf("// m2_562915447 = %s = %10d\n", format8X(m2_562915447), round(m2_562915447))
fmt.Println()
for x := 0; x < 8; x++ {
@@ -109,31 +109,36 @@ func replace(s string, m map[string]string) string {
}
func addConsts(m map[string]string) map[string]string {
m["$p0_298631336$"] = fmt.Sprintf("0x%04X", round(p0_298631336))
m["$p0_509795579$"] = fmt.Sprintf("0x%04X", round(p0_509795579))
m["$p0_541196100$"] = fmt.Sprintf("0x%04X", round(p0_541196100))
m["$p0_601344887$"] = fmt.Sprintf("0x%04X", round(p0_601344887))
m["$p0_765366865$"] = fmt.Sprintf("0x%04X", round(p0_765366865))
m["$p0_785694958$"] = fmt.Sprintf("0x%04X", round(p0_785694958))
m["$p1_175875602$"] = fmt.Sprintf("0x%04X", round(p1_175875602))
m["$p1_306562965$"] = fmt.Sprintf("0x%04X", round(p1_306562965))
m["$p1_501321110$"] = fmt.Sprintf("0x%04X", round(p1_501321110))
m["$p1_847759065$"] = fmt.Sprintf("0x%04X", round(p1_847759065))
m["$p2_053119869$"] = fmt.Sprintf("0x%04X", round(p2_053119869))
m["$p3_072711026$"] = fmt.Sprintf("0x%04X", round(p3_072711026))
m["$p0_298631336$"] = format8X(p0_298631336)
m["$p0_509795579$"] = format8X(p0_509795579)
m["$p0_541196100$"] = format8X(p0_541196100)
m["$p0_601344887$"] = format8X(p0_601344887)
m["$p0_765366865$"] = format8X(p0_765366865)
m["$p0_785694958$"] = format8X(p0_785694958)
m["$p1_175875602$"] = format8X(p1_175875602)
m["$p1_306562965$"] = format8X(p1_306562965)
m["$p1_501321110$"] = format8X(p1_501321110)
m["$p1_847759065$"] = format8X(p1_847759065)
m["$p2_053119869$"] = format8X(p2_053119869)
m["$p3_072711026$"] = format8X(p3_072711026)
m["$m0_390180644$"] = fmt.Sprintf("0x%08X", round(m0_390180644))
m["$m0_509795579$"] = fmt.Sprintf("0x%08X", round(m0_509795579))
m["$m0_601344887$"] = fmt.Sprintf("0x%08X", round(m0_601344887))
m["$m0_785694958$"] = fmt.Sprintf("0x%08X", round(m0_785694958))
m["$m0_899976223$"] = fmt.Sprintf("0x%08X", round(m0_899976223))
m["$m1_306562965$"] = fmt.Sprintf("0x%08X", round(m1_306562965))
m["$m1_961570560$"] = fmt.Sprintf("0x%08X", round(m1_961570560))
m["$m2_562915447$"] = fmt.Sprintf("0x%08X", round(m2_562915447))
m["$m0_390180644$"] = format8X(m0_390180644)
m["$m0_509795579$"] = format8X(m0_509795579)
m["$m0_601344887$"] = format8X(m0_601344887)
m["$m0_785694958$"] = format8X(m0_785694958)
m["$m0_899976223$"] = format8X(m0_899976223)
m["$m1_306562965$"] = format8X(m1_306562965)
m["$m1_961570560$"] = format8X(m1_961570560)
m["$m2_562915447$"] = format8X(m2_562915447)
return m
}
func format8X(x float64) string {
s := fmt.Sprintf("0x%08X", round(x))
return s[:6] + "_" + s[6:]
}
func round(x float64) uint32 {
// Hard-code some rounding errors to match libjpeg-turbo exactly.
//
@@ -257,10 +262,8 @@ bq6 = this.util.sign_extend_convert_u16_u32(a: this.mcu_blocks[0][$row6colX$]) ~
// This code...
ca = (bq2 ~mod+ bq6) ~mod* $p0_541196100$
cb2 = ca ~mod+ (bq2 ~mod* $p0_765366865$)
cb6 = ca ~mod- (bq6 ~mod* $p1_847759065$)
// ...is equivalent to this more-SIMD-like code.
//
// cb2 = (bq2 ~mod* $p1_306562965$) ~mod+ (bq6 ~mod* $p0_541196100$)
@@ -291,25 +294,20 @@ ci73 = bq7 ~mod+ bq3
// This code...
cj = (ci73 ~mod+ ci51) ~mod* $p1_175875602$
ck1 = bq1 ~mod* $p1_501321110$
ck3 = bq3 ~mod* $p3_072711026$
ck5 = bq5 ~mod* $p2_053119869$
ck7 = bq7 ~mod* $p0_298631336$
ci51 ~mod*= $m0_390180644$
ci53 ~mod*= $m2_562915447$
ci71 ~mod*= $m0_899976223$
ci73 ~mod*= $m1_961570560$
cl51 = ci51 ~mod+ cj
cl73 = ci73 ~mod+ cj
ck1 ~mod+= ci71 ~mod+ cl51
ck3 ~mod+= ci53 ~mod+ cl73
ck5 ~mod+= ci53 ~mod+ cl51
ck7 ~mod+= ci71 ~mod+ cl73
// ...is equivalent to this more-SIMD-like code.
//
// cl73 = (ci73 ~mod* $m0_785694958$) ~mod+ (ci51 ~mod* $p1_175875602$)
@@ -365,10 +363,8 @@ in6 = intermediate[$rowYcol6$]
// This code...
ra = (in2 ~mod+ in6) ~mod* $p0_541196100$
rb2 = ra ~mod+ (in2 ~mod* $p0_765366865$)
rb6 = ra ~mod- (in6 ~mod* $p1_847759065$)
// ...is equivalent to this more-SIMD-like code.
//
// rb2 = (in2 ~mod* $p1_306562965$) ~mod+ (in6 ~mod* $p0_541196100$)
@@ -399,25 +395,20 @@ ri73 = in7 ~mod+ in3
// This code...
rj = (ri73 ~mod+ ri51) ~mod* $p1_175875602$
rk1 = in1 ~mod* $p1_501321110$
rk3 = in3 ~mod* $p3_072711026$
rk5 = in5 ~mod* $p2_053119869$
rk7 = in7 ~mod* $p0_298631336$
ri51 ~mod*= $m0_390180644$
ri53 ~mod*= $m2_562915447$
ri71 ~mod*= $m0_899976223$
ri73 ~mod*= $m1_961570560$
rl51 = ri51 ~mod+ rj
rl73 = ri73 ~mod+ rj
rk1 ~mod+= ri71 ~mod+ rl51
rk3 ~mod+= ri53 ~mod+ rl73
rk5 ~mod+= ri53 ~mod+ rl51
rk7 ~mod+= ri71 ~mod+ rl73
// ...is equivalent to this more-SIMD-like code.
//
// rl73 = (ri73 ~mod* $m0_785694958$) ~mod+ (ri51 ~mod* $p1_175875602$)