From 8f110572ad41de65484323346325640fe40cb745 Mon Sep 17 00:00:00 2001 From: David Michael Barr Date: Tue, 6 Sep 2016 11:41:07 +0900 Subject: [PATCH] Use stable sort with PVQ. Cherry-pick Daala 85433214 Fully order the pvq search candidates For portable and stable sorting, break ties. Large differences in output were observed between AWCY and an OS X machine because of the platform qsort implementation. Change-Id: I294dd2e167c1e0464c7f61f32d60ab478341446e --- av1/encoder/pvq_encoder.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/av1/encoder/pvq_encoder.c b/av1/encoder/pvq_encoder.c index b72e7bacb..284b807c1 100644 --- a/av1/encoder/pvq_encoder.c +++ b/av1/encoder/pvq_encoder.c @@ -286,7 +286,9 @@ typedef struct { } pvq_search_item; int items_compare(pvq_search_item *a, pvq_search_item *b) { - return a->k - b->k; + /* Break ties in K with gain to ensure a stable sort. + Otherwise, the order depends on qsort implementation. */ + return a->k == b->k ? a->gain - b->gain : a->k - b->k; } /** Perform PVQ quantization with prediction, trying several -- GitLab