From chandlerc at gmail.com Mon Jan 8 00:25:46 2007 From: chandlerc at gmail.com (Chandler Carruth) Date: Mon, 8 Jan 2007 00:25:46 -0600 Subject: [llvm-commits] CVS: llvm/tools/Makefile Message-ID: <200701080625.l086Pkdi013033@zion.cs.uiuc.edu> Changes in directory llvm/tools: Makefile updated: 1.60 -> 1.61 --- Log message: Build libLLVMlto on non-Darwin architectures. Resolves PR1055: http://llvm.org/PR1055 : http://llvm.org/PR1055: http://llvm.org/PR1055 --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/tools/Makefile diff -u llvm/tools/Makefile:1.60 llvm/tools/Makefile:1.61 --- llvm/tools/Makefile:1.60 Fri Dec 1 22:46:36 2006 +++ llvm/tools/Makefile Mon Jan 8 00:25:29 2007 @@ -22,8 +22,8 @@ include $(LEVEL)/Makefile.config -# Disable liblto on non-darwin platforms right now until LLVM is built PIC. -ifeq ($(OS), Darwin) +# Disable liblto on Windows until compatability is determined. +ifneq ($(OS), MingW) PARALLEL_DIRS += lto endif From chandlerc at gmail.com Mon Jan 8 00:25:45 2007 From: chandlerc at gmail.com (Chandler Carruth) Date: Mon, 8 Jan 2007 00:25:45 -0600 Subject: [llvm-commits] CVS: llvm/tools/lto/Makefile lto.cpp Message-ID: <200701080625.l086PjXC013028@zion.cs.uiuc.edu> Changes in directory llvm/tools/lto: Makefile updated: 1.6 -> 1.7 lto.cpp updated: 1.28 -> 1.29 --- Log message: Build libLLVMlto on non-Darwin architectures. Resolves PR1055: http://llvm.org/PR1055 : http://llvm.org/PR1055: http://llvm.org/PR1055 --- Diffs of the changes: (+10 -3) Makefile | 10 +++++++--- lto.cpp | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) Index: llvm/tools/lto/Makefile diff -u llvm/tools/lto/Makefile:1.6 llvm/tools/lto/Makefile:1.7 --- llvm/tools/lto/Makefile:1.6 Thu Sep 7 16:36:55 2006 +++ llvm/tools/lto/Makefile Mon Jan 8 00:25:29 2007 @@ -11,9 +11,13 @@ LIBRARYNAME = LLVMlto LINK_LIBS_IN_SHARED = 1 -SHARED_LIBRARY = 1 -LOADABLE_MODULE = 1 -DONT_BUILD_RELINKED = 1 +ifeq ($(OS),Darwin) + SHARED_LIBRARY = 1 + LOADABLE_MODULE = 1 + DONT_BUILD_RELINKED = 1 +else + BUILD_ARCHIVE = 1 +endif # Include this here so we can get the configuration of the targets # that have been configured for construction. We have to do this Index: llvm/tools/lto/lto.cpp diff -u llvm/tools/lto/lto.cpp:1.28 llvm/tools/lto/lto.cpp:1.29 --- llvm/tools/lto/lto.cpp:1.28 Sat Jan 6 17:51:31 2007 +++ llvm/tools/lto/lto.cpp Mon Jan 8 00:25:29 2007 @@ -455,6 +455,9 @@ return LTO_OPT_SUCCESS; } +/// Unused pure-virtual destructor. Must remain empty. +LinkTimeOptimizer::~LinkTimeOptimizer() {} + /// Destruct LTO. Delete all modules, symbols and target. LTO::~LTO() { From reid at x10sys.com Mon Jan 8 00:58:47 2007 From: reid at x10sys.com (Reid Spencer) Date: Mon, 8 Jan 2007 00:58:47 -0600 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200701080658.l086wlNn013558@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.304 -> 1.305 --- Log message: Fix PR1090: http://llvm.org/PR1090 : Implemented some llvm_fcmp_{pred} functions at the start of the function bodies and use them for fcmp instructions and constant expressions. These help implement the ordered and unordered comparisons necessary for correct exectuion of these comparisons. --- Diffs of the changes: (+97 -41) Writer.cpp | 138 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 97 insertions(+), 41 deletions(-) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.304 llvm/lib/Target/CBackend/Writer.cpp:1.305 --- llvm/lib/Target/CBackend/Writer.cpp:1.304 Sat Jan 6 21:24:48 2007 +++ llvm/lib/Target/CBackend/Writer.cpp Mon Jan 8 00:58:32 2007 @@ -732,7 +732,6 @@ case Instruction::Or: case Instruction::Xor: case Instruction::ICmp: - case Instruction::FCmp: case Instruction::Shl: case Instruction::LShr: case Instruction::AShr: @@ -771,25 +770,6 @@ default: assert(0 && "Illegal ICmp predicate"); } break; - case Instruction::FCmp: - switch (CE->getPredicate()) { - case FCmpInst::FCMP_ORD: - case FCmpInst::FCMP_UEQ: - case FCmpInst::FCMP_OEQ: Out << " == "; break; - case FCmpInst::FCMP_UNO: - case FCmpInst::FCMP_UNE: - case FCmpInst::FCMP_ONE: Out << " != "; break; - case FCmpInst::FCMP_OLT: - case FCmpInst::FCMP_ULT: Out << " < "; break; - case FCmpInst::FCMP_OLE: - case FCmpInst::FCMP_ULE: Out << " <= "; break; - case FCmpInst::FCMP_OGT: - case FCmpInst::FCMP_UGT: Out << " > "; break; - case FCmpInst::FCMP_OGE: - case FCmpInst::FCMP_UGE: Out << " >= "; break; - default: assert(0 && "Illegal FCmp predicate"); - } - break; default: assert(0 && "Illegal opcode here!"); } printConstantWithCast(CE->getOperand(1), CE->getOpcode()); @@ -798,7 +778,42 @@ Out << ')'; return; } - + case Instruction::FCmp: { + Out << '('; + bool NeedsClosingParens = printConstExprCast(CE); + if (CE->getPredicate() == FCmpInst::FCMP_FALSE) + Out << "0"; + else if (CE->getPredicate() == FCmpInst::FCMP_TRUE) + Out << "1"; + else { + const char* op = 0; + switch (CE->getPredicate()) { + default: assert(0 && "Illegal FCmp predicate"); + case FCmpInst::FCMP_ORD: op = "ord"; break; + case FCmpInst::FCMP_UNO: op = "uno"; break; + case FCmpInst::FCMP_UEQ: op = "ueq"; break; + case FCmpInst::FCMP_UNE: op = "une"; break; + case FCmpInst::FCMP_ULT: op = "ult"; break; + case FCmpInst::FCMP_ULE: op = "ule"; break; + case FCmpInst::FCMP_UGT: op = "ugt"; break; + case FCmpInst::FCMP_UGE: op = "uge"; break; + case FCmpInst::FCMP_OEQ: op = "oeq"; break; + case FCmpInst::FCMP_ONE: op = "one"; break; + case FCmpInst::FCMP_OLT: op = "olt"; break; + case FCmpInst::FCMP_OLE: op = "ole"; break; + case FCmpInst::FCMP_OGT: op = "ogt"; break; + case FCmpInst::FCMP_OGE: op = "oge"; break; + } + Out << "llvm_fcmp_" << op << "("; + printConstantWithCast(CE->getOperand(0), CE->getOpcode()); + Out << ", "; + printConstantWithCast(CE->getOperand(1), CE->getOpcode()); + Out << ")"; + } + if (NeedsClosingParens) + Out << "))"; + Out << ')'; + } default: cerr << "CWriter Error: Unhandled constant expression: " << *CE << "\n"; @@ -1563,6 +1578,37 @@ if (!M.empty()) Out << "\n\n/* Function Bodies */\n"; + + // Emit some helper functions for dealing with FCMP instruction's + // predicates + Out << "static inline int llvm_fcmp_ord(double X, double Y) { "; + Out << "return X == X && Y == Y; }\n"; + Out << "static inline int llvm_fcmp_uno(double X, double Y) { "; + Out << "return X != X || Y != Y; }\n"; + Out << "static inline int llvm_fcmp_ueq(double X, double Y) { "; + Out << "return X == Y || X != X || Y != Y; }\n"; + Out << "static inline int llvm_fcmp_une(double X, double Y) { "; + Out << "return X != Y || X != X || Y != Y; }\n"; + Out << "static inline int llvm_fcmp_ult(double X, double Y) { "; + Out << "return X < Y || X != X || Y != Y; }\n"; + Out << "static inline int llvm_fcmp_ugt(double X, double Y) { "; + Out << "return X > Y || X != X || Y != Y; }\n"; + Out << "static inline int llvm_fcmp_ule(double X, double Y) { "; + Out << "return X <= Y || X != X || Y != Y; }\n"; + Out << "static inline int llvm_fcmp_uge(double X, double Y) { "; + Out << "return X >= Y || X != X || Y != Y; }\n"; + Out << "static inline int llvm_fcmp_oeq(double X, double Y) { "; + Out << "return X == Y && X == X && Y == Y; }\n"; + Out << "static inline int llvm_fcmp_one(double X, double Y) { "; + Out << "return X != Y && X == X && Y == Y; }\n"; + Out << "static inline int llvm_fcmp_olt(double X, double Y) { "; + Out << "return X < Y && X == X && Y == Y; }\n"; + Out << "static inline int llvm_fcmp_ogt(double X, double Y) { "; + Out << "return X > Y && X == X && Y == Y; }\n"; + Out << "static inline int llvm_fcmp_ole(double X, double Y) { "; + Out << "return X <= Y && X == X && Y == Y; }\n"; + Out << "static inline int llvm_fcmp_oge(double X, double Y) { "; + Out << "return X >= Y && X == X && Y == Y; }\n"; return false; } @@ -2147,31 +2193,41 @@ } void CWriter::visitFCmpInst(FCmpInst &I) { - // Write the first operand - writeOperand(I.getOperand(0)); + if (I.getPredicate() == FCmpInst::FCMP_FALSE) { + Out << "0"; + return; + } + if (I.getPredicate() == FCmpInst::FCMP_TRUE) { + Out << "1"; + return; + } - // Write the predicate + const char* op = 0; switch (I.getPredicate()) { - case FCmpInst::FCMP_FALSE: Out << " 0 "; break; - case FCmpInst::FCMP_ORD: - case FCmpInst::FCMP_OEQ: - case FCmpInst::FCMP_UEQ: Out << " == "; break; - case FCmpInst::FCMP_UNO: - case FCmpInst::FCMP_ONE: - case FCmpInst::FCMP_UNE: Out << " != "; break; - case FCmpInst::FCMP_ULE: - case FCmpInst::FCMP_OLE: Out << " <= "; break; - case FCmpInst::FCMP_UGE: - case FCmpInst::FCMP_OGE: Out << " >= "; break; - case FCmpInst::FCMP_ULT: - case FCmpInst::FCMP_OLT: Out << " < "; break; - case FCmpInst::FCMP_UGT: - case FCmpInst::FCMP_OGT: Out << " > "; break; - case FCmpInst::FCMP_TRUE: Out << " 1 "; break; - default: cerr << "Invalid fcmp predicate!" << I; abort(); + default: assert(0 && "Illegal FCmp predicate"); + case FCmpInst::FCMP_ORD: op = "ord"; break; + case FCmpInst::FCMP_UNO: op = "uno"; break; + case FCmpInst::FCMP_UEQ: op = "ueq"; break; + case FCmpInst::FCMP_UNE: op = "une"; break; + case FCmpInst::FCMP_ULT: op = "ult"; break; + case FCmpInst::FCMP_ULE: op = "ule"; break; + case FCmpInst::FCMP_UGT: op = "ugt"; break; + case FCmpInst::FCMP_UGE: op = "uge"; break; + case FCmpInst::FCMP_OEQ: op = "oeq"; break; + case FCmpInst::FCMP_ONE: op = "one"; break; + case FCmpInst::FCMP_OLT: op = "olt"; break; + case FCmpInst::FCMP_OLE: op = "ole"; break; + case FCmpInst::FCMP_OGT: op = "ogt"; break; + case FCmpInst::FCMP_OGE: op = "oge"; break; } + + Out << "llvm_fcmp_" << op << "("; + // Write the first operand + writeOperand(I.getOperand(0)); + Out << ", "; // Write the second operand writeOperand(I.getOperand(1)); + Out << ")"; } static const char * getFloatBitCastField(const Type *Ty) { From clattner at apple.com Mon Jan 8 01:17:44 2007 From: clattner at apple.com (Chris Lattner) Date: Sun, 7 Jan 2007 23:17:44 -0800 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp In-Reply-To: <200701080658.l086wlNn013558@zion.cs.uiuc.edu> References: <200701080658.l086wlNn013558@zion.cs.uiuc.edu> Message-ID: <50B098B9-52B6-42A3-83B9-3B8A6071C8AB@apple.com> > + // Emit some helper functions for dealing with FCMP instruction's > + // predicates > + Out << "static inline int llvm_fcmp_ord(double X, double Y) { "; > + Out << "return X == X && Y == Y; }\n"; > + Out << "static inline int llvm_fcmp_uno(double X, double Y) { "; > + Out << "return X != X || Y != Y; }\n"; > + Out << "static inline int llvm_fcmp_ueq(double X, double Y) { "; > + Out << "return X == Y || X != X || Y != Y; }\n"; These would be more obvious if written as: return X == Y || llvm_fcmp_uno(X, Y) > + Out << "static inline int llvm_fcmp_ult(double X, double Y) { "; > + Out << "return X < Y || X != X || Y != Y; }\n"; > + Out << "static inline int llvm_fcmp_ugt(double X, double Y) { "; > + Out << "return X > Y || X != X || Y != Y; }\n"; > + Out << "static inline int llvm_fcmp_ule(double X, double Y) { "; > + Out << "return X <= Y || X != X || Y != Y; }\n"; > + Out << "static inline int llvm_fcmp_uge(double X, double Y) { "; > + Out << "return X >= Y || X != X || Y != Y; }\n"; > + Out << "static inline int llvm_fcmp_une(double X, double Y) { "; > + Out << "return X != Y || X != X || Y != Y; }\n"; > + Out << "static inline int llvm_fcmp_oeq(double X, double Y) { "; > + Out << "return X == Y && X == X && Y == Y; }\n"; > + Out << "static inline int llvm_fcmp_olt(double X, double Y) { "; > + Out << "return X < Y && X == X && Y == Y; }\n"; > + Out << "static inline int llvm_fcmp_ogt(double X, double Y) { "; > + Out << "return X > Y && X == X && Y == Y; }\n"; > + Out << "static inline int llvm_fcmp_ole(double X, double Y) { "; > + Out << "return X <= Y && X == X && Y == Y; }\n"; > + Out << "static inline int llvm_fcmp_oge(double X, double Y) { "; > + Out << "return X >= Y && X == X && Y == Y; }\n"; You can drop the 2nd and 3rd term of each of thse. > + Out << "static inline int llvm_fcmp_one(double X, double Y) { "; > + Out << "return X != Y && X == X && Y == Y; }\n"; This one is needed though. -Chris From sabre at nondot.org Mon Jan 8 01:36:49 2007 From: sabre at nondot.org (Chris Lattner) Date: Mon, 8 Jan 2007 01:36:49 -0600 Subject: [llvm-commits] CVS: llvm/tools/lli/lli.cpp Message-ID: <200701080736.l087anJc014272@zion.cs.uiuc.edu> Changes in directory llvm/tools/lli: lli.cpp updated: 1.64 -> 1.65 --- Log message: fix atexit. This is an overcomplex way of calling exit, but it is required, as the jit intercepts exit calls to implement atexit handlers. This fixes SingleSource/UnitTests/2003-05-14-AtExit --- Diffs of the changes: (+16 -3) lli.cpp | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) Index: llvm/tools/lli/lli.cpp diff -u llvm/tools/lli/lli.cpp:1.64 llvm/tools/lli/lli.cpp:1.65 --- llvm/tools/lli/lli.cpp:1.64 Sun Jan 7 00:43:08 2007 +++ llvm/tools/lli/lli.cpp Mon Jan 8 01:36:34 2007 @@ -118,9 +118,22 @@ // Run static destructors. EE->runStaticConstructorsDestructors(true); - exit(Result); - std::cerr << "ERROR: exit(" << Result << ") returned!\n"; - abort(); + // If the program didn't explicitly call exit, call exit now, for the + // program. This ensures that any atexit handlers get called correctly. + Constant *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy, + Type::Int32Ty, NULL); + if (Function *ExitF = dyn_cast(Exit)) { + std::vector Args; + GenericValue ResultGV; + ResultGV.Int32Val = Result; + Args.push_back(ResultGV); + EE->runFunction(ExitF, Args); + std::cerr << "ERROR: exit(" << Result << ") returned!\n"; + abort(); + } else { + std::cerr << "ERROR: exit defined with wrong prototype!\n"; + abort(); + } } catch (const std::string& msg) { std::cerr << argv[0] << ": " << msg << "\n"; } catch (...) { From clattner at apple.com Mon Jan 8 01:48:24 2007 From: clattner at apple.com (Chris Lattner) Date: Sun, 7 Jan 2007 23:48:24 -0800 Subject: [llvm-commits] llvm-gcc portion of PR1093 Message-ID: <00C65389-7CAD-40B7-B697-8BEAEA91558E@apple.com> This corrects llvm-gcc to always emit the llvm.va* intrinsics with i8* as the valist pointer type. This fixes llvm-gcc to comply with PR1093. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch.txt Url: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070107/90a8e353/attachment.txt -------------- next part -------------- -Chris From sabre at nondot.org Mon Jan 8 01:55:31 2007 From: sabre at nondot.org (Chris Lattner) Date: Mon, 8 Jan 2007 01:55:31 -0600 Subject: [llvm-commits] CVS: llvm/docs/LangRef.html Message-ID: <200701080755.l087tV1r014643@zion.cs.uiuc.edu> Changes in directory llvm/docs: LangRef.html updated: 1.189 -> 1.190 --- Log message: Fully specify the type of the llvm.va* intrinsics. This helps resolve Pr1093: http://llvm.org/PR1093 --- Diffs of the changes: (+16 -9) LangRef.html | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-) Index: llvm/docs/LangRef.html diff -u llvm/docs/LangRef.html:1.189 llvm/docs/LangRef.html:1.190 --- llvm/docs/LangRef.html:1.189 Sun Jan 7 02:53:26 2007 +++ llvm/docs/LangRef.html Mon Jan 8 01:55:15 2007 @@ -3519,18 +3519,20 @@ define i32 %test(i32 %X, ...) { ; Initialize variable argument processing %ap = alloca i8 * - call void %llvm.va_start(i8 ** %ap) + %ap2 = bitcast i8** %ap to i8* + call void %llvm.va_start(i8* %ap2) ; Read a single integer argument %tmp = va_arg i8 ** %ap, i32 ; Demonstrate usage of llvm.va_copy and llvm.va_end %aq = alloca i8 * - call void %llvm.va_copy(i8 ** %aq, i8 ** %ap) - call void %llvm.va_end(i8 ** %aq) + %aq2 = bitcast i8** %aq to i8* + call void %llvm.va_copy(i8 *%aq2, i8* %ap2) + call void %llvm.va_end(i8* %aq2) ; Stop processing of arguments. - call void %llvm.va_end(i8 ** %ap) + call void %llvm.va_end(i8* %ap2) ret i32 %tmp } @@ -3544,7 +3546,7 @@
Syntax:
-
  declare void %llvm.va_start(<va_list>* <arglist>)
+
  declare void %llvm.va_start(i8* <arglist>)
Overview:

The 'llvm.va_start' intrinsic initializes *<arglist> for subsequent use by

Syntax:
-
  declare void %llvm.va_end(<va_list*> <arglist>)
+
  declare void %llvm.va_end(i8* <arglist>)
Overview:
+

The 'llvm.va_end' intrinsic destroys <arglist> which has been initialized previously with llvm.va_start or llvm.va_copy.

+
Arguments:
+

The argument is a va_list to destroy.

+
Semantics:
+

The 'llvm.va_end' intrinsic works just like the va_end macro available in C. In a target-dependent way, it destroys the va_list. Calls to llvm.va_start and llvm.va_copy must be matched exactly with calls to llvm.va_end.

+
@@ -3597,8 +3605,7 @@
Syntax:
-  declare void %llvm.va_copy(<va_list>* <destarglist>,
-                                          <va_list>* <srcarglist>)
+  declare void %llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
 
Overview:
@@ -4468,7 +4475,7 @@ Chris Lattner
The LLVM Compiler Infrastructure
- Last modified: $Date: 2007/01/07 08:53:26 $ + Last modified: $Date: 2007/01/08 07:55:15 $ From reid at x10sys.com Mon Jan 8 02:00:15 2007 From: reid at x10sys.com (Reid Spencer) Date: Mon, 8 Jan 2007 02:00:15 -0600 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200701080800.l0880Fmg014768@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.305 -> 1.306 --- Log message: For PR1090: http://llvm.org/PR1090 : Clean up the definitions of the helper functions per Chris' review suggestions so they are easier to read. For PR1091: http://llvm.org/PR1091 : Print minimum signed integer values as unsigned so that we get no warnings from the C compiler about constant ranges and value comparisons. --- Diffs of the changes: (+31 -28) Writer.cpp | 59 +++++++++++++++++++++++++++++++---------------------------- 1 files changed, 31 insertions(+), 28 deletions(-) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.305 llvm/lib/Target/CBackend/Writer.cpp:1.306 --- llvm/lib/Target/CBackend/Writer.cpp:1.305 Mon Jan 8 00:58:32 2007 +++ llvm/lib/Target/CBackend/Writer.cpp Mon Jan 8 02:00:00 2007 @@ -826,23 +826,26 @@ return; } - switch (CPV->getType()->getTypeID()) { - case Type::BoolTyID: - Out << (cast(CPV)->getValue() ? '1' : '0'); - break; - case Type::Int8TyID: - Out << "((char)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int16TyID: - Out << "((short)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int32TyID: - Out << "((int)" << cast(CPV)->getSExtValue() << ")"; - break; - case Type::Int64TyID: - Out << "((long long)" << cast(CPV)->getSExtValue() << "ll)"; - break; + if (ConstantBool *CB = dyn_cast(CPV)) { + Out << (CB->getValue() ? '1' : '0') ; + return; + } + if (ConstantInt *CI = dyn_cast(CPV)) { + const Type* Ty = CI->getType(); + Out << "(("; + printPrimitiveType(Out, Ty, true) << ')'; + if (CI->isMinValue(true)) + Out << CI->getZExtValue() << 'u'; + else + Out << CI->getSExtValue(); + if (Ty->getPrimitiveSizeInBits() > 32) + Out << "ll"; + Out << ')'; + return; + } + + switch (CPV->getType()->getTypeID()) { case Type::FloatTyID: case Type::DoubleTyID: { ConstantFP *FPC = cast(CPV); @@ -1586,29 +1589,29 @@ Out << "static inline int llvm_fcmp_uno(double X, double Y) { "; Out << "return X != X || Y != Y; }\n"; Out << "static inline int llvm_fcmp_ueq(double X, double Y) { "; - Out << "return X == Y || X != X || Y != Y; }\n"; + Out << "return X == Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_une(double X, double Y) { "; - Out << "return X != Y || X != X || Y != Y; }\n"; + Out << "return X != Y; }\n"; Out << "static inline int llvm_fcmp_ult(double X, double Y) { "; - Out << "return X < Y || X != X || Y != Y; }\n"; + Out << "return X < Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_ugt(double X, double Y) { "; - Out << "return X > Y || X != X || Y != Y; }\n"; + Out << "return X > Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_ule(double X, double Y) { "; - Out << "return X <= Y || X != X || Y != Y; }\n"; + Out << "return X <= Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_uge(double X, double Y) { "; - Out << "return X >= Y || X != X || Y != Y; }\n"; + Out << "return X >= Y || llvm_fcmp_uno(X, Y); }\n"; Out << "static inline int llvm_fcmp_oeq(double X, double Y) { "; - Out << "return X == Y && X == X && Y == Y; }\n"; + Out << "return X == Y ; }\n"; Out << "static inline int llvm_fcmp_one(double X, double Y) { "; - Out << "return X != Y && X == X && Y == Y; }\n"; + Out << "return X != Y && llvm_fcmp_ord(X, Y); }\n"; Out << "static inline int llvm_fcmp_olt(double X, double Y) { "; - Out << "return X < Y && X == X && Y == Y; }\n"; + Out << "return X < Y ; }\n"; Out << "static inline int llvm_fcmp_ogt(double X, double Y) { "; - Out << "return X > Y && X == X && Y == Y; }\n"; + Out << "return X > Y ; }\n"; Out << "static inline int llvm_fcmp_ole(double X, double Y) { "; - Out << "return X <= Y && X == X && Y == Y; }\n"; + Out << "return X <= Y ; }\n"; Out << "static inline int llvm_fcmp_oge(double X, double Y) { "; - Out << "return X >= Y && X == X && Y == Y; }\n"; + Out << "return X >= Y ; }\n"; return false; } From reid at x10sys.com Mon Jan 8 10:18:06 2007 From: reid at x10sys.com (Reid Spencer) Date: Mon, 8 Jan 2007 10:18:06 -0600 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200701081618.l08GI6We032142@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.104 -> 1.105 --- Log message: For PR1097: http://llvm.org/PR1097 : Enable complex addressing modes on 64-bit platforms involving two induction variables by keeping a size and scale in 64-bits not 32. Patch by Dan Gohman. --- Diffs of the changes: (+1 -1) LoopStrengthReduce.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.104 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.105 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.104 Fri Jan 5 19:37:35 2007 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Jan 8 10:17:51 2007 @@ -893,7 +893,7 @@ if (unsigned(abs(SInt)) < Scale || (SInt % Scale) != 0) continue; std::map::iterator SI = - IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, Type::Int32Ty)); + IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy)); if (SI == IVsByStride.end()) continue; for (std::vector::iterator II = SI->second.IVs.begin(), From reid at x10sys.com Mon Jan 8 10:32:15 2007 From: reid at x10sys.com (Reid Spencer) Date: Mon, 8 Jan 2007 10:32:15 -0600 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp InstructionCombining.cpp ScalarReplAggregates.cpp Message-ID: <200701081632.l08GWFjZ032541@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: IndVarSimplify.cpp updated: 1.101 -> 1.102 InstructionCombining.cpp updated: 1.586 -> 1.587 ScalarReplAggregates.cpp updated: 1.62 -> 1.63 --- Log message: Comparison of primitive type sizes should now be done in bits, not bytes. This patch converts getPrimitiveSize to getPrimitiveSizeInBits where it is appropriate to do so (comparison of integer primitive types). --- Diffs of the changes: (+14 -12) IndVarSimplify.cpp | 5 +++-- InstructionCombining.cpp | 17 +++++++++-------- ScalarReplAggregates.cpp | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.101 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.102 --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.101 Sat Jan 6 19:14:12 2007 +++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Jan 8 10:32:00 2007 @@ -498,8 +498,9 @@ bool DifferingSizes = false; for (unsigned i = 1, e = IndVars.size(); i != e; ++i) { const Type *Ty = IndVars[i].first->getType(); - DifferingSizes |= Ty->getPrimitiveSize() != LargestType->getPrimitiveSize(); - if (Ty->getPrimitiveSize() > LargestType->getPrimitiveSize()) + DifferingSizes |= + Ty->getPrimitiveSizeInBits() != LargestType->getPrimitiveSizeInBits(); + if (Ty->getPrimitiveSizeInBits() > LargestType->getPrimitiveSizeInBits()) LargestType = Ty; } Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.586 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.587 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.586 Sun Jan 7 00:58:05 2007 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jan 8 10:32:00 2007 @@ -1926,8 +1926,8 @@ Other = LHS; } if (CI && CI->getType()->isSized() && - (CI->getType()->getPrimitiveSize() == - TD->getIntPtrType()->getPrimitiveSize()) + (CI->getType()->getPrimitiveSizeInBits() == + TD->getIntPtrType()->getPrimitiveSizeInBits()) && isa(CI->getOperand(0)->getType())) { Value *I2 = InsertCastBefore(Instruction::BitCast, CI->getOperand(0), PointerType::get(Type::Int8Ty), I); @@ -7239,9 +7239,9 @@ bool isConvertible = ActTy == ParamTy || (isa(ParamTy) && isa(ActTy)) || (ParamTy->isIntegral() && ActTy->isIntegral() && - ParamTy->getPrimitiveSize() >= ActTy->getPrimitiveSize()) || - (c && ParamTy->getPrimitiveSize() >= ActTy->getPrimitiveSize() && - c->getSExtValue() > 0); + ParamTy->getPrimitiveSizeInBits() >= ActTy->getPrimitiveSizeInBits()) || + (c && ParamTy->getPrimitiveSizeInBits() >= ActTy->getPrimitiveSizeInBits() + && c->getSExtValue() > 0); if (Callee->isExternal() && !isConvertible) return false; } @@ -7594,8 +7594,8 @@ static Value *InsertCastToIntPtrTy(Value *V, const Type *DTy, Instruction *InsertPoint, InstCombiner *IC) { - unsigned PtrSize = DTy->getPrimitiveSize(); - unsigned VTySize = V->getType()->getPrimitiveSize(); + unsigned PtrSize = DTy->getPrimitiveSizeInBits(); + unsigned VTySize = V->getType()->getPrimitiveSizeInBits(); // We must cast correctly to the pointer type. Ensure that we // sign extend the integer value if it is smaller as this is // used for address computation. @@ -7642,7 +7642,8 @@ MadeChange = true; GEP.setOperand(i, Src); } - } else if (SrcTy->getPrimitiveSize() < DestTy->getPrimitiveSize() && + } else if (SrcTy->getPrimitiveSizeInBits() < + DestTy->getPrimitiveSizeInBits() && SrcTy->getPrimitiveSize() == 4) { // We can eliminate a cast from [u]int to [u]long iff the target // is a 32-bit pointer target. Index: llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp diff -u llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.62 llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.63 --- llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.62 Sat Dec 30 23:48:39 2006 +++ llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp Mon Jan 8 10:32:00 2007 @@ -665,8 +665,8 @@ LI->getName(), LI); } else if (LI->getType()->isFloatingPoint()) { // If needed, truncate the integer to the appropriate size. - if (NV->getType()->getPrimitiveSize() > - LI->getType()->getPrimitiveSize()) { + if (NV->getType()->getPrimitiveSizeInBits() > + LI->getType()->getPrimitiveSizeInBits()) { switch (LI->getType()->getTypeID()) { default: assert(0 && "Unknown FP type!"); case Type::FloatTyID: From sabre at nondot.org Mon Jan 8 11:52:48 2007 From: sabre at nondot.org (Chris Lattner) Date: Mon, 8 Jan 2007 11:52:48 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/IndVarsSimplify/2007-01-08-X86-64-Pointer.ll Message-ID: <200701081752.l08HqmHn001703@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/IndVarsSimplify: 2007-01-08-X86-64-Pointer.ll added (r1.1) --- Log message: testcase for PR1097: http://llvm.org/PR1097 --- Diffs of the changes: (+19 -0) 2007-01-08-X86-64-Pointer.ll | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+) Index: llvm/test/Regression/Transforms/IndVarsSimplify/2007-01-08-X86-64-Pointer.ll diff -c /dev/null llvm/test/Regression/Transforms/IndVarsSimplify/2007-01-08-X86-64-Pointer.ll:1.1 *** /dev/null Mon Jan 8 11:52:39 2007 --- llvm/test/Regression/Transforms/IndVarsSimplify/2007-01-08-X86-64-Pointer.ll Mon Jan 8 11:52:29 2007 *************** *** 0 **** --- 1,19 ---- + ; RUN: llvm-as < %s | llc -march=x86-64 | grep '(%rdi,%rax,8)' && + ; RUN: llvm-as < %s | llc -march=x86-64 | not grep 'addq.*8' + + define void %foo(double* %y) { + entry: + br label %bb + + bb: + %i = phi i64 [ 0, %entry ], [ %k, %bb ] + %j = getelementptr double* %y, i64 %i + store double 0.000000e+00, double* %j + %k = add i64 %i, 1 + %n = icmp eq i64 %k, 0 + br bool %n, label %return, label %bb + + return: + ret void + } + From alenhar2 at cs.uiuc.edu Mon Jan 8 12:16:06 2007 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Mon, 8 Jan 2007 12:16:06 -0600 Subject: [llvm-commits] CVS: llvm/test/Feature/packed_struct.ll Message-ID: <200701081816.l08IG6Y6030494@apoc.cs.uiuc.edu> Changes in directory llvm/test/Feature: packed_struct.ll updated: 1.3 -> 1.4 --- Log message: Packed structs use packed struct initializers --- Diffs of the changes: (+17 -17) packed_struct.ll | 34 +++++++++++++++++----------------- 1 files changed, 17 insertions(+), 17 deletions(-) Index: llvm/test/Feature/packed_struct.ll diff -u llvm/test/Feature/packed_struct.ll:1.3 llvm/test/Feature/packed_struct.ll:1.4 --- llvm/test/Feature/packed_struct.ll:1.3 Fri Dec 29 14:21:51 2006 +++ llvm/test/Feature/packed_struct.ll Mon Jan 8 12:15:35 2007 @@ -1,33 +1,33 @@ -; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as < %s | llvm-dis > %t1.ll ; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll ; RUN: diff %t1.ll %t2.ll && ; RUN: not grep cast %t2.ll && ; RUN: grep "<{" %t2.ll -%struct.anon = type <{ sbyte, int, int, int }> +%struct.anon = type <{ i8, i32, i32, i32 }> %foos = external global %struct.anon -%bara = external global [2 x <{ int, sbyte }>] +%bara = external global [2 x <{ i32, i8 }>] ;initializers should work for packed and non-packed the same way -%E1 = global <{sbyte, int, int}> {sbyte 1, int 2, int 3} -%E2 = global {sbyte, int, int} {sbyte 4, int 5, int 6} +%E1 = global <{i8, i32, i32}> <{i8 1, i32 2, i32 3}> +%E2 = global {i8, i32, i32} {i8 4, i32 5, i32 6} implementation ; Functions: -int %main() +define i32 %main() { - %tmp = load int* getelementptr (%struct.anon* %foos, int 0, uint 1) ; [#uses=1] - %tmp3 = load int* getelementptr (%struct.anon* %foos, int 0, uint 2) ; [#uses=1] - %tmp6 = load int* getelementptr (%struct.anon* %foos, int 0, uint 3) ; [#uses=1] - %tmp4 = add int %tmp3, %tmp ; [#uses=1] - %tmp7 = add int %tmp4, %tmp6 ; [#uses=1] - ret int %tmp7 + %tmp = load i32* getelementptr (%struct.anon* %foos, i32 0, i32 1) ; [#uses=1] + %tmp3 = load i32* getelementptr (%struct.anon* %foos, i32 0, i32 2) ; [#uses=1] + %tmp6 = load i32* getelementptr (%struct.anon* %foos, i32 0, i32 3) ; [#uses=1] + %tmp4 = add i32 %tmp3, %tmp ; [#uses=1] + %tmp7 = add i32 %tmp4, %tmp6 ; [#uses=1] + ret i32 %tmp7 } -int %bar() { +define i32 %bar() { entry: - %tmp = load int* getelementptr([2 x <{ int, sbyte }>]* %bara, int 0, int 0, uint 0 ) ; [#uses=1] - %tmp4 = load int* getelementptr ([2 x <{ int, sbyte }>]* %bara, int 0, int 1, uint 0) ; [#uses=1] - %tmp5 = add int %tmp4, %tmp ; [#uses=1] - ret int %tmp5 + %tmp = load i32* getelementptr([2 x <{ i32, i8 }>]* %bara, i32 0, i32 0, i32 0 ) ; [#uses=1] + %tmp4 = load i32* getelementptr ([2 x <{ i32, i8 }>]* %bara, i32 0, i32 1, i32 0) ; [#uses=1] + %tmp5 = add i32 %tmp4, %tmp ; [#uses=1] + ret i32 %tmp5 } From alenhar2 at cs.uiuc.edu Mon Jan 8 12:17:19 2007 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Mon, 8 Jan 2007 12:17:19 -0600 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y Message-ID: <200701081817.l08IHJ9P030524@apoc.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: llvmAsmParser.y updated: 1.301 -> 1.302 --- Log message: Make packed structs use packed initialiers for consistency --- Diffs of the changes: (+52 -0) llvmAsmParser.y | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+) Index: llvm/lib/AsmParser/llvmAsmParser.y diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.301 llvm/lib/AsmParser/llvmAsmParser.y:1.302 --- llvm/lib/AsmParser/llvmAsmParser.y:1.301 Sat Jan 6 01:24:43 2007 +++ llvm/lib/AsmParser/llvmAsmParser.y Mon Jan 8 12:16:47 2007 @@ -1484,6 +1484,10 @@ "' for element #" + utostr(i) + " of structure initializer!"); + // Check to ensure that Type is not packed + if (STy->isPacked()) + GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'"); + $$ = ConstantStruct::get(STy, *$3); delete $1; delete $3; CHECK_FOR_ERROR @@ -1499,6 +1503,54 @@ if (STy->getNumContainedTypes() != 0) GEN_ERROR("Illegal number of initializers for structure type!"); + // Check to ensure that Type is not packed + if (STy->isPacked()) + GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'"); + + $$ = ConstantStruct::get(STy, std::vector()); + delete $1; + CHECK_FOR_ERROR + } + | Types '<' '{' ConstVector '}' '>' { + const StructType *STy = dyn_cast($1->get()); + if (STy == 0) + GEN_ERROR("Cannot make struct constant with type: '" + + (*$1)->getDescription() + "'!"); + + if ($4->size() != STy->getNumContainedTypes()) + GEN_ERROR("Illegal number of initializers for structure type!"); + + // Check to ensure that constants are compatible with the type initializer! + for (unsigned i = 0, e = $4->size(); i != e; ++i) + if ((*$4)[i]->getType() != STy->getElementType(i)) + GEN_ERROR("Expected type '" + + STy->getElementType(i)->getDescription() + + "' for element #" + utostr(i) + + " of structure initializer!"); + + // Check to ensure that Type is packed + if (!STy->isPacked()) + GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'"); + + $$ = ConstantStruct::get(STy, *$4); + delete $1; delete $4; + CHECK_FOR_ERROR + } + | Types '<' '{' '}' '>' { + if (!UpRefs.empty()) + GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription()); + const StructType *STy = dyn_cast($1->get()); + if (STy == 0) + GEN_ERROR("Cannot make struct constant with type: '" + + (*$1)->getDescription() + "'!"); + + if (STy->getNumContainedTypes() != 0) + GEN_ERROR("Illegal number of initializers for structure type!"); + + // Check to ensure that Type is packed + if (!STy->isPacked()) + GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'"); + $$ = ConstantStruct::get(STy, std::vector()); delete $1; CHECK_FOR_ERROR From alenhar2 at cs.uiuc.edu Mon Jan 8 12:22:08 2007 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Mon, 8 Jan 2007 12:22:08 -0600 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200701081822.l08IM8UK001747@apoc.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.235 -> 1.236 --- Log message: And asm writing for packed struct initializers --- Diffs of the changes: (+4 -0) AsmWriter.cpp | 4 ++++ 1 files changed, 4 insertions(+) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.235 llvm/lib/VMCore/AsmWriter.cpp:1.236 --- llvm/lib/VMCore/AsmWriter.cpp:1.235 Sat Jan 6 01:24:44 2007 +++ llvm/lib/VMCore/AsmWriter.cpp Mon Jan 8 12:21:30 2007 @@ -501,6 +501,8 @@ Out << " ]"; } } else if (const ConstantStruct *CS = dyn_cast(CV)) { + if (CS->getType()->isPacked()) + Out << '<'; Out << '{'; unsigned N = CS->getNumOperands(); if (N) { @@ -525,6 +527,8 @@ } Out << " }"; + if (CS->getType()->isPacked()) + Out << '>'; } else if (const ConstantPacked *CP = dyn_cast(CV)) { const Type *ETy = CP->getType()->getElementType(); assert(CP->getNumOperands() > 0 && From dpatel at apple.com Mon Jan 8 12:40:05 2007 From: dpatel at apple.com (Devang Patel) Date: Mon, 8 Jan 2007 10:40:05 -0800 Subject: [llvm-commits] [llvm-gcc] Cumulative Patch 2007-01-07 (Take 2) In-Reply-To: <1168223091.796.83.camel@bashful.x10sys.com> References: <1168218849.796.64.camel@bashful.x10sys.com> <1168223091.796.83.camel@bashful.x10sys.com> Message-ID: <4FB95D9A-E63A-4B9D-9B49-DA96133A75D8@apple.com> On Jan 7, 2007, at 6:24 PM, Reid Spencer wrote: > I wish I could retract email. > > The patch I just sent didn't have differences for sub-directories in > it. > Please don't apply it. Instead use this one which should bring you > up to > date with Apple's changes. Again, this applies to r240 of the llvm-gcc > SVN mirror. > > Some things to note. If your target is not x86, x86-64, or ppc and > your > operating system is not darwin or linux, this probably won't work. > You'll get a link error like this: > > ../../src-1/gcc/llvm-convert.cpp:3118: undefined reference to > `TreeToLLVM::TargetIntrinsicLower(unsigned int, llvm::Value*, > llvm::Value*&, llvm::Type const*, std::vector std::allocator >&, llvm::SmallVector&, > llvm::BasicBlock*, bool, bool)' > > That's because the makefiles aren't quite ready to compile a target > specific C++ file yet. After quick look, I think makefiles are ready. However, if any target relies on llvm-i386.cpp to provide these undefined symbols then config.gcc needs to be updated to inform this to makefiles for such targets. Each target can use their own target specific C++ source file, no need to put everything in llvm-i386.c pp or llvm-ppc.cpp. > Fortunately there is a work around: So this is not a work around, but right way to fix it. Thanks! - Devang > > 1. Edit gcc/config.gcc > 2. Find the case statement at line 558 > 3. Find the pattern that matches your target in the cases that follow. > 4. Add the following right after the "tmake_file" line for your > target. > # APPLE LOCAL begin LLVM > out_cxx_file=i386/llvm-i386.cpp > # APPLE LOCAL end LLVM > > For example, find the line that matches this pattern: ^i.*linux > around line 964. That has an example of the correct patch. It looks > like > this: > > i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*- > knetbsd*-gnu) > # Intel 80386's running GNU/* > # with ELF format using glibc 2 > tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h > svr4.h linux.h i386/linux.h" > # APPLE LOCAL begin LLVM > out_cxx_file=i386/llvm-i386.cpp > # APPLE LOCAL end LLVM > case ${target} in > > The APPLE section is what you add. > > Reid. > > > > Reid. > > On Sun, 2007-01-07 at 17:14 -0800, Reid Spencer wrote: >> All, >> >> Attached is a cumulative patch with all changes in the Apple >> repository >> since the mirror's r240 revision. If you haven't applied the various >> patches sent in the last few days, this one will be much easier. >> >> The attached patch also contains one thing that the Apple repository >> doesn't have: fixes to i386.h for changes in the result type of >> Module::getOrInsertFunction. >> >> This patch compiles/works fine for me on Linux/x86 >> >> Reid. >> _______________________________________________ >> llvm-commits mailing list >> llvm-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits> GCC-2007-01-07.patch> > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits From dpatel at apple.com Mon Jan 8 12:42:42 2007 From: dpatel at apple.com (Devang Patel) Date: Mon, 8 Jan 2007 12:42:42 -0600 Subject: [llvm-commits] CVS: llvm/tools/lto/lto.cpp Message-ID: <200701081842.l08Igg4U002711@zion.cs.uiuc.edu> Changes in directory llvm/tools/lto: lto.cpp updated: 1.29 -> 1.30 --- Log message: Modules are consumed when they are merged together by Linker. Clear modules vector so that destructure does not try to delete these modules again. Patch by Chandler Carruth. --- Diffs of the changes: (+2 -0) lto.cpp | 2 ++ 1 files changed, 2 insertions(+) Index: llvm/tools/lto/lto.cpp diff -u llvm/tools/lto/lto.cpp:1.29 llvm/tools/lto/lto.cpp:1.30 --- llvm/tools/lto/lto.cpp:1.29 Mon Jan 8 00:25:29 2007 +++ llvm/tools/lto/lto.cpp Mon Jan 8 12:42:27 2007 @@ -353,6 +353,8 @@ for (unsigned i = 1, e = modules.size(); i != e; ++i) if (theLinker.LinkModules(bigOne, modules[i], errMsg)) return LTO_MODULE_MERGE_FAILURE; + // all modules have been handed off to the linker. + modules.clear(); sys::Path FinalOutputPath(FinalOutputFilename); FinalOutputPath.eraseSuffix(); From clattner at apple.com Mon Jan 8 12:45:29 2007 From: clattner at apple.com (Chris Lattner) Date: Mon, 8 Jan 2007 10:45:29 -0800 Subject: [llvm-commits] [llvm-gcc] Cumulative Patch 2007-01-07 (Take 2) In-Reply-To: <4FB95D9A-E63A-4B9D-9B49-DA96133A75D8@apple.com> References: <1168218849.796.64.camel@bashful.x10sys.com> <1168223091.796.83.camel@bashful.x10sys.com> <4FB95D9A-E63A-4B9D-9B49-DA96133A75D8@apple.com> Message-ID: <728CAA85-B3F2-457F-9AFC-9F1D94909AF5@apple.com> > After quick look, I think makefiles are ready. However, if any target > relies on llvm-i386.cpp to provide these undefined symbols then > config.gcc needs to be updated to inform this to makefiles for such > targets. Each target can use their own target specific C++ source > file, no need to put everything in llvm-i386.c pp or llvm-ppc.cpp. Ok. This will be every target that uses i386.h >> Fortunately there is a work around: > > So this is not a work around, but right way to fix it. Thanks! Devang, can you commit a patch to add llvm-i386.cpp for every target that uses i386.c ? -Chris From dpatel at apple.com Mon Jan 8 12:51:50 2007 From: dpatel at apple.com (Devang Patel) Date: Mon, 8 Jan 2007 10:51:50 -0800 Subject: [llvm-commits] [llvm-gcc] Cumulative Patch 2007-01-07 (Take 2) In-Reply-To: <728CAA85-B3F2-457F-9AFC-9F1D94909AF5@apple.com> References: <1168218849.796.64.camel@bashful.x10sys.com> <1168223091.796.83.camel@bashful.x10sys.com> <4FB95D9A-E63A-4B9D-9B49-DA96133A75D8@apple.com> <728CAA85-B3F2-457F-9AFC-9F1D94909AF5@apple.com> Message-ID: On Jan 8, 2007, at 10:45 AM, Chris Lattner wrote: >> After quick look, I think makefiles are ready. However, if any target >> relies on llvm-i386.cpp to provide these undefined symbols then >> config.gcc needs to be updated to inform this to makefiles for such >> targets. Each target can use their own target specific C++ source >> file, no need to put everything in llvm-i386.c pp or llvm-ppc.cpp. > > Ok. This will be every target that uses i386.h > >>> Fortunately there is a work around: >> >> So this is not a work around, but right way to fix it. Thanks! > > Devang, can you commit a patch to add llvm-i386.cpp for every target > that uses i386.c ? OK. I suspect this may not be straight forward. Let's see. - Devang From rspencer at reidspencer.com Mon Jan 8 13:05:33 2007 From: rspencer at reidspencer.com (Reid Spencer) Date: Mon, 08 Jan 2007 11:05:33 -0800 Subject: [llvm-commits] [llvm-gcc] Cumulative Patch 2007-01-07 (Take 2) In-Reply-To: References: <1168218849.796.64.camel@bashful.x10sys.com> <1168223091.796.83.camel@bashful.x10sys.com> <4FB95D9A-E63A-4B9D-9B49-DA96133A75D8@apple.com> <728CAA85-B3F2-457F-9AFC-9F1D94909AF5@apple.com> Message-ID: <1168283133.21552.16.camel@bashful.x10sys.com> The attached patch worked for me on x86-linux and for Chandler on x86-64-linux. This is a delta from r240 of the mirror .. YMMV. Reid. On Mon, 2007-01-08 at 10:51 -0800, Devang Patel wrote: > On Jan 8, 2007, at 10:45 AM, Chris Lattner wrote: > > >> After quick look, I think makefiles are ready. However, if any target > >> relies on llvm-i386.cpp to provide these undefined symbols then > >> config.gcc needs to be updated to inform this to makefiles for such > >> targets. Each target can use their own target specific C++ source > >> file, no need to put everything in llvm-i386.c pp or llvm-ppc.cpp. > > > > Ok. This will be every target that uses i386.h > > > >>> Fortunately there is a work around: > >> > >> So this is not a work around, but right way to fix it. Thanks! > > > > Devang, can you commit a patch to add llvm-i386.cpp for every target > > that uses i386.c ? > > OK. I suspect this may not be straight forward. Let's see. > > - > Devang > -------------- next part -------------- A non-text attachment was scrubbed... Name: i386.patch Type: text/x-patch Size: 1116 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070108/22d84917/attachment.bin From dpatel at apple.com Mon Jan 8 13:08:52 2007 From: dpatel at apple.com (Devang Patel) Date: Mon, 8 Jan 2007 11:08:52 -0800 Subject: [llvm-commits] [llvm-gcc] Cumulative Patch 2007-01-07 (Take 2) In-Reply-To: <1168283133.21552.16.camel@bashful.x10sys.com> References: <1168218849.796.64.camel@bashful.x10sys.com> <1168223091.796.83.camel@bashful.x10sys.com> <4FB95D9A-E63A-4B9D-9B49-DA96133A75D8@apple.com> <728CAA85-B3F2-457F-9AFC-9F1D94909AF5@apple.com> <1168283133.21552.16.camel@bashful.x10sys.com> Message-ID: On Jan 8, 2007, at 11:05 AM, Reid Spencer wrote: >> OK. I suspect this may not be straight forward. Let's see. >> >> - >> Devang >> >> config.gcc selects target specific C source file name based on cpu_type (by default). So, I thought it may not be super easy to trace all uses of i386.c. Your patch should work. However, I am testing following to cover everything under i386* and x86* umbrella in one shot. - Devang Index: config.gcc =================================================================== --- config.gcc (revision 122065) +++ config.gcc (working copy) @@ -269,11 +269,17 @@ xscale-*-*) # APPLE LOCAL begin mni 4424835 i[34567]86-*-*) cpu_type=i386 +# APPLE LOCAL begin LLVM + out_cxx_file=i386/llvm-i386.cpp +# APPLE LOCAL end LLVM extra_headers="mmintrin.h mm3dnow.h xmmintrin.h emmintrin.h pmmintrin.h tmmintrin.h" ;; x86_64-*-*) cpu_type=i386 +# APPLE LOCAL begin LLVM + out_cxx_file=i386/llvm-i386.cpp +# APPLE LOCAL end LLVM extra_headers="mmintrin.h mm3dnow.h xmmintrin.h emmintrin.h pmmintrin.h tmmintrin.h" need_64bit_hwint=yes @@ -966,9 +972,6 @@ i[34567]86-*-darwin*) # APPLE LOCAL end mainline 2005-10-02 4218570 # APPLE LOCAL 4099000 tmake_file="${tmake_file} i386/t-darwin" -# APPLE LOCAL begin LLVM - out_cxx_file=i386/llvm-i386.cpp -# APPLE LOCAL end LLVM # APPLE LOCAL 4126124 need_64bit_hwint=yes ;; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070108/c156800d/attachment.html From clattner at apple.com Mon Jan 8 13:11:32 2007 From: clattner at apple.com (Chris Lattner) Date: Mon, 8 Jan 2007 11:11:32 -0800 Subject: [llvm-commits] Corrected K&R prototype patch Message-ID: <4F28A095-A6FD-4BF6-B29C-5DE322044F72@apple.com> Basically the same as before, but I have this: - FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv); + FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv, false/ *not K&R*/); instead of this: - FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv); + FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv, true/ *not K&R*/); Whoops. I've verified that the CFE builds from scratch with this patch and that Shootout-C++ now passes. -Chris -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch.txt Url: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070108/3b9084eb/attachment.txt From dpatel at apple.com Mon Jan 8 13:29:55 2007 From: dpatel at apple.com (Devang Patel) Date: Mon, 8 Jan 2007 13:29:55 -0600 Subject: [llvm-commits] CVS: llvm/include/llvm/Pass.h Message-ID: <200701081929.l08JTtdJ003671@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: Pass.h updated: 1.70 -> 1.71 --- Log message: Add PMStack, a Pass Manager stack. Eventually, Top level pass managers will use this to keep track of active pass managers. Eass pass will also learn how to find appropriate manager from these managers stack. --- Diffs of the changes: (+32 -2) Pass.h | 34 ++++++++++++++++++++++++++++++++-- 1 files changed, 32 insertions(+), 2 deletions(-) Index: llvm/include/llvm/Pass.h diff -u llvm/include/llvm/Pass.h:1.70 llvm/include/llvm/Pass.h:1.71 --- llvm/include/llvm/Pass.h:1.70 Fri Jan 5 16:47:07 2007 +++ llvm/include/llvm/Pass.h Mon Jan 8 13:29:38 2007 @@ -31,6 +31,7 @@ #include "llvm/Support/Streams.h" #include +#include #include #include #include @@ -49,6 +50,7 @@ class BasicBlockPassManager; class FunctionPassManagerT; class ModulePassManager; +class PMStack; class AnalysisResolver; // AnalysisID - Use the PassInfo to identify a pass... @@ -133,8 +135,6 @@ // dumpPassStructure - Implement the -debug-passes=PassStructure option virtual void dumpPassStructure(unsigned Offset = 0); - - // getPassInfo - Static method to get the pass information from a class name. template static const PassInfo *getClassPassInfo() { return lookupPassInfo(typeid(AnalysisClass)); @@ -198,6 +198,7 @@ virtual bool runPass(Module &M) { return runOnModule(M); } virtual bool runPass(BasicBlock&) { return false; } + virtual void assignPassManager(PMStack &PMS); // Force out-of-line virtual method. virtual ~ModulePass(); }; @@ -263,6 +264,7 @@ /// bool run(Function &F); + virtual void assignPassManager(PMStack &PMS); }; @@ -316,8 +318,36 @@ virtual bool runPass(Module &M) { return false; } virtual bool runPass(BasicBlock &BB); + virtual void assignPassManager(PMStack &PMS); +}; + +/// PMStack +/// Top level pass manager (see PasManager.cpp) maintains active Pass Managers +/// using PMStack. Each Pass implements assignPassManager() to connect itself +/// with appropriate manager. assignPassManager() walks PMStack to find +/// suitable manager. +/// +/// PMStack is just a wrapper around standard deque that overrides pop() and +/// push() methods. +class PMDataManager; +class PMStack { +public: + typedef std::deque::reverse_iterator iterator; + iterator begin() { return S.rbegin(); } + iterator end() { return S.rend(); } + + void handleLastUserOverflow(); + + void pop(); + inline PMDataManager *top() { return S.back(); } + void push(PMDataManager *PM); + inline bool empty() { return S.empty(); } + +private: + std::deque S; }; + /// If the user specifies the -time-passes argument on an LLVM tool command line /// then the value of this boolean will be true, otherwise false. /// @brief This is the storage for the -time-passes option. From dpatel at apple.com Mon Jan 8 13:29:55 2007 From: dpatel at apple.com (Devang Patel) Date: Mon, 8 Jan 2007 13:29:55 -0600 Subject: [llvm-commits] CVS: llvm/lib/VMCore/PassManager.cpp Message-ID: <200701081929.l08JTt2l003666@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: PassManager.cpp updated: 1.112 -> 1.113 --- Log message: Add PMStack, a Pass Manager stack. Eventually, Top level pass managers will use this to keep track of active pass managers. Eass pass will also learn how to find appropriate manager from these managers stack. --- Diffs of the changes: (+138 -0) PassManager.cpp | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 138 insertions(+) Index: llvm/lib/VMCore/PassManager.cpp diff -u llvm/lib/VMCore/PassManager.cpp:1.112 llvm/lib/VMCore/PassManager.cpp:1.113 --- llvm/lib/VMCore/PassManager.cpp:1.112 Fri Jan 5 16:47:07 2007 +++ llvm/lib/VMCore/PassManager.cpp Mon Jan 8 13:29:38 2007 @@ -1514,7 +1514,9 @@ bool PassManagerImpl::addPass(Pass *P) { if (!activeManager || !activeManager->addPass(P)) { + activeManager = new MPPassManager(getDepth() + 1); + // Inherit top level manager activeManager->setTopLevelManager(this->getTopLevelManager()); @@ -1601,4 +1603,140 @@ TheTimeInfo = &*TTI; } +//===----------------------------------------------------------------------===// +// PMStack implementation +// +// Pop Pass Manager from the stack and clear its analysis info. +void PMStack::pop() { + + PMDataManager *Top = this->top(); + Top->initializeAnalysisInfo(); + + S.pop_back(); +} + +// Push PM on the stack and set its top level manager. +void PMStack::push(PMDataManager *PM) { + + PMDataManager *Top = this->top(); + + // Inherit top level manager + PMTopLevelManager *TPM = Top->getTopLevelManager(); + PM->setTopLevelManager(TPM); + TPM->addIndirectPassManager(PM); +} + +// Walk Pass Manager stack and set LastUse markers if any +// manager is transfering this priviledge to its parent manager +void PMStack::handleLastUserOverflow() { + + for(PMStack::iterator I = this->begin(), E = this->end(); I != E;) { + + PMDataManager *Child = *I++; + if (I != E) { + PMDataManager *Parent = *I++; + PMTopLevelManager *TPM = Parent->getTopLevelManager(); + std::vector &TLU = Child->getTransferredLastUses(); + if (!TLU.empty()) { + Pass *P = dynamic_cast(Parent); + TPM->setLastUser(TLU, P); + } + } + } +} + +/// Find appropriate Module Pass Manager in the PM Stack and +/// add self into that manager. +void ModulePass::assignPassManager(PMStack &PMS) { + + MPPassManager *MPP = NULL; + + // Find Module Pass Manager + while(!PMS.empty()) { + + MPP = dynamic_cast(PMS.top()); + if (MPP) + break; // Found it + else + PMS.pop(); // Pop children pass managers + } + + assert(MPP && "Unable to find Module Pass Manager"); + + MPP->addPassToManager(this); +} + +/// Find appropriate Function Pass Manager or Call Graph Pass Manager +/// in the PM Stack and add self into that manager. +void FunctionPass::assignPassManager(PMStack &PMS) { + + FPPassManager *FPP = NULL; + + // Find Module Pass Manager + while(!PMS.empty()) { + + FPP = dynamic_cast(PMS.top()); + if (FPP || dynamic_cast(PMS.top())) + break; // Found it or it is not here + else + PMS.pop(); // Pop children pass managers + } + + if (!FPP) { + /// Create new Function Pass Manager + + /// Function Pass Manager does not live by itself + assert(!PMS.empty() && "Unable to create Function Pass Manager"); + + PMDataManager *PMD = PMS.top(); + + /// PMD should be either Module Pass Manager or Call Graph Pass Manager + assert(dynamic_cast(PMD) && + "Unable to create Function Pass Manager"); + + FPP = new FPPassManager(PMD->getDepth() + 1); + PMD->addPassToManager(FPP, false); + PMS.push(FPP); + } + + + FPP->addPassToManager(this); +} + +/// Find appropriate Basic Pass Manager or Call Graph Pass Manager +/// in the PM Stack and add self into that manager. +void BasicBlockPass::assignPassManager(PMStack &PMS) { + + BBPassManager *BBP = NULL; + + // Find Module Pass Manager + while(!PMS.empty()) { + + BBP = dynamic_cast(PMS.top()); + if (BBP || dynamic_cast(PMS.top())) + break; // Found it or it is not here + else + PMS.pop(); // Pop children pass managers + } + + if (!BBP) { + /// Create new BasicBlock Pass Manager + + /// BasicBlock Pass Manager does not live by itself + assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager"); + + PMDataManager *PMD = PMS.top(); + + /// PMD should be Function Pass Manager + assert(dynamic_cast(PMD) && + "Unable to create BasicBlock Pass Manager"); + + BBP = new BBPassManager(PMD->getDepth() + 1); + PMD->addPassToManager(BBP, false); + PMS.push(BBP); + } + + BBP->addPassToManager(this); +} + From dpatel at apple.com Mon Jan 8 13:31:10 2007 From: dpatel at apple.com (Devang Patel) Date: Mon, 8 Jan 2007 11:31:10 -0800 Subject: [llvm-commits] [llvm-gcc] Cumulative Patch 2007-01-07 (Take 2) In-Reply-To: References: <1168218849.796.64.camel@bashful.x10sys.com> <1168223091.796.83.camel@bashful.x10sys.com> <4FB95D9A-E63A-4B9D-9B49-DA96133A75D8@apple.com> <728CAA85-B3F2-457F-9AFC-9F1D94909AF5@apple.com> <1168283133.21552.16.camel@bashful.x10sys.com> Message-ID: <06F1A607-B910-43B9-BEE8-107C39B13CED@apple.com> On Jan 8, 2007, at 11:08 AM, Devang Patel wrote: > > On Jan 8, 2007, at 11:05 AM, Reid Spencer wrote: > >>> OK. I suspect this may not be straight forward. Let's see. >>> >>> - >>> Devang >>> >>> > > config.gcc selects target specific C source file name based on > cpu_type (by default). So, I thought it may not be super easy to > trace all uses of i386.c. > > Your patch should work. However, I am testing following to cover > everything under i386* and x86* umbrella in one shot. Following works for darwin-x86. I applied this. Let me know if this does not work for your target. - Devang > > - > Devang > > Index: config.gcc > =================================================================== > --- config.gcc (revision 122065) > +++ config.gcc (working copy) > @@ -269,11 +269,17 @@ xscale-*-*) > # APPLE LOCAL begin mni 4424835 > i[34567]86-*-*) > cpu_type=i386 > +# APPLE LOCAL begin LLVM > + out_cxx_file=i386/llvm-i386.cpp > +# APPLE LOCAL end LLVM > extra_headers="mmintrin.h mm3dnow.h xmmintrin.h emmintrin.h > pmmintrin.h tmmintrin.h" > ;; > x86_64-*-*) > cpu_type=i386 > +# APPLE LOCAL begin LLVM > + out_cxx_file=i386/llvm-i386.cpp > +# APPLE LOCAL end LLVM > extra_headers="mmintrin.h mm3dnow.h xmmintrin.h emmintrin.h > pmmintrin.h tmmintrin.h" > need_64bit_hwint=yes > @@ -966,9 +972,6 @@ i[34567]86-*-darwin*) > # APPLE LOCAL end mainline 2005-10-02 4218570 > # APPLE LOCAL 4099000 > tmake_file="${tmake_file} i386/t-darwin" > -# APPLE LOCAL begin LLVM > - out_cxx_file=i386/llvm-i386.cpp > -# APPLE LOCAL end LLVM > # APPLE LOCAL 4126124 > need_64bit_hwint=yes > ;; > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070108/33378a43/attachment.html From reid at x10sys.com Mon Jan 8 13:39:14 2007 From: reid at x10sys.com (Reid Spencer) Date: Mon, 8 Jan 2007 13:39:14 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp Message-ID: <200701081939.l08JdEN5003861@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/C++Frontend: 2007-01-06-ELF-Thunk-Sections.cpp updated: 1.1 -> 1.2 --- Log message: XFAIL this test until PR1085: http://llvm.org/PR1085 mystery is resolved. --- Diffs of the changes: (+1 -0) 2007-01-06-ELF-Thunk-Sections.cpp | 1 + 1 files changed, 1 insertion(+) Index: llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp diff -u llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp:1.1 llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp:1.2 --- llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp:1.1 Sat Jan 6 18:32:15 2007 +++ llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp Mon Jan 8 13:38:58 2007 @@ -1,6 +1,7 @@ // RUN: %llvmgxx %s -emit-llvm -S -o - && // RUN: %llvmgxx %s -emit-llvm -S -o - | not grep 'gnu.linkonce.' // PR1085 +// XFAIL: i.86-pc-linux-* class __attribute__((visibility("default"))) QGenericArgument From reid at x10sys.com Mon Jan 8 13:41:16 2007 From: reid at x10sys.com (Reid Spencer) Date: Mon, 8 Jan 2007 13:41:16 -0600 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Type.cpp Message-ID: <200701081941.l08JfGq4003913@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Type.cpp updated: 1.155 -> 1.156 --- Log message: Parameter attributes are part of a FunctionType and deserve to be factored into comparisons of two FunctionTypes. Make it so. --- Diffs of the changes: (+6 -1) Type.cpp | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletion(-) Index: llvm/lib/VMCore/Type.cpp diff -u llvm/lib/VMCore/Type.cpp:1.155 llvm/lib/VMCore/Type.cpp:1.156 --- llvm/lib/VMCore/Type.cpp:1.155 Fri Jan 5 11:06:19 2007 +++ llvm/lib/VMCore/Type.cpp Mon Jan 8 13:41:01 2007 @@ -607,11 +607,16 @@ const FunctionType *FTy2 = cast(Ty2); if (FTy->isVarArg() != FTy2->isVarArg() || FTy->getNumParams() != FTy2->getNumParams() || + FTy->getNumAttrs() != FTy2->getNumAttrs() || + FTy->getParamAttrs(0) != FTy2->getParamAttrs(0) || !TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes)) return false; - for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) + for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) { + if (FTy->getParamAttrs(i+1) != FTy->getParamAttrs(i+1)) + return false; if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes)) return false; + } return true; } else { assert(0 && "Unknown derived type!"); From clattner at apple.com Mon Jan 8 14:15:06 2007 From: clattner at apple.com (Chris Lattner) Date: Mon, 8 Jan 2007 12:15:06 -0800 Subject: [llvm-commits] fixed patch for PR1085 Message-ID: <93744687-D120-473F-9D3F-823F94855541@apple.com> Index: method.c =================================================================== --- method.c (revision 122094) +++ method.c (working copy) @@ -392,7 +392,7 @@ use_thunk (tree thunk_fndecl, bool emit_ if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function) /* APPLE LOCAL begin LLVM */ /* PR1085 */ -#ifndef ENABLE_LLVM +#ifdef ENABLE_LLVM && 0 #endif /* APPLE LOCAL end LLVM */ -Chris From jeffc at jolt-lang.org Mon Jan 8 14:17:35 2007 From: jeffc at jolt-lang.org (Jeff Cohen) Date: Mon, 8 Jan 2007 14:17:35 -0600 Subject: [llvm-commits] CVS: llvm/win32/VMCore/VMCore.vcproj Message-ID: <200701082017.l08KHZvV004676@zion.cs.uiuc.edu> Changes in directory llvm/win32/VMCore: VMCore.vcproj updated: 1.24 -> 1.25 --- Log message: Unbreak VC++ build. --- Diffs of the changes: (+0 -3) VMCore.vcproj | 3 --- 1 files changed, 3 deletions(-) Index: llvm/win32/VMCore/VMCore.vcproj diff -u llvm/win32/VMCore/VMCore.vcproj:1.24 llvm/win32/VMCore/VMCore.vcproj:1.25 --- llvm/win32/VMCore/VMCore.vcproj:1.24 Fri Dec 15 15:47:01 2006 +++ llvm/win32/VMCore/VMCore.vcproj Mon Jan 8 14:17:17 2007 @@ -291,9 +291,6 @@ RelativePath="..\..\include\llvm\PassManager.h"> - - Changes in directory llvm/win32/Transforms: Transforms.vcproj updated: 1.23 -> 1.24 --- Log message: Unbreak VC++ build. --- Diffs of the changes: (+0 -3) Transforms.vcproj | 3 --- 1 files changed, 3 deletions(-) Index: llvm/win32/Transforms/Transforms.vcproj diff -u llvm/win32/Transforms/Transforms.vcproj:1.23 llvm/win32/Transforms/Transforms.vcproj:1.24 --- llvm/win32/Transforms/Transforms.vcproj:1.23 Sun Nov 5 13:31:28 2006 +++ llvm/win32/Transforms/Transforms.vcproj Mon Jan 8 14:17:17 2007 @@ -147,9 +147,6 @@ - - Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.587 -> 1.588 --- Log message: Unbreak VC++ build. --- Diffs of the changes: (+1 -1) InstructionCombining.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.587 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.588 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.587 Mon Jan 8 10:32:00 2007 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jan 8 14:17:17 2007 @@ -1091,7 +1091,7 @@ // If the top bit of the output is demanded, demand everything from the // input. Otherwise, we demand all the input bits except NLZ top bits. - uint64_t InDemandedBits = ~0ULL >> 64-BitWidth+NLZ; + uint64_t InDemandedBits = ~0ULL >> (64-BitWidth+NLZ); // Find information about known zero/one bits in the input. if (SimplifyDemandedBits(I->getOperand(0), InDemandedBits, From jlaskey at apple.com Mon Jan 8 16:15:33 2007 From: jlaskey at apple.com (Jim Laskey) Date: Mon, 8 Jan 2007 16:15:33 -0600 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/DwarfWriter.cpp Message-ID: <200701082215.l08MFXQX008036@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: DwarfWriter.cpp updated: 1.110 -> 1.111 --- Log message: Need to handle static declarations properly. --- Diffs of the changes: (+9 -6) DwarfWriter.cpp | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) Index: llvm/lib/CodeGen/DwarfWriter.cpp diff -u llvm/lib/CodeGen/DwarfWriter.cpp:1.110 llvm/lib/CodeGen/DwarfWriter.cpp:1.111 --- llvm/lib/CodeGen/DwarfWriter.cpp:1.110 Wed Jan 3 07:36:40 2007 +++ llvm/lib/CodeGen/DwarfWriter.cpp Mon Jan 8 16:15:18 2007 @@ -1614,7 +1614,8 @@ AddType(Static, StaticTy, Unit); // Add flags. - AddUInt(Static, DW_AT_external, DW_FORM_flag, 1); + if (!StaticDesc->isStatic()) + AddUInt(Static, DW_AT_external, DW_FORM_flag, 1); AddUInt(Static, DW_AT_declaration, DW_FORM_flag, 1); Buffer.AddChild(Static); @@ -1662,7 +1663,8 @@ } // Add flags. - AddUInt(Method, DW_AT_external, DW_FORM_flag, 1); + if (!MethodDesc->isStatic()) + AddUInt(Method, DW_AT_external, DW_FORM_flag, 1); AddUInt(Method, DW_AT_declaration, DW_FORM_flag, 1); Buffer.AddChild(Method); @@ -1773,8 +1775,9 @@ AddString(VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string, LinkageName); } - AddType(VariableDie, GVD->getType(), Unit); - AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1); + AddType(VariableDie, GVD->getType(), Unit); + if (!GVD->isStatic()) + AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1); // Add source line info if available. AddSourceLine(VariableDie, UnitDesc, GVD->getLine()); @@ -1814,7 +1817,6 @@ const std::string &Name = SPD->getName(); const std::string &FullName = SPD->getFullName(); const std::string &LinkageName = SPD->getLinkageName(); - unsigned IsExternal = SPD->isStatic() ? 0 : 1; DIE *SubprogramDie = new DIE(DW_TAG_subprogram); AddString(SubprogramDie, DW_AT_name, DW_FORM_string, Name); @@ -1823,7 +1825,8 @@ LinkageName); } if (SPD->getType()) AddType(SubprogramDie, SPD->getType(), Unit); - AddUInt(SubprogramDie, DW_AT_external, DW_FORM_flag, IsExternal); + if (!SPD->isStatic()) + AddUInt(SubprogramDie, DW_AT_external, DW_FORM_flag, 1); AddUInt(SubprogramDie, DW_AT_prototyped, DW_FORM_flag, 1); // Add source line info if available. From jlaskey at apple.com Mon Jan 8 16:19:48 2007 From: jlaskey at apple.com (Jim Laskey) Date: Mon, 8 Jan 2007 18:19:48 -0400 Subject: [llvm-commits] [llvm-commit][llvm-gcc]Proper way to check for statics. Message-ID: This fixes a problem where debug info was missing static declarations on class members. Cheers, -- Jim -------------- next part -------------- A non-text attachment was scrubbed... Name: static.patch Type: application/octet-stream Size: 1103 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070108/438f0135/attachment.obj -------------- next part -------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070108/438f0135/attachment.bin From sabre at nondot.org Mon Jan 8 17:03:34 2007 From: sabre at nondot.org (Chris Lattner) Date: Mon, 8 Jan 2007 17:03:34 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/PowerPC/unsafe-math.ll Message-ID: <200701082303.l08N3YXP008873@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/PowerPC: unsafe-math.ll added (r1.1) --- Log message: new testcase --- Diffs of the changes: (+9 -0) unsafe-math.ll | 9 +++++++++ 1 files changed, 9 insertions(+) Index: llvm/test/Regression/CodeGen/PowerPC/unsafe-math.ll diff -c /dev/null llvm/test/Regression/CodeGen/PowerPC/unsafe-math.ll:1.1 *** /dev/null Mon Jan 8 17:03:29 2007 --- llvm/test/Regression/CodeGen/PowerPC/unsafe-math.ll Mon Jan 8 17:03:19 2007 *************** *** 0 **** --- 1,9 ---- + ; RUN: llvm-as < %s | llc -march=ppc32 | grep fmul | wc -l | grep 2 && + ; RUN: llvm-as < %s | llc -march=ppc32 -enable-unsafe-fp-math | grep fmul | wc -l | grep 1 + + define double %foo(double %X) { + %tmp1 = mul double %X, 1.23 + %tmp2 = mul double %tmp1, 4.124 + ret double %tmp2 + } + From sabre at nondot.org Mon Jan 8 17:04:21 2007 From: sabre at nondot.org (Chris Lattner) Date: Mon, 8 Jan 2007 17:04:21 -0600 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Message-ID: <200701082304.l08N4Lnv008914@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: DAGCombiner.cpp updated: 1.264 -> 1.265 --- Log message: Implement some trivial FP foldings when -enable-unsafe-fp-math is specified. This implements CodeGen/PowerPC/unsafe-math.ll --- Diffs of the changes: (+15 -0) DAGCombiner.cpp | 15 +++++++++++++++ 1 files changed, 15 insertions(+) Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.264 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.265 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.264 Tue Dec 19 16:41:21 2006 +++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Jan 8 17:04:05 2007 @@ -35,6 +35,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetLowering.h" +#include "llvm/Target/TargetOptions.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/CommandLine.h" #include @@ -2401,6 +2402,13 @@ // fold ((-A) + B) -> B-A if (N0.getOpcode() == ISD::FNEG) return DAG.getNode(ISD::FSUB, VT, N1, N0.getOperand(0)); + + // If allowed, fold (fadd (fadd x, c1), c2) -> (fadd x, (fadd c1, c2)) + if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FADD && + N0.Val->hasOneUse() && isa(N0.getOperand(1))) + return DAG.getNode(ISD::FADD, VT, N0.getOperand(0), + DAG.getNode(ISD::FADD, VT, N0.getOperand(1), N1)); + return SDOperand(); } @@ -2436,6 +2444,13 @@ // fold (fmul X, 2.0) -> (fadd X, X) if (N1CFP && N1CFP->isExactlyValue(+2.0)) return DAG.getNode(ISD::FADD, VT, N0, N0); + + // If allowed, fold (fmul (fmul x, c1), c2) -> (fmul x, (fmul c1, c2)) + if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FMUL && + N0.Val->hasOneUse() && isa(N0.getOperand(1))) + return DAG.getNode(ISD::FMUL, VT, N0.getOperand(0), + DAG.getNode(ISD::FMUL, VT, N0.getOperand(1), N1)); + return SDOperand(); } From evan.cheng at apple.com Mon Jan 8 17:50:53 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 8 Jan 2007 17:50:53 -0600 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp Message-ID: <200701082350.l08Norx5009713@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: ScheduleDAGRRList.cpp updated: 1.23 -> 1.24 --- Log message: Fix for PR1075: http://llvm.org/PR1075 : bottom-up register-reduction scheduling actually increases register pressure. - Fixed bugs in sethi-ullman number computation and priority queue comparison functions. - Separate code that handles priority computation special cases from SU number computation. --- Diffs of the changes: (+72 -120) ScheduleDAGRRList.cpp | 192 ++++++++++++++++++-------------------------------- 1 files changed, 72 insertions(+), 120 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp diff -u llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp:1.23 llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp:1.24 --- llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp:1.23 Thu Dec 7 14:04:42 2006 +++ llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp Mon Jan 8 17:50:38 2007 @@ -414,6 +414,12 @@ }; } // end anonymous namespace +static inline bool isCopyFromLiveIn(const SUnit *SU) { + SDNode *N = SU->Node; + return N->getOpcode() == ISD::CopyFromReg && + N->getOperand(N->getNumOperands()-1).getValueType() != MVT::Flag; +} + namespace { template class VISIBILITY_HIDDEN RegReductionPriorityQueue @@ -428,7 +434,7 @@ std::vector &sunits) {} virtual void releaseState() {} - virtual int getSethiUllmanNumber(unsigned NodeNum) const { + virtual unsigned getSethiUllmanNumber(const SUnit *SU) const { return 0; } @@ -464,7 +470,7 @@ const std::vector *SUnits; // SethiUllmanNumbers - The SethiUllman number for each node. - std::vector SethiUllmanNumbers; + std::vector SethiUllmanNumbers; const TargetInstrInfo *TII; public: @@ -486,9 +492,30 @@ SethiUllmanNumbers.clear(); } - int getSethiUllmanNumber(unsigned NodeNum) const { - assert(NodeNum < SethiUllmanNumbers.size()); - return SethiUllmanNumbers[NodeNum]; + unsigned getSethiUllmanNumber(const SUnit *SU) const { + assert(SU->NodeNum < SethiUllmanNumbers.size()); + unsigned Opc = SU->Node->getOpcode(); + if (Opc == ISD::CopyFromReg && !isCopyFromLiveIn(SU)) + // CopyFromReg should be close to its def because it restricts + // allocation choices. But if it is a livein then perhaps we want it + // closer to its uses so it can be coalesced. + return 0xffff; + else if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg) + // CopyToReg should be close to its uses to facilitate coalescing and + // avoid spilling. + return 0; + else if (SU->NumSuccs == 0) + // If SU does not have a use, i.e. it doesn't produce a value that would + // be consumed (e.g. store), then it terminates a chain of computation. + // Give it a large SethiUllman number so it will be scheduled right + // before its predecessors that it doesn't lengthen their live ranges. + return 0xffff; + else if (SU->NumPreds == 0) + // If SU does not have a def, schedule it close to its uses because it + // does not lengthen any live ranges. + return 0; + else + return SethiUllmanNumbers[SU->NodeNum]; } bool isDUOperand(const SUnit *SU1, const SUnit *SU2) { @@ -507,7 +534,7 @@ bool canClobber(SUnit *SU, SUnit *Op); void AddPseudoTwoAddrDeps(); void CalculatePriorities(); - int CalcNodePriority(const SUnit *SU); + unsigned CalcNodePriority(const SUnit *SU); }; @@ -520,7 +547,7 @@ const std::vector *SUnits; // SethiUllmanNumbers - The SethiUllman number for each node. - std::vector SethiUllmanNumbers; + std::vector SethiUllmanNumbers; public: TDRegReductionPriorityQueue() {} @@ -538,86 +565,38 @@ SethiUllmanNumbers.clear(); } - int getSethiUllmanNumber(unsigned NodeNum) const { - assert(NodeNum < SethiUllmanNumbers.size()); - return SethiUllmanNumbers[NodeNum]; + unsigned getSethiUllmanNumber(const SUnit *SU) const { + assert(SU->NodeNum < SethiUllmanNumbers.size()); + return SethiUllmanNumbers[SU->NodeNum]; } private: void CalculatePriorities(); - int CalcNodePriority(const SUnit *SU); + unsigned CalcNodePriority(const SUnit *SU); }; } -static bool isFloater(const SUnit *SU) { - if (SU->Node->isTargetOpcode()) { - if (SU->NumPreds == 0) - return true; - if (SU->NumPreds == 1) { - for (SUnit::const_pred_iterator I = SU->Preds.begin(),E = SU->Preds.end(); - I != E; ++I) { - if (I->second) continue; - - SUnit *PredSU = I->first; - unsigned Opc = PredSU->Node->getOpcode(); - if (Opc != ISD::EntryToken && Opc != ISD::TokenFactor && - Opc != ISD::CopyToReg) - return false; - } - return true; - } - } - return false; -} - -static bool isSimpleFloaterUse(const SUnit *SU) { - unsigned NumOps = 0; - for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); - I != E; ++I) { - if (I->second) continue; - if (++NumOps > 1) - return false; - if (!isFloater(I->first)) - return false; - } - return true; -} - // Bottom up bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { - unsigned LeftNum = left->NodeNum; - unsigned RightNum = right->NodeNum; bool LIsTarget = left->Node->isTargetOpcode(); bool RIsTarget = right->Node->isTargetOpcode(); - int LPriority = SPQ->getSethiUllmanNumber(LeftNum); - int RPriority = SPQ->getSethiUllmanNumber(RightNum); - int LBonus = 0; - int RBonus = 0; - - // Schedule floaters (e.g. load from some constant address) and those nodes - // with a single predecessor each first. They maintain / reduce register - // pressure. - if (isFloater(left) || isSimpleFloaterUse(left)) - LBonus += 2; - if (isFloater(right) || isSimpleFloaterUse(right)) - RBonus += 2; + unsigned LPriority = SPQ->getSethiUllmanNumber(left); + unsigned RPriority = SPQ->getSethiUllmanNumber(right); // Special tie breaker: if two nodes share a operand, the one that use it // as a def&use operand is preferred. if (LIsTarget && RIsTarget) { - if (left->isTwoAddress && !right->isTwoAddress) { + if (left->isTwoAddress && !right->isTwoAddress) if (SPQ->isDUOperand(left, right)) - LBonus += 2; - } - if (!left->isTwoAddress && right->isTwoAddress) { + return false; + if (!left->isTwoAddress && right->isTwoAddress) if (SPQ->isDUOperand(right, left)) - RBonus += 2; - } + return true; } - if (LPriority+LBonus < RPriority+RBonus) + if (LPriority > RPriority) return true; - else if (LPriority+LBonus == RPriority+RBonus) + else if (LPriority == RPriority) if (left->Height > right->Height) return true; else if (left->Height == right->Height) @@ -629,12 +608,6 @@ return false; } -static inline bool isCopyFromLiveIn(const SUnit *SU) { - SDNode *N = SU->Node; - return N->getOpcode() == ISD::CopyFromReg && - N->getOperand(N->getNumOperands()-1).getValueType() != MVT::Flag; -} - // FIXME: This is probably too slow! static void isReachable(SUnit *SU, SUnit *TargetSU, std::set &Visited, bool &Reached) { @@ -723,47 +696,28 @@ /// CalcNodePriority - Priority is the Sethi Ullman number. /// Smaller number is the higher priority. template -int BURegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { - int &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; +unsigned BURegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { + unsigned &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; if (SethiUllmanNumber != 0) return SethiUllmanNumber; - unsigned Opc = SU->Node->getOpcode(); - if (Opc == ISD::CopyFromReg && !isCopyFromLiveIn(SU)) - // CopyFromReg should be close to its def because it restricts allocation - // choices. But if it is a livein then perhaps we want it closer to the - // uses so it can be coalesced. - SethiUllmanNumber = INT_MIN + 10; - else if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg) - // CopyToReg should be close to its uses to facilitate coalescing and avoid - // spilling. - SethiUllmanNumber = INT_MAX - 10; - else if (SU->NumSuccsLeft == 0) - // If SU does not have a use, i.e. it doesn't produce a value that would - // be consumed (e.g. store), then it terminates a chain of computation. - // Give it a small SethiUllman number so it will be scheduled right before its - // predecessors that it doesn't lengthen their live ranges. - SethiUllmanNumber = INT_MIN + 10; - else if (SU->NumPredsLeft == 0) - // If SU does not have a def, schedule it close to its uses because it does - // not lengthen any live ranges. - SethiUllmanNumber = INT_MAX - 10; - else { - int Extra = 0; - for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); - I != E; ++I) { - if (I->second) continue; // ignore chain preds - SUnit *PredSU = I->first; - int PredSethiUllman = CalcNodePriority(PredSU); - if (PredSethiUllman > SethiUllmanNumber) { - SethiUllmanNumber = PredSethiUllman; - Extra = 0; - } else if (PredSethiUllman == SethiUllmanNumber && !I->second) - Extra++; - } - - SethiUllmanNumber += Extra; + unsigned Extra = 0; + for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); + I != E; ++I) { + if (I->second) continue; // ignore chain preds + SUnit *PredSU = I->first; + unsigned PredSethiUllman = CalcNodePriority(PredSU); + if (PredSethiUllman > SethiUllmanNumber) { + SethiUllmanNumber = PredSethiUllman; + Extra = 0; + } else if (PredSethiUllman == SethiUllmanNumber && !I->second) + Extra++; } + + SethiUllmanNumber += Extra; + + if (SethiUllmanNumber == 0) + SethiUllmanNumber = 1; return SethiUllmanNumber; } @@ -796,10 +750,8 @@ // Top down bool td_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { - unsigned LeftNum = left->NodeNum; - unsigned RightNum = right->NodeNum; - int LPriority = SPQ->getSethiUllmanNumber(LeftNum); - int RPriority = SPQ->getSethiUllmanNumber(RightNum); + unsigned LPriority = SPQ->getSethiUllmanNumber(left); + unsigned RPriority = SPQ->getSethiUllmanNumber(right); bool LIsTarget = left->Node->isTargetOpcode(); bool RIsTarget = right->Node->isTargetOpcode(); bool LIsFloater = LIsTarget && left->NumPreds == 0; @@ -852,30 +804,30 @@ /// CalcNodePriority - Priority is the Sethi Ullman number. /// Smaller number is the higher priority. template -int TDRegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { - int &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; +unsigned TDRegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { + unsigned &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; if (SethiUllmanNumber != 0) return SethiUllmanNumber; unsigned Opc = SU->Node->getOpcode(); if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg) - SethiUllmanNumber = INT_MAX - 10; + SethiUllmanNumber = 0xffff; else if (SU->NumSuccsLeft == 0) // If SU does not have a use, i.e. it doesn't produce a value that would // be consumed (e.g. store), then it terminates a chain of computation. // Give it a small SethiUllman number so it will be scheduled right before its // predecessors that it doesn't lengthen their live ranges. - SethiUllmanNumber = INT_MIN + 10; + SethiUllmanNumber = 0; else if (SU->NumPredsLeft == 0 && (Opc != ISD::CopyFromReg || isCopyFromLiveIn(SU))) - SethiUllmanNumber = 1; + SethiUllmanNumber = 0xffff; else { int Extra = 0; for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); I != E; ++I) { if (I->second) continue; // ignore chain preds SUnit *PredSU = I->first; - int PredSethiUllman = CalcNodePriority(PredSU); + unsigned PredSethiUllman = CalcNodePriority(PredSU); if (PredSethiUllman > SethiUllmanNumber) { SethiUllmanNumber = PredSethiUllman; Extra = 0; From evan.cheng at apple.com Mon Jan 8 17:56:08 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 8 Jan 2007 17:56:08 -0600 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp Message-ID: <200701082356.l08Nu8PC009824@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: ScheduleDAGRRList.cpp updated: 1.24 -> 1.25 --- Log message: Naming consistency. --- Diffs of the changes: (+27 -25) ScheduleDAGRRList.cpp | 52 +++++++++++++++++++++++++------------------------- 1 files changed, 27 insertions(+), 25 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp diff -u llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp:1.24 llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp:1.25 --- llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp:1.24 Mon Jan 8 17:50:38 2007 +++ llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp Mon Jan 8 17:55:53 2007 @@ -434,7 +434,7 @@ std::vector &sunits) {} virtual void releaseState() {} - virtual unsigned getSethiUllmanNumber(const SUnit *SU) const { + virtual unsigned getNodePriority(const SUnit *SU) const { return 0; } @@ -484,7 +484,7 @@ // Add pseudo dependency edges for two-address nodes. AddPseudoTwoAddrDeps(); // Calculate node priorities. - CalculatePriorities(); + CalculateSethiUllmanNumbers(); } void releaseState() { @@ -492,7 +492,7 @@ SethiUllmanNumbers.clear(); } - unsigned getSethiUllmanNumber(const SUnit *SU) const { + unsigned getNodePriority(const SUnit *SU) const { assert(SU->NodeNum < SethiUllmanNumbers.size()); unsigned Opc = SU->Node->getOpcode(); if (Opc == ISD::CopyFromReg && !isCopyFromLiveIn(SU)) @@ -533,8 +533,8 @@ private: bool canClobber(SUnit *SU, SUnit *Op); void AddPseudoTwoAddrDeps(); - void CalculatePriorities(); - unsigned CalcNodePriority(const SUnit *SU); + void CalculateSethiUllmanNumbers(); + unsigned CalcNodeSethiUllmanNumber(const SUnit *SU); }; @@ -557,7 +557,7 @@ SUnitMap = &sumap; SUnits = &sunits; // Calculate node priorities. - CalculatePriorities(); + CalculateSethiUllmanNumbers(); } void releaseState() { @@ -565,14 +565,14 @@ SethiUllmanNumbers.clear(); } - unsigned getSethiUllmanNumber(const SUnit *SU) const { + unsigned getNodePriority(const SUnit *SU) const { assert(SU->NodeNum < SethiUllmanNumbers.size()); return SethiUllmanNumbers[SU->NodeNum]; } private: - void CalculatePriorities(); - unsigned CalcNodePriority(const SUnit *SU); + void CalculateSethiUllmanNumbers(); + unsigned CalcNodeSethiUllmanNumber(const SUnit *SU); }; } @@ -580,8 +580,6 @@ bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { bool LIsTarget = left->Node->isTargetOpcode(); bool RIsTarget = right->Node->isTargetOpcode(); - unsigned LPriority = SPQ->getSethiUllmanNumber(left); - unsigned RPriority = SPQ->getSethiUllmanNumber(right); // Special tie breaker: if two nodes share a operand, the one that use it // as a def&use operand is preferred. @@ -594,6 +592,8 @@ return true; } + unsigned LPriority = SPQ->getNodePriority(left); + unsigned RPriority = SPQ->getNodePriority(right); if (LPriority > RPriority) return true; else if (LPriority == RPriority) @@ -693,10 +693,10 @@ } } -/// CalcNodePriority - Priority is the Sethi Ullman number. +/// CalcNodeSethiUllmanNumber - Priority is the Sethi Ullman number. /// Smaller number is the higher priority. template -unsigned BURegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { +unsigned BURegReductionPriorityQueue::CalcNodeSethiUllmanNumber(const SUnit *SU) { unsigned &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; if (SethiUllmanNumber != 0) return SethiUllmanNumber; @@ -706,7 +706,7 @@ I != E; ++I) { if (I->second) continue; // ignore chain preds SUnit *PredSU = I->first; - unsigned PredSethiUllman = CalcNodePriority(PredSU); + unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU); if (PredSethiUllman > SethiUllmanNumber) { SethiUllmanNumber = PredSethiUllman; Extra = 0; @@ -722,13 +722,14 @@ return SethiUllmanNumber; } -/// CalculatePriorities - Calculate priorities of all scheduling units. +/// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all +/// scheduling units. template -void BURegReductionPriorityQueue::CalculatePriorities() { +void BURegReductionPriorityQueue::CalculateSethiUllmanNumbers() { SethiUllmanNumbers.assign(SUnits->size(), 0); for (unsigned i = 0, e = SUnits->size(); i != e; ++i) - CalcNodePriority(&(*SUnits)[i]); + CalcNodeSethiUllmanNumber(&(*SUnits)[i]); } static unsigned SumOfUnscheduledPredsOfSuccs(const SUnit *SU) { @@ -750,8 +751,8 @@ // Top down bool td_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const { - unsigned LPriority = SPQ->getSethiUllmanNumber(left); - unsigned RPriority = SPQ->getSethiUllmanNumber(right); + unsigned LPriority = SPQ->getNodePriority(left); + unsigned RPriority = SPQ->getNodePriority(right); bool LIsTarget = left->Node->isTargetOpcode(); bool RIsTarget = right->Node->isTargetOpcode(); bool LIsFloater = LIsTarget && left->NumPreds == 0; @@ -801,10 +802,10 @@ return false; } -/// CalcNodePriority - Priority is the Sethi Ullman number. +/// CalcNodeSethiUllmanNumber - Priority is the Sethi Ullman number. /// Smaller number is the higher priority. template -unsigned TDRegReductionPriorityQueue::CalcNodePriority(const SUnit *SU) { +unsigned TDRegReductionPriorityQueue::CalcNodeSethiUllmanNumber(const SUnit *SU) { unsigned &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum]; if (SethiUllmanNumber != 0) return SethiUllmanNumber; @@ -827,7 +828,7 @@ I != E; ++I) { if (I->second) continue; // ignore chain preds SUnit *PredSU = I->first; - unsigned PredSethiUllman = CalcNodePriority(PredSU); + unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU); if (PredSethiUllman > SethiUllmanNumber) { SethiUllmanNumber = PredSethiUllman; Extra = 0; @@ -841,13 +842,14 @@ return SethiUllmanNumber; } -/// CalculatePriorities - Calculate priorities of all scheduling units. +/// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all +/// scheduling units. template -void TDRegReductionPriorityQueue::CalculatePriorities() { +void TDRegReductionPriorityQueue::CalculateSethiUllmanNumbers() { SethiUllmanNumbers.assign(SUnits->size(), 0); for (unsigned i = 0, e = SUnits->size(); i != e; ++i) - CalcNodePriority(&(*SUnits)[i]); + CalcNodeSethiUllmanNumber(&(*SUnits)[i]); } //===----------------------------------------------------------------------===// From evan.cheng at apple.com Mon Jan 8 17:57:55 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 8 Jan 2007 17:57:55 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/X86/2006-05-02-InstrSched2.ll Message-ID: <200701082357.l08NvtBu009890@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/X86: 2006-05-02-InstrSched2.ll updated: 1.3 -> 1.4 --- Log message: Undo xfail now scheduler deficiency has been fixed. --- Diffs of the changes: (+1 -2) 2006-05-02-InstrSched2.ll | 3 +-- 1 files changed, 1 insertion(+), 2 deletions(-) Index: llvm/test/Regression/CodeGen/X86/2006-05-02-InstrSched2.ll diff -u llvm/test/Regression/CodeGen/X86/2006-05-02-InstrSched2.ll:1.3 llvm/test/Regression/CodeGen/X86/2006-05-02-InstrSched2.ll:1.4 --- llvm/test/Regression/CodeGen/X86/2006-05-02-InstrSched2.ll:1.3 Fri Dec 1 22:23:08 2006 +++ llvm/test/Regression/CodeGen/X86/2006-05-02-InstrSched2.ll Mon Jan 8 17:57:40 2007 @@ -1,5 +1,4 @@ -; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 -stats 2>&1 | grep "asm-printer" | grep 19 -; XFAIL: * +; RUN: llvm-upgrade < %s | llvm-as | llc -march=x86 -stats 2>&1 | grep "asm-printer" | grep 18 void %_ZN9__gnu_cxx9hashtableISt4pairIKPKciES3_NS_4hashIS3_EESt10_Select1stIS5_E5eqstrSaIiEE14find_or_insertERKS5__cond_true456.i(sbyte* %tmp435.i, uint* %tmp449.i.out) { newFuncRoot: From evan.cheng at apple.com Mon Jan 8 17:58:42 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 8 Jan 2007 17:58:42 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll Message-ID: <200701082358.l08NwgYg009914@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/X86: 2007-01-08-InstrSched.ll added (r1.1) --- Log message: Added a test case from PR1075: http://llvm.org/PR1075 . --- Diffs of the changes: (+13 -0) 2007-01-08-InstrSched.ll | 13 +++++++++++++ 1 files changed, 13 insertions(+) Index: llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll diff -c /dev/null llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll:1.1 *** /dev/null Mon Jan 8 17:58:37 2007 --- llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll Mon Jan 8 17:58:27 2007 *************** *** 0 **** --- 1,13 ---- + ; RUN: llvm-as < %s | llvm-as | llc -mtriple=x86_64-apple-darwin | \ + ; RUN: %prcontext 'mulss LCPI1_3' 1 | grep mulss | wc -l | grep 1 + + define float %foo(float %x) { + %tmp1 = mul float %x, 3.000000e+00 + %tmp3 = mul float %x, 5.000000e+00 + %tmp5 = mul float %x, 7.000000e+00 + %tmp7 = mul float %x, 1.100000e+01 + %tmp10 = add float %tmp1, %tmp3 + %tmp12 = add float %tmp10, %tmp5 + %tmp14 = add float %tmp12, %tmp7 + ret float %tmp14 + } From reid at x10sys.com Mon Jan 8 18:06:11 2007 From: reid at x10sys.com (Reid Spencer) Date: Mon, 8 Jan 2007 18:06:11 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp Message-ID: <200701090006.l0906Bcd010051@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/C++Frontend: 2007-01-06-ELF-Thunk-Sections.cpp updated: 1.2 -> 1.3 --- Log message: PR1085: http://llvm.org/PR1085 is fixed now. --- Diffs of the changes: (+0 -1) 2007-01-06-ELF-Thunk-Sections.cpp | 1 - 1 files changed, 1 deletion(-) Index: llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp diff -u llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp:1.2 llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp:1.3 --- llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp:1.2 Mon Jan 8 13:38:58 2007 +++ llvm/test/Regression/C++Frontend/2007-01-06-ELF-Thunk-Sections.cpp Mon Jan 8 18:05:55 2007 @@ -1,7 +1,6 @@ // RUN: %llvmgxx %s -emit-llvm -S -o - && // RUN: %llvmgxx %s -emit-llvm -S -o - | not grep 'gnu.linkonce.' // PR1085 -// XFAIL: i.86-pc-linux-* class __attribute__((visibility("default"))) QGenericArgument From evan.cheng at apple.com Mon Jan 8 18:09:49 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Mon, 8 Jan 2007 18:09:49 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll Message-ID: <200701090009.l0909nts010126@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/X86: 2007-01-08-InstrSched.ll updated: 1.1 -> 1.2 --- Log message: Fix test case. --- Diffs of the changes: (+1 -1) 2007-01-08-InstrSched.ll | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll diff -u llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll:1.1 llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll:1.2 --- llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll:1.1 Mon Jan 8 17:58:27 2007 +++ llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll Mon Jan 8 18:09:34 2007 @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | llvm-as | llc -mtriple=x86_64-apple-darwin | \ +; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin | \ ; RUN: %prcontext 'mulss LCPI1_3' 1 | grep mulss | wc -l | grep 1 define float %foo(float %x) { From sabre at nondot.org Mon Jan 8 18:32:08 2007 From: sabre at nondot.org (Chris Lattner) Date: Mon, 8 Jan 2007 18:32:08 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll Message-ID: <200701090032.l090W8RF010572@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/X86: 2007-01-08-InstrSched.ll updated: 1.2 -> 1.3 --- Log message: Add PR number for future reference --- Diffs of the changes: (+1 -0) 2007-01-08-InstrSched.ll | 1 + 1 files changed, 1 insertion(+) Index: llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll diff -u llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll:1.2 llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll:1.3 --- llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll:1.2 Mon Jan 8 18:09:34 2007 +++ llvm/test/Regression/CodeGen/X86/2007-01-08-InstrSched.ll Mon Jan 8 18:31:52 2007 @@ -1,5 +1,6 @@ ; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin | \ ; RUN: %prcontext 'mulss LCPI1_3' 1 | grep mulss | wc -l | grep 1 +; PR1075 define float %foo(float %x) { %tmp1 = mul float %x, 3.000000e+00 From chandlerc at gmail.com Mon Jan 8 20:38:44 2007 From: chandlerc at gmail.com (Chandler Carruth) Date: Mon, 8 Jan 2007 20:38:44 -0600 Subject: [llvm-commits] CVS: llvm/tools/llvm-config/Makefile Message-ID: <200701090238.l092ci5Z012841@zion.cs.uiuc.edu> Changes in directory llvm/tools/llvm-config: Makefile updated: 1.20 -> 1.21 --- Log message: Fixing a ">" redirect to be a ">>" redirect, so a sed command doesn't get clobbered. --- Diffs of the changes: (+1 -1) Makefile | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/tools/llvm-config/Makefile diff -u llvm/tools/llvm-config/Makefile:1.20 llvm/tools/llvm-config/Makefile:1.21 --- llvm/tools/llvm-config/Makefile:1.20 Fri Jan 5 20:48:03 2007 +++ llvm/tools/llvm-config/Makefile Mon Jan 8 20:38:29 2007 @@ -57,7 +57,7 @@ $(ToolDir)/llvm-config: llvm-config.in $(FinalLibDeps) $(Echo) "Building llvm-config script." $(Verb) $(ECHO) 's, at LLVM_CFLAGS@,$(SUB_CFLAGS),' > temp.sed - $(Verb) $(ECHO) 's, at LLVM_CXXFLAGS@,$(SUB_CXXFLAGS),' > temp.sed + $(Verb) $(ECHO) 's, at LLVM_CXXFLAGS@,$(SUB_CXXFLAGS),' >> temp.sed $(Verb) $(ECHO) 's, at LLVM_LDFLAGS@,$(SUB_LDFLAGS),' >> temp.sed $(Verb) $(ECHO) 's, at LLVM_BUILDMODE@,$(BuildMode),' >> temp.sed $(Verb) $(SED) -f temp.sed < $< > $@ From llvm at cs.uiuc.edu Mon Jan 8 20:48:27 2007 From: llvm at cs.uiuc.edu (LLVM) Date: Mon, 8 Jan 2007 20:48:27 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/ Message-ID: <200701090248.l092mRD3013010@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From llvm at cs.uiuc.edu Mon Jan 8 21:16:46 2007 From: llvm at cs.uiuc.edu (LLVM) Date: Mon, 8 Jan 2007 21:16:46 -0600 Subject: [llvm-commits] CVS: llvm-test/MutiSource/Benchmarks/MiBench/ Message-ID: <200701090316.l093GkYf013438@zion.cs.uiuc.edu> Changes in directory llvm-test/MutiSource/Benchmarks/MiBench: --- Log message: Add selected tests from MiBench 1.0 to LLVM test suite. Status: Vendor Tag: UofM Release Tags: V1_0 N llvm-test/MutiSource/Benchmarks/MiBench/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/automotive/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/basicmath.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/round.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/pi.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/isqrt.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/cubic.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/sniptype.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/snipmath.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/automotive/basicmath/rad2deg.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitcnt_3.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitcnt_2.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitcnts.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/conio.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/extkword.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitarray.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitops.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitfiles.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/sniptype.h N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitstrng.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitcnt_4.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bstr_i.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/bitcnt_1.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/bitcount/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/automotive/susan/input_large.pgm N llvm-test/MutiSource/Benchmarks/MiBench/automotive/susan/susan.c N llvm-test/MutiSource/Benchmarks/MiBench/automotive/susan/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/automotive/susan/input_small.pgm N llvm-test/MutiSource/Benchmarks/MiBench/automotive/susan/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/network/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/network/patricia/small.udp N llvm-test/MutiSource/Benchmarks/MiBench/network/patricia/patricia.h N llvm-test/MutiSource/Benchmarks/MiBench/network/patricia/patricia_test.c N llvm-test/MutiSource/Benchmarks/MiBench/network/patricia/patricia.c N llvm-test/MutiSource/Benchmarks/MiBench/network/patricia/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/network/patricia/large.udp N llvm-test/MutiSource/Benchmarks/MiBench/network/patricia/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/network/dijkstra/dijkstra.c N llvm-test/MutiSource/Benchmarks/MiBench/network/dijkstra/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/network/dijkstra/input.dat N llvm-test/MutiSource/Benchmarks/MiBench/network/dijkstra/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/security/sha/sha.h N llvm-test/MutiSource/Benchmarks/MiBench/security/sha/input_large.asc N llvm-test/MutiSource/Benchmarks/MiBench/security/sha/sha.c N llvm-test/MutiSource/Benchmarks/MiBench/security/sha/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/security/sha/input_small.asc N llvm-test/MutiSource/Benchmarks/MiBench/security/sha/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/security/sha/sha_driver.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_ecb.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_skey.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_cfb64.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_cbc.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/COPYRIGHT N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_ofb64.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/blowfish.h N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/input_large.asc N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bftest.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_enc.c N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_locl.h N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/bf_pi.h N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/input_small.asc N llvm-test/MutiSource/Benchmarks/MiBench/security/blowfish/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/output_large.enc N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/aesxam.c N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/output_large.dec N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/input_large.asc N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/aestab.h N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/aes.c N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/aes.h N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/input_small.asc N llvm-test/MutiSource/Benchmarks/MiBench/security/rijndael/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/consumer/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/wrbmp.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdmaster.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/input_small.jpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jinclude.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jfdctint.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jconfig.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jidctint.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcparam.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdtrans.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jpeglib.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jmemmgr.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdmerge.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jmorecfg.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/cderror.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/cdjpeg.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/cdjpeg.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jccolor.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdinput.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/input_small.ppm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jidctfst.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdmarker.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdsample.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jmemnobs.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcmaster.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/wrrle.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jidctflt.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdphuff.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/djpeg.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/wrtarga.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdcoefct.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/rdcolmap.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/input_large.jpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jquant2.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jchuff.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/wrgif.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcsample.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdcolor.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcapimin.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jfdctfst.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdapistd.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcmarker.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdhuff.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/README N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jmemsys.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jchuff.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jfdctflt.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdatadst.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcmainct.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcomapi.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jerror.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdhuff.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdct.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdatasrc.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jquant1.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jerror.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jidctred.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcapistd.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdmainct.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/wrppm.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jutils.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jctrans.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcdctmgr.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jpegint.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcinit.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdpostct.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jddctmgr.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jdapimin.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/input_large.ppm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jccoefct.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcprepct.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jcphuff.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/jpeg/jversion.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/get_audio.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/tables.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/output_large.mp3 N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/timestatus.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/gtkanal.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/VbrTag.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/newmdct.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/tabinit.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/version.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/gpkplotting.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/util.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/rtp.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/formatBitstream.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/gtkanal.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/formatBitstream.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/parse.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/encoder.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/huffman.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/l3bitstream-pvt.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/.cvsignore N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/portableio.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/mpg123.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/util.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/psymodel.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/l3bitstream.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/quantize-pvt.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/ieeefloat.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/machine.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/quantize.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/tables.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/reservoir.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/quantize.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/ieeefloat.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/id3tag.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/l3side.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/portableio.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/get_audio.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/VbrTag.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/rtp.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/layer3.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/README N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/id3tag.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/gpkplotting.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/l3bitstream.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/mpglib.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/main.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/newmdct.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/version.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/takehiro.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/reservoir.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/common.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/fft.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/decode_i386.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/lame.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/brhist.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/large.wav N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/quantize-pvt.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/dct64_i386.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/timestatus.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/brhist.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/fft.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/vbrquantize.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/small.wav N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/mpglib_main.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/interface.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/psymodel.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/lame.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/lame/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z33.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z40.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z23.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z04.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z03.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z45.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z44.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/small.lout N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z01.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z38.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z29.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z21.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z15.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z36.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z37.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z47.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z10.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z35.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z28.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z12.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/externs.h N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z25.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z08.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z43.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z26.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z30.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z19.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/lout.li N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z14.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z05.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z32.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/large.lout.ld N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z31.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z06.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z09.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z22.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z11.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z34.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z51.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z20.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z17.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z48.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z18.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z42.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z24.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z49.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z39.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/large.lout N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z13.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z46.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z02.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z07.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z16.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z27.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z50.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/z41.c N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/slovenia.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/portugal.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/engluk.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/dutch.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/polish.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/swedish.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/danish.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/finnish.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/english.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/czech.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/norweg.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/README N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/german.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/english.lp N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/russian.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/italian.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/spanish.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/hyph/french.lh N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-UlCm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-NrBdO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr-BdO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-DmO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Bl N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Rm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-RmSC+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Lt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnLi+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-DmIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnLiO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Rm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr-O+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-BdItF+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-BdIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-SC N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-BlO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Cm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-BdO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Bk N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-BdItF N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-It N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnLiO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-MdIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Dm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBlO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-LtIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-BdIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZD N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-Rm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBlO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-BdItF N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Nr+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-DmIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-MdO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-NrBdO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Dm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-BlO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-BdIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-ItF N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-ExLtO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-Rm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-Rm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-It N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnMd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-ExLt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-BdSC+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnLi N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-NrO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Dm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr-BdO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-Rm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-MdIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Md+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-ExBd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-LtIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Dm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Bl+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Lt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-O+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-NrO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-It N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-ExtC+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-MdO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnBk+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-It+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBdO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnBd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-SmIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Lt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-O N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-LtIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Cm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-RmSC N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnDm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-It+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-LtO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Md N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Lt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-MdIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-BdSC N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBdO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-SmIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-UlCm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnBd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-ItF+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-It+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-BdF N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-SC+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnBk N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnDm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Bk+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr-O N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Nr N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-ExtC N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Md+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-BdIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-BdO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-BdIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-ItF N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Md N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-NrBd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Lt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Symbol N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-NrBd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Cr N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-BkO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-BdIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/00README N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Dm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-Rm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-DmO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-LtO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-ExLtO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Cn+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-Bd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBl N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-CnBl+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/NCS-BdIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-BdItF+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-Sm+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He-Cn N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-BdO+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/He N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Pa-BdF+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-MdIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-LtIt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-It+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-ExLt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-ItF+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-Rm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-It N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-CnMd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-Sm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Ti-ExBd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-BdIt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-BdO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Bd+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/AG-BkO N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/ZC-Lt+ N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/font/Bk-Dm N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/python N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/eiffel N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/cprint N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/book N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/podf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/bookf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/figf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/doc N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/ts N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/russian.fd N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/reportf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/init N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/mydefs N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/graphf.etc N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/modula N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/graphf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/docf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/picture N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/pas N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/latin2 N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/eqf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/figf.lpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/langdefs N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/cprintf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/eiffelf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/russian N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/tab N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/bluef N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/perl N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/diag N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/perlf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/report N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/tblf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/bsf.lpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/pod N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/README N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/pythonf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/diagf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/modulaf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/slidesf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/slides N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/dsf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/bsf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/tabf.lpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/tblf.lpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/graphf.lpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/blue N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/pasf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/fig N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/eq N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/tabf N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/tbl N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/diagf.etc N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/graph N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/diagf.lpg N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/include/picturef N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/koi8r.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/LtLatin2.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/Std.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/Latin1.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/null.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/LtLatin1.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/Ding.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/00README N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/maps/Symb.LCM N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/standard.li N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/fcvt.awk N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/latin2.ld N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/fcvt N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/loutrefs.li N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/fontdefs.ld N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/oldrefs.ld N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/standard.ld N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/README N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/loutrefs.ld N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/fontdefs.li N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/refstyle.ld N llvm-test/MutiSource/Benchmarks/MiBench/consumer/typeset/data/data/refstyle.li N llvm-test/MutiSource/Benchmarks/MiBench/office/stringsearch/bmhsrch.c N llvm-test/MutiSource/Benchmarks/MiBench/office/stringsearch/bmhisrch.c N llvm-test/MutiSource/Benchmarks/MiBench/office/stringsearch/bmhasrch.c N llvm-test/MutiSource/Benchmarks/MiBench/office/stringsearch/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/office/stringsearch/search.h N llvm-test/MutiSource/Benchmarks/MiBench/office/stringsearch/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/office/stringsearch/pbmsrch.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/Contributors N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/defmt.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/parse.output N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/tree.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/fields.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/correct.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/small.txt N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/large.txt N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/hash.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/ispell.info N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/americanmed+.hash N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/xgets.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/lookup.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/msgs.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/makedent.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/ispell.el N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/proto.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/tgood.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/README N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/ispell.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/good.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/parse.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/version.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/dump.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/ispell.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/config.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/term.c N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/local.h N llvm-test/MutiSource/Benchmarks/MiBench/office/ispell/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/adpcm/README.MB N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/adpcm/adpcm.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/adpcm/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/adpcm/adpcm.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/adpcm/large.adpcm N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/adpcm/rawdaudio.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/adpcm/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/toast.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/preprocess.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_decode.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_print.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/rpe.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/COPYRIGHT N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/debug.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_explode.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/lpc.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/private.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/toast.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_implode.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/short_term.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/table.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/code.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/proto.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/add.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/toast_ulaw.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/toast_alaw.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/toast_audio.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/README N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/unproto.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/large.au.run.gsm N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/long_term.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/decode.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/config.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_destroy.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/INSTALL N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_option.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_create.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/gsm_encode.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/gsm/toast_lin.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/CRC32/crc_32.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/CRC32/crc.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/CRC32/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/CRC32/sniptype.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/CRC32/large.pcm N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/CRC32/LICENSE N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/fourierf.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/fftmisc.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/fourier.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/ddc.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/README N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/Makefile N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/ddcmath.h N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/main.c N llvm-test/MutiSource/Benchmarks/MiBench/telecomm/FFT/LICENSE No conflicts created by this import --- Diffs of the changes: (+0 -0) 0 files changed From reid at x10sys.com Tue Jan 9 00:25:31 2007 From: reid at x10sys.com (Reid Spencer) Date: Tue, 9 Jan 2007 00:25:31 -0600 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/CBackend/2007-01-08-ParamAttr-ICmp.ll Message-ID: <200701090625.l096PVvT016885@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/CBackend: 2007-01-08-ParamAttr-ICmp.ll added (r1.1) --- Log message: Test case for PR1099: http://llvm.org/PR1099 . --- Diffs of the changes: (+31 -0) 2007-01-08-ParamAttr-ICmp.ll | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+) Index: llvm/test/Regression/CodeGen/CBackend/2007-01-08-ParamAttr-ICmp.ll diff -c /dev/null llvm/test/Regression/CodeGen/CBackend/2007-01-08-ParamAttr-ICmp.ll:1.1 *** /dev/null Tue Jan 9 00:25:25 2007 --- llvm/test/Regression/CodeGen/CBackend/2007-01-08-ParamAttr-ICmp.ll Tue Jan 9 00:25:15 2007 *************** *** 0 **** --- 1,31 ---- + ; RUN: llvm-as < %s | llc -march=c | \ + ; RUN: grep 'return ((((ltmp_2_2 == (signed int)ltmp_1_2)) ? (1) : (0)))' + ; For PR1099 + ; XFAIL: * + + target datalayout = "e-p:32:32" + target endian = little + target pointersize = 32 + target triple = "i686-apple-darwin8" + %struct.Connector = type { i16, i16, i8, i8, %struct.Connector*, i8* } + + implementation ; Functions: + + define bool %prune_match_entry_2E_ce(%struct.Connector* %a, i16 %b.0.0.val) { + newFuncRoot: + br label %entry.ce + + cond_next.exitStub: ; preds = %entry.ce + ret bool true + + entry.return_crit_edge.exitStub: ; preds = %entry.ce + ret bool false + + entry.ce: ; preds = %newFuncRoot + %tmp = getelementptr %struct.Connector* %a, i32 0, i32 0 ; [#uses=1] + %tmp = load i16* %tmp ; [#uses=1] + %tmp = icmp eq i16 %tmp, %b.0.0.val ; [#uses=1] + br bool %tmp, label %cond_next.exitStub, label %entry.return_crit_edge.exitStub + } + + From reid at x10sys.com Tue Jan 9 00:38:21 2007 From: reid at x10sys.com (Reid Spencer) Date: Tue, 9 Jan 2007 00:38:21 -0600 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200701090638.l096cLuw017068@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.306 -> 1.307 --- Log message: For PR1099: http://llvm.org/PR1099 : Partial fix for this PR. Default function parameters to signed integer, just like everything else in CBE. The bug was caused by incorrectly introducing parameter attributes feature by choosing "signed" parameter if the SExtAttribute was specified. Howeer, if no attribute is specified, this causes it to become unsigned which is incorrect. Reversing the logic so that signedness is detected by "not ZExtAttribute" set fixes the issue. This fixes 197.parser but there is more to do. Any comparison and possibly other operators involving arguments may need to correctly cast the parameter before its use, depending on the sign of the operator. --- Diffs of the changes: (+9 -8) Writer.cpp | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.306 llvm/lib/Target/CBackend/Writer.cpp:1.307 --- llvm/lib/Target/CBackend/Writer.cpp:1.306 Mon Jan 8 02:00:00 2007 +++ llvm/lib/Target/CBackend/Writer.cpp Tue Jan 9 00:38:06 2007 @@ -348,7 +348,7 @@ if (PrintedType) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), ""); + /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), ""); PrintedType = true; } if (FTy->isVarArg()) { @@ -360,7 +360,7 @@ FunctionInnards << ')'; std::string tstr = FunctionInnards.str(); printType(Out, RetTy, - /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); + /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); } std::ostream & @@ -417,7 +417,7 @@ if (I != FTy->param_begin()) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), ""); + /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), ""); ++Idx; } if (FTy->isVarArg()) { @@ -429,7 +429,7 @@ FunctionInnards << ')'; std::string tstr = FunctionInnards.str(); printType(Out, FTy->getReturnType(), - /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); + /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::ZExtAttribute), tstr); return Out; } case Type::StructTyID: { @@ -1775,7 +1775,7 @@ else ArgName = ""; printType(FunctionInnards, I->getType(), - /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute), + /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute), ArgName); PrintedArg = true; ++Idx; @@ -1796,7 +1796,7 @@ for (; I != E; ++I) { if (PrintedArg) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute)); + /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute)); PrintedArg = true; ++Idx; } @@ -1823,7 +1823,8 @@ } // Print out the return type and the signature built above. - printType(Out, RetTy, FT->paramHasAttr(0, FunctionType::SExtAttribute), + printType(Out, RetTy, + /*isSigned=*/!FT->paramHasAttr(0, FunctionType::ZExtAttribute), FunctionInnards.str()); } @@ -2516,7 +2517,7 @@ (*AI)->getType() != FTy->getParamType(ArgNo)) { Out << '('; printType(Out, FTy->getParamType(ArgNo), - /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute)); + /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute)); Out << ')'; } writeOperand(*AI); From sabre at nondot.org Tue Jan 9 01:46:36 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 01:46:36 -0600 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200701090746.l097kael018201@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.236 -> 1.237 --- Log message: Remove extraneous return value from insertValue and getOrCreateSlot. Since getOrCreateSlot no longer gets the slot, rename it to CreateSlot. --- Diffs of the changes: (+35 -54) AsmWriter.cpp | 89 ++++++++++++++++++++++------------------------------------ 1 files changed, 35 insertions(+), 54 deletions(-) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.236 llvm/lib/VMCore/AsmWriter.cpp:1.237 --- llvm/lib/VMCore/AsmWriter.cpp:1.236 Mon Jan 8 12:21:30 2007 +++ llvm/lib/VMCore/AsmWriter.cpp Tue Jan 9 01:46:21 2007 @@ -102,15 +102,12 @@ /// This function does the actual initialization. inline void initialize(); - /// Values can be crammed into here at will. If they haven't - /// been inserted already, they get inserted, otherwise they are ignored. - /// Either way, the slot number for the Value* is returned. - unsigned getOrCreateSlot(const Value *V); - - /// Insert a value into the value table. Return the slot number - /// that it now occupies. BadThings(TM) will happen if you insert a - /// Value that's already been inserted. - unsigned insertValue(const Value *V); + /// CreateSlot - If the specified Value* doesn't have a name, assign it a slot + /// number. + void CreateSlot(const Value *V); + + /// Insert a value into the value table. + void insertValue(const Value *V); /// Add all of the module level global variables (and their initializers) /// and function declarations, but not the contents of those functions. @@ -1427,13 +1424,13 @@ for (Module::const_global_iterator I = TheModule->global_begin(), E = TheModule->global_end(); I != E; ++I) if (!I->hasName()) - getOrCreateSlot(I); + CreateSlot(I); // Add all the unnamed functions to the table. for (Module::const_iterator I = TheModule->begin(), E = TheModule->end(); I != E; ++I) if (!I->hasName()) - getOrCreateSlot(I); + CreateSlot(I); SC_DEBUG("end processModule!\n"); } @@ -1447,7 +1444,7 @@ for(Function::const_arg_iterator AI = TheFunction->arg_begin(), AE = TheFunction->arg_end(); AI != AE; ++AI) if (!AI->hasName()) - getOrCreateSlot(AI); + CreateSlot(AI); SC_DEBUG("Inserting Instructions:\n"); @@ -1455,10 +1452,10 @@ for (Function::const_iterator BB = TheFunction->begin(), E = TheFunction->end(); BB != E; ++BB) { if (!BB->hasName()) - getOrCreateSlot(BB); + CreateSlot(BB); for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) if (I->getType() != Type::VoidTy && !I->hasName()) - getOrCreateSlot(I); + CreateSlot(I); } FunctionProcessed = true; @@ -1467,9 +1464,8 @@ } /// Clean up after incorporating a function. This is the only way to get out of -/// the function incorporation state that affects the -/// getSlot/getOrCreateSlot lock. Function incorporation state is indicated -/// by TheFunction != 0. +/// the function incorporation state that affects getSlot/CreateSlot. Function +/// incorporation state is indicated by TheFunction != 0. void SlotMachine::purgeFunction() { SC_DEBUG("begin purgeFunction!\n"); fMap.clear(); // Simply discard the function level map @@ -1479,8 +1475,7 @@ } /// Get the slot number for a value. This function will assert if you -/// ask for a Value that hasn't previously been inserted with getOrCreateSlot. -/// Types are forbidden because Type does not inherit from Value (any more). +/// ask for a Value that hasn't previously been inserted with CreateSlot. int SlotMachine::getSlot(const Value *V) { assert(V && "Can't get slot for null Value"); assert(!isa(V) || isa(V) && @@ -1540,10 +1535,8 @@ } -// Create a new slot, or return the existing slot if it is already -// inserted. Note that the logic here parallels getSlot but instead -// of asserting when the Value* isn't found, it inserts the value. -unsigned SlotMachine::getOrCreateSlot(const Value *V) { +/// CreateSlot - Create a new slot for the specified value if it has no name. +void SlotMachine::CreateSlot(const Value *V) { const Type* VTy = V->getType(); assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!"); assert(!isa(V) || isa(V) && @@ -1557,32 +1550,21 @@ TypedPlanes::const_iterator FI = fMap.find(VTy); // If there is a corresponding type plane in the function map if (FI != fMap.end()) { - // Lookup the Value in the function map + // Lookup the Value in the function map. ValueMap::const_iterator FVI = FI->second.map.find(V); - // If the value doesn't exist in the function map - if (FVI == FI->second.map.end()) { - // If there is no corresponding type plane in the module map - if (MI == mMap.end()) - return insertValue(V); - // Look up the value in the module map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we didn't find it, it wasn't inserted - if (MVI == MI->second.map.end()) - return insertValue(V); - else - // We found it only at the module level - return MVI->second; - - // else the value exists in the function map - } else { - if (MI == mMap.end()) - return FVI->second; - else - // Return the slot number as the module's contribution to - // the type plane plus the index in the function's contribution - // to the type plane. - return MI->second.next_slot + FVI->second; - } + // If the value exists in the function map, we're done. + if (FVI != FI->second.map.end()) + return; + + // If there is no corresponding type plane in the module map + if (MI == mMap.end()) + return insertValue(V); + // Look up the value in the module map + ValueMap::const_iterator MVI = MI->second.map.find(V); + // If we found it, it was already inserted + if (MVI != MI->second.map.end()) + return; + return insertValue(V); // else there is not a corresponding type plane in the function map } else { @@ -1597,9 +1579,9 @@ if (MVI == MI->second.map.end()) // Return the slot number as the module's contribution to // the type plane plus the index of the function map insertion. - return MI->second.next_slot + insertValue(V); + return insertValue(V); else - return MVI->second; + return; } } } @@ -1611,7 +1593,7 @@ // Lookup the value in the module's map ValueMap::const_iterator MVI = MI->second.map.find(V); if (MVI != MI->second.map.end()) - return MVI->second; + return; } return insertValue(V); @@ -1619,8 +1601,8 @@ // Low level insert function. Minimal checking is done. This -// function is just for the convenience of getOrCreateSlot (above). -unsigned SlotMachine::insertValue(const Value *V) { +// function is just for the convenience of CreateSlot (above). +void SlotMachine::insertValue(const Value *V) { assert(V && "Can't insert a null Value into SlotMachine!"); assert(!isa(V) || isa(V) && "Can't insert a non-GlobalValue Constant into SlotMachine"); @@ -1646,5 +1628,4 @@ // G = Global, F = Function, o = other SC_DEBUG((isa(V) ? 'G' : (isa(V) ? 'F' : 'o'))); SC_DEBUG("]\n"); - return DestSlot; } From sabre at nondot.org Tue Jan 9 01:56:05 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 01:56:05 -0600 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200701090756.l097u5BX018362@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.237 -> 1.238 --- Log message: Split CreateSlot into two versions, one for globals and one for function-local values --- Diffs of the changes: (+68 -61) AsmWriter.cpp | 129 ++++++++++++++++++++++++++++++---------------------------- 1 files changed, 68 insertions(+), 61 deletions(-) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.237 llvm/lib/VMCore/AsmWriter.cpp:1.238 --- llvm/lib/VMCore/AsmWriter.cpp:1.237 Tue Jan 9 01:46:21 2007 +++ llvm/lib/VMCore/AsmWriter.cpp Tue Jan 9 01:55:49 2007 @@ -102,9 +102,11 @@ /// This function does the actual initialization. inline void initialize(); - /// CreateSlot - If the specified Value* doesn't have a name, assign it a slot - /// number. - void CreateSlot(const Value *V); + /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. + void CreateModuleSlot(const GlobalValue *V); + + /// CreateFunctionSlot - Insert the specified Value* into the slot table. + void CreateFunctionSlot(const Value *V); /// Insert a value into the value table. void insertValue(const Value *V); @@ -1424,13 +1426,13 @@ for (Module::const_global_iterator I = TheModule->global_begin(), E = TheModule->global_end(); I != E; ++I) if (!I->hasName()) - CreateSlot(I); + CreateModuleSlot(I); // Add all the unnamed functions to the table. for (Module::const_iterator I = TheModule->begin(), E = TheModule->end(); I != E; ++I) if (!I->hasName()) - CreateSlot(I); + CreateModuleSlot(I); SC_DEBUG("end processModule!\n"); } @@ -1444,7 +1446,7 @@ for(Function::const_arg_iterator AI = TheFunction->arg_begin(), AE = TheFunction->arg_end(); AI != AE; ++AI) if (!AI->hasName()) - CreateSlot(AI); + CreateFunctionSlot(AI); SC_DEBUG("Inserting Instructions:\n"); @@ -1452,10 +1454,10 @@ for (Function::const_iterator BB = TheFunction->begin(), E = TheFunction->end(); BB != E; ++BB) { if (!BB->hasName()) - CreateSlot(BB); + CreateFunctionSlot(BB); for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) if (I->getType() != Type::VoidTy && !I->hasName()) - CreateSlot(I); + CreateFunctionSlot(I); } FunctionProcessed = true; @@ -1464,7 +1466,7 @@ } /// Clean up after incorporating a function. This is the only way to get out of -/// the function incorporation state that affects getSlot/CreateSlot. Function +/// the function incorporation state that affects getSlot/Create*Slot. Function /// incorporation state is indicated by TheFunction != 0. void SlotMachine::purgeFunction() { SC_DEBUG("begin purgeFunction!\n"); @@ -1475,7 +1477,7 @@ } /// Get the slot number for a value. This function will assert if you -/// ask for a Value that hasn't previously been inserted with CreateSlot. +/// ask for a Value that hasn't previously been inserted with Create*Slot. int SlotMachine::getSlot(const Value *V) { assert(V && "Can't get slot for null Value"); assert(!isa(V) || isa(V) && @@ -1535,68 +1537,73 @@ } +/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. +void SlotMachine::CreateModuleSlot(const GlobalValue *V) { + assert(!V->hasName() && "Doesn't need a slot!"); + const Type *VTy = V->getType(); + + // Look up the type plane for the Value's type from the module map + TypedPlanes::const_iterator MI = mMap.find(VTy); + + // If the module map's type plane is not for the Value's type + if (MI != mMap.end()) { + // Lookup the value in the module's map + ValueMap::const_iterator MVI = MI->second.map.find(V); + if (MVI != MI->second.map.end()) + return; + } + + return insertValue(V); +} + + /// CreateSlot - Create a new slot for the specified value if it has no name. -void SlotMachine::CreateSlot(const Value *V) { - const Type* VTy = V->getType(); +void SlotMachine::CreateFunctionSlot(const Value *V) { + const Type *VTy = V->getType(); assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!"); - assert(!isa(V) || isa(V) && - "Can't insert a non-GlobalValue Constant into SlotMachine"); + assert(!isa(V) && "Can't insert a Constants into SlotMachine"); // Look up the type plane for the Value's type from the module map TypedPlanes::const_iterator MI = mMap.find(VTy); - if (TheFunction) { - // Get the type plane for the Value's type from the function map - TypedPlanes::const_iterator FI = fMap.find(VTy); - // If there is a corresponding type plane in the function map - if (FI != fMap.end()) { - // Lookup the Value in the function map. - ValueMap::const_iterator FVI = FI->second.map.find(V); - // If the value exists in the function map, we're done. - if (FVI != FI->second.map.end()) - return; - - // If there is no corresponding type plane in the module map - if (MI == mMap.end()) - return insertValue(V); - // Look up the value in the module map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we found it, it was already inserted - if (MVI != MI->second.map.end()) - return; + // Get the type plane for the Value's type from the function map + TypedPlanes::const_iterator FI = fMap.find(VTy); + // If there is a corresponding type plane in the function map + if (FI != fMap.end()) { + // Lookup the Value in the function map. + ValueMap::const_iterator FVI = FI->second.map.find(V); + // If the value exists in the function map, we're done. + if (FVI != FI->second.map.end()) + return; + + // If there is no corresponding type plane in the module map + if (MI == mMap.end()) return insertValue(V); - - // else there is not a corresponding type plane in the function map - } else { - // If the type plane doesn't exists at the module level - if (MI == mMap.end()) { - return insertValue(V); - // else type plane exists at the module level, examine it - } else { - // Look up the value in the module's map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we didn't find it there either - if (MVI == MI->second.map.end()) - // Return the slot number as the module's contribution to - // the type plane plus the index of the function map insertion. - return insertValue(V); - else - return; - } - } - } - - // N.B. Can only get here if TheFunction == 0 - - // If the module map's type plane is not for the Value's type - if (MI != mMap.end()) { - // Lookup the value in the module's map + // Look up the value in the module map ValueMap::const_iterator MVI = MI->second.map.find(V); + // If we found it, it was already inserted if (MVI != MI->second.map.end()) return; + return insertValue(V); + } + + // Otherwise, there is no corresponding type plane in the function map yet. + + // If the type plane doesn't exists at the module level + if (MI == mMap.end()) { + return insertValue(V); + // else type plane exists at the module level, examine it + } else { + // Look up the value in the module's map + ValueMap::const_iterator MVI = MI->second.map.find(V); + // If we didn't find it there either + if (MVI == MI->second.map.end()) + // Return the slot number as the module's contribution to + // the type plane plus the index of the function map insertion. + return insertValue(V); + else + return; } - - return insertValue(V); } From sabre at nondot.org Tue Jan 9 01:58:26 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 01:58:26 -0600 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200701090758.l097wQuu018422@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.238 -> 1.239 --- Log message: Remove a bunch of complex logic that is completely dead: duplicates can never be inserted! --- Diffs of the changes: (+1 -57) AsmWriter.cpp | 58 +--------------------------------------------------------- 1 files changed, 1 insertion(+), 57 deletions(-) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.238 llvm/lib/VMCore/AsmWriter.cpp:1.239 --- llvm/lib/VMCore/AsmWriter.cpp:1.238 Tue Jan 9 01:55:49 2007 +++ llvm/lib/VMCore/AsmWriter.cpp Tue Jan 9 01:58:11 2007 @@ -1539,20 +1539,6 @@ /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. void SlotMachine::CreateModuleSlot(const GlobalValue *V) { - assert(!V->hasName() && "Doesn't need a slot!"); - const Type *VTy = V->getType(); - - // Look up the type plane for the Value's type from the module map - TypedPlanes::const_iterator MI = mMap.find(VTy); - - // If the module map's type plane is not for the Value's type - if (MI != mMap.end()) { - // Lookup the value in the module's map - ValueMap::const_iterator MVI = MI->second.map.find(V); - if (MVI != MI->second.map.end()) - return; - } - return insertValue(V); } @@ -1561,49 +1547,7 @@ void SlotMachine::CreateFunctionSlot(const Value *V) { const Type *VTy = V->getType(); assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!"); - assert(!isa(V) && "Can't insert a Constants into SlotMachine"); - - // Look up the type plane for the Value's type from the module map - TypedPlanes::const_iterator MI = mMap.find(VTy); - - // Get the type plane for the Value's type from the function map - TypedPlanes::const_iterator FI = fMap.find(VTy); - // If there is a corresponding type plane in the function map - if (FI != fMap.end()) { - // Lookup the Value in the function map. - ValueMap::const_iterator FVI = FI->second.map.find(V); - // If the value exists in the function map, we're done. - if (FVI != FI->second.map.end()) - return; - - // If there is no corresponding type plane in the module map - if (MI == mMap.end()) - return insertValue(V); - // Look up the value in the module map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we found it, it was already inserted - if (MVI != MI->second.map.end()) - return; - return insertValue(V); - } - - // Otherwise, there is no corresponding type plane in the function map yet. - - // If the type plane doesn't exists at the module level - if (MI == mMap.end()) { - return insertValue(V); - // else type plane exists at the module level, examine it - } else { - // Look up the value in the module's map - ValueMap::const_iterator MVI = MI->second.map.find(V); - // If we didn't find it there either - if (MVI == MI->second.map.end()) - // Return the slot number as the module's contribution to - // the type plane plus the index of the function map insertion. - return insertValue(V); - else - return; - } + return insertValue(V); } From sabre at nondot.org Tue Jan 9 02:05:16 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 02:05:16 -0600 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200701090805.l0985GS0018574@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.239 -> 1.240 --- Log message: Inline insertValue into CreateModuleSlot/CreateFunctionSlot --- Diffs of the changes: (+24 -35) AsmWriter.cpp | 59 +++++++++++++++++++++++----------------------------------- 1 files changed, 24 insertions(+), 35 deletions(-) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.239 llvm/lib/VMCore/AsmWriter.cpp:1.240 --- llvm/lib/VMCore/AsmWriter.cpp:1.239 Tue Jan 9 01:58:11 2007 +++ llvm/lib/VMCore/AsmWriter.cpp Tue Jan 9 02:04:59 2007 @@ -108,9 +108,6 @@ /// CreateFunctionSlot - Insert the specified Value* into the slot table. void CreateFunctionSlot(const Value *V); - /// Insert a value into the value table. - void insertValue(const Value *V); - /// Add all of the module level global variables (and their initializers) /// and function declarations, but not the contents of those functions. void processModule(); @@ -1539,7 +1536,20 @@ /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. void SlotMachine::CreateModuleSlot(const GlobalValue *V) { - return insertValue(V); + assert(V && "Can't insert a null Value into SlotMachine!"); + + unsigned DestSlot = 0; + const Type *VTy = V->getType(); + + TypedPlanes::iterator I = mMap.find(VTy); + if (I == mMap.end()) + I = mMap.insert(std::make_pair(VTy,ValuePlane())).first; + DestSlot = I->second.map[V] = I->second.next_slot++; + + SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" << + DestSlot << " ["); + // G = Global, F = Function, o = other + SC_DEBUG((isa(V) ? 'G' : 'F') << "]\n"); } @@ -1547,36 +1557,15 @@ void SlotMachine::CreateFunctionSlot(const Value *V) { const Type *VTy = V->getType(); assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!"); - return insertValue(V); -} - - -// Low level insert function. Minimal checking is done. This -// function is just for the convenience of CreateSlot (above). -void SlotMachine::insertValue(const Value *V) { - assert(V && "Can't insert a null Value into SlotMachine!"); - assert(!isa(V) || isa(V) && - "Can't insert a non-GlobalValue Constant into SlotMachine"); - assert(V->getType() != Type::VoidTy && !V->hasName()); - - const Type *VTy = V->getType(); + unsigned DestSlot = 0; - - if (TheFunction) { - TypedPlanes::iterator I = fMap.find(VTy); - if (I == fMap.end()) - I = fMap.insert(std::make_pair(VTy,ValuePlane())).first; - DestSlot = I->second.map[V] = I->second.next_slot++; - } else { - TypedPlanes::iterator I = mMap.find(VTy); - if (I == mMap.end()) - I = mMap.insert(std::make_pair(VTy,ValuePlane())).first; - DestSlot = I->second.map[V] = I->second.next_slot++; - } - - SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" << - DestSlot << " ["); + + TypedPlanes::iterator I = fMap.find(VTy); + if (I == fMap.end()) + I = fMap.insert(std::make_pair(VTy,ValuePlane())).first; + DestSlot = I->second.map[V] = I->second.next_slot++; + // G = Global, F = Function, o = other - SC_DEBUG((isa(V) ? 'G' : (isa(V) ? 'F' : 'o'))); - SC_DEBUG("]\n"); -} + SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" << + DestSlot << " [o]\n"); +} From isanbard at gmail.com Tue Jan 9 02:25:58 2007 From: isanbard at gmail.com (Bill Wendling) Date: Tue, 9 Jan 2007 00:25:58 -0800 Subject: [llvm-commits] Potential Patch for PR1095 Message-ID: Hi all, I would like someone to review this patch for PR1095. This gives us a "dialect" for the assembler code if we're given something like: __asm__("{cntlz|cntlzw} ... Before, we were defaulting to the first one. But there are some platforms which need the second form. Here's the patch. Lemme know what you think! -bw -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch.txt Url: http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20070109/14fa32ec/attachment.txt From criswell at cs.uiuc.edu Tue Jan 9 10:33:36 2007 From: criswell at cs.uiuc.edu (John Criswell) Date: Tue, 9 Jan 2007 10:33:36 -0600 Subject: [llvm-commits] CVS: llvm-www/demo/index.cgi Message-ID: <200701091633.l09GXaAI001966@zion.cs.uiuc.edu> Changes in directory llvm-www/demo: index.cgi updated: 1.66 -> 1.67 --- Log message: Updated to use my copy of the new LLVM tools and Andrew's newly built CFE. --- Diffs of the changes: (+5 -5) index.cgi | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) Index: llvm-www/demo/index.cgi diff -u llvm-www/demo/index.cgi:1.66 llvm-www/demo/index.cgi:1.67 --- llvm-www/demo/index.cgi:1.66 Fri Sep 15 01:31:45 2006 +++ llvm-www/demo/index.cgi Tue Jan 9 10:33:12 2007 @@ -5,7 +5,7 @@ # doing remote web JO99C compilations. (It could still be used for that # purpose, though the two scripts have diverged somewhat.) # -# Last modified $Date: 2006/09/15 06:31:45 $ +# Last modified $Date: 2007/01/09 16:33:12 $ # use strict; @@ -29,9 +29,9 @@ my @PREPENDPATHDIRS = ( - '/home/vadve/criswell/box/x86/llvm-gcc/bin/', - '/home/vadve/gaeke/llvm/Release/bin', '/home/vadve/gaeke/bin', - '/home/vadve/gaeke/llvm/projects/Stacker/Release/bin' ); + '/home/vadve/alenhar2/cfe/install/bin/', + '/home/vadve/criswell/box/x86/latestllvm/Debug/bin', + '/home/vadve/criswell/box/x86/projects/Stacker/Debug/bin'); sub getname { my ($extension) = @_; @@ -377,7 +377,7 @@ $stats = "-Wa,--stats,--time-passes,--info-output-file=$timerFile" if ( $c->param('showstats') ); try_run( "llvm C/C++ front-end (llvm-gcc)", - "llvm-gcc -W -Wall -O2 $stats -o $bytecodeFile -c $inputFile > $outputFile 2>&1", + "llvm-gcc -emit-llvm -W -Wall -O2 $stats -o $bytecodeFile -c $inputFile > $outputFile 2>&1", $outputFile ); } From reid at x10sys.com Tue Jan 9 11:09:33 2007 From: reid at x10sys.com (Reid Spencer) Date: Tue, 9 Jan 2007 11:09:33 -0600 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200701091709.l09H9X5S004343@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.307 -> 1.308 --- Log message: For PR1099: http://llvm.org/PR1099 : Invert the "isSigned" logic in calls to printType and printPrimitiveType. We want variables to be declared unsigned by default so that signless operators like + and - perform the unsigned operation that LLVM expects by default. Parameters with the sext attribute will be declared signed and signed instructions will case operand values to signed regardless of the type of the variable. This passes all tests and fixes PR1099: http://llvm.org/PR1099 . --- Diffs of the changes: (+33 -33) Writer.cpp | 66 ++++++++++++++++++++++++++++++------------------------------- 1 files changed, 33 insertions(+), 33 deletions(-) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.307 llvm/lib/Target/CBackend/Writer.cpp:1.308 --- llvm/lib/Target/CBackend/Writer.cpp:1.307 Tue Jan 9 00:38:06 2007 +++ llvm/lib/Target/CBackend/Writer.cpp Tue Jan 9 11:09:09 2007 @@ -115,7 +115,7 @@ } std::ostream &printType(std::ostream &Out, const Type *Ty, - bool isSigned = true, + bool isSigned = false, const std::string &VariableName = "", bool IgnoreName = false); std::ostream &printPrimitiveType(std::ostream &Out, const Type *Ty, @@ -348,7 +348,7 @@ if (PrintedType) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), ""); + /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), ""); PrintedType = true; } if (FTy->isVarArg()) { @@ -360,7 +360,7 @@ FunctionInnards << ')'; std::string tstr = FunctionInnards.str(); printType(Out, RetTy, - /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); + /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); } std::ostream & @@ -417,7 +417,7 @@ if (I != FTy->param_begin()) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), ""); + /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), ""); ++Idx; } if (FTy->isVarArg()) { @@ -429,7 +429,7 @@ FunctionInnards << ')'; std::string tstr = FunctionInnards.str(); printType(Out, FTy->getReturnType(), - /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::ZExtAttribute), tstr); + /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); return Out; } case Type::StructTyID: { @@ -439,7 +439,7 @@ for (StructType::element_iterator I = STy->element_begin(), E = STy->element_end(); I != E; ++I) { Out << " "; - printType(Out, *I, true, "field" + utostr(Idx++)); + printType(Out, *I, false, "field" + utostr(Idx++)); Out << ";\n"; } return Out << '}'; @@ -453,14 +453,14 @@ isa(PTy->getElementType())) ptrName = "(" + ptrName + ")"; - return printType(Out, PTy->getElementType(), true, ptrName); + return printType(Out, PTy->getElementType(), false, ptrName); } case Type::ArrayTyID: { const ArrayType *ATy = cast(Ty); unsigned NumElements = ATy->getNumElements(); if (NumElements == 0) NumElements = 1; - return printType(Out, ATy->getElementType(), true, + return printType(Out, ATy->getElementType(), false, NameSoFar + "[" + utostr(NumElements) + "]"); } @@ -468,7 +468,7 @@ const PackedType *PTy = cast(Ty); unsigned NumElements = PTy->getNumElements(); if (NumElements == 0) NumElements = 1; - return printType(Out, PTy->getElementType(), true, + return printType(Out, PTy->getElementType(), false, NameSoFar + "[" + utostr(NumElements) + "]"); } @@ -834,7 +834,7 @@ if (ConstantInt *CI = dyn_cast(CPV)) { const Type* Ty = CI->getType(); Out << "(("; - printPrimitiveType(Out, Ty, true) << ')'; + printPrimitiveType(Out, Ty, false) << ')'; if (CI->isMinValue(true)) Out << CI->getZExtValue() << 'u'; else @@ -1019,10 +1019,10 @@ } if (NeedsExplicitCast) { Out << "(("; - if (Ty->isPrimitiveType()) + if (Ty->isInteger()) printPrimitiveType(Out, Ty, TypeIsSigned); else - printType(Out, Ty); + printType(Out, Ty); // not integer, sign doesn't matter Out << ")("; } return NeedsExplicitCast; @@ -1222,10 +1222,10 @@ // operand. if (shouldCast) { Out << "(("; - if (OpTy->isPrimitiveType()) + if (OpTy->isInteger()) printPrimitiveType(Out, OpTy, castIsSigned); else - printType(Out, OpTy); + printType(Out, OpTy); // not integer, sign doesn't matter Out << ")"; writeOperand(Operand); Out << ")"; @@ -1457,17 +1457,17 @@ I != E; ++I) { if (I->hasExternalLinkage()) { Out << "extern "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); Out << ";\n"; } else if (I->hasDLLImportLinkage()) { Out << "__declspec(dllimport) "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); Out << ";\n"; } else if (I->hasExternalWeakLinkage()) { Out << "extern "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); Out << " __EXTERNAL_WEAK__ ;\n"; } @@ -1516,7 +1516,7 @@ Out << "static "; else Out << "extern "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); if (I->hasLinkOnceLinkage()) @@ -1546,7 +1546,7 @@ else if (I->hasDLLExportLinkage()) Out << "__declspec(dllexport) "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); if (I->hasLinkOnceLinkage()) Out << " __attribute__((common))"; @@ -1685,7 +1685,7 @@ const Type *Ty = cast(I->second); std::string Name = "l_" + Mang->makeNameProper(I->first); Out << "typedef "; - printType(Out, Ty, true, Name); + printType(Out, Ty, false, Name); Out << ";\n"; } @@ -1724,7 +1724,7 @@ if (StructPrinted.insert(STy).second) { // Print structure type out. std::string Name = TypeNames[STy]; - printType(Out, STy, true, Name, true); + printType(Out, STy, false, Name, true); Out << ";\n\n"; } } @@ -1775,7 +1775,7 @@ else ArgName = ""; printType(FunctionInnards, I->getType(), - /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute), + /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute), ArgName); PrintedArg = true; ++Idx; @@ -1796,7 +1796,7 @@ for (; I != E; ++I) { if (PrintedArg) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute)); + /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute)); PrintedArg = true; ++Idx; } @@ -1824,7 +1824,7 @@ // Print out the return type and the signature built above. printType(Out, RetTy, - /*isSigned=*/!FT->paramHasAttr(0, FunctionType::ZExtAttribute), + /*isSigned=*/FT->paramHasAttr(0, FunctionType::SExtAttribute), FunctionInnards.str()); } @@ -1846,11 +1846,11 @@ const Type *StructTy = cast(F.arg_begin()->getType())->getElementType(); Out << " "; - printType(Out, StructTy, true, "StructReturn"); + printType(Out, StructTy, false, "StructReturn"); Out << "; /* Struct return temporary */\n"; Out << " "; - printType(Out, F.arg_begin()->getType(), true, + printType(Out, F.arg_begin()->getType(), false, Mang->getValueName(F.arg_begin())); Out << " = &StructReturn;\n"; } @@ -1861,17 +1861,17 @@ for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I) { if (const AllocaInst *AI = isDirectAlloca(&*I)) { Out << " "; - printType(Out, AI->getAllocatedType(), true, Mang->getValueName(AI)); + printType(Out, AI->getAllocatedType(), false, Mang->getValueName(AI)); Out << "; /* Address-exposed local */\n"; PrintedVar = true; } else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) { Out << " "; - printType(Out, I->getType(), true, Mang->getValueName(&*I)); + printType(Out, I->getType(), false, Mang->getValueName(&*I)); Out << ";\n"; if (isa(*I)) { // Print out PHI node temporaries as well... Out << " "; - printType(Out, I->getType(), true, + printType(Out, I->getType(), false, Mang->getValueName(&*I)+"__PHI_TEMPORARY"); Out << ";\n"; } @@ -2100,7 +2100,7 @@ || (I.getType() == Type::FloatTy)) { needsCast = true; Out << "(("; - printType(Out, I.getType()); + printType(Out, I.getType(), false); Out << ")("; } @@ -2517,7 +2517,7 @@ (*AI)->getType() != FTy->getParamType(ArgNo)) { Out << '('; printType(Out, FTy->getParamType(ArgNo), - /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute)); + /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute)); Out << ')'; } writeOperand(*AI); @@ -2734,7 +2734,7 @@ Out << '*'; if (I.isVolatile()) { Out << "(("; - printType(Out, I.getType(), true, "volatile*"); + printType(Out, I.getType(), false, "volatile*"); Out << ")"; } @@ -2748,7 +2748,7 @@ Out << '*'; if (I.isVolatile()) { Out << "(("; - printType(Out, I.getOperand(0)->getType(), true, " volatile*"); + printType(Out, I.getOperand(0)->getType(), false, " volatile*"); Out << ")"; } writeOperand(I.getPointerOperand()); From andrewl at lenharth.org Tue Jan 9 12:48:36 2007 From: andrewl at lenharth.org (Andrew Lenharth) Date: Tue, 9 Jan 2007 12:48:36 -0600 Subject: [llvm-commits] CVS: llvm-www/demo/index.cgi In-Reply-To: <200701091633.l09GXaAI001966@zion.cs.uiuc.edu> References: <200701091633.l09GXaAI001966@zion.cs.uiuc.edu> Message-ID: <85dfcd7f0701091048u692c8701pc42136bbdd7fd790@mail.gmail.com> On 1/9/07, John Criswell wrote: > Updated to use my copy of the new LLVM tools and Andrew's newly built CFE. The llvm-gcc you want to use is in ~alenhar2/base/cfe-install/bin the cfe/install one will go away once the packed struct patch is done. Andrew > > --- > Diffs of the changes: (+5 -5) > > index.cgi | 10 +++++----- > 1 files changed, 5 insertions(+), 5 deletions(-) > > > Index: llvm-www/demo/index.cgi > diff -u llvm-www/demo/index.cgi:1.66 llvm-www/demo/index.cgi:1.67 > --- llvm-www/demo/index.cgi:1.66 Fri Sep 15 01:31:45 2006 > +++ llvm-www/demo/index.cgi Tue Jan 9 10:33:12 2007 > @@ -5,7 +5,7 @@ > # doing remote web JO99C compilations. (It could still be used for that > # purpose, though the two scripts have diverged somewhat.) > # > -# Last modified $Date: 2006/09/15 06:31:45 $ > +# Last modified $Date: 2007/01/09 16:33:12 $ > # > > use strict; > @@ -29,9 +29,9 @@ > > my @PREPENDPATHDIRS = > ( > - '/home/vadve/criswell/box/x86/llvm-gcc/bin/', > - '/home/vadve/gaeke/llvm/Release/bin', '/home/vadve/gaeke/bin', > - '/home/vadve/gaeke/llvm/projects/Stacker/Release/bin' ); > + '/home/vadve/alenhar2/cfe/install/bin/', > + '/home/vadve/criswell/box/x86/latestllvm/Debug/bin', > + '/home/vadve/criswell/box/x86/projects/Stacker/Debug/bin'); > > sub getname { > my ($extension) = @_; > @@ -377,7 +377,7 @@ > $stats = "-Wa,--stats,--time-passes,--info-output-file=$timerFile" > if ( $c->param('showstats') ); > try_run( "llvm C/C++ front-end (llvm-gcc)", > - "llvm-gcc -W -Wall -O2 $stats -o $bytecodeFile -c $inputFile > $outputFile 2>&1", > + "llvm-gcc -emit-llvm -W -Wall -O2 $stats -o $bytecodeFile -c $inputFile > $outputFile 2>&1", > $outputFile ); > } > > > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > From evan.cheng at apple.com Tue Jan 9 13:36:38 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 9 Jan 2007 13:36:38 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/Makefile Message-ID: <200701091936.l09Jacjn003257@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks: Makefile updated: 1.11 -> 1.12 --- Log message: Added MiBench. --- Diffs of the changes: (+1 -1) Makefile | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm-test/MultiSource/Benchmarks/Makefile diff -u llvm-test/MultiSource/Benchmarks/Makefile:1.11 llvm-test/MultiSource/Benchmarks/Makefile:1.12 --- llvm-test/MultiSource/Benchmarks/Makefile:1.11 Tue Feb 14 00:11:36 2006 +++ llvm-test/MultiSource/Benchmarks/Makefile Tue Jan 9 13:36:13 2007 @@ -4,6 +4,6 @@ PARALLEL_DIRS := Fhourstones Fhourstones-3.1 \ McCat Olden OptimizerEval Ptrdist llubenchmark \ sim FreeBench MallocBench Prolangs-C Prolangs-C++ SciMark2-C\ - mediabench ASCI_Purple + mediabench ASCI_Purple MiBench include $(LEVEL)/Makefile.programs From evan.cheng at apple.com Tue Jan 9 13:55:02 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 9 Jan 2007 13:55:02 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive/Makefile Message-ID: <200701091955.l09Jt20V012765@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: No qsort. --- Diffs of the changes: (+1 -1) Makefile | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/automotive/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/automotive/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive/Makefile:1.1.1.1 Mon Jan 8 20:53:45 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/automotive/Makefile Tue Jan 9 13:54:41 2007 @@ -2,6 +2,6 @@ LEVEL = ../../../.. -PARALLEL_DIRS := basicmath bitcount qsort susan +PARALLEL_DIRS := basicmath bitcount susan include $(LEVEL)/Makefile.programs From evan.cheng at apple.com Tue Jan 9 13:56:14 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 9 Jan 2007 13:56:14 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/office/Makefile Message-ID: <200701091956.l09JuEjH013190@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/office: Makefile added (r1.1) --- Log message: Missed a makefile --- Diffs of the changes: (+7 -0) Makefile | 7 +++++++ 1 files changed, 7 insertions(+) Index: llvm-test/MultiSource/Benchmarks/MiBench/office/Makefile diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/office/Makefile:1.1 *** /dev/null Tue Jan 9 13:56:07 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/office/Makefile Tue Jan 9 13:55:57 2007 *************** *** 0 **** --- 1,7 ---- + # MultiSource/MiBench/office Makefile: Build all subdirectories automatically + + LEVEL = ../../../.. + + PARALLEL_DIRS := ispell stringsearch + + include $(LEVEL)/Makefile.programs From evan.cheng at apple.com Tue Jan 9 13:57:46 2007 From: evan.cheng at apple.com (Evan Cheng) Date: Tue, 9 Jan 2007 13:57:46 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/security/Makefile Message-ID: <200701091957.l09JvkcF013486@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/security: Makefile added (r1.1) --- Log message: Missed a makefile --- Diffs of the changes: (+7 -0) Makefile | 7 +++++++ 1 files changed, 7 insertions(+) Index: llvm-test/MultiSource/Benchmarks/MiBench/security/Makefile diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/security/Makefile:1.1 *** /dev/null Tue Jan 9 13:57:39 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/security/Makefile Tue Jan 9 13:57:29 2007 *************** *** 0 **** --- 1,7 ---- + # MultiSource/MiBench/security Makefile: Build all subdirectories automatically + + LEVEL = ../../../.. + + PARALLEL_DIRS := blowfish rijndael sha + + include $(LEVEL)/Makefile.programs From reid at x10sys.com Tue Jan 9 14:09:15 2007 From: reid at x10sys.com (Reid Spencer) Date: Tue, 9 Jan 2007 14:09:15 -0600 Subject: [llvm-commits] CVS: llvm/docs/LangRef.html Message-ID: <200701092009.l09K9Fg4018809@zion.cs.uiuc.edu> Changes in directory llvm/docs: LangRef.html updated: 1.190 -> 1.191 --- Log message: Explain that bitcast can only cast a pointer to another pointer. --- Diffs of the changes: (+3 -2) LangRef.html | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) Index: llvm/docs/LangRef.html diff -u llvm/docs/LangRef.html:1.190 llvm/docs/LangRef.html:1.191 --- llvm/docs/LangRef.html:1.190 Mon Jan 8 01:55:15 2007 +++ llvm/docs/LangRef.html Tue Jan 9 14:08:58 2007 @@ -3090,7 +3090,8 @@

The 'bitcast' instruction takes a value to cast, which must be a first class value, and a type to cast it to, which must also be a first class type. The bit sizes of value -and the destination type, ty2, must be identical.

+and the destination type, ty2, must be identical. If the source +type is a pointer, the destination type must also be a pointer.

Semantics:

The 'bitcast' instruction converts value to type @@ -4475,7 +4476,7 @@ Chris Lattner
The LLVM Compiler Infrastructure
- Last modified: $Date: 2007/01/08 07:55:15 $ + Last modified: $Date: 2007/01/09 20:08:58 $ From criswell at cs.uiuc.edu Tue Jan 9 15:12:52 2007 From: criswell at cs.uiuc.edu (John Criswell) Date: Tue, 9 Jan 2007 15:12:52 -0600 Subject: [llvm-commits] [release_19] CVS: llvm-poolalloc/include/poolalloc/Config/config.h.in Message-ID: <200701092112.l09LCqXP005596@zion.cs.uiuc.edu> Changes in directory llvm-poolalloc/include/poolalloc/Config: config.h.in updated: 1.3.2.1 -> 1.3.2.2 --- Log message: Merge in some DSA cleanup from mainline. --- Diffs of the changes: (+2 -0) config.h.in | 2 ++ 1 files changed, 2 insertions(+) Index: llvm-poolalloc/include/poolalloc/Config/config.h.in diff -u llvm-poolalloc/include/poolalloc/Config/config.h.in:1.3.2.1 llvm-poolalloc/include/poolalloc/Config/config.h.in:1.3.2.2 --- llvm-poolalloc/include/poolalloc/Config/config.h.in:1.3.2.1 Wed Dec 13 15:58:21 2006 +++ llvm-poolalloc/include/poolalloc/Config/config.h.in Tue Jan 9 15:12:35 2007 @@ -410,6 +410,7 @@ /* Define if dlsym() requires a leading underscore in symbol names. */ #undef NEED_USCORE +#if 0 /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT @@ -424,6 +425,7 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +#endif /* Define as the return type of signal handlers (`int' or `void'). */ #undef RETSIGTYPE From sabre at nondot.org Tue Jan 9 16:44:28 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:28 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile Message-ID: <200701092244.l09MiSfT019439@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile:1.1.1.1 Mon Jan 8 20:55:39 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = lame +PROG = consumer-lame CPPFLAGS = -DHAVEMPGLIB -DLAMEPARSE -DNDEBUG -D__NO_MATH_INLINES -O -DLAMESNDFILE LDFLAGS = -lm RUN_OPTIONS = -S large.wav output_large.mp3 From sabre at nondot.org Tue Jan 9 16:44:50 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:50 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile Message-ID: <200701092244.l09MiowF019449@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile:1.1.1.1 Mon Jan 8 20:54:30 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = djpeg +PROG = consumer-jpeg LDFLAGS = -lm RUN_OPTIONS = -dct int -ppm -outfile output_large_decode.ppm input_large.jpg include $(LEVEL)/MultiSource/Makefile.multisrc From sabre at nondot.org Tue Jan 9 16:44:51 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:51 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish/Makefile Message-ID: <200701092244.l09MipB8019455@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish/Makefile:1.1.1.1 Mon Jan 8 21:00:27 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = blowfish +PROG = security-blowfish LDFLAGS = -lm RUN_OPTIONS = e input_large.asc output_large.enc 1234567890abcdeffedcba0987654321 #RUN_OPTIONS = d output_large.enc output_large.asc 1234567890abcdeffedcba0987654321 From sabre at nondot.org Tue Jan 9 16:44:54 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:54 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile Message-ID: <200701092244.l09MisZB019475@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile:1.1.1.1 Mon Jan 8 21:16:26 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = fft +PROG = telecomm-fft LDFLAGS = -lm RUN_OPTIONS = 8 32768 -i From sabre at nondot.org Tue Jan 9 16:44:56 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:56 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile Message-ID: <200701092244.l09MiuYK019515@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile:1.1.1.1 Mon Jan 8 20:53:46 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = bitcount +PROG = automotive-bitcount LDFLAGS = -lm RUN_OPTIONS = 1125000 include $(LEVEL)/MultiSource/Makefile.multisrc From sabre at nondot.org Tue Jan 9 16:44:55 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:55 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm/Makefile Message-ID: <200701092244.l09MitpC019495@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm/Makefile:1.1.1.1 Mon Jan 8 21:06:42 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = rawdaudio +PROG = telecomm-adpcm LDFLAGS = -lm RUN_OPTIONS = < large.adpcm From sabre at nondot.org Tue Jan 9 16:44:54 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:54 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch/Makefile Message-ID: <200701092244.l09Mis1e019482@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch/Makefile:1.1.1.1 Mon Jan 8 20:59:06 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = stringsearch +PROG = office-stringsearch LDFLAGS = -lm include $(LEVEL)/MultiSource/Makefile.multisrc From sabre at nondot.org Tue Jan 9 16:44:56 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:56 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/security-sha/Makefile Message-ID: <200701092244.l09MiuLb019517@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/security-sha: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/security-sha/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/security-sha/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/security-sha/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/security-sha/Makefile:1.1.1.1 Mon Jan 8 21:04:16 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/security-sha/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = sha +PROG = security-sha LDFLAGS = -lm RUN_OPTIONS = input_large.asc From sabre at nondot.org Tue Jan 9 16:44:53 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:53 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael/Makefile Message-ID: <200701092244.l09Mir4r019470@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael/Makefile:1.1.1.1 Mon Jan 8 21:01:47 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = rijndael +PROG = security-rijndael LDFLAGS = -lm #RUN_OPTIONS = input_large.asc output_large.enc e 1234567890abcdeffedcba09876543211234567890abcdeffedcba0987654321 RUN_OPTIONS = output_large.enc output_large.dec d 1234567890abcdeffedcba09876543211234567890abcdeffedcba0987654321 From sabre at nondot.org Tue Jan 9 16:44:51 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:51 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile Message-ID: <200701092244.l09Mip7X019461@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile:1.1.1.1 Mon Jan 8 21:16:32 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = untoast +PROG = telecomm-gsm CPPFLAGS = -DSTUPID_COMPILER -DNeedFunctionPrototypes=1 -DSASR LDFLAGS = -lm RUN_OPTIONS = -fps -c large.au.run.gsm From sabre at nondot.org Tue Jan 9 16:44:56 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:56 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile Message-ID: <200701092244.l09MiuWQ019521@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile:1.1.1.1 Mon Jan 8 20:56:05 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = lout +PROG = consumer-typeset CPPFLAGS = -DOS_UNIX=1 -DOS_DOS=0 -DOS_MAC=0 -DDB_FIX=0 -DUSE_STAT=1 -DSAFE_DFT=0 -DCOLLATE=1 -DLIB_DIR=\"lout.lib\" -DFONT_DIR=\"font\" -DMAPS_DIR=\"maps\" -DINCL_DIR=\"include\" -DDATA_DIR=\"data\" -DHYPH_DIR=\"hyph\" -DLOCALE_DIR=\"locale\" -DCHAR_IN=1 -DCHAR_OUT=0 -DLOCALE_ON=1 -DASSERT_ON=1 -DDEBUG_ON=0 -DPDF_COMPRESSION=0 LDFLAGS = -lm RUN_OPTIONS = -I data/include -D data/data -F data/font -C data/maps -H data/hyph large.lout > output_large.ps From sabre at nondot.org Tue Jan 9 16:44:56 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:56 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan/Makefile Message-ID: <200701092244.l09MiuxF019500@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan/Makefile:1.1.1.1 Mon Jan 8 20:53:49 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = susan +PROG = automotive-susan LDFLAGS = -lm RUN_OPTIONS = input_large.pgm output_large.smoothing.pgm -s include $(LEVEL)/MultiSource/Makefile.multisrc From sabre at nondot.org Tue Jan 9 16:44:56 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:56 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath/Makefile Message-ID: <200701092244.l09MiuPs019510@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath/Makefile:1.1.1.1 Mon Jan 8 20:53:45 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath/Makefile Tue Jan 9 16:44:02 2007 @@ -1,5 +1,5 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = basicmath +PROG = automotive-basicmath LDFLAGS = -lm include $(LEVEL)/MultiSource/Makefile.multisrc From sabre at nondot.org Tue Jan 9 16:44:54 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:54 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/network-patricia/Makefile Message-ID: <200701092244.l09Mis3H019481@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/network-patricia: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/network-patricia/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/network-patricia/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/network-patricia/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/network-patricia/Makefile:1.1.1.1 Mon Jan 8 20:58:26 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/network-patricia/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = patricia +PROG = network-patricia LDFLAGS = -lm RUN_OPTIONS = large.udp include $(LEVEL)/MultiSource/Makefile.multisrc From sabre at nondot.org Tue Jan 9 16:44:52 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:52 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/Makefile Message-ID: <200701092244.l09MiqCH019465@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+20 -2) Makefile | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/Makefile:1.1.1.1 Mon Jan 8 20:53:45 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/Makefile Tue Jan 9 16:44:02 2007 @@ -1,9 +1,27 @@ -# MultiSource/MiBench Makefile: Build all subdirectories automatically +# MultiSource/Benchmarks/MiBench Makefile LEVEL = ../../.. ## NOTE: This must remain in this order, so that the labels in the nightly ## tester gnuplot scripts are correct. -PARALLEL_DIRS := automotive consumer network office security telecomm +PARALLEL_DIRS := \ + automotive-basicmath \ + automotive-bitcount \ + automotive-susan \ + consumer-jpeg \ + consumer-lame \ + consumer-typeset \ + network-dijkstra \ + network-patricia \ + office-ispell \ + office-stringsearch \ + security-blowfish \ + security-rijndael \ + security-sha \ + telecomm-CRC32 \ + telecomm-FFT \ + telecomm-adpcm \ + telecomm-gsm include $(LEVEL)/Makefile.programs + From sabre at nondot.org Tue Jan 9 16:44:55 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:55 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra/Makefile Message-ID: <200701092244.l09Mit0t019490@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra/Makefile:1.1.1.1 Mon Jan 8 20:57:53 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = dijkstra +PROG = network-dijkstra LDFLAGS = -lm RUN_OPTIONS = input.dat include $(LEVEL)/MultiSource/Makefile.multisrc From sabre at nondot.org Tue Jan 9 16:44:56 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:56 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/office-ispell/Makefile Message-ID: <200701092244.l09MiuoZ019505@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/office-ispell: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/office-ispell/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/office-ispell/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/office-ispell/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/office-ispell/Makefile:1.1.1.1 Mon Jan 8 20:59:03 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/office-ispell/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = ispell +PROG = office-ispell CPPFLAGS = -Dconst= LDFLAGS = -lm RUN_OPTIONS = -a -d americanmed+ < large.txt From sabre at nondot.org Tue Jan 9 16:44:57 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 16:44:57 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32/Makefile Message-ID: <200701092244.l09Miveq019530@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32: Makefile updated: 1.1.1.1 -> 1.2 --- Log message: flatten directory hierarchy --- Diffs of the changes: (+2 -2) Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32/Makefile diff -u llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32/Makefile:1.1.1.1 llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32/Makefile:1.2 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32/Makefile:1.1.1.1 Mon Jan 8 21:16:25 2007 +++ llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32/Makefile Tue Jan 9 16:44:02 2007 @@ -1,6 +1,6 @@ -LEVEL = ../../../../.. +LEVEL = ../../../.. -PROG = CRC32 +PROG = telecomm-CRC32 LDFLAGS = -lm RUN_OPTIONS = large.pcm From sabre at nondot.org Tue Jan 9 17:29:55 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 17:29:55 -0600 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/GlobalOpt.cpp Message-ID: <200701092329.l09NTtTp023825@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: GlobalOpt.cpp updated: 1.82 -> 1.83 --- Log message: Fix a bug in heap-sra that caused compilation failure of office-ispell. --- Diffs of the changes: (+19 -3) GlobalOpt.cpp | 22 +++++++++++++++++++--- 1 files changed, 19 insertions(+), 3 deletions(-) Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp diff -u llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.82 llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.83 --- llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.82 Sat Dec 30 23:48:39 2006 +++ llvm/lib/Transforms/IPO/GlobalOpt.cpp Tue Jan 9 17:29:37 2007 @@ -1016,9 +1016,25 @@ // loads, and all uses of those loads are simple. Rewrite them to use loads // of the per-field globals instead. while (!GV->use_empty()) { - LoadInst *LI = cast(GV->use_back()); - RewriteUsesOfLoadForHeapSRoA(LI, FieldGlobals); - LI->eraseFromParent(); + if (LoadInst *LI = dyn_cast(GV->use_back())) { + RewriteUsesOfLoadForHeapSRoA(LI, FieldGlobals); + LI->eraseFromParent(); + } else { + // Must be a store of null. + StoreInst *SI = cast(GV->use_back()); + assert(isa(SI->getOperand(0)) && + cast(SI->getOperand(0))->isNullValue() && + "Unexpected heap-sra user!"); + + // Insert a store of null into each global. + for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) { + Constant *Null = + Constant::getNullValue(FieldGlobals[i]->getType()->getElementType()); + new StoreInst(Null, FieldGlobals[i], SI); + } + // Erase the original store. + SI->eraseFromParent(); + } } // The old global is now dead, remove it. From lattner at cs.uiuc.edu Tue Jan 9 17:36:05 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:36:05 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/ Message-ID: <200701092336.l09Na5ok025806@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/ Message-ID: <200701092337.l09NbdCs026004@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/network-patricia/ Message-ID: <200701092337.l09NbdaD026028@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/network-patricia: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/network-patricia added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath/ Message-ID: <200701092337.l09NbdqB026002@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/automotive-basicmath added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan/ Message-ID: <200701092337.l09Nbd5Z026007@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/automotive-susan added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/ Message-ID: <200701092337.l09NbdxJ026010@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch/ Message-ID: <200701092337.l09NbdDm026037@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/office-stringsearch added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish/ Message-ID: <200701092337.l09Nbdck026043@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/security-blowfish added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:40 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:40 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32/ Message-ID: <200701092337.l09NbeC6026056@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-CRC32 added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/ Message-ID: <200701092337.l09NbdHR026015@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset/ Message-ID: <200701092337.l09Nbdql026020@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/consumer-typeset added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:40 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:40 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/security-sha/ Message-ID: <200701092337.l09Nbeo5026053@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/security-sha: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/security-sha added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/office-ispell/ Message-ID: <200701092337.l09NbdmE026033@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/office-ispell: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/office-ispell added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:40 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:40 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/ Message-ID: <200701092337.l09Nbeda026072@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:40 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:40 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/ Message-ID: <200701092337.l09NbeMf026060@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael/ Message-ID: <200701092337.l09Nbd3J026047@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/security-rijndael added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:40 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:40 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm/ Message-ID: <200701092337.l09Nbeiw026068@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-adpcm added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From lattner at cs.uiuc.edu Tue Jan 9 17:37:39 2007 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 9 Jan 2007 17:37:39 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra/ Message-ID: <200701092337.l09Nbdbi026025@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra: --- Log message: Directory /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/network-dijkstra added to the repository --- Diffs of the changes: (+0 -0) 0 files changed From sabre at nondot.org Tue Jan 9 17:38:30 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 17:38:30 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/Makefile Message-ID: <200701092338.l09NcUBD026676@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench: Makefile added (r1.1) --- Log message: re-check-in MiBench --- Diffs of the changes: (+27 -0) Makefile | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+) Index: llvm-test/MultiSource/Benchmarks/MiBench/Makefile diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/Makefile:1.1 *** /dev/null Tue Jan 9 17:38:24 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/Makefile Tue Jan 9 17:38:14 2007 *************** *** 0 **** --- 1,27 ---- + # MultiSource/Benchmarks/MiBench Makefile + + LEVEL = ../../.. + + ## NOTE: This must remain in this order, so that the labels in the nightly + ## tester gnuplot scripts are correct. + PARALLEL_DIRS := \ + automotive-basicmath \ + automotive-bitcount \ + automotive-susan \ + consumer-jpeg \ + consumer-lame \ + consumer-typeset \ + network-dijkstra \ + network-patricia \ + office-ispell \ + office-stringsearch \ + security-blowfish \ + security-rijndael \ + security-sha \ + telecomm-CRC32 \ + telecomm-FFT \ + telecomm-adpcm \ + telecomm-gsm + + include $(LEVEL)/Makefile.programs + From sabre at nondot.org Tue Jan 9 17:45:02 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 17:45:02 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/LICENSE Makefile bitarray.c bitcnt_1.c bitcnt_2.c bitcnt_3.c bitcnt_4.c bitcnts.c bitfiles.c bitops.h bitstrng.c bstr_i.c conio.h extkword.h sniptype.h Message-ID: <200701092345.l09Nj2dZ028864@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount: LICENSE added (r1.1) Makefile added (r1.1) bitarray.c added (r1.1) bitcnt_1.c added (r1.1) bitcnt_2.c added (r1.1) bitcnt_3.c added (r1.1) bitcnt_4.c added (r1.1) bitcnts.c added (r1.1) bitfiles.c added (r1.1) bitops.h added (r1.1) bitstrng.c added (r1.1) bstr_i.c added (r1.1) conio.h added (r1.1) extkword.h added (r1.1) sniptype.h added (r1.1) --- Log message: Readd mibench --- Diffs of the changes: (+933 -0) LICENSE | 3 + Makefile | 6 ++ bitarray.c | 34 +++++++++++++++ bitcnt_1.c | 43 +++++++++++++++++++ bitcnt_2.c | 40 +++++++++++++++++ bitcnt_3.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bitcnt_4.c | 82 ++++++++++++++++++++++++++++++++++++ bitcnts.c | 94 +++++++++++++++++++++++++++++++++++++++++ bitfiles.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bitops.h | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ bitstrng.c | 62 +++++++++++++++++++++++++++ bstr_i.c | 42 ++++++++++++++++++ conio.h | 22 +++++++++ extkword.h | 102 +++++++++++++++++++++++++++++++++++++++++++++ sniptype.h | 37 ++++++++++++++++ 15 files changed, 933 insertions(+) Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/LICENSE diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/LICENSE:1.1 *** /dev/null Tue Jan 9 17:44:44 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/LICENSE Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,3 ---- + From http://www.snippets.org/. + + This code is FREE with no restrictions. Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/Makefile Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,6 ---- + LEVEL = ../../../.. + + PROG = automotive-bitcount + LDFLAGS = -lm + RUN_OPTIONS = 1125000 + include $(LEVEL)/MultiSource/Makefile.multisrc Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitarray.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitarray.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitarray.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,34 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** Functions to maintain an arbitrary length array of bits + */ + + #include "bitops.h" + + char *alloc_bit_array(size_t bits) + { + char *set = calloc((bits + CHAR_BIT - 1) / CHAR_BIT, sizeof(char)); + + return set; + } + + int getbit(char *set, int number) + { + set += number / CHAR_BIT; + return (*set & (1 << (number % CHAR_BIT))) != 0; /* 0 or 1 */ + } + + void setbit(char *set, int number, int value) + { + set += number / CHAR_BIT; + if (value) + *set |= 1 << (number % CHAR_BIT); /* set bit */ + else *set &= ~(1 << (number % CHAR_BIT)); /* clear bit*/ + } + + void flipbit(char *set, int number) + { + set += number / CHAR_BIT; + *set ^= 1 << (number % CHAR_BIT); /* flip bit */ + } Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_1.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_1.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_1.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,43 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** Bit counter by Ratko Tomic + */ + + #include "bitops.h" + + int CDECL bit_count(long x) + { + int n = 0; + /* + ** The loop will execute once for each bit of x set, this is in average + ** twice as fast as the shift/test method. + */ + if (x) do + n++; + while (0 != (x = x&(x-1))) ; + return(n); + } + + #ifdef TEST + + #include + #include "snip_str.h" /* For plural_text() macro */ + + main(int argc, char *argv[]) + { + long n; + + while(--argc) + { + int i; + + n = atol(*++argv); + i = bit_count(n); + printf("%ld contains %d bit%s set\n", + n, i, plural_text(i)); + } + return 0; + } + + #endif /* TEST */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_2.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_2.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_2.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,40 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** Bit counter by Ratko Tomic + */ + + #include "bitops.h" + + int CDECL bitcount(long i) + { + i = ((i & 0xAAAAAAAAL) >> 1) + (i & 0x55555555L); + i = ((i & 0xCCCCCCCCL) >> 2) + (i & 0x33333333L); + i = ((i & 0xF0F0F0F0L) >> 4) + (i & 0x0F0F0F0FL); + i = ((i & 0xFF00FF00L) >> 8) + (i & 0x00FF00FFL); + i = ((i & 0xFFFF0000L) >> 16) + (i & 0x0000FFFFL); + return (int)i; + } + + #ifdef TEST + + #include + #include "snip_str.h" /* For plural_text() macro */ + + main(int argc, char *argv[]) + { + long n; + + while(--argc) + { + int i; + + n = atol(*++argv); + i = bitcount(n); + printf("%ld contains %d bit%s set\n", + n, i, plural_text(i)); + } + return 0; + } + + #endif /* TEST */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_3.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_3.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_3.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,117 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** BITCNT_3.C - Bit counting functions using table lookup + ** + ** public domain by Auke Reitsma and Bruce Wedding + */ + + #include "bitops.h" /* from Snippets */ + + /* + ** Bits table + */ + + static char bits[256] = + { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, /* 0 - 15 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 16 - 31 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 32 - 47 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 48 - 63 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 64 - 79 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 80 - 95 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 96 - 111 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 112 - 127 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 128 - 143 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 144 - 159 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 160 - 175 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 176 - 191 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 192 - 207 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 208 - 223 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 224 - 239 */ + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 /* 240 - 255 */ + }; + + /* + ** Count bits in each nybble + ** + ** Note: Only the first 16 table entries are used, the rest could be + ** omitted. + */ + + int CDECL ntbl_bitcount(long int x) + { + return + bits[ (int) (x & 0x0000000FUL) ] + + bits[ (int)((x & 0x000000F0UL) >> 4) ] + + bits[ (int)((x & 0x00000F00UL) >> 8) ] + + bits[ (int)((x & 0x0000F000UL) >> 12)] + + bits[ (int)((x & 0x000F0000UL) >> 16)] + + bits[ (int)((x & 0x00F00000UL) >> 20)] + + bits[ (int)((x & 0x0F000000UL) >> 24)] + + bits[ (int)((x & 0xF0000000UL) >> 28)]; + } + + /* + ** Count bits in each byte + ** + ** by Bruce Wedding, works best on Watcom & Borland + */ + + int CDECL BW_btbl_bitcount(long int x) + { + union + { + unsigned char ch[4]; + long y; + } U; + + U.y = x; + + return bits[ U.ch[0] ] + bits[ U.ch[1] ] + + bits[ U.ch[3] ] + bits[ U.ch[2] ]; + } + + /* + ** Count bits in each byte + ** + ** by Auke Reitsma, works best on Microsoft, Symantec, and others + */ + + int CDECL AR_btbl_bitcount(long int x) + { + unsigned char * Ptr = (unsigned char *) &x ; + int Accu ; + + Accu = bits[ *Ptr++ ]; + Accu += bits[ *Ptr++ ]; + Accu += bits[ *Ptr++ ]; + Accu += bits[ *Ptr ]; + return Accu; + } + + #ifdef TEST + + #include + #include "snip_str.h" /* For plural_text() macro */ + + main(int argc, char *argv[]) + { + long n; + + while(--argc) + { + int i; + + n = atol(*++argv); + i = BW_btbl_bitcount(n); + printf("%ld contains %d bit%s set\n", + n, i, plural_text(i)); + i = AR_btbl_bitcount(n); + printf("%ld contains %d bit%s set\n", + n, i, plural_text(i)); + } + return 0; + } + + #endif /* TEST */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_4.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_4.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnt_4.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,82 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** BITCNT_4.C - Recursive bit counting functions using table lookup + ** + ** public domain by Bob Stout + */ + + #include "bitops.h" /* from Snippets */ + + static char bits[256] = + { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, /* 0 - 15 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 16 - 31 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 32 - 47 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 48 - 63 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 64 - 79 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 80 - 95 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 96 - 111 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 112 - 127 */ + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 128 - 143 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 144 - 159 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 160 - 175 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 176 - 191 */ + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 192 - 207 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 208 - 223 */ + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 224 - 239 */ + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 /* 240 - 255 */ + }; + + /* + ** Count bits in each nybble + ** + ** Note: Only the first 16 table entries are used, the rest could be + ** omitted. + */ + + int CDECL ntbl_bitcnt(long x) + { + int cnt = bits[(int)(x & 0x0000000FL)]; + + if (0L != (x >>= 4)) + cnt += ntbl_bitcnt(x); + + return cnt; + } + + /* + ** Count bits in each byte + */ + + int CDECL btbl_bitcnt(long x) + { + int cnt = bits[ ((char *)&x)[0] & 0xFF ]; + + if (0L != (x >>= 8)) + cnt += btbl_bitcnt(x); + return cnt; + } + + #ifdef TEST + + #include + #include "snip_str.h" /* For plural_text() macro */ + + main(int argc, char *argv[]) + { + long n; + + while(--argc) + { + int i; + + n = atol(*++argv); + i = btbl_bitcnt(n); + printf("%ld contains %d bit%s set\n", + n, i, plural_text(i)); + } + return 0; + } + + #endif /* TEST */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnts.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnts.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitcnts.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,94 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** BITCNTS.C - Test program for bit counting functions + ** + ** public domain by Bob Stout & Auke Reitsma + */ + + #include + #include + #include "conio.h" + #include + #include + #include + #include "bitops.h" + + #define FUNCS 7 + + static int CDECL bit_shifter(long int x); + + int main(int argc, char *argv[]) + { + clock_t start, stop; + double ct, cmin = DBL_MAX, cmax = 0; + int i, cminix, cmaxix; + long j, n, seed; + int iterations; + static int (* CDECL pBitCntFunc[FUNCS])(long) = { + bit_count, + bitcount, + ntbl_bitcnt, + ntbl_bitcount, + /* btbl_bitcnt, DOESNT WORK*/ + BW_btbl_bitcount, + AR_btbl_bitcount, + bit_shifter + }; + static char *text[FUNCS] = { + "Optimized 1 bit/loop counter", + "Ratko's mystery algorithm", + "Recursive bit count by nybbles", + "Non-recursive bit count by nybbles", + /* "Recursive bit count by bytes",*/ + "Non-recursive bit count by bytes (BW)", + "Non-recursive bit count by bytes (AR)", + "Shift and count bits" + }; + if (argc<2) { + fprintf(stderr,"Usage: bitcnts \n"); + exit(-1); + } + iterations=atoi(argv[1]); + + puts("Bit counter algorithm benchmark\n"); + + for (i = 0; i < FUNCS; i++) { + #if 0 + start = clock(); + #endif + + for (j = n = 0, seed = rand(); j < iterations; j++, seed += 13) + n += pBitCntFunc[i](seed); + + #if 0 + stop = clock(); + ct = (stop - start) / (double)CLOCKS_PER_SEC; + if (ct < cmin) { + cmin = ct; + cminix = i; + } + if (ct > cmax) { + cmax = ct; + cmaxix = i; + } + + printf("%-38s> Time: %7.3f sec.; Bits: %ld\n", text[i], ct, n); + #endif + printf("%-38s> Bits: %ld\n", text[i], n); + } + #if 0 + printf("\nBest > %s\n", text[cminix]); + printf("Worst > %s\n", text[cmaxix]); + #endif + return 0; + } + + static int CDECL bit_shifter(long int x) + { + int i, n; + + for (i = n = 0; x && (i < (sizeof(long) * CHAR_BIT)); ++i, x >>= 1) + n += (int)(x & 1L); + return n; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitfiles.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitfiles.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitfiles.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,137 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** BITFILES.C - reading/writing bit files + ** + ** Public domain by Aare Tali + */ + + #include + #include "bitops.h" + + bfile *bfopen(char *name, char *mode) + { + bfile * bf; + + bf = malloc(sizeof(bfile)); + if (NULL == bf) + return NULL; + bf->file = fopen(name, mode); + if (NULL == bf->file) + { + free(bf); + return NULL; + } + bf->rcnt = 0; + bf->wcnt = 0; + return bf; + } + + int bfread(bfile *bf) + { + if (0 == bf->rcnt) /* read new byte */ + { + bf->rbuf = (char)fgetc(bf->file); + bf->rcnt = 8; + } + bf->rcnt--; + return (bf->rbuf & (1 << bf->rcnt)) != 0; + } + + void bfwrite(int bit, bfile *bf) + { + if (8 == bf->wcnt) /* write full byte */ + { + fputc(bf->wbuf, bf->file); + bf->wcnt = 0; + } + bf->wcnt++; + bf->wbuf <<= 1; + bf->wbuf |= bit & 1; + } + + void bfclose(bfile *bf) + { + fclose(bf->file); + free(bf); + } + + #ifdef TEST + + void test1(void) + { + bfile *out; + bfile *in; + FILE *in1; + FILE *in2; + + in = bfopen("bitfiles.c", "rb"); + out = bfopen("bitfiles.cc", "wb"); + if ((NULL == in) || (NULL == out)) + { + printf("Can't open/create test files\n"); + exit(1); + } + while (!feof(in->file)) + bfwrite(bfread(in), out); + bfclose(in); + bfclose(out); + in1 = fopen("bitfiles.c", "rb"); + in2 = fopen("bitfiles.cc", "rb"); + if ((NULL == in1) || (NULL == in2)) + { + printf("Can't open test files for verifying\n"); + exit(1); + } + while (!feof(in1) && !feof(in2)) + { + if (fgetc(in1) != fgetc(in2)) + { + printf("Files not identical, copy failed!\n"); + exit(1); + } + } + if (!feof(in1) || !feof(in2)) + { + printf("Not same size, copy failed!\n"); + exit(1); + } + fclose(in1); + fclose(in2); + } + + void test2(void) + { + FILE *in1; + bfile *in2; + int ch; + + in1 = fopen("bitfiles.c", "rb"); + in2 = bfopen("bitfiles.cc", "rb"); + if ((NULL == in1) || (NULL == in2)) + { + printf("Can't open test files\n"); + exit(1); + } + while (!feof(in1) && !feof(in2->file)) + { + ch = fgetc(in1); + if (ch < ' ') + ch = '.'; + printf(" '%c' ", ch); + for (ch = 0; ch < 8; ch++) + printf("%c", "01"[bfread(in2)]); + printf(" "); + } + fclose(in1); + bfclose(in2); + } + + main() + { + test1(); + test2(); + return 0; + } + + #endif /* TEST */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitops.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitops.h:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitops.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,112 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** Macros and prototypes for bit operations + ** + ** public domain for SNIPPETS by: + ** Scott Dudley + ** Auke Reitsma + ** Ratko Tomic + ** Aare Tali + ** J. Blauth + ** Bruce Wedding + ** Bob Stout + */ + + #ifndef BITOPS__H + #define BITOPS__H + + #include + #include /* For size_t */ + #include /* For CHAR_BIT */ + #include "sniptype.h" /* For TOBOOL() */ + #include "extkword.h" /* For CDECL */ + + /* + ** Macros to manipulate bits in any integral data type. + */ + + #define BitSet(arg,posn) ((arg) | (1L << (posn))) + #define BitClr(arg,posn) ((arg) & ~(1L << (posn))) + #define BitFlp(arg,posn) ((arg) ^ (1L << (posn))) + #define BitTst(arg,posn) TOBOOL((arg) & (1L << (posn))) + + /* + ** Macros to manipulate bits in an array of char. + ** These macros assume CHAR_BIT is one of either 8, 16, or 32. + */ + + #define MASK CHAR_BIT-1 + #define SHIFT ((CHAR_BIT==8)?3:(CHAR_BIT==16)?4:8) + + #define BitOff(a,x) ((void)((a)[(x)>>SHIFT] &= ~(1 << ((x)&MASK)))) + #define BitOn(a,x) ((void)((a)[(x)>>SHIFT] |= (1 << ((x)&MASK)))) + #define BitFlip(a,x) ((void)((a)[(x)>>SHIFT] ^= (1 << ((x)&MASK)))) + #define IsBit(a,x) ((a)[(x)>>SHIFT] & (1 << ((x)&MASK))) + + /* + ** BITARRAY.C + */ + + char *alloc_bit_array(size_t bits); + int getbit(char *set, int number); + void setbit(char *set, int number, int value); + void flipbit(char *set, int number); + + /* + ** BITFILES.C + */ + + typedef struct { + FILE * file; /* for stream I/O */ + char rbuf; /* read bit buffer */ + char rcnt; /* read bit count */ + char wbuf; /* write bit buffer */ + char wcnt; /* write bit count */ + } bfile; + + bfile * bfopen(char *name, char *mode); + int bfread(bfile *bf); + void bfwrite(int bit, bfile *bf); + void bfclose(bfile *bf); + + /* + ** BITSTRNG.C + */ + + void bitstring(char *str, long byze, int biz, int strwid); + + /* + ** BSTR_I.C + */ + + unsigned int bstr_i(char *cptr); + + /* + ** BITCNT_1.C + */ + + int CDECL bit_count(long x); + + /* + ** BITCNT_2.C + */ + + int CDECL bitcount(long i); + + /* + ** BITCNT_3.C + */ + + int CDECL ntbl_bitcount(long int x); + int CDECL BW_btbl_bitcount(long int x); + int CDECL AR_btbl_bitcount(long int x); + + /* + ** BITCNT_4.C + */ + + int CDECL ntbl_bitcnt(long x); + int CDECL btbl_bitcnt(long x); + + #endif /* BITOPS__H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitstrng.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitstrng.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bitstrng.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,62 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** bitstring(): print bit pattern of bytes formatted to string. + ** + ** By J. Blauth, Sept. 1992. Hereby placed into the public domain. + ** + ** byze: value to transform to bitstring. + ** biz: count of bits to be shown (counted from lowest bit, can be any + ** even or odd number). + ** strwid: total width the string shall have. Since between every 4 bits a + ** blank (0x20) is inserted (not added after lowest bit), width of + ** bitformat only is (biz+(biz/4-1)). Bits are printed right aligned, + ** positions from highest bit to start of string filled with blanks. + ** If value of strwid smaller than space needed to print all bits, + ** strwid is ignored (e.g.: + ** bitstr(s,b,16,5) results in 19 chars +'\0'). + ** + ** EXAMPLE: + ** for (j = 1; j <= 16; j++) { bitstring(s, j, j, 16); puts(s); } + ** 1: 1 + ** 2: 10 + ** 3: 011 + ** d: 0 0000 0000 1101 + ** e: 00 0000 0000 1110 + ** f: 000 0000 0000 1111 + */ + + #include "bitops.h" + + void bitstring(char *str, long byze, int biz, int strwid) + { + int i, j; + + j = strwid - (biz + (biz >> 2)- (biz % 4 ? 0 : 1)); + for (i = 0; i < j; i++) + *str++ = ' '; + while (--biz >= 0) + { + *str++ = ((byze >> biz) & 1) + '0'; + if (!(biz % 4) && biz) + *str++ = ' '; + } + *str = '\0'; + } + + #ifdef TEST + + #include + + int main(void) + { + char s[80]; long j; + for (j = 1L; j <= 16L; j++) + { + bitstring(s, (long)j, (int)j, 16); + printf("%2ld: %s\n", j, s); + } + return EXIT_SUCCESS; + } + + #endif /* TEST */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bstr_i.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bstr_i.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/bstr_i.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,42 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** Make an ascii binary string into an integer. + ** + ** Public domain by Bob Stout + */ + + #include + #include "bitops.h" + + unsigned int bstr_i(char *cptr) + { + unsigned int i, j = 0; + + while (cptr && *cptr && strchr("01", *cptr)) + { + i = *cptr++ - '0'; + j <<= 1; + j |= (i & 0x01); + } + return(j); + } + + #ifdef TEST + + #include + + int main(int argc, char *argv[]) + { + char *arg; + unsigned int x; + + while (--argc) + { + x = bstr_i(arg = *++argv); + printf("Binary %s = %d = %04Xh\n", arg, x, x); + } + return EXIT_SUCCESS; + } + + #endif /* TEST */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/conio.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/conio.h:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/conio.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,22 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** UNXCONIO.H - Port crucial DOS|Win|OS/2 non-blocking console I/O + ** functions to Unix/Posix. + ** + ** public domain SNIPPETS header for use with Steve Poole's TERM_OPT.C + */ + + #ifndef UNXCONIO__H + #define UNXCONIO__H + + #include + #include + + #define echo_on() term_option(0) + #define echo_off() term_option(1) + + int term_option(); + int getch(); + + #endif /* UNXCONIO__H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/extkword.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/extkword.h:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/extkword.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,102 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /*==================================================================== + + _MSC_VER Microsoft C 6.0 and later + _QC Microsoft Quick C 2.51 and later + __TURBOC__ Borland Turbo C, Turbo C++ and BC++ + __BORLANDC__ Borland C++ + __ZTC__ Zortech C and C++ + __SC__ Symantec C++ + __WATCOMC__ WATCOM C + __POWERC Mix Power C + __GNUC__ Gnu C + + Revised: + + 25-Sep-95 Bob Stout Original from PC-PORT.H + 30-Mar-96 Ed Blackman OS/2 mods for OS/2 ver 2.0 and up + 30-May-96 Andrew Clarke Added support for WATCOM C/C++ __NT__ macro. + 17-Jun-96 Bob Stout Added __FLAT__ macros support + 20-Aug-96 Bob Stout Eliminate Win32 conflicts + ======================================================================*/ + + + /* prevent multiple inclusions of this header file */ + + #ifndef EXTKWORD__H + #define EXTKWORD__H + + #include /* For INT_MAX, LONG_MAX */ + + /* + ** Watcom defines __FLAT__ for 32-bit environments and so will we + */ + + #if !defined(__FLAT__) && !defined(__WATCOMC__) && !defined(_MSC_VER) + #if defined(__GNUC__) + #define __FLAT__ 1 + #elif defined (_WIN32) || defined(WIN32) || defined(__NT__) + #define __FLAT__ 1 + #elif defined(__INTSIZE) + #if (4 == __INTSIZE) + #define __FLAT__ 1 + #endif + #elif (defined(__ZTC__) && !defined(__SC__)) || defined(__TURBOC__) + #if ((INT_MAX != SHRT_MAX) && (SHRT_MAX == 32767)) + #define __FLAT__ 1 + #endif + #endif + #endif + + /* + ** Correct extended keywords syntax + */ + + #if defined(__OS2__) /* EBB: not sure this works for OS/2 1.x */ + #include + #define INTERRUPT + #define HUGE + #elif defined(_WIN32) || defined(WIN32) || defined(__NT__) + #define WIN32_LEAN_AND_MEAN + #define NOGDI + #define NOSERVICE + #undef INC_OLE1 + #undef INC_OLE2 + #include + #define INTERRUPT + #define HUGE + #else /* ! Win 32 or OS/2 */ + /* #if (defined(__POWERC) || (defined(__TURBOC__) && !defined(__BORLANDC__)) \ + || (defined(__ZTC__) && !defined(__SC__))) && !defined(__FLAT__) + #define FAR far + #define NEAR near + #define PASCAL pascal + #define CDECL cdecl + #if (defined(__ZTC__) && !defined(__SC__)) || (defined(__SC__) && \ + (__SC__ < 0x700)) + #define HUGE far + #define INTERRUPT + #else + #define HUGE huge + #define INTERRUPT interrupt + #endif*/ + /* #else + #if (defined(__MSDOS__) || defined(MSDOS)) && !defined(__FLAT__) + #define FAR _far + #define NEAR _near + #define HUGE _huge + #define PASCAL _pascal + #define CDECL _cdecl + #define INTERRUPT _interrupt + #else*/ + #define FAR + #define NEAR + #define HUGE + #define PASCAL + #define CDECL + #endif + /* #endif + #endif*/ + + #endif /* EXTKWORD__H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/sniptype.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/sniptype.h:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/automotive-bitcount/sniptype.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,37 ---- + /* +++Date last modified: 05-Jul-1997 */ + + /* + ** SNIPTYPE.H - Include file for SNIPPETS data types and commonly used macros + */ + + #ifndef SNIPTYPE__H + #define SNIPTYPE__H + + #include /* For free() */ + #include /* For NULL & strlen() */ + + typedef enum {Error_ = -1, Success_, False_ = 0, True_} Boolean_T; + + /*#if !defined(WIN32) && !defined(_WIN32) && !defined(__NT__) \ + && !defined(_WINDOWS) + #if !defined(OS2)*/ + typedef unsigned char BYTE; + typedef unsigned long DWORD; + /* #endif*/ + typedef unsigned short WORD; + /*#else + #define WIN32_LEAN_AND_MEAN + #define NOGDI + #define NOSERVICE + #undef INC_OLE1 + #undef INC_OLE2 + #include + #define HUGE + #endif*/ + + #define NUL '\0' + #define LAST_CHAR(s) (((char *)s)[strlen(s) - 1]) + #define TOBOOL(x) (!(!(x))) + #define FREE(p) (free(p),(p)=NULL) + + #endif /* SNIPTYPE__H */ From sabre at nondot.org Tue Jan 9 17:45:04 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 17:45:04 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/LICENSE Makefile README VbrTag.c VbrTag.h brhist.c brhist.h common.c dct64_i386.c decode_i386.c encoder.h fft.c fft.h formatBitstream.c formatBitstream.h get_audio.c get_audio.h gpkplotting.c gpkplotting.h gtkanal.c gtkanal.h huffman.h id3tag.c id3tag.h ieeefloat.c ieeefloat.h interface.c l3bitstream-pvt.h l3bitstream.c l3bitstream.h l3side.h lame.c lame.h large.wav layer3.c machine.h main.c mpg123.h mpglib.h mpglib_main.c newmdct.c newmdct.h output_large.mp3 parse.c portableio.c portableio.h psymodel.c psymodel.h quantize-pvt.c quantize-pvt.h quantize.c quantize.h reservoir.c reservoir.h rtp.c rtp.h small.wav tabinit.c tables.c tables.h takehiro.c timestatus.c timestatus.h util.c util.h vbrquantize.c version.c version.h Message-ID: <200701092345.l09Nj4D4029309@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame: LICENSE added (r1.1) Makefile added (r1.1) README added (r1.1) VbrTag.c added (r1.1) VbrTag.h added (r1.1) brhist.c added (r1.1) brhist.h added (r1.1) common.c added (r1.1) dct64_i386.c added (r1.1) decode_i386.c added (r1.1) encoder.h added (r1.1) fft.c added (r1.1) fft.h added (r1.1) formatBitstream.c added (r1.1) formatBitstream.h added (r1.1) get_audio.c added (r1.1) get_audio.h added (r1.1) gpkplotting.c added (r1.1) gpkplotting.h added (r1.1) gtkanal.c added (r1.1) gtkanal.h added (r1.1) huffman.h added (r1.1) id3tag.c added (r1.1) id3tag.h added (r1.1) ieeefloat.c added (r1.1) ieeefloat.h added (r1.1) interface.c added (r1.1) l3bitstream-pvt.h added (r1.1) l3bitstream.c added (r1.1) l3bitstream.h added (r1.1) l3side.h added (r1.1) lame.c added (r1.1) lame.h added (r1.1) large.wav added (r1.1) layer3.c added (r1.1) machine.h added (r1.1) main.c added (r1.1) mpg123.h added (r1.1) mpglib.h added (r1.1) mpglib_main.c added (r1.1) newmdct.c added (r1.1) newmdct.h added (r1.1) output_large.mp3 added (r1.1) parse.c added (r1.1) portableio.c added (r1.1) portableio.h added (r1.1) psymodel.c added (r1.1) psymodel.h added (r1.1) quantize-pvt.c added (r1.1) quantize-pvt.h added (r1.1) quantize.c added (r1.1) quantize.h added (r1.1) reservoir.c added (r1.1) reservoir.h added (r1.1) rtp.c added (r1.1) rtp.h added (r1.1) small.wav added (r1.1) tabinit.c added (r1.1) tables.c added (r1.1) tables.h added (r1.1) takehiro.c added (r1.1) timestatus.c added (r1.1) timestatus.h added (r1.1) util.c added (r1.1) util.h added (r1.1) vbrquantize.c added (r1.1) version.c added (r1.1) version.h added (r1.1) --- Log message: Readd mibench --- Diffs of the changes: (+21837 -0) LICENSE | 44 + Makefile | 7 README | 33 + VbrTag.c | 494 +++++++++++++++ VbrTag.h | 86 ++ brhist.c | 135 ++++ brhist.h | 15 common.c | 265 ++++++++ dct64_i386.c | 317 +++++++++ decode_i386.c | 156 ++++ encoder.h | 78 ++ fft.c | 356 +++++++++++ fft.h | 10 formatBitstream.c | 543 ++++++++++++++++ formatBitstream.h | 132 ++++ get_audio.c | 937 +++++++++++++++++++++++++++++ get_audio.h | 94 ++ gpkplotting.c | 282 ++++++++ gpkplotting.h | 27 gtkanal.c | 1410 +++++++++++++++++++++++++++++++++++++++++++ gtkanal.h | 68 ++ huffman.h | 332 ++++++++++ id3tag.c | 112 +++ id3tag.h | 29 ieeefloat.c | 962 +++++++++++++++++++++++++++++ ieeefloat.h | 90 ++ interface.c | 220 ++++++ l3bitstream-pvt.h | 48 + l3bitstream.c | 854 ++++++++++++++++++++++++++ l3bitstream.h | 54 + l3side.h | 78 ++ lame.c | 1428 ++++++++++++++++++++++++++++++++++++++++++++ lame.h | 336 ++++++++++ large.wav | 0 layer3.c | 1738 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ machine.h | 112 +++ main.c | 142 ++++ mpg123.h | 174 +++++ mpglib.h | 49 + mpglib_main.c | 203 ++++++ newmdct.c | 631 +++++++++++++++++++ newmdct.h | 6 output_large.mp3 | 0 parse.c | 724 ++++++++++++++++++++++ portableio.c | 358 +++++++++++ portableio.h | 105 +++ psymodel.c | 1253 ++++++++++++++++++++++++++++++++++++++ psymodel.h | 15 quantize-pvt.c | 1320 +++++++++++++++++++++++++++++++++++++++++ quantize-pvt.h | 124 +++ quantize.c | 1201 +++++++++++++++++++++++++++++++++++++ quantize.h | 76 ++ reservoir.c | 183 +++++ reservoir.h | 49 + rtp.c | 102 +++ rtp.h | 24 small.wav | 0 tabinit.c | 82 ++ tables.c | 1215 +++++++++++++++++++++++++++++++++++++ tables.h | 43 + takehiro.c | 765 +++++++++++++++++++++++ timestatus.c | 146 ++++ timestatus.h | 8 util.c | 342 ++++++++++ util.h | 158 ++++ vbrquantize.c | 342 ++++++++++ version.c | 69 ++ version.h | 46 + 68 files changed, 21837 insertions(+) Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/LICENSE diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/LICENSE:1.1 *** /dev/null Tue Jan 9 17:44:45 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/LICENSE Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,44 ---- + Can I use LAME in my commercial program? + + Yes, you can, under the restrictions of the LGPL. In particular, you + can include a compiled version of the LAME library (for example, + lame.dll) with a commercial program. Some notable requirements of + the LGPL: + + 1. In your program, you cannot include any source code from LAME, with + the exception of files whose only purpose is to describe the library + interface (such as lame.h). + + 2. Any modifications of LAME must be released under the LGPL. + The LAME project (www.sulaco.org/mp3) would appreciate being + notified of any modifications. + + 3. You must give prominent notice that your program is: + A. using LAME (including version number) + B. LAME is under the LGPL + C. Provide a copy of the LGPL. (the file COPYING contains the LGPL) + D. Provide a copy of LAME source, or a pointer where the LAME + source can be obtained (such as www.sulaco.org/mp3) + An example of prominent notice would be an "About the LAME encoding engine" + button in some pull down menu within the executable of your program. + + 4. If you determine that distribution of LAME requires a patent license, + you must obtain such license. + + + ***IMPORTANT NOTE*** + + The decoding functions provided in LAME use the mpglib decoding + engine which is under the GPL. They may not be used by any + program not released under the GPL unless you obtain such + permission from the MPG123 project. (www.mpg123.de). + + LAME has built in support to read raw pcm and some wav and aiff files. + More robust file I/O can be handled by compiling in LIBSNDFILE, + but LIBSNDFILE is also under the GPL and my not be used by other + programs not under the GPL. + + + + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/Makefile Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,7 ---- + LEVEL = ../../../.. + + PROG = consumer-lame + CPPFLAGS = -DHAVEMPGLIB -DLAMEPARSE -DNDEBUG -D__NO_MATH_INLINES -O -DLAMESNDFILE + LDFLAGS = -lm + RUN_OPTIONS = -S large.wav output_large.mp3 + include $(LEVEL)/MultiSource/Makefile.multisrc Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/README diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/README:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/README Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,33 ---- + MP3 library + ----------- + Version 0.2 + + This decoder is a 'light' version (thrown out all unnecessay parts) + from the mpg123 package. I made this for a company. + + Currently only Layer3 is enabled to save some space. Layer1,2 isn't + tested at all. The interface will not change significantly. + A backport to the mpg123 package is planed. + + comiled and tested only on Solaris 2.6 + main.c contains a simple demo application for library. + + COPYING: you may use this source under GPL terms! + + PLEASE NOTE: This software may contain patented alogrithm (at least + patented in some countries). It may be not allowed to sell/use products + based on this source code in these countries. Check this out first! + + COPYRIGHT of MP3 music: + Please note, that the duplicating of copyrighted music without explicit + permission violates the rights of the owner. + + SENDING PATCHES: + Maybe I change the copyright policy (ie some kind of more free BSD licencse). + Please consider this when sending patches/changes. + + FEEDBACK: + I'm interessted to here from you, when you use this package as part + of another project. + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/VbrTag.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/VbrTag.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/VbrTag.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,494 ---- + /* + * Xing VBR tagging for LAME. + * + * Copyright (c) 1999 A.L. Faber + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + #include "machine.h" + #include + #include "VbrTag.h" + #include "version.h" + + #ifdef _DEBUG + /* #define DEBUG_VBRTAG */ + #endif + + + int SizeOfEmptyFrame[2][2]= + { + {32,17}, + {17,9}, + }; + + static u_char pbtStreamBuffer[216]; + static long g_Position[NUMTOCENTRIES]; + static int nZeroStreamSize=0; + static int TotalFrameSize=0; + static char VBRTag[]={"Xing"}; + + + int* pVbrFrames=NULL; + int nVbrNumFrames=0; + int nVbrFrameBufferSize=0; + + /**************************************************************************** + * AddVbrFrame: Add VBR entry, used to fill the VBR the TOC entries + * Paramters: + * nStreamPos: how many bytes did we write to the bitstream so far + * (in Bytes NOT Bits) + **************************************************************************** + */ + void AddVbrFrame(int nStreamPos) + { + /* Simple exponential growing buffer */ + if (pVbrFrames==NULL || nVbrFrameBufferSize==0) + { + /* Start with 100 frames */ + nVbrFrameBufferSize=100; + + /* Allocate them */ + pVbrFrames=(int*)malloc((size_t)(nVbrFrameBufferSize*sizeof(int))); + } + + /* Is buffer big enough to store this new frame */ + if (nVbrNumFrames==nVbrFrameBufferSize) + { + /* Guess not, double th e buffer size */ + nVbrFrameBufferSize*=2; + + /* Allocate new buffer */ + pVbrFrames=(int*)realloc(pVbrFrames,(size_t)(nVbrFrameBufferSize*sizeof(int))); + } + + /* Store values */ + pVbrFrames[nVbrNumFrames++]=nStreamPos; + } + + + /*-------------------------------------------------------------*/ + static int ExtractI4(unsigned char *buf) + { + int x; + /* big endian extract */ + x = buf[0]; + x <<= 8; + x |= buf[1]; + x <<= 8; + x |= buf[2]; + x <<= 8; + x |= buf[3]; + return x; + } + + void CreateI4(unsigned char *buf, int nValue) + { + /* big endian create */ + buf[0]=(nValue>>24)&0xff; + buf[1]=(nValue>>16)&0xff; + buf[2]=(nValue>> 8)&0xff; + buf[3]=(nValue )&0xff; + } + + + /*-------------------------------------------------------------*/ + /* Same as GetVbrTag below, but only checks for the Xing tag. + requires buf to contain only 40 bytes */ + /*-------------------------------------------------------------*/ + int CheckVbrTag(unsigned char *buf) + { + int h_id, h_mode, h_sr_index; + + /* get selected MPEG header data */ + h_id = (buf[1] >> 3) & 1; + h_sr_index = (buf[2] >> 2) & 3; + h_mode = (buf[3] >> 6) & 3; + + /* determine offset of header */ + if( h_id ) + { + /* mpeg1 */ + if( h_mode != 3 ) buf+=(32+4); + else buf+=(17+4); + } + else + { + /* mpeg2 */ + if( h_mode != 3 ) buf+=(17+4); + else buf+=(9+4); + } + + if( buf[0] != VBRTag[0] ) return 0; /* fail */ + if( buf[1] != VBRTag[1] ) return 0; /* header not found*/ + if( buf[2] != VBRTag[2] ) return 0; + if( buf[3] != VBRTag[3] ) return 0; + return 1; + } + + int GetVbrTag(VBRTAGDATA *pTagData, unsigned char *buf) + { + int i, head_flags; + int h_id, h_mode, h_sr_index; + static int sr_table[4] = { 44100, 48000, 32000, 99999 }; + + /* get Vbr header data */ + pTagData->flags = 0; + + /* get selected MPEG header data */ + h_id = (buf[1] >> 3) & 1; + h_sr_index = (buf[2] >> 2) & 3; + h_mode = (buf[3] >> 6) & 3; + + /* determine offset of header */ + if( h_id ) + { + /* mpeg1 */ + if( h_mode != 3 ) buf+=(32+4); + else buf+=(17+4); + } + else + { + /* mpeg2 */ + if( h_mode != 3 ) buf+=(17+4); + else buf+=(9+4); + } + + if( buf[0] != VBRTag[0] ) return 0; /* fail */ + if( buf[1] != VBRTag[1] ) return 0; /* header not found*/ + if( buf[2] != VBRTag[2] ) return 0; + if( buf[3] != VBRTag[3] ) return 0; + + buf+=4; + + pTagData->h_id = h_id; + + pTagData->samprate = sr_table[h_sr_index]; + + if( h_id == 0 ) + pTagData->samprate >>= 1; + + head_flags = pTagData->flags = ExtractI4(buf); buf+=4; /* get flags */ + + if( head_flags & FRAMES_FLAG ) + { + pTagData->frames = ExtractI4(buf); buf+=4; + } + + if( head_flags & BYTES_FLAG ) + { + pTagData->bytes = ExtractI4(buf); buf+=4; + } + + if( head_flags & TOC_FLAG ) + { + if( pTagData->toc != NULL ) + { + for(i=0;itoc[i] = buf[i]; + } + buf+=NUMTOCENTRIES; + } + + pTagData->vbr_scale = -1; + + if( head_flags & VBR_SCALE_FLAG ) + { + pTagData->vbr_scale = ExtractI4(buf); buf+=4; + } + + #ifdef DEBUG_VBRTAG + printf("\n\n********************* VBR TAG INFO *****************\n"); + printf("tag :%s\n",VBRTag); + printf("head_flags :%d\n",head_flags); + printf("bytes :%d\n",pTagData->bytes); + printf("frames :%d\n",pTagData->frames); + printf("VBR Scale :%d\n",pTagData->vbr_scale); + printf("toc:\n"); + if( pTagData->toc != NULL ) + { + for(i=0;itoc[i])); + } + } + printf("\n***************** END OF VBR TAG INFO ***************\n"); + #endif + return 1; /* success */ + } + + + /**************************************************************************** + * InitVbrTag: Initializes the header, and write empty frame to stream + * Paramters: + * fpStream: pointer to output file stream + * nVersion: 0= MPEG1 1=MPEG2 + * nMode : Channel Mode: 0=STEREO 1=JS 2=DS 3=MONO + **************************************************************************** + */ + int InitVbrTag(Bit_stream_struc* pBs,int nVersion, int nMode, int SampIndex) + { + int i; + + /* Clear Frame position array variables */ + pVbrFrames=NULL; + nVbrNumFrames=0; + nVbrFrameBufferSize=0; + + /* Clear struct */ + memset(g_Position,0x00,sizeof(g_Position)); + + /* Clear stream buffer */ + memset(pbtStreamBuffer,0x00,sizeof(pbtStreamBuffer)); + + /* Set TOC values to 255 */ + for (i=0;i2) { + fprintf(stderr,"illegal sampling frequency index\n"); + exit(-1); + } + TotalFrameSize= framesize[SampIndex]; + tot = (nZeroStreamSize+VBRHEADERSIZE); + tot += 20; /* extra 20 bytes for LAME & version string */ + + if (TotalFrameSize < tot ) { + fprintf(stderr,"Xing VBR header problem...use -t\n"); + exit(-1); + } + } + + + /* Put empty bytes into the bitstream */ + for (i=0;i255) fRelStreamPos=255; + + /* Assign toc entry value */ + btToc[i]=(u_char) fRelStreamPos; + } + + + + /* Start writing the tag after the zero frame */ + nStreamIndex=nZeroStreamSize; + + /* Put Vbr tag */ + pbtStreamBuffer[nStreamIndex++]=VBRTag[0]; + pbtStreamBuffer[nStreamIndex++]=VBRTag[1]; + pbtStreamBuffer[nStreamIndex++]=VBRTag[2]; + pbtStreamBuffer[nStreamIndex++]=VBRTag[3]; + + /* Put header flags */ + CreateI4(&pbtStreamBuffer[nStreamIndex],FRAMES_FLAG+BYTES_FLAG+TOC_FLAG+VBR_SCALE_FLAG); + nStreamIndex+=4; + + /* Put Total Number of frames */ + CreateI4(&pbtStreamBuffer[nStreamIndex],nVbrNumFrames); + nStreamIndex+=4; + + /* Put Total file size */ + CreateI4(&pbtStreamBuffer[nStreamIndex],(int)lFileSize); + nStreamIndex+=4; + + /* Put TOC */ + memcpy(&pbtStreamBuffer[nStreamIndex],btToc,sizeof(btToc)); + nStreamIndex+=sizeof(btToc); + + /* Put VBR SCALE */ + CreateI4(&pbtStreamBuffer[nStreamIndex],nVbrScale); + nStreamIndex+=4; + + /* Put LAME id */ + sprintf(str1,"LAME%s",get_lame_version()); + strncpy((char *)&pbtStreamBuffer[nStreamIndex],str1,(size_t) 20); + nStreamIndex+=20; + + + #ifdef DEBUG_VBRTAG + { + VBRTAGDATA TestHeader; + GetVbrTag(&TestHeader,pbtStreamBuffer); + } + #endif + + /* Put it all to disk again */ + if (fwrite(pbtStreamBuffer,TotalFrameSize,1,fpStream)!=1) + { + return -1; + } + fclose(fpStream); + + /* Save to delete the frame buffer */ + free(pVbrFrames); + pVbrFrames=NULL; + + return 0; /* success */ + } + + /*-------------------------------------------------------------*/ + int SeekPoint(unsigned char TOC[NUMTOCENTRIES], int file_bytes, float percent) + { + /* interpolate in TOC to get file seek point in bytes */ + int a, seekpoint; + float fa, fb, fx; + + + if( percent < (float)0.0 ) percent = (float)0.0; + if( percent > (float)100.0 ) percent = (float)100.0; + + a = (int)percent; + if( a > 99 ) a = 99; + fa = TOC[a]; + if( a < 99 ) { + fb = TOC[a+1]; + } + else { + fb = (float)256.0; + } + + + fx = fa + (fb-fa)*(percent-a); + + seekpoint = (int)(((float)(1.0/256.0))*fx*file_bytes); + + + return seekpoint; + } + /*-------------------------------------------------------------*/ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/VbrTag.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/VbrTag.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/VbrTag.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,86 ---- + /* + * Xing VBR tagging for LAME. + * + * Copyright (c) 1999 A.L. Faber + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + #ifndef VRBTAG_H_INCLUDED + #define VRBTAG_H_INCLUDED + + /* ----------------------------------------------------------- + * A Vbr header may be present in the ancillary + * data field of the first frame of an mp3 bitstream + * The Vbr header (optionally) contains + * frames total number of audio frames in the bitstream + * bytes total number of bytes in the bitstream + * toc table of contents + + * toc (table of contents) gives seek points + * for random access + * the ith entry determines the seek point for + * i-percent duration + * seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes + * e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes + */ + + #include "l3bitstream.h" + + #define FRAMES_FLAG 0x0001 + #define BYTES_FLAG 0x0002 + #define TOC_FLAG 0x0004 + #define VBR_SCALE_FLAG 0x0008 + + #define NUMTOCENTRIES 100 + + #define FRAMES_AND_BYTES (FRAMES_FLAG | BYTES_FLAG) + + /*structure to receive extracted header */ + /* toc may be NULL*/ + typedef struct + { + int h_id; /* from MPEG header, 0=MPEG2, 1=MPEG1 */ + int samprate; /* determined from MPEG header */ + int flags; /* from Vbr header data */ + int frames; /* total bit stream frames from Vbr header data */ + int bytes; /* total bit stream bytes from Vbr header data*/ + int vbr_scale; /* encoded vbr scale from Vbr header data*/ + u_char toc[NUMTOCENTRIES]; /* may be NULL if toc not desired*/ + } VBRTAGDATA; + /* + // 4 bytes for Header Tag + // 4 bytes for Header Flags + // 100 bytes for entry (NUMTOCENTRIES) + // 4 bytes for FRAME SIZE + // 4 bytes for STREAM_SIZE + // 4 bytes for VBR SCALE. a VBR quality indicator: 0=best 100=worst + // 20 bytes for LAME tag. for example, "LAME3.12 (beta 6)" + // ___________ + // 140 bytes + */ + + #define VBRHEADERSIZE (NUMTOCENTRIES+4+4+4+4+4) + + int CheckVbrTag(unsigned char *buf); + int GetVbrTag(VBRTAGDATA *pTagData, unsigned char *buf); + int SeekPoint(unsigned char TOC[NUMTOCENTRIES], int file_bytes, float percent); + int InitVbrTag(Bit_stream_struc* pBs,int nVersion,int nMode, int SampIndex); + int PutVbrTag(char* lpszFileName,int nVbrScale,int nVersion); + void AddVbrFrame(int nStreamPos); + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/brhist.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/brhist.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/brhist.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,135 ---- + #ifdef BRHIST + #include + #include "brhist.h" + #include "util.h" + #include + + + #define BRHIST_BARMAX 50 + int disp_brhist = 1; + long brhist_count[15]; + long brhist_temp[15]; + int brhist_vbrmin; + int brhist_vbrmax; + long brhist_max; + char brhist_bps[15][5]; + char brhist_backcur[200]; + char brhist_bar[BRHIST_BARMAX+10]; + char brhist_spc[BRHIST_BARMAX+1]; + + char stderr_buff[BUFSIZ]; + + + void brhist_init(lame_global_flags *gfp,int br_min, int br_max) + { + int i; + char term_buff[1024]; + char *termname; + char *tp; + char tc[10]; + + for(i = 0; i < 15; i++) + { + sprintf(brhist_bps[i], "%3d:", bitrate_table[gfp->version][i]); + brhist_count[i] = 0; + brhist_temp[i] = 0; + } + + brhist_vbrmin = br_min; + brhist_vbrmax = br_max; + + brhist_max = 0; + + memset(&brhist_bar[0], '*', BRHIST_BARMAX); + brhist_bar[BRHIST_BARMAX] = '\0'; + memset(&brhist_spc[0], ' ', BRHIST_BARMAX); + brhist_spc[BRHIST_BARMAX] = '\0'; + brhist_backcur[0] = '\0'; + + if ((termname = getenv("TERM")) == NULL) + { + fprintf(stderr, "can't get TERM environment string.\n"); + disp_brhist = 0; + return; + } + + if (tgetent(term_buff, termname) != 1) + { + fprintf(stderr, "can't find termcap entry: %s\n", termname); + disp_brhist = 0; + return; + } + + tc[0] = '\0'; + tp = &tc[0]; + tp=tgetstr("up", &tp); + brhist_backcur[0] = '\0'; + for(i = br_min-1; i <= br_max; i++) + strcat(brhist_backcur, tp); + setbuf(stderr, stderr_buff); + } + + void brhist_add_count(void) + { + int i; + + for(i = brhist_vbrmin; i <= brhist_vbrmax; i++) + { + brhist_count[i] += brhist_temp[i]; + if (brhist_count[i] > brhist_max) + brhist_max = brhist_count[i]; + brhist_temp[i] = 0; + } + } + + void brhist_disp(void) + { + int i; + long full; + int barlen; + + full = (brhist_max < BRHIST_BARMAX) ? BRHIST_BARMAX : brhist_max; + fputc('\n', stderr); + for(i = brhist_vbrmin; i <= brhist_vbrmax; i++) + { + barlen = (brhist_count[i]*BRHIST_BARMAX+full-1) / full; + fputs(brhist_bps[i], stderr); + fputs(&brhist_bar[BRHIST_BARMAX - barlen], stderr); + fputs(&brhist_spc[barlen], stderr); + fputc('\n', stderr); + } + fputs(brhist_backcur, stderr); + fflush(stderr); + } + + void brhist_disp_total(lame_global_flags *gfp) + { + int i; + FLOAT ave; + + for(i = brhist_vbrmin; i <= brhist_vbrmax; i++) + fputc('\n', stderr); + + ave=0; + for(i = brhist_vbrmin; i <= brhist_vbrmax; i++) + ave += bitrate_table[gfp->version][i]* + (FLOAT)brhist_count[i] / gfp->totalframes; + fprintf(stderr, "\naverage: %2.0f kbs\n",ave); + + #if 0 + fprintf(stderr, "----- bitrate statistics -----\n"); + fprintf(stderr, " [kbps] frames\n"); + for(i = brhist_vbrmin; i <= brhist_vbrmax; i++) + { + fprintf(stderr, " %3d %8ld (%.1f%%)\n", + bitrate_table[gfp->version][i], + brhist_count[i], + (FLOAT)brhist_count[i] / gfp->totalframes * 100.0); + } + #endif + fflush(stderr); + } + + #endif /* BRHIST */ + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/brhist.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/brhist.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/brhist.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,15 ---- + #ifdef BRHIST + #ifndef BRHIST_H_INCLUDED + #define BRHIST_H_INCLUDED + + extern int disp_brhist; + + #include "lame.h" + void brhist_init(lame_global_flags *gfp,int br_min, int br_max); + void brhist_add_count(void); + void brhist_disp(void); + void brhist_disp_total(lame_global_flags *gfp); + extern long brhist_temp[15]; + #endif + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/common.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/common.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/common.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,265 ---- + #ifdef HAVEMPGLIB + #include + #include + #include + + #include + #include + #include + + #include "mpg123.h" + + struct parameter param = { 1 , 1 , 0 , 0 }; + + int tabsel_123[2][3][16] = { + { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,}, + {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,}, + {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} }, + + { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} } + }; + + long freqs[9] = { 44100, 48000, 32000, + 22050, 24000, 16000 , + 11025 , 12000 , 8000 }; + + int bitindex; + unsigned char *wordpointer; + unsigned char *pcm_sample; + int pcm_point = 0; + + + #if 0 + static void get_II_stuff(struct frame *fr) + { + static int translate[3][2][16] = + { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } , + { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } , + { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } , + { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } , + { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } , + { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } }; + + int table,sblim; + static struct al_table *tables[5] = + { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 }; + static int sblims[5] = { 27 , 30 , 8, 12 , 30 }; + + if(fr->lsf) + table = 4; + else + table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index]; + sblim = sblims[table]; + + fr->alloc = tables[table]; + fr->II_sblimit = sblim; + } + #endif + + #define HDRCMPMASK 0xfffffd00 + + #if 0 + int head_check(unsigned long head) + { + if( (head & 0xffe00000) != 0xffe00000) + return FALSE; + if(!((head>>17)&3)) + return FALSE; + if( ((head>>12)&0xf) == 0xf) + return FALSE; + if( ((head>>10)&0x3) == 0x3 ) + return FALSE; + return TRUE; + } + #endif + + /* + * the code a header and write the information + * into the frame structure + */ + int decode_header(struct frame *fr,unsigned long newhead) + { + + + if( newhead & (1<<20) ) { + fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1; + fr->mpeg25 = 0; + } + else { + fr->lsf = 1; + fr->mpeg25 = 1; + } + + + fr->lay = 4-((newhead>>17)&3); + if( ((newhead>>10)&0x3) == 0x3) { + fprintf(stderr,"Stream error\n"); + exit(1); + } + if(fr->mpeg25) { + fr->sampling_frequency = 6 + ((newhead>>10)&0x3); + } + else + fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3); + fr->error_protection = ((newhead>>16)&0x1)^0x1; + + if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */ + fr->bitrate_index = ((newhead>>12)&0xf); + + fr->bitrate_index = ((newhead>>12)&0xf); + fr->padding = ((newhead>>9)&0x1); + fr->extension = ((newhead>>8)&0x1); + fr->mode = ((newhead>>6)&0x3); + fr->mode_ext = ((newhead>>4)&0x3); + fr->copyright = ((newhead>>3)&0x1); + fr->original = ((newhead>>2)&0x1); + fr->emphasis = newhead & 0x3; + + fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2; + + if(!fr->bitrate_index) + { + fprintf(stderr,"Free format not supported.\n"); + return (0); + } + + switch(fr->lay) + { + case 1: + #if 0 + fr->do_layer = do_layer1; + fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? + (fr->mode_ext<<2)+4 : 32; + fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000; + fr->framesize /= freqs[fr->sampling_frequency]; + fr->framesize = ((fr->framesize+fr->padding)<<2)-4; + #else + fprintf(stderr,"layer=1 Not supported!\n"); + #endif + break; + case 2: + #if 0 + fr->do_layer = do_layer2; + get_II_stuff(fr); + fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? + (fr->mode_ext<<2)+4 : fr->II_sblimit; + fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000; + fr->framesize /= freqs[fr->sampling_frequency]; + fr->framesize += fr->padding - 4; + #else + fprintf(stderr,"layer=2 Not supported!\n"); + #endif + break; + case 3: + #if 0 + fr->do_layer = do_layer3; + if(fr->lsf) + ssize = (fr->stereo == 1) ? 9 : 17; + else + ssize = (fr->stereo == 1) ? 17 : 32; + #endif + + #if 0 + if(fr->error_protection) + ssize += 2; + #endif + fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000; + fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf); + fr->framesize = fr->framesize + fr->padding - 4; + break; + default: + fprintf(stderr,"Sorry, unknown layer type.\n"); + return (0); + } + + /* print_header(fr); */ + + return 1; + } + + + #if 1 + void print_header(struct frame *fr) + { + static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" }; + static char *layers[4] = { "Unknown" , "I", "II", "III" }; + + fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n", + fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), + layers[fr->lay],freqs[fr->sampling_frequency], + modes[fr->mode],fr->mode_ext,fr->framesize+4); + fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n", + fr->stereo,fr->copyright?"Yes":"No", + fr->original?"Yes":"No",fr->error_protection?"Yes":"No", + fr->emphasis); + fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n", + tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension); + } + + void print_header_compact(struct frame *fr) + { + static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" }; + static char *layers[4] = { "Unknown" , "I", "II", "III" }; + + fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n", + fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), + layers[fr->lay], + tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index], + freqs[fr->sampling_frequency], modes[fr->mode]); + } + + #endif + + unsigned int getbits(int number_of_bits) + { + unsigned long rval; + + if(!number_of_bits) + return 0; + + { + rval = wordpointer[0]; + rval <<= 8; + rval |= wordpointer[1]; + rval <<= 8; + rval |= wordpointer[2]; + rval <<= bitindex; + rval &= 0xffffff; + + bitindex += number_of_bits; + + rval >>= (24-number_of_bits); + + wordpointer += (bitindex>>3); + bitindex &= 7; + } + return rval; + } + + unsigned int getbits_fast(int number_of_bits) + { + unsigned long rval; + + { + rval = wordpointer[0]; + rval <<= 8; + rval |= wordpointer[1]; + rval <<= bitindex; + rval &= 0xffff; + bitindex += number_of_bits; + + rval >>= (16-number_of_bits); + + wordpointer += (bitindex>>3); + bitindex &= 7; + } + return rval; + } + + + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/dct64_i386.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/dct64_i386.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/dct64_i386.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,317 ---- + #ifdef HAVEMPGLIB + /* + * Discrete Cosine Tansform (DCT) for subband synthesis + * optimized for machines with no auto-increment. + * The performance is highly compiler dependend. Maybe + * the dct64.c version for 'normal' processor may be faster + * even for Intel processors. + */ + + #include "mpg123.h" + + static void dct64_1(real *out0,real *out1,real *b1,real *b2,real *samples) + { + + { + register real *costab = pnts[0]; + + b1[0x00] = samples[0x00] + samples[0x1F]; + b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0]; + + b1[0x01] = samples[0x01] + samples[0x1E]; + b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1]; + + b1[0x02] = samples[0x02] + samples[0x1D]; + b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2]; + + b1[0x03] = samples[0x03] + samples[0x1C]; + b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3]; + + b1[0x04] = samples[0x04] + samples[0x1B]; + b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4]; + + b1[0x05] = samples[0x05] + samples[0x1A]; + b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5]; + + b1[0x06] = samples[0x06] + samples[0x19]; + b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6]; + + b1[0x07] = samples[0x07] + samples[0x18]; + b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7]; + + b1[0x08] = samples[0x08] + samples[0x17]; + b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8]; + + b1[0x09] = samples[0x09] + samples[0x16]; + b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9]; + + b1[0x0A] = samples[0x0A] + samples[0x15]; + b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA]; + + b1[0x0B] = samples[0x0B] + samples[0x14]; + b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB]; + + b1[0x0C] = samples[0x0C] + samples[0x13]; + b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC]; + + b1[0x0D] = samples[0x0D] + samples[0x12]; + b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD]; + + b1[0x0E] = samples[0x0E] + samples[0x11]; + b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE]; + + b1[0x0F] = samples[0x0F] + samples[0x10]; + b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF]; + } + + + { + register real *costab = pnts[1]; + + b2[0x00] = b1[0x00] + b1[0x0F]; + b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0]; + b2[0x01] = b1[0x01] + b1[0x0E]; + b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1]; + b2[0x02] = b1[0x02] + b1[0x0D]; + b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2]; + b2[0x03] = b1[0x03] + b1[0x0C]; + b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3]; + b2[0x04] = b1[0x04] + b1[0x0B]; + b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4]; + b2[0x05] = b1[0x05] + b1[0x0A]; + b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5]; + b2[0x06] = b1[0x06] + b1[0x09]; + b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6]; + b2[0x07] = b1[0x07] + b1[0x08]; + b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7]; + + b2[0x10] = b1[0x10] + b1[0x1F]; + b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0]; + b2[0x11] = b1[0x11] + b1[0x1E]; + b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1]; + b2[0x12] = b1[0x12] + b1[0x1D]; + b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2]; + b2[0x13] = b1[0x13] + b1[0x1C]; + b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3]; + b2[0x14] = b1[0x14] + b1[0x1B]; + b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4]; + b2[0x15] = b1[0x15] + b1[0x1A]; + b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5]; + b2[0x16] = b1[0x16] + b1[0x19]; + b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6]; + b2[0x17] = b1[0x17] + b1[0x18]; + b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7]; + } + + { + register real *costab = pnts[2]; + + b1[0x00] = b2[0x00] + b2[0x07]; + b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0]; + b1[0x01] = b2[0x01] + b2[0x06]; + b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1]; + b1[0x02] = b2[0x02] + b2[0x05]; + b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2]; + b1[0x03] = b2[0x03] + b2[0x04]; + b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3]; + + b1[0x08] = b2[0x08] + b2[0x0F]; + b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0]; + b1[0x09] = b2[0x09] + b2[0x0E]; + b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1]; + b1[0x0A] = b2[0x0A] + b2[0x0D]; + b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2]; + b1[0x0B] = b2[0x0B] + b2[0x0C]; + b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3]; + + b1[0x10] = b2[0x10] + b2[0x17]; + b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0]; + b1[0x11] = b2[0x11] + b2[0x16]; + b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1]; + b1[0x12] = b2[0x12] + b2[0x15]; + b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2]; + b1[0x13] = b2[0x13] + b2[0x14]; + b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3]; + + b1[0x18] = b2[0x18] + b2[0x1F]; + b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0]; + b1[0x19] = b2[0x19] + b2[0x1E]; + b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1]; + b1[0x1A] = b2[0x1A] + b2[0x1D]; + b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2]; + b1[0x1B] = b2[0x1B] + b2[0x1C]; + b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3]; + } + + { + register real const cos0 = pnts[3][0]; + register real const cos1 = pnts[3][1]; + + b2[0x00] = b1[0x00] + b1[0x03]; + b2[0x03] = (b1[0x00] - b1[0x03]) * cos0; + b2[0x01] = b1[0x01] + b1[0x02]; + b2[0x02] = (b1[0x01] - b1[0x02]) * cos1; + + b2[0x04] = b1[0x04] + b1[0x07]; + b2[0x07] = (b1[0x07] - b1[0x04]) * cos0; + b2[0x05] = b1[0x05] + b1[0x06]; + b2[0x06] = (b1[0x06] - b1[0x05]) * cos1; + + b2[0x08] = b1[0x08] + b1[0x0B]; + b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0; + b2[0x09] = b1[0x09] + b1[0x0A]; + b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1; + + b2[0x0C] = b1[0x0C] + b1[0x0F]; + b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0; + b2[0x0D] = b1[0x0D] + b1[0x0E]; + b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1; + + b2[0x10] = b1[0x10] + b1[0x13]; + b2[0x13] = (b1[0x10] - b1[0x13]) * cos0; + b2[0x11] = b1[0x11] + b1[0x12]; + b2[0x12] = (b1[0x11] - b1[0x12]) * cos1; + + b2[0x14] = b1[0x14] + b1[0x17]; + b2[0x17] = (b1[0x17] - b1[0x14]) * cos0; + b2[0x15] = b1[0x15] + b1[0x16]; + b2[0x16] = (b1[0x16] - b1[0x15]) * cos1; + + b2[0x18] = b1[0x18] + b1[0x1B]; + b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0; + b2[0x19] = b1[0x19] + b1[0x1A]; + b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1; + + b2[0x1C] = b1[0x1C] + b1[0x1F]; + b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0; + b2[0x1D] = b1[0x1D] + b1[0x1E]; + b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1; + } + + { + register real const cos0 = pnts[4][0]; + + b1[0x00] = b2[0x00] + b2[0x01]; + b1[0x01] = (b2[0x00] - b2[0x01]) * cos0; + b1[0x02] = b2[0x02] + b2[0x03]; + b1[0x03] = (b2[0x03] - b2[0x02]) * cos0; + b1[0x02] += b1[0x03]; + + b1[0x04] = b2[0x04] + b2[0x05]; + b1[0x05] = (b2[0x04] - b2[0x05]) * cos0; + b1[0x06] = b2[0x06] + b2[0x07]; + b1[0x07] = (b2[0x07] - b2[0x06]) * cos0; + b1[0x06] += b1[0x07]; + b1[0x04] += b1[0x06]; + b1[0x06] += b1[0x05]; + b1[0x05] += b1[0x07]; + + b1[0x08] = b2[0x08] + b2[0x09]; + b1[0x09] = (b2[0x08] - b2[0x09]) * cos0; + b1[0x0A] = b2[0x0A] + b2[0x0B]; + b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0; + b1[0x0A] += b1[0x0B]; + + b1[0x0C] = b2[0x0C] + b2[0x0D]; + b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0; + b1[0x0E] = b2[0x0E] + b2[0x0F]; + b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0; + b1[0x0E] += b1[0x0F]; + b1[0x0C] += b1[0x0E]; + b1[0x0E] += b1[0x0D]; + b1[0x0D] += b1[0x0F]; + + b1[0x10] = b2[0x10] + b2[0x11]; + b1[0x11] = (b2[0x10] - b2[0x11]) * cos0; + b1[0x12] = b2[0x12] + b2[0x13]; + b1[0x13] = (b2[0x13] - b2[0x12]) * cos0; + b1[0x12] += b1[0x13]; + + b1[0x14] = b2[0x14] + b2[0x15]; + b1[0x15] = (b2[0x14] - b2[0x15]) * cos0; + b1[0x16] = b2[0x16] + b2[0x17]; + b1[0x17] = (b2[0x17] - b2[0x16]) * cos0; + b1[0x16] += b1[0x17]; + b1[0x14] += b1[0x16]; + b1[0x16] += b1[0x15]; + b1[0x15] += b1[0x17]; + + b1[0x18] = b2[0x18] + b2[0x19]; + b1[0x19] = (b2[0x18] - b2[0x19]) * cos0; + b1[0x1A] = b2[0x1A] + b2[0x1B]; + b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0; + b1[0x1A] += b1[0x1B]; + + b1[0x1C] = b2[0x1C] + b2[0x1D]; + b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0; + b1[0x1E] = b2[0x1E] + b2[0x1F]; + b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0; + b1[0x1E] += b1[0x1F]; + b1[0x1C] += b1[0x1E]; + b1[0x1E] += b1[0x1D]; + b1[0x1D] += b1[0x1F]; + } + + out0[0x10*16] = b1[0x00]; + out0[0x10*12] = b1[0x04]; + out0[0x10* 8] = b1[0x02]; + out0[0x10* 4] = b1[0x06]; + out0[0x10* 0] = b1[0x01]; + out1[0x10* 0] = b1[0x01]; + out1[0x10* 4] = b1[0x05]; + out1[0x10* 8] = b1[0x03]; + out1[0x10*12] = b1[0x07]; + + b1[0x08] += b1[0x0C]; + out0[0x10*14] = b1[0x08]; + b1[0x0C] += b1[0x0a]; + out0[0x10*10] = b1[0x0C]; + b1[0x0A] += b1[0x0E]; + out0[0x10* 6] = b1[0x0A]; + b1[0x0E] += b1[0x09]; + out0[0x10* 2] = b1[0x0E]; + b1[0x09] += b1[0x0D]; + out1[0x10* 2] = b1[0x09]; + b1[0x0D] += b1[0x0B]; + out1[0x10* 6] = b1[0x0D]; + b1[0x0B] += b1[0x0F]; + out1[0x10*10] = b1[0x0B]; + out1[0x10*14] = b1[0x0F]; + + b1[0x18] += b1[0x1C]; + out0[0x10*15] = b1[0x10] + b1[0x18]; + out0[0x10*13] = b1[0x18] + b1[0x14]; + b1[0x1C] += b1[0x1a]; + out0[0x10*11] = b1[0x14] + b1[0x1C]; + out0[0x10* 9] = b1[0x1C] + b1[0x12]; + b1[0x1A] += b1[0x1E]; + out0[0x10* 7] = b1[0x12] + b1[0x1A]; + out0[0x10* 5] = b1[0x1A] + b1[0x16]; + b1[0x1E] += b1[0x19]; + out0[0x10* 3] = b1[0x16] + b1[0x1E]; + out0[0x10* 1] = b1[0x1E] + b1[0x11]; + b1[0x19] += b1[0x1D]; + out1[0x10* 1] = b1[0x11] + b1[0x19]; + out1[0x10* 3] = b1[0x19] + b1[0x15]; + b1[0x1D] += b1[0x1B]; + out1[0x10* 5] = b1[0x15] + b1[0x1D]; + out1[0x10* 7] = b1[0x1D] + b1[0x13]; + b1[0x1B] += b1[0x1F]; + out1[0x10* 9] = b1[0x13] + b1[0x1B]; + out1[0x10*11] = b1[0x1B] + b1[0x17]; + out1[0x10*13] = b1[0x17] + b1[0x1F]; + out1[0x10*15] = b1[0x1F]; + } + + /* + * the call via dct64 is a trick to force GCC to use + * (new) registers for the b1,b2 pointer to the bufs[xx] field + */ + void dct64(real *a,real *b,real *c) + { + real bufs[0x40]; + dct64_1(a,b,bufs,bufs+0x20,c); + } + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/decode_i386.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/decode_i386.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/decode_i386.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,156 ---- + #ifdef HAVEMPGLIB + /* + * Mpeg Layer-1,2,3 audio decoder + * ------------------------------ + * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved. + * See also 'README' + * + * slighlty optimized for machines without autoincrement/decrement. + * The performance is highly compiler dependend. Maybe + * the decode.c version for 'normal' processor may be faster + * even for Intel processors. + */ + + #include + #include + #include + + #include "mpg123.h" + #include "mpglib.h" + + extern struct mpstr *gmp; + + /* old WRITE_SAMPLE */ + #define WRITE_SAMPLE(samples,sum,clip) \ + if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \ + else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \ + else { *(samples) = sum; } + + int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt) + { + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; + + ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; + + for(i=0;i<32;i++) { + *( (short *) samples) = *tmp1; + samples += 2; + tmp1 += 2; + } + *pnt += 64; + + return ret; + } + + + int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt) + { + static const int step = 2; + int bo; + short *samples = (short *) (out + *pnt); + + real *b0,(*buf)[0x110]; + int clip = 0; + int bo1; + + bo = gmp->synth_bo; + + if(!channel) { + bo--; + bo &= 0xf; + buf = gmp->synth_buffs[0]; + } + else { + samples++; + buf = gmp->synth_buffs[1]; + } + + if(bo & 0x1) { + b0 = buf[0]; + bo1 = bo; + dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); + } + else { + b0 = buf[1]; + bo1 = bo+1; + dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); + } + + gmp->synth_bo = bo; + + { + register int j; + real *window = decwin + 16 - bo1; + + for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) + { + real sum; + sum = window[0x0] * b0[0x0]; + sum -= window[0x1] * b0[0x1]; + sum += window[0x2] * b0[0x2]; + sum -= window[0x3] * b0[0x3]; + sum += window[0x4] * b0[0x4]; + sum -= window[0x5] * b0[0x5]; + sum += window[0x6] * b0[0x6]; + sum -= window[0x7] * b0[0x7]; + sum += window[0x8] * b0[0x8]; + sum -= window[0x9] * b0[0x9]; + sum += window[0xA] * b0[0xA]; + sum -= window[0xB] * b0[0xB]; + sum += window[0xC] * b0[0xC]; + sum -= window[0xD] * b0[0xD]; + sum += window[0xE] * b0[0xE]; + sum -= window[0xF] * b0[0xF]; + + WRITE_SAMPLE(samples,sum,clip); + } + + { + real sum; + sum = window[0x0] * b0[0x0]; + sum += window[0x2] * b0[0x2]; + sum += window[0x4] * b0[0x4]; + sum += window[0x6] * b0[0x6]; + sum += window[0x8] * b0[0x8]; + sum += window[0xA] * b0[0xA]; + sum += window[0xC] * b0[0xC]; + sum += window[0xE] * b0[0xE]; + WRITE_SAMPLE(samples,sum,clip); + b0-=0x10,window-=0x20,samples+=step; + } + window += bo1<<1; + + for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) + { + real sum; + sum = -window[-0x1] * b0[0x0]; + sum -= window[-0x2] * b0[0x1]; + sum -= window[-0x3] * b0[0x2]; + sum -= window[-0x4] * b0[0x3]; + sum -= window[-0x5] * b0[0x4]; + sum -= window[-0x6] * b0[0x5]; + sum -= window[-0x7] * b0[0x6]; + sum -= window[-0x8] * b0[0x7]; + sum -= window[-0x9] * b0[0x8]; + sum -= window[-0xA] * b0[0x9]; + sum -= window[-0xB] * b0[0xA]; + sum -= window[-0xC] * b0[0xB]; + sum -= window[-0xD] * b0[0xC]; + sum -= window[-0xE] * b0[0xD]; + sum -= window[-0xF] * b0[0xE]; + sum -= window[-0x0] * b0[0xF]; + + WRITE_SAMPLE(samples,sum,clip); + } + } + *pnt += 128; + + return clip; + } + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/encoder.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/encoder.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/encoder.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,78 ---- + #ifndef ENCODER_DOT_H + #define ENCODER_DOT_H + /*********************************************************************** + * + * encoder and decoder delays + * + ***********************************************************************/ + /* + layerIII enc->dec delay: 1056 (observed) + layerII enc->dec dealy: 480 (observed) + + + polyphase 256-16 (dec or enc) = 240 + mdct 256+32 (9*32) (dec or enc) = 288 + total: 512+16 + + */ + + + + /* ENCDELAY The encoder delay. + + Minimum allowed is MDCTDELAY (see below) + + The first 96 samples will be attenuated, so using a value + less than 96 will result in lost data in the first 96-ENCDELAY + samples. + + suggested: 800 + set to 1160 to sync with FhG. + */ + #define ENCDELAY 800 + + + + + /* delay of the MDCT used in mdct.c */ + /* original ISO routiens had a delay of 528! Takehiro's routines: */ + #define MDCTDELAY 48 + #define FFTOFFSET (224+MDCTDELAY) + + /* + Most decoders, including the one we use, have a delay of 528 samples. + */ + #define DECDELAY 528 + + + /* number of subbands */ + #define SBLIMIT 32 + + /* parition bands bands */ + #define CBANDS 63 + + /* number of critical bands/scale factor bands where masking is computed*/ + #define SBPSY_l 21 + #define SBPSY_s 12 + + /* total number of scalefactor bands encoded */ + #define SBMAX_l 22 + #define SBMAX_s 13 + + + + /* FFT sizes */ + #define BLKSIZE 1024 + #define HBLKSIZE 513 + #define BLKSIZE_s 256 + #define HBLKSIZE_s 129 + + + /* #define switch_pe 1800 */ + #define NORM_TYPE 0 + #define START_TYPE 1 + #define SHORT_TYPE 2 + #define STOP_TYPE 3 + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/fft.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/fft.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/fft.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,356 ---- + /* + ** FFT and FHT routines + ** Copyright 1988, 1993; Ron Mayer + ** + ** fht(fz,n); + ** Does a hartley transform of "n" points in the array "fz". + ** + ** NOTE: This routine uses at least 2 patented algorithms, and may be + ** under the restrictions of a bunch of different organizations. + ** Although I wrote it completely myself; it is kind of a derivative + ** of a routine I once authored and released under the GPL, so it + ** may fall under the free software foundation's restrictions; + ** it was worked on as a Stanford Univ project, so they claim + ** some rights to it; it was further optimized at work here, so + ** I think this company claims parts of it. The patents are + ** held by R. Bracewell (the FHT algorithm) and O. Buneman (the + ** trig generator), both at Stanford Univ. + ** If it were up to me, I'd say go do whatever you want with it; + ** but it would be polite to give credit to the following people + ** if you use this anywhere: + ** Euler - probable inventor of the fourier transform. + ** Gauss - probable inventor of the FFT. + ** Hartley - probable inventor of the hartley transform. + ** Buneman - for a really cool trig generator + ** Mayer(me) - for authoring this particular version and + ** including all the optimizations in one package. + ** Thanks, + ** Ron Mayer; mayer at acuson.com + ** and added some optimization by + ** Mather - idea of using lookup table + ** Takehiro - some dirty hack for speed up + */ + + #include + #include "util.h" + #include "psymodel.h" + #include "lame.h" + + #define TRI_SIZE (5-1) /* 1024 = 4**5 */ + static FLOAT costab[TRI_SIZE*2]; + static FLOAT window[BLKSIZE / 2], window_s[BLKSIZE_s / 2]; + + static INLINE void fht(FLOAT *fz, short n) + { + short k4; + FLOAT *fi, *fn, *gi; + FLOAT *tri; + + fn = fz + n; + tri = &costab[0]; + k4 = 4; + do { + FLOAT s1, c1; + short i, k1, k2, k3, kx; + kx = k4 >> 1; + k1 = k4; + k2 = k4 << 1; + k3 = k2 + k1; + k4 = k2 << 1; + fi = fz; + gi = fi + kx; + do { + FLOAT f0,f1,f2,f3; + f1 = fi[0] - fi[k1]; + f0 = fi[0] + fi[k1]; + f3 = fi[k2] - fi[k3]; + f2 = fi[k2] + fi[k3]; + fi[k2] = f0 - f2; + fi[0 ] = f0 + f2; + fi[k3] = f1 - f3; + fi[k1] = f1 + f3; + f1 = gi[0] - gi[k1]; + f0 = gi[0] + gi[k1]; + f3 = SQRT2 * gi[k3]; + f2 = SQRT2 * gi[k2]; + gi[k2] = f0 - f2; + gi[0 ] = f0 + f2; + gi[k3] = f1 - f3; + gi[k1] = f1 + f3; + gi += k4; + fi += k4; + } while (fi= 0); + } else if (chn == 2) { + do { + FLOAT f0,f1,f2,f3, w; + + i = rv_tbl[j << 2]; + + f0 = ms00(ch2); w = ms10(ch2); f1 = f0 - w; f0 = f0 + w; + f2 = ms20(ch2); w = ms30(ch2); f3 = f2 - w; f2 = f2 + w; + + x -= 4; + x[0] = f0 + f2; + x[2] = f0 - f2; + x[1] = f1 + f3; + x[3] = f1 - f3; + + f0 = ms01(ch2); w = ms11(ch2); f1 = f0 - w; f0 = f0 + w; + f2 = ms21(ch2); w = ms31(ch2); f3 = f2 - w; f2 = f2 + w; + + x[BLKSIZE_s / 2 + 0] = f0 + f2; + x[BLKSIZE_s / 2 + 2] = f0 - f2; + x[BLKSIZE_s / 2 + 1] = f1 + f3; + x[BLKSIZE_s / 2 + 3] = f1 - f3; + } while (--j >= 0); + } else { + do { + FLOAT f0,f1,f2,f3, w; + + i = rv_tbl[j << 2]; + + f0 = ms00(ch3); w = ms10(ch3); f1 = f0 - w; f0 = f0 + w; + f2 = ms20(ch3); w = ms30(ch3); f3 = f2 - w; f2 = f2 + w; + + x -= 4; + x[0] = f0 + f2; + x[2] = f0 - f2; + x[1] = f1 + f3; + x[3] = f1 - f3; + + f0 = ms01(ch3); w = ms11(ch3); f1 = f0 - w; f0 = f0 + w; + f2 = ms21(ch3); w = ms31(ch3); f3 = f2 - w; f2 = f2 + w; + + x[BLKSIZE_s / 2 + 0] = f0 + f2; + x[BLKSIZE_s / 2 + 2] = f0 - f2; + x[BLKSIZE_s / 2 + 1] = f1 + f3; + x[BLKSIZE_s / 2 + 3] = f1 - f3; + } while (--j >= 0); + } + + fht(x, BLKSIZE_s); + } + } + + void fft_long( + FLOAT x[BLKSIZE], int chn, short *buffer[2]) + { + short i,jj = BLKSIZE / 8 - 1; + x += BLKSIZE / 2; + + if (chn < 2) { + do { + FLOAT f0,f1,f2,f3, w; + + i = rv_tbl[jj]; + f0 = ml00(ch01); w = ml10(ch01); f1 = f0 - w; f0 = f0 + w; + f2 = ml20(ch01); w = ml30(ch01); f3 = f2 - w; f2 = f2 + w; + + x -= 4; + x[0] = f0 + f2; + x[2] = f0 - f2; + x[1] = f1 + f3; + x[3] = f1 - f3; + + f0 = ml01(ch01); w = ml11(ch01); f1 = f0 - w; f0 = f0 + w; + f2 = ml21(ch01); w = ml31(ch01); f3 = f2 - w; f2 = f2 + w; + + x[BLKSIZE / 2 + 0] = f0 + f2; + x[BLKSIZE / 2 + 2] = f0 - f2; + x[BLKSIZE / 2 + 1] = f1 + f3; + x[BLKSIZE / 2 + 3] = f1 - f3; + } while (--jj >= 0); + } else if (chn == 2) { + do { + FLOAT f0,f1,f2,f3, w; + + i = rv_tbl[jj]; + f0 = ml00(ch2); w = ml10(ch2); f1 = f0 - w; f0 = f0 + w; + f2 = ml20(ch2); w = ml30(ch2); f3 = f2 - w; f2 = f2 + w; + + x -= 4; + x[0] = f0 + f2; + x[2] = f0 - f2; + x[1] = f1 + f3; + x[3] = f1 - f3; + + f0 = ml01(ch2); w = ml11(ch2); f1 = f0 - w; f0 = f0 + w; + f2 = ml21(ch2); w = ml31(ch2); f3 = f2 - w; f2 = f2 + w; + + x[BLKSIZE / 2 + 0] = f0 + f2; + x[BLKSIZE / 2 + 2] = f0 - f2; + x[BLKSIZE / 2 + 1] = f1 + f3; + x[BLKSIZE / 2 + 3] = f1 - f3; + } while (--jj >= 0); + } else { + do { + FLOAT f0,f1,f2,f3, w; + + i = rv_tbl[jj]; + f0 = ml00(ch3); w = ml10(ch3); f1 = f0 - w; f0 = f0 + w; + f2 = ml20(ch3); w = ml30(ch3); f3 = f2 - w; f2 = f2 + w; + + x -= 4; + x[0] = f0 + f2; + x[2] = f0 - f2; + x[1] = f1 + f3; + x[3] = f1 - f3; + + f0 = ml01(ch3); w = ml11(ch3); f1 = f0 - w; f0 = f0 + w; + f2 = ml21(ch3); w = ml31(ch3); f3 = f2 - w; f2 = f2 + w; + + x[BLKSIZE / 2 + 0] = f0 + f2; + x[BLKSIZE / 2 + 2] = f0 - f2; + x[BLKSIZE / 2 + 1] = f1 + f3; + x[BLKSIZE / 2 + 3] = f1 - f3; + } while (--jj >= 0); + } + + fht(x, BLKSIZE); + } + + + void init_fft(void) + { + int i; + + FLOAT r = PI*0.125; + for (i = 0; i < TRI_SIZE; i++) { + costab[i*2 ] = cos(r); + costab[i*2+1] = sin(r); + r *= 0.25; + } + + /* + * calculate HANN window coefficients + */ + for (i = 0; i < BLKSIZE / 2; i++) + window[i] = 0.5 * (1.0 - cos(2.0 * PI * (i + 0.5) / BLKSIZE)); + for (i = 0; i < BLKSIZE_s / 2; i++) + window_s[i] = 0.5 * (1.0 - cos(2.0 * PI * (i + 0.5) / BLKSIZE_s)); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/fft.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/fft.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/fft.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,10 ---- + #ifndef FFT_H + #define FFT_H + + #include "encoder.h" + + void fft_long(FLOAT x_real[BLKSIZE], int, short **); + void fft_short(FLOAT x_real[3][BLKSIZE_s], int, short **); + void init_fft(void); + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/formatBitstream.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/formatBitstream.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/formatBitstream.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,543 ---- + /********************************************************************* + Copyright (c) 1995 ISO/IEC JTC1 SC29 WG1, All Rights Reserved + formatBitstream.c + **********************************************************************/ + /* + Revision History: + + Date Programmer Comment + ========== ========================= =============================== + 1995/09/06 mc at fivebats.com created + 1995/09/18 mc at fivebats.com bugfix: WriteMainDataBits + 1995/09/20 mc at fivebats.com bugfix: store_side_info + */ + + #include "formatBitstream.h" + #include + #include + #include + + /* globals */ + static int BitCount = 0; + static int ThisFrameSize = 0; + static int BitsRemaining = 0; + + void InitFormatBitStream(void) + { + BitCount = 0; + ThisFrameSize = 0; + BitsRemaining = 0; + } + + /* forward declarations */ + static int store_side_info( BF_FrameData *frameInfo ); + static int main_data( BF_FrameData *frameInfo, BF_FrameResults *results ); + static int side_queue_elements( int *forwardFrameLength, int *forwardSILength ); + static void free_side_queues(void); + static void WriteMainDataBits( u_int val,u_int nbits,BF_FrameResults *results ); + + /* + BitStreamFrame is the public interface to the bitstream + formatting package. It writes one frame of main data per call. + + Assumptions: + - The back pointer is zero on the first call + - An integral number of bytes is written each frame + + You should be able to change the frame length, side info + length, #channels, #granules on a frame-by-frame basis. + + See formatBitstream.h for more information about the data + structures and the bitstream syntax. + */ + static int elements, forwardFrameLength, forwardSILength; + void + BF_BitstreamFrame( BF_FrameData *frameInfo, BF_FrameResults *results ) + { + /* int elements, forwardFrameLength, forwardSILength; */ + + assert( frameInfo->nGranules <= MAX_GRANULES ); + assert( frameInfo->nChannels <= MAX_CHANNELS ); + + /* save SI and compute its length */ + results->SILength = store_side_info( frameInfo ); + + /* write the main data, inserting SI to maintain framing */ + results->mainDataLength = main_data( frameInfo, results ); + + /* + Caller must ensure that back SI and main data are + an integral number of bytes, since the back pointer + can only point to a byte boundary and this code + does not add stuffing bits + */ + assert( (BitsRemaining % 8) == 0 ); + + /* calculate nextBackPointer */ + elements = side_queue_elements( &forwardFrameLength, &forwardSILength ); + results->nextBackPtr = (BitsRemaining / 8) + (forwardFrameLength / 8) - (forwardSILength / 8); + } + + /* + FlushBitstream writes zeros into main data + until all queued headers are written. The + queue data buffers are also freed. + */ + void + BF_FlushBitstream( BF_FrameData *frameInfo, BF_FrameResults *results ) + { + /* int elements, forwardFrameLength, forwardSILength; */ + + if ( elements ) + { + int bitsRemaining = forwardFrameLength - forwardSILength; + int wordsRemaining = bitsRemaining / 32; + while ( wordsRemaining-- ) { + WriteMainDataBits( 0, 32, results ); + } + WriteMainDataBits( 0, (bitsRemaining % 32), results ); + } + + + results->mainDataLength = forwardFrameLength - forwardSILength; + results->SILength = forwardSILength; + results->nextBackPtr = 0; + + /* reclaim queue space */ + free_side_queues(); + + /* reinitialize globals */ + BitCount = 0; + ThisFrameSize = 0; + BitsRemaining = 0; + return; + } + + int + BF_PartLength( BF_BitstreamPart *part ) + { + BF_BitstreamElement *ep = part->element; + u_int i; + int bits=0; + + for ( i = 0; i < part->nrEntries; i++, ep++ ) + bits += ep->length; + return bits; + } + + + /* + The following is all private to this file + */ + + typedef struct + { + int frameLength; + int SILength; + int nGranules; + int nChannels; + BF_PartHolder *headerPH; + BF_PartHolder *frameSIPH; + BF_PartHolder *channelSIPH[MAX_CHANNELS]; + BF_PartHolder *spectrumSIPH[MAX_GRANULES][MAX_CHANNELS]; + } MYSideInfo; + + static MYSideInfo *get_side_info(void); + static int write_side_info(void); + typedef int (*PartWriteFcnPtr)( BF_BitstreamPart *part, BF_FrameResults *results ); + + + static int + writePartMainData( BF_BitstreamPart *part, BF_FrameResults *results ) + { + BF_BitstreamElement *ep; + u_int i; + int bits=0; + + assert( results ); + assert( part ); + + ep = part->element; + for ( i = 0; i < part->nrEntries; i++, ep++ ) + { + WriteMainDataBits( ep->value, ep->length, results ); + bits += ep->length; + } + return bits; + } + + static int + writePartSideInfo( BF_BitstreamPart *part, BF_FrameResults *results ) + { + BF_BitstreamElement *ep; + u_int i; + int bits=0; + + assert( part ); + + ep = part->element; + for ( i = 0; i < part->nrEntries; i++, ep++ ) + { + putMyBits( ep->value, ep->length ); + bits += ep->length; + } + return bits; + } + + static int + main_data( BF_FrameData *fi, BF_FrameResults *results ) + { + int gr, ch, bits; + PartWriteFcnPtr wp = writePartMainData; + bits = 0; + results->mainDataLength = 0; + + for ( gr = 0; gr < fi->nGranules; gr++ ) + for ( ch = 0; ch < fi->nChannels; ch++ ) + { + bits += (*wp)( fi->scaleFactors[gr][ch], results ); + bits += (*wp)( fi->codedData[gr][ch], results ); + bits += (*wp)( fi->userSpectrum[gr][ch], results ); + } + bits += (*wp)( fi->userFrameData, results ); + return bits; + } + + /* + This is a wrapper around PutBits() that makes sure that the + framing header and side info are inserted at the proper + locations + */ + + static void + WriteMainDataBits( u_int val, + u_int nbits, + BF_FrameResults *results ) + { + assert( nbits <= 32 ); + if ( nbits == 0 ) + return; + if ( BitCount == ThisFrameSize ) + { + BitCount = write_side_info(); + BitsRemaining = ThisFrameSize - BitCount; + } + if ( nbits > (u_int)BitsRemaining ) + { + unsigned extra = val >> (nbits - BitsRemaining); + nbits -= BitsRemaining; + putMyBits( extra, BitsRemaining ); + BitCount = write_side_info(); + BitsRemaining = ThisFrameSize - BitCount; + putMyBits( val, nbits ); + } + else + putMyBits( val, nbits ); + BitCount += nbits; + BitsRemaining -= nbits; + assert( BitCount <= ThisFrameSize ); + assert( BitsRemaining >= 0 ); + assert( (BitCount + BitsRemaining) == ThisFrameSize ); + } + + + static int + write_side_info(void) + { + MYSideInfo *si; + int bits, ch, gr; + PartWriteFcnPtr wp = writePartSideInfo; + + bits = 0; + si = get_side_info(); + ThisFrameSize = si->frameLength; + bits += (*wp)( si->headerPH->part, NULL ); + bits += (*wp)( si->frameSIPH->part, NULL ); + + for ( ch = 0; ch < si->nChannels; ch++ ) + bits += (*wp)( si->channelSIPH[ch]->part, NULL ); + + for ( gr = 0; gr < si->nGranules; gr++ ) + for ( ch = 0; ch < si->nChannels; ch++ ) + bits += (*wp)( si->spectrumSIPH[gr][ch]->part, NULL ); + return bits; + } + + typedef struct side_info_link + { + struct side_info_link *next; + MYSideInfo side_info; + } side_info_link; + + static struct side_info_link *side_queue_head = NULL; + static struct side_info_link *side_queue_free = NULL; + + static void free_side_info_link( side_info_link *l ); + + static int + side_queue_elements( int *frameLength, int *SILength ) + { + int elements = 0; + side_info_link *l; + + *frameLength = 0; + *SILength = 0; + + for ( l = side_queue_head; l; l = l->next ) + { + elements++; + *frameLength += l->side_info.frameLength; + *SILength += l->side_info.SILength; + } + return elements; + } + + static int + store_side_info( BF_FrameData *info ) + { + int ch, gr; + side_info_link *l; + /* obtain a side_info_link to store info */ + side_info_link *f = side_queue_free; + int bits = 0; + + if ( f == NULL ) + { /* must allocate another */ + #ifdef DEBUG + static int n_si = 0; + n_si += 1; + fprintf( stderr, "allocating side_info_link number %d\n", n_si ); + #endif + l = (side_info_link *) calloc( 1, sizeof(side_info_link) ); + if ( l == NULL ) + { + fprintf( stderr, "cannot allocate side_info_link" ); + exit( 1); + } + l->next = NULL; + l->side_info.headerPH = BF_newPartHolder( info->header->nrEntries ); + l->side_info.frameSIPH = BF_newPartHolder( info->frameSI->nrEntries ); + for ( ch = 0; ch < info->nChannels; ch++ ) + l->side_info.channelSIPH[ch] = BF_newPartHolder( info->channelSI[ch]->nrEntries ); + for ( gr = 0; gr < info->nGranules; gr++ ) + for ( ch = 0; ch < info->nChannels; ch++ ) + l->side_info.spectrumSIPH[gr][ch] = BF_newPartHolder( info->spectrumSI[gr][ch]->nrEntries ); + + } + else + { /* remove from the free list */ + side_queue_free = f->next; + f->next = NULL; + l = f; + } + /* copy data */ + l->side_info.frameLength = info->frameLength; + l->side_info.nGranules = info->nGranules; + l->side_info.nChannels = info->nChannels; + l->side_info.headerPH = BF_LoadHolderFromBitstreamPart( l->side_info.headerPH, info->header ); + l->side_info.frameSIPH = BF_LoadHolderFromBitstreamPart( l->side_info.frameSIPH, info->frameSI ); + + bits += BF_PartLength( info->header ); + bits += BF_PartLength( info->frameSI ); + + for ( ch = 0; ch < info->nChannels; ch++ ) + { + l->side_info.channelSIPH[ch] = BF_LoadHolderFromBitstreamPart( l->side_info.channelSIPH[ch], + info->channelSI[ch] ); + bits += BF_PartLength( info->channelSI[ch] ); + } + + for ( gr = 0; gr < info->nGranules; gr++ ) + for ( ch = 0; ch < info->nChannels; ch++ ) + { + l->side_info.spectrumSIPH[gr][ch] = BF_LoadHolderFromBitstreamPart( l->side_info.spectrumSIPH[gr][ch], + info->spectrumSI[gr][ch] ); + bits += BF_PartLength( info->spectrumSI[gr][ch] ); + } + l->side_info.SILength = bits; + /* place at end of queue */ + f = side_queue_head; + if ( f == NULL ) + { /* empty queue */ + side_queue_head = l; + } + else + { /* find last element */ + while ( f->next ) + f = f->next; + f->next = l; + } + return bits; + } + + static MYSideInfo* + get_side_info(void) + { + side_info_link *f = side_queue_free; + side_info_link *l = side_queue_head; + + /* + If we stop here it means you didn't provide enough + headers to support the amount of main data that was + written. + */ + assert( l ); + + /* update queue head */ + side_queue_head = l->next; + + /* + Append l to the free list. You can continue + to use it until store_side_info is called + again, which will not happen again for this + frame. + */ + side_queue_free = l; + l->next = f; + return &l->side_info; + } + + static void + free_side_queues(void) + { + side_info_link *l, *next; + + for ( l = side_queue_head; l; l = next ) + { + next = l->next; + free_side_info_link( l ); + } + side_queue_head = NULL; + + for ( l = side_queue_free; l; l = next ) + { + next = l->next; + free_side_info_link( l ); + } + side_queue_free = NULL; + } + + static void + free_side_info_link( side_info_link *l ) + { + int gr, ch; + + l->side_info.headerPH = BF_freePartHolder( l->side_info.headerPH ); + l->side_info.frameSIPH = BF_freePartHolder( l->side_info.frameSIPH ); + + for ( ch = 0; ch < l->side_info.nChannels; ch++ ) + l->side_info.channelSIPH[ch] = BF_freePartHolder( l->side_info.channelSIPH[ch] ); + + for ( gr = 0; gr < l->side_info.nGranules; gr++ ) + for ( ch = 0; ch < l->side_info.nChannels; ch++ ) + l->side_info.spectrumSIPH[gr][ch] = BF_freePartHolder( l->side_info.spectrumSIPH[gr][ch] ); + + free( l ); + } + /* + Allocate a new holder of a given size + */ + BF_PartHolder *BF_newPartHolder( int max_elements ) + { + BF_PartHolder *newPH = (BF_PartHolder*) calloc( 1, sizeof(BF_PartHolder) ); + assert( newPH ); + newPH->max_elements = max_elements; + newPH->part = (BF_BitstreamPart*) calloc( 1, sizeof(BF_BitstreamPart) ); + assert( newPH->part ); + newPH->part->element = (BF_BitstreamElement*) calloc( max_elements, sizeof(BF_BitstreamElement) ); + if (max_elements>0) assert( newPH->part->element ); + newPH->part->nrEntries = 0; + return newPH; + } + + BF_PartHolder *BF_NewHolderFromBitstreamPart( BF_BitstreamPart *thePart ) + { + BF_PartHolder *newHolder = BF_newPartHolder( thePart->nrEntries ); + return BF_LoadHolderFromBitstreamPart( newHolder, thePart ); + } + + BF_PartHolder *BF_LoadHolderFromBitstreamPart( BF_PartHolder *theHolder, BF_BitstreamPart *thePart ) + { + BF_BitstreamElement *pElem; + u_int i; + + theHolder->part->nrEntries = 0; + for ( i = 0; i < thePart->nrEntries; i++ ) + { + pElem = &(thePart->element[i]); + theHolder = BF_addElement( theHolder, pElem ); + } + return theHolder; + } + + /* + Grow or shrink a part holder. Always creates a new + one of the right length and frees the old one after + copying the data. + */ + BF_PartHolder *BF_resizePartHolder( BF_PartHolder *oldPH, int max_elements ) + { + int elems, i; + BF_PartHolder *newPH; + + #ifdef DEBUG + fprintf( stderr, "Resizing part holder from %d to %d\n", + oldPH->max_elements, max_elements ); + #endif + /* create new holder of the right length */ + newPH = BF_newPartHolder( max_elements ); + + /* copy values from old to new */ + elems = (oldPH->max_elements > max_elements) ? max_elements : oldPH->max_elements; + newPH->part->nrEntries = elems; + for ( i = 0; i < elems; i++ ) + newPH->part->element[i] = oldPH->part->element[i]; + + /* free old holder */ + BF_freePartHolder( oldPH ); + + return newPH; + } + + BF_PartHolder *BF_freePartHolder( BF_PartHolder *thePH ) + { + free( thePH->part->element ); + free( thePH->part ); + free( thePH ); + return NULL; + } + + /* + Add theElement to thePH, growing the holder if + necessary. Returns ptr to the holder, which may + not be the one you called it with! + */ + BF_PartHolder *BF_addElement( BF_PartHolder *thePH, BF_BitstreamElement *theElement ) + { + BF_PartHolder *retPH = thePH; + int needed_entries = thePH->part->nrEntries + 1; + int extraPad = 8; /* add this many more if we need to resize */ + + /* grow if necessary */ + if ( needed_entries > thePH->max_elements ) + retPH = BF_resizePartHolder( thePH, needed_entries + extraPad ); + + /* copy the data */ + retPH->part->element[retPH->part->nrEntries++] = *theElement; + return retPH; + } + + /* + Add a bit value and length to the element list in thePH + */ + BF_PartHolder *BF_addEntry( BF_PartHolder *thePH, u_int value, u_int length ) + { + BF_BitstreamElement myElement; + myElement.value = value; + myElement.length = length; + + if ( length ) + return BF_addElement( thePH, &myElement ); + else + return thePH; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/formatBitstream.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/formatBitstream.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/formatBitstream.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,132 ---- + #ifndef _FORMAT_BITSTREAM_H + #define _FORMAT_BITSTREAM_H + /********************************************************************* + Copyright (c) 1995 ISO/IEC JTC1 SC29 WG1, All Rights Reserved + formatBitstream.h + **********************************************************************/ + + /* + Revision History: + + Date Programmer Comment + ========== ========================= =============================== + 1995/09/06 mc at fivebats.com created + + */ + + #include "machine.h" + + #ifndef MAX_CHANNELS + #define MAX_CHANNELS 2 + #endif + + #ifndef MAX_GRANULES + #define MAX_GRANULES 2 + #endif + + /* + This is the prototype for the function pointer you must + provide to write bits to the bitstream. It should write + 'length' bits from 'value,' msb first. Bits in value are + assumed to be right-justified. + */ + void putMyBits( u_int value, u_int length ); + + /* + A BitstreamElement contains encoded data + to be written to the bitstream. + 'length' bits of 'value' will be written to + the bitstream msb-first. + */ + typedef struct + { + u_int value; + u_short length; + } BF_BitstreamElement; + + /* + A BitstreamPart contains a group + of 'nrEntries' of BitstreamElements. + Each BitstreamElement will be written + to the bitstream in the order it appears + in the 'element' array. + */ + typedef struct + { + u_int nrEntries; + BF_BitstreamElement *element; + } BF_BitstreamPart; + + /* + This structure contains all the information needed by the + bitstream formatter to encode one frame of data. You must + fill this out and provide a pointer to it when you call + the formatter. + Maintainers: If you add or remove part of the side + information, you will have to update the routines that + make local copies of that information (in formatBitstream.c) + */ + + typedef struct BF_FrameData + { + int frameLength; + int nGranules; + int nChannels; + BF_BitstreamPart *header; + BF_BitstreamPart *frameSI; + BF_BitstreamPart *channelSI[MAX_CHANNELS]; + BF_BitstreamPart *spectrumSI[MAX_GRANULES][MAX_CHANNELS]; + BF_BitstreamPart *scaleFactors[MAX_GRANULES][MAX_CHANNELS]; + BF_BitstreamPart *codedData[MAX_GRANULES][MAX_CHANNELS]; + BF_BitstreamPart *userSpectrum[MAX_GRANULES][MAX_CHANNELS]; + BF_BitstreamPart *userFrameData; + } BF_FrameData; + + /* + This structure contains information provided by + the bitstream formatter. You can use this to + check to see if your code agrees with the results + of the call to the formatter. + */ + typedef struct BF_FrameResults + { + int SILength; + int mainDataLength; + int nextBackPtr; + } BF_FrameResults; + + + /* + public functions in formatBitstream.c + */ + + + /* Initialize the bitstream */ + void InitFormatBitStream(void); + + /* count the bits in a BitstreamPart */ + int BF_PartLength( BF_BitstreamPart *part ); + + /* encode a frame of audio and write it to your bitstream */ + void BF_BitstreamFrame( BF_FrameData *frameInfo, BF_FrameResults *results ); + + /* write any remaining frames to the bitstream, padding with zeros */ + void BF_FlushBitstream( BF_FrameData *frameInfo, BF_FrameResults *results ); + + + + typedef struct BF_PartHolder + { + int max_elements; + BF_BitstreamPart *part; + } BF_PartHolder; + + BF_PartHolder *BF_newPartHolder( int max_elements ); + BF_PartHolder *BF_resizePartHolder( BF_PartHolder *oldPH, int max_elements ); + BF_PartHolder *BF_addElement( BF_PartHolder *thePH, BF_BitstreamElement *theElement ); + BF_PartHolder *BF_addEntry( BF_PartHolder *thePH, u_int value, u_int length ); + BF_PartHolder *BF_NewHolderFromBitstreamPart( BF_BitstreamPart *thePart ); + BF_PartHolder *BF_LoadHolderFromBitstreamPart( BF_PartHolder *theHolder, BF_BitstreamPart *thePart ); + BF_PartHolder *BF_freePartHolder( BF_PartHolder *thePH ); + + #endif /* #ifndef _FORMAT_BITSTREAM_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/get_audio.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/get_audio.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/get_audio.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,937 ---- + #include "util.h" + #include "get_audio.h" + #ifdef HAVEGTK + #include "gtkanal.h" + #include + #endif + + #if (defined LIBSNDFILE || defined LAMESNDFILE) + + #ifdef _WIN32 + /* needed to set stdin to binary on windoze machines */ + #include + #endif + + + + static FILE *musicin=NULL; /* input file pointer */ + static unsigned long num_samples; + static int samp_freq; + static int input_bitrate; + static int num_channels; + static int count_samples_carefully; + + int read_samples_pcm(lame_global_flags *gfp,short sample_buffer[2304],int frame_size, int samples_to_read); + int read_samples_mp3(lame_global_flags *gfp,FILE *musicin,short int mpg123pcm[2][1152],int num_chan); + + + + + + void lame_init_infile(lame_global_flags *gfp) + { + /* open the input file */ + count_samples_carefully=0; + OpenSndFile(gfp,gfp->inPath,gfp->in_samplerate,gfp->num_channels); + /* if GetSndSampleRate is non zero, use it to overwrite the default */ + if (GetSndSampleRate()) gfp->in_samplerate=GetSndSampleRate(); + if (GetSndChannels()) gfp->num_channels=GetSndChannels(); + gfp->num_samples = GetSndSamples(); + } + void lame_close_infile(lame_global_flags *gfp) + { + CloseSndFile(gfp); + } + + + + + /************************************************************************ + * + * lame_readframe() + * + * PURPOSE: reads a frame of audio data from a file to the buffer, + * aligns the data for future processing, and separates the + * left and right channels + * + * + ************************************************************************/ + int lame_readframe(lame_global_flags *gfp,short int Buffer[2][1152]) + { + int iread; + + /* note: if input is gfp->stereo and output is mono, get_audio() + * will return .5*(L+R) in channel 0, and nothing in channel 1. */ + iread = get_audio(gfp,Buffer,gfp->stereo); + + /* check to see if we overestimated/underestimated totalframes */ + if (iread==0) gfp->totalframes = Min(gfp->totalframes,gfp->frameNum+2); + if (gfp->frameNum > (gfp->totalframes-1)) gfp->totalframes = gfp->frameNum; + return iread; + } + + + + + + /************************************************************************ + * + * get_audio() + * + * PURPOSE: reads a frame of audio data from a file to the buffer, + * aligns the data for future processing, and separates the + * left and right channels + * + * + ************************************************************************/ + int get_audio(lame_global_flags *gfp,short buffer[2][1152],int stereo) + { + + int j; + short insamp[2304]; + int samples_read; + int framesize,samples_to_read; + static unsigned long num_samples_read; + unsigned long remaining; + int num_channels = gfp->num_channels; + + if (gfp->frameNum==0) { + num_samples_read=0; + num_samples= GetSndSamples(); + } + framesize = gfp->mode_gr*576; + + samples_to_read = framesize; + if (count_samples_carefully) { + /* if this flag has been set, then we are carefull to read + * exactly num_samples and no more. This is usefull for .wav and .aiff + * files which have id3 or other tags at the end. Note that if you + * are using LIBSNDFILE, this is not necessary */ + remaining=num_samples-Min(num_samples,num_samples_read); + if (remaining < (unsigned long)framesize) + samples_to_read = remaining; + } + + + if (gfp->input_format==sf_mp3) { + /* decode an mp3 file for the input */ + samples_read=read_samples_mp3(gfp,musicin,buffer,num_channels); + }else{ + samples_read = read_samples_pcm(gfp,insamp,num_channels*framesize,num_channels*samples_to_read); + samples_read /=num_channels; + + for(j=0;jgtkflag) { + framesize=1152; + if (out==576) framesize=576; + + /* add a delay of framesize-DECDELAY, which will make the total delay + * exactly one frame, so we can sync MP3 output with WAV input */ + + for ( ch = 0; ch < stereo; ch++ ) { + for ( j = 0; j < framesize-DECDELAY; j++ ) + pinfo->pcmdata2[ch][j] = pinfo->pcmdata2[ch][j+framesize]; + for ( j = 0; j < framesize; j++ ) + pinfo->pcmdata2[ch][j+framesize-DECDELAY] = mpg123pcm[ch][j]; + } + + pinfo->frameNum123 = gfp->frameNum-1; + pinfo->frameNum = gfp->frameNum; + } + #endif + if (out==-1) return 0; + else return out; + #else + fprintf(stderr,"Error: libmp3lame was not compiled with I/O support \n"); + exit(1); + #endif + } + #endif /* LAMESNDFILE or LIBSNDFILE */ + + + + + #ifdef LIBSNDFILE + /* + ** Copyright (C) 1999 Albert Faber + ** + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + + #include + + /* External references */ + + static SNDFILE* gs_pSndFileIn=NULL; + static SF_INFO gs_wfInfo; + + + unsigned long GetSndSamples(void) + { + return gs_wfInfo.samples; + } + int GetSndSampleRate(void) + { + return gs_wfInfo.samplerate; + } + + int GetSndChannels(void) + { + return gs_wfInfo.channels; + } + + void CloseSndFile(lame_global_flags *gfp) + { + if (gfp->input_format==sf_mp3) { + #ifndef AMIGA_MPEGA + if (fclose(musicin) != 0){ + fprintf(stderr, "Could not close audio input file\n"); + exit(2); + } + #endif + }else{ + if (gs_pSndFileIn) + { + if (sf_close(gs_pSndFileIn) !=0) + { + fprintf(stderr, "Could not close sound file \n"); + exit(2); + } + } + } + } + + + + FILE * OpenSndFile(lame_global_flags *gfp,const char* lpszFileName, int default_samp, + int default_channels) + { + input_bitrate=0; + if (gfp->input_format==sf_mp3) { + #ifdef AMIGA_MPEGA + if (-1==lame_decode_initfile(lpszFileName,&num_channels,&samp_freq,&input_bitrate,&num_samples)) { + fprintf(stderr,"Error reading headers in mp3 input file %s.\n", lpszFileName); + exit(1); + } + #endif + #ifdef HAVEMPGLIB + if ((musicin = fopen(lpszFileName, "rb")) == NULL) { + fprintf(stderr, "Could not find \"%s\".\n", lpszFileName); + exit(1); + } + if (-1==lame_decode_initfile(musicin,&num_channels,&samp_freq,&input_bitrate,&num_samples)) { + fprintf(stderr,"Error reading headers in mp3 input file %s.\n", lpszFileName); + exit(1); + } + #endif + gs_wfInfo.samples=num_samples; + gs_wfInfo.channels=num_channels; + gs_wfInfo.samplerate=samp_freq; + + } else { + + /* Try to open the sound file */ + /* set some defaults incase input is raw PCM */ + gs_wfInfo.seekable=(gfp->input_format!=sf_raw); /* if user specified -r, set to not seekable */ + gs_wfInfo.samplerate=default_samp; + gs_wfInfo.pcmbitwidth=16; + gs_wfInfo.channels=default_channels; + if (DetermineByteOrder()==order_littleEndian) { + if (gfp->swapbytes) gs_wfInfo.format=SF_FORMAT_RAW_BE; + else gs_wfInfo.format=SF_FORMAT_RAW_LE; + } else { + if (gfp->swapbytes) gs_wfInfo.format=SF_FORMAT_RAW_LE; + else gs_wfInfo.format=SF_FORMAT_RAW_BE; + } + + gs_pSndFileIn=sf_open_read(lpszFileName,&gs_wfInfo); + + /* Check result */ + if (gs_pSndFileIn==NULL) + { + sf_perror(gs_pSndFileIn); + fprintf(stderr, "Could not open sound file \"%s\".\n", lpszFileName); + exit(1); + } + + if ((gs_wfInfo.format==SF_FORMAT_RAW_LE) || + (gs_wfInfo.format==SF_FORMAT_RAW_BE)) + gfp->input_format=sf_raw; + + #ifdef _DEBUG_SND_FILE + printf("\n\nSF_INFO structure\n"); + printf("samplerate :%d\n",gs_wfInfo.samplerate); + printf("samples :%d\n",gs_wfInfo.samples); + printf("channels :%d\n",gs_wfInfo.channels); + printf("pcmbitwidth :%d\n",gs_wfInfo.pcmbitwidth); + printf("format :"); + + /* new formats from sbellon at sbellon.de 1/2000 */ + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_WAV) + printf("Microsoft WAV format (big endian). "); + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_AIFF) + printf("Apple/SGI AIFF format (little endian). "); + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_AU) + printf("Sun/NeXT AU format (big endian). "); + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_AULE) + printf("DEC AU format (little endian). "); + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_RAW) + printf("RAW PCM data. "); + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_PAF) + printf("Ensoniq PARIS file format. "); + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_SVX) + printf("Amiga IFF / SVX8 / SV16 format. "); + if ((gs_wfInfo.format&SF_FORMAT_TYPEMASK)==SF_FORMAT_NIST) + printf("Sphere NIST format. "); + + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM) + printf("PCM data in 8, 16, 24 or 32 bits."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_FLOAT) + printf("32 bit Intel x86 floats."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_ULAW) + printf("U-Law encoded."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_ALAW) + printf("A-Law encoded."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_IMA_ADPCM) + printf("IMA ADPCM."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_MS_ADPCM) + printf("Microsoft ADPCM."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_BE) + printf("Big endian PCM data."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_LE) + printf("Little endian PCM data."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_S8) + printf("Signed 8 bit PCM."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_U8) + printf("Unsigned 8 bit PCM."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_SVX_FIB) + printf("SVX Fibonacci Delta encoding."); + if ((gs_wfInfo.format&SF_FORMAT_SUBMASK)==SF_FORMAT_SVX_EXP) + printf("SVX Exponential Delta encoding."); + + + + + printf("\n"); + printf("pcmbitwidth :%d\n",gs_wfInfo.pcmbitwidth); + printf("sections :%d\n",gs_wfInfo.sections); + printf("seekable :\n",gs_wfInfo.seekable); + #endif + } + + if (gs_wfInfo.samples==MAX_U_32_NUM) { + struct stat sb; + /* try to figure out num_samples */ + if (0==stat(lpszFileName,&sb)) { + /* try file size, assume 2 bytes per sample */ + if (gfp->input_format == sf_mp3) { + FLOAT totalseconds = (sb.st_size*8.0/(1000.0*GetSndBitrate())); + gs_wfInfo.samples= totalseconds*GetSndSampleRate(); + }else{ + gs_wfInfo.samples = sb.st_size/(2*GetSndChannels()); + } + } + } + return musicin; + } + + + /************************************************************************ + * + * read_samples() + * + * PURPOSE: reads the PCM samples from a file to the buffer + * + * SEMANTICS: + * Reads #samples_read# number of shorts from #musicin# filepointer + * into #sample_buffer[]#. Returns the number of samples read. + * + ************************************************************************/ + + int read_samples_pcm(lame_global_flags *gfp,short sample_buffer[2304],int frame_size,int samples_to_read) + { + int samples_read; + int rcode; + + samples_read=sf_read_short(gs_pSndFileIn,sample_buffer,samples_to_read); + + rcode = samples_read; + if (samples_read < frame_size) + { + /*fprintf(stderr,"Insufficient PCM input for one frame - fillout with zeros\n"); + */ + if (samples_read<0) samples_read=0; + for (; samples_read < frame_size; sample_buffer[samples_read++] = 0); + } + + if (8==gs_wfInfo.pcmbitwidth) + for (; samples_read >= 0; sample_buffer[samples_read] = sample_buffer[samples_read--] * 256); + + return(rcode); + } + + + #endif /* ifdef LIBSNDFILE */ + #ifdef LAMESNDFILE + + /************************************************************************ + ************************************************************************ + ************************************************************************ + ************************************************************************ + ************************************************************************ + ************************************************************************ + * + * OLD ISO/LAME routines follow. Used if you dont have LIBSNDFILE + * or for stdin/stdout support + * + ************************************************************************ + ************************************************************************ + ************************************************************************ + ************************************************************************ + ************************************************************************ + ************************************************************************/ + + /* Replacement for forward fseek(,,SEEK_CUR), because fseek() fails on pipes */ + int fskip(FILE *sf,long num_bytes,int dummy) + { + char data[1024]; + int nskip = 0; + while (num_bytes > 0) { + nskip = (num_bytes>1024) ? 1024 : num_bytes; + num_bytes -= fread(data,(size_t)1,(size_t)nskip,sf); + } + /* return 0 if last read was successful */ + return num_bytes; + } + + + + void CloseSndFile(lame_global_flags *gfp) + { + if (fclose(musicin) != 0){ + fprintf(stderr, "Could not close audio input file\n"); + exit(2); + } + } + + + unsigned long GetSndSamples(void) + { + return num_samples; + } + int GetSndSampleRate(void) + { + return samp_freq; + } + + int GetSndChannels(void) + { + return num_channels; + } + + + FILE * OpenSndFile(lame_global_flags *gfp,const char* inPath, int default_samp, + int default_channels) + { + struct stat sb; + void parse_file_header(lame_global_flags *gfp,FILE *sf); + /* set the defaults from info incase we cannot determine them from file */ + num_samples=MAX_U_32_NUM; + samp_freq=default_samp; + num_channels = default_channels; + + if (!strcmp(inPath, "-")) { + /* Read from standard input. */ + #ifdef __EMX__ + _fsetmode(stdin,"b"); + #elif (defined __BORLANDC__) + setmode(_fileno(stdin), O_BINARY); + #elif (defined __CYGWIN__) + setmode(fileno(stdin), _O_BINARY); + #elif (defined _WIN32) + _setmode(_fileno(stdin), _O_BINARY); + #endif + musicin = stdin; + } else { + if ((musicin = fopen(inPath, "rb")) == NULL) { + fprintf(stderr, "Could not find \"%s\".\n", inPath); + exit(1); + } + } + + input_bitrate=0; + if (gfp->input_format==sf_mp3) { + #ifdef AMIGA_MPEGA + if (-1==lame_decode_initfile(inPath,&num_channels,&samp_freq,&input_bitrate,&num_samples)) { + fprintf(stderr,"Error reading headers in mp3 input file %s.\n", inPath); + exit(1); + } + #endif + #ifdef HAVEMPGLIB + if (-1==lame_decode_initfile(musicin,&num_channels,&samp_freq,&input_bitrate,&num_samples)) { + fprintf(stderr,"Error reading headers in mp3 input file %s.\n", inPath); + exit(1); + } + #endif + }else{ + if (gfp->input_format != sf_raw) { + parse_file_header(gfp,musicin); + } + + if (gfp->input_format==sf_raw) { + /* assume raw PCM */ + fprintf(stderr, "Assuming raw pcm input file"); + if (gfp->swapbytes==TRUE) + fprintf(stderr, " : Forcing byte-swapping\n"); + else + fprintf(stderr, "\n"); + } + } + + if (num_samples==MAX_U_32_NUM && musicin != stdin) { + /* try to figure out num_samples */ + if (0==stat(inPath,&sb)) { + /* try file size, assume 2 bytes per sample */ + if (gfp->input_format == sf_mp3) { + FLOAT totalseconds = (sb.st_size*8.0/(1000.0*GetSndBitrate())); + num_samples= totalseconds*GetSndSampleRate(); + }else{ + num_samples = sb.st_size/(2*GetSndChannels()); + } + } + } + return musicin; + } + + + /************************************************************************ + * + * read_samples() + * + * PURPOSE: reads the PCM samples from a file to the buffer + * + * SEMANTICS: + * Reads #samples_read# number of shorts from #musicin# filepointer + * into #sample_buffer[]#. Returns the number of samples read. + * + ************************************************************************/ + + int read_samples_pcm(lame_global_flags *gfp,short sample_buffer[2304], int frame_size,int samples_to_read) + { + int samples_read; + int rcode; + int iswav=(gfp->input_format==sf_wave); + + samples_read = fread(sample_buffer, sizeof(short), samples_to_read, musicin); + if (ferror(musicin)) { + fprintf(stderr, "Error reading input file\n"); + exit(2); + } + + /* + Samples are big-endian. If this is a little-endian machine + we must swap + */ + if ( NativeByteOrder == order_unknown ) + { + NativeByteOrder = DetermineByteOrder(); + if ( NativeByteOrder == order_unknown ) + { + fprintf( stderr, "byte order not determined\n" ); + exit( 1 ); + } + } + /* intel=littleEndian */ + if (!iswav && ( NativeByteOrder == order_littleEndian )) + SwapBytesInWords( sample_buffer, samples_read ); + + if (iswav && ( NativeByteOrder == order_bigEndian )) + SwapBytesInWords( sample_buffer, samples_read ); + + if (gfp->swapbytes==TRUE) + SwapBytesInWords( sample_buffer, samples_read ); + + + rcode=samples_read; + if (samples_read < frame_size) { + if (samples_read<0) samples_read=0; + /*fprintf(stderr,"Insufficient PCM input for one frame - fillout with zeros\n"); + */ + for (; samples_read < frame_size; sample_buffer[samples_read++] = 0); + } + return(rcode); + } + + + + #define WAV_ID_RIFF 0x52494646 /* "RIFF" */ + #define WAV_ID_WAVE 0x57415645 /* "WAVE" */ + #define WAV_ID_FMT 0x666d7420 /* "fmt " */ + #define WAV_ID_DATA 0x64617461 /* "data" */ + + typedef struct fmt_chunk_data_struct { + short format_tag; /* Format category */ + u_short channels; /* Number of channels */ + u_long samples_per_sec; /* Sampling rate */ + u_long avg_bytes_per_sec; /* For buffer estimation */ + u_short block_align; /* Data block size */ + u_short bits_per_sample; /* for PCM data, anyway... */ + } fmt_chunk_data; + + + + + + + /************************************************************************ + * + * wave_check + * + * PURPOSE: Checks Wave header information to make sure it is valid. + * Exits if not. + * + ************************************************************************/ + + static void + wave_check(char *file_name, fmt_chunk_data *wave_info) + { + if (wave_info->bits_per_sample != 16) { + fprintf(stderr, "%d-bit sample-size is not supported!\n", + wave_info->bits_per_sample); + exit(1); + } + } + + + /***************************************************************************** + * + * Read Microsoft Wave headers + * + * By the time we get here the first 32-bits of the file have already been + * read, and we're pretty sure that we're looking at a WAV file. + * + *****************************************************************************/ + + static int + parse_wave_header(FILE *sf) + { + fmt_chunk_data wave_info; + int is_wav = 0; + long data_length = 0, file_length, subSize = 0; + int loop_sanity = 0; + + memset(&wave_info, 0, sizeof(wave_info)); + + file_length = Read32BitsHighLow(sf); + + if (Read32BitsHighLow(sf) != WAV_ID_WAVE) + return 0; + + for (loop_sanity = 0; loop_sanity < 20; ++loop_sanity) { + u_int type = Read32BitsHighLow(sf); + + if (type == WAV_ID_FMT) { + subSize = Read32BitsLowHigh(sf); + if (subSize < 16) { + /*fprintf(stderr, + "'fmt' chunk too short (only %ld bytes)!", subSize); */ + return 0; + } + + wave_info.format_tag = Read16BitsLowHigh(sf); + subSize -= 2; + wave_info.channels = Read16BitsLowHigh(sf); + subSize -= 2; + wave_info.samples_per_sec = Read32BitsLowHigh(sf); + subSize -= 4; + wave_info.avg_bytes_per_sec = Read32BitsLowHigh(sf); + subSize -= 4; + wave_info.block_align = Read16BitsLowHigh(sf); + subSize -= 2; + wave_info.bits_per_sample = Read16BitsLowHigh(sf); + subSize -= 2; + + /* fprintf(stderr, " skipping %d bytes\n", subSize); */ + + if (subSize > 0) { + if (fskip(sf, (long)subSize, SEEK_CUR) != 0 ) + return 0; + }; + + } else if (type == WAV_ID_DATA) { + subSize = Read32BitsLowHigh(sf); + data_length = subSize; + is_wav = 1; + /* We've found the audio data. Read no further! */ + break; + + } else { + subSize = Read32BitsLowHigh(sf); + if (fskip(sf, (long) subSize, SEEK_CUR) != 0 ) return 0; + } + } + + if (is_wav) { + /* make sure the header is sane */ + wave_check("name", &wave_info); + + num_channels = wave_info.channels; + samp_freq = wave_info.samples_per_sec; + num_samples = data_length / (wave_info.channels * wave_info.bits_per_sample / 8); + } + return is_wav; + } + + + + /************************************************************************ + * + * aiff_check + * + * PURPOSE: Checks AIFF header information to make sure it is valid. + * Exits if not. + * + ************************************************************************/ + + static void + aiff_check2(const char *file_name, IFF_AIFF *pcm_aiff_data) + { + if (pcm_aiff_data->sampleType != IFF_ID_SSND) { + fprintf(stderr, "Sound data is not PCM in \"%s\".\n", file_name); + exit(1); + } + + if (pcm_aiff_data->sampleSize != sizeof(short) * BITS_IN_A_BYTE) { + fprintf(stderr, "Sound data is not %d bits in \"%s\".\n", + (unsigned int) sizeof(short) * BITS_IN_A_BYTE, file_name); + exit(1); + } + + if (pcm_aiff_data->numChannels != 1 && + pcm_aiff_data->numChannels != 2) { + fprintf(stderr, "Sound data is not mono or stereo in \"%s\".\n", + file_name); + exit(1); + } + + if (pcm_aiff_data->blkAlgn.blockSize != 0) { + fprintf(stderr, "Block size is not %d bytes in \"%s\".\n", + 0, file_name); + exit(1); + } + + if (pcm_aiff_data->blkAlgn.offset != 0) { + fprintf(stderr, "Block offset is not %d bytes in \"%s\".\n", + 0, file_name); + exit(1); + } + } + + /***************************************************************************** + * + * Read Audio Interchange File Format (AIFF) headers. + * + * By the time we get here the first 32-bits of the file have already been + * read, and we're pretty sure that we're looking at an AIFF file. + * + *****************************************************************************/ + + static int + parse_aiff_header(FILE *sf) + { + int is_aiff = 0; + long chunkSize = 0, subSize = 0; + IFF_AIFF aiff_info; + + memset(&aiff_info, 0, sizeof(aiff_info)); + chunkSize = Read32BitsHighLow(sf); + + if ( Read32BitsHighLow(sf) != IFF_ID_AIFF ) + return 0; + + while ( chunkSize > 0 ) + { + u_int type = 0; + chunkSize -= 4; + + type = Read32BitsHighLow(sf); + + /* fprintf(stderr, + "found chunk type %08x '%4.4s'\n", type, (char*)&type); */ + + /* don't use a switch here to make it easier to use 'break' for SSND */ + if (type == IFF_ID_COMM) { + subSize = Read32BitsHighLow(sf); + chunkSize -= subSize; + + aiff_info.numChannels = Read16BitsHighLow(sf); + subSize -= 2; + aiff_info.numSampleFrames = Read32BitsHighLow(sf); + subSize -= 4; + aiff_info.sampleSize = Read16BitsHighLow(sf); + subSize -= 2; + aiff_info.sampleRate = ReadIeeeExtendedHighLow(sf); + subSize -= 10; + + if (fskip(sf, (long) subSize, SEEK_CUR) != 0 ) + return 0; + + } else if (type == IFF_ID_SSND) { + subSize = Read32BitsHighLow(sf); + chunkSize -= subSize; + + aiff_info.blkAlgn.offset = Read32BitsHighLow(sf); + subSize -= 4; + aiff_info.blkAlgn.blockSize = Read32BitsHighLow(sf); + subSize -= 4; + + if (fskip(sf, aiff_info.blkAlgn.offset, SEEK_CUR) != 0 ) + return 0; + + aiff_info.sampleType = IFF_ID_SSND; + is_aiff = 1; + + /* We've found the audio data. Read no further! */ + break; + + } else { + subSize = Read32BitsHighLow(sf); + chunkSize -= subSize; + + if (fskip(sf, (long) subSize, SEEK_CUR) != 0 ) + return 0; + } + } + + /* fprintf(stderr, "Parsed AIFF %d\n", is_aiff); */ + if (is_aiff) { + /* make sure the header is sane */ + aiff_check2("name", &aiff_info); + num_channels = aiff_info.numChannels; + samp_freq = aiff_info.sampleRate; + num_samples = aiff_info.numSampleFrames; + } + return is_aiff; + } + + + + /************************************************************************ + * + * parse_file_header + * + * PURPOSE: Read the header from a bytestream. Try to determine whether + * it's a WAV file or AIFF without rewinding, since rewind + * doesn't work on pipes and there's a good chance we're reading + * from stdin (otherwise we'd probably be using libsndfile). + * + * When this function returns, the file offset will be positioned at the + * beginning of the sound data. + * + ************************************************************************/ + + void parse_file_header(lame_global_flags *gfp,FILE *sf) + { + u_int type = 0; + type = Read32BitsHighLow(sf); + + /* fprintf(stderr, + "First word of input stream: %08x '%4.4s'\n", type, (char*) &type); */ + + count_samples_carefully=0; + gfp->input_format = sf_raw; + + if (type == WAV_ID_RIFF) { + /* It's probably a WAV file */ + if (parse_wave_header(sf)) { + gfp->input_format = sf_wave; + count_samples_carefully=1; + } + + } else if (type == IFF_ID_FORM) { + /* It's probably an AIFF file */ + if (parse_aiff_header(sf)) { + gfp->input_format = sf_aiff; + count_samples_carefully=1; + } + } + if (gfp->input_format==sf_raw) { + /* + ** Assume it's raw PCM. Since the audio data is assumed to begin + ** at byte zero, this will unfortunately require seeking. + */ + if (fseek(sf, 0L, SEEK_SET) != 0) { + /* ignore errors */ + } + gfp->input_format = sf_raw; + } + } + #endif /* LAMESNDFILE */ + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/get_audio.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/get_audio.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/get_audio.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,94 ---- + /* + ** Copyright (C) 1999 Albert Faber + ** + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + + #ifndef GET_AUDIO_H_INCLUDED + #define GET_AUDIO_H_INCLUDED + + #if (defined LIBSNDFILE || defined LAMESNDFILE) + + + /* AIFF Definitions */ + + #define IFF_ID_FORM 0x464f524d /* "FORM" */ + #define IFF_ID_AIFF 0x41494646 /* "AIFF" */ + #define IFF_ID_COMM 0x434f4d4d /* "COMM" */ + #define IFF_ID_SSND 0x53534e44 /* "SSND" */ + #define IFF_ID_MPEG 0x4d504547 /* "MPEG" */ + + + + void CloseSndFile(lame_global_flags *gfp); + FILE * OpenSndFile(lame_global_flags *gfp,const char* lpszFileName,int default_samp, int + default_chan); + unsigned long GetSndSamples(void); + int GetSndSampleRate(void); + int GetSndChannels(void); + int GetSndBitrate(void); + + + int get_audio(lame_global_flags *gfp,short buffer[2][1152],int stereo); + + + + #ifdef LIBSNDFILE + /* INCLUDE the sound library header file */ + #ifdef _MSC_VER + /* one byte alignment for WIN32 platforms */ + #pragma pack(push,1) + #include "./libsndfile/src/sndfile.h" + #pragma pack(pop,1) + #else + #include "sndfile.h" + #endif + + + #else + /***************************************************************** + * LAME/ISO built in audio file I/O routines + *******************************************************************/ + #include "portableio.h" + #include "ieeefloat.h" + + + typedef struct blockAlign_struct { + unsigned long offset; + unsigned long blockSize; + } blockAlign; + + typedef struct IFF_AIFF_struct { + short numChannels; + unsigned long numSampleFrames; + short sampleSize; + FLOAT sampleRate; + unsigned long sampleType; + blockAlign blkAlgn; + } IFF_AIFF; + + extern int aiff_read_headers(FILE*, IFF_AIFF*); + extern int aiff_seek_to_sound_data(FILE*); + extern int aiff_write_headers(FILE*, IFF_AIFF*); + extern int parse_wavheader(void); + extern int parse_aiff(const char fn[]); + extern void aiff_check(const char*, IFF_AIFF*, int*); + + + #endif /* ifndef _LIBSNDDLL */ + #endif /* ifdef LAMESNDFILE or LIBSNDFILE */ + #endif /* ifndef GET_AUDIO_H_INCLUDED*/ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gpkplotting.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gpkplotting.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gpkplotting.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,282 ---- + #ifdef HAVEGTK + #include "gpkplotting.h" + #include "string.h" + + static gint num_plotwindows = 0; + static gint max_plotwindows = 10; + static GdkPixmap *pixmaps[10]; + static GtkWidget *pixmapboxes[10]; + + + + + /* compute a gdkcolor */ + void setcolor(GtkWidget *widget, GdkColor *color, gint red,gint green,gint blue) + { + + /* colors in GdkColor are taken from 0 to 65535, not 0 to 255. */ + color->red = red * (65535/255); + color->green = green * (65535/255); + color->blue = blue * (65535/255); + color->pixel = (gulong)(color->red*65536 + color->green*256 + color->blue); + /* find closest in colormap, if needed */ + gdk_color_alloc(gtk_widget_get_colormap(widget),color); + } + + + void gpk_redraw(GdkPixmap *pixmap, GtkWidget *pixmapbox) + { + /* redraw the entire pixmap */ + gdk_draw_pixmap(pixmapbox->window, + pixmapbox->style->fg_gc[GTK_WIDGET_STATE (pixmapbox)], + pixmap,0,0,0,0, + pixmapbox->allocation.width, + pixmapbox->allocation.height); + } + + + static GdkPixmap **findpixmap(GtkWidget *widget) + { + int i; + for (i=0; i=num_plotwindows) { + g_print("findpixmap(): bad argument widget \n"); + return NULL; + } + return &pixmaps[i]; + } + + void gpk_graph_draw(GtkWidget *widget, /* plot on this widged */ + int n, /* number of data points */ + gdouble *xcord, gdouble *ycord, /* data */ + gdouble xmn,gdouble ymn, /* coordinates of corners */ + gdouble xmx,gdouble ymx, + int clear, /* clear old plot first */ + char *title, /* add a title (only if clear=1) */ + GdkColor *color) + { + GdkPixmap **ppixmap; + GdkPoint *points; + int i; + gint16 width,height; + GdkFont *fixed_font; + GdkGC *gc; + + gc = gdk_gc_new(widget->window); + gdk_gc_set_foreground(gc, color); + + + + if ((ppixmap=findpixmap(widget))) { + width = widget->allocation.width; + height = widget->allocation.height; + + + if (clear) { + /* white background */ + gdk_draw_rectangle (*ppixmap, + widget->style->white_gc, + TRUE,0, 0,width,height); + /* title */ + #ifndef _WIN32 + fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-100-*-*-*-*-*-*"); + #else + fixed_font = gdk_font_load ("-misc-fixed-large-r-*-*-*-100-*-*-*-*-*-*"); + #endif + + gdk_draw_text (*ppixmap,fixed_font, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + 0,10,title,strlen(title)); + } + + + points = g_malloc(n*sizeof(GdkPoint)); + for (i=0; iwindow); + gdk_gc_set_foreground(gc, color); + + + if ((ppixmap=findpixmap(widget))) { + width = widget->allocation.width; + height = widget->allocation.height; + + + for (i=0; i<2 ; i++) { + points[i].x =.5+ ((xcord[i]-xmn)*(width-1)/(xmx-xmn)); + points[i].y =.5+ ((ycord[i]-ymx)*(height-1)/(ymn-ymx)); + } + width=points[1].x-points[0].x + 1; + height=points[1].y-points[0].y + 1; + gdk_draw_rectangle(*ppixmap,gc,TRUE, + points[0].x,points[0].y,width,height); + gpk_redraw(*ppixmap,widget); + } + gdk_gc_destroy(gc); + } + + + + void gpk_bargraph_draw(GtkWidget *widget, /* plot on this widged */ + int n, /* number of data points */ + gdouble *xcord, gdouble *ycord, /* data */ + gdouble xmn,gdouble ymn, /* coordinates of corners */ + gdouble xmx,gdouble ymx, + int clear, /* clear old plot first */ + char *title, /* add a title (only if clear=1) */ + int barwidth, /* bar width. 0=compute based on window size */ + GdkColor *color) + { + GdkPixmap **ppixmap; + GdkPoint points[2]; + int i; + gint16 width,height,x,y,barheight; + GdkFont *fixed_font; + GdkGC *gc; + + + gc = gdk_gc_new(widget->window); + gdk_gc_set_foreground(gc, color); + + + if ((ppixmap=findpixmap(widget))) { + width = widget->allocation.width; + height = widget->allocation.height; + + + if (clear) { + /* white background */ + gdk_draw_rectangle (*ppixmap, + widget->style->white_gc, + TRUE,0, 0,width,height); + /* title */ + #ifndef _WIN32 + fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-100-*-*-*-*-*-*"); + #else + fixed_font = gdk_font_load ("-misc-fixed-large-r-*-*-*-100-*-*-*-*-*-*"); + #endif + + gdk_draw_text (*ppixmap,fixed_font, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + 0,10,title,strlen(title)); + } + + + for (i=0; i 5 ? 5 : barwidth; + barwidth = barwidth < 1 ? 1 : barwidth; + barheight = height-1 - y; + /* gdk_draw_lines(*ppixmap,gc,points,2); */ + gdk_draw_rectangle(*ppixmap,gc,TRUE,x,y,barwidth,barheight); + + } + gpk_redraw(*ppixmap,widget); + } + gdk_gc_destroy(gc); + } + + + + + + /* Create a new backing pixmap of the appropriate size */ + static gint + configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer data) + { + GdkPixmap **ppixmap; + if ((ppixmap=findpixmap(widget))){ + if (*ppixmap) gdk_pixmap_unref(*ppixmap); + *ppixmap = gdk_pixmap_new(widget->window, + widget->allocation.width, + widget->allocation.height, + -1); + gdk_draw_rectangle (*ppixmap, + widget->style->white_gc, + TRUE, + 0, 0, + widget->allocation.width, + widget->allocation.height); + } + return TRUE; + } + + + + /* Redraw the screen from the backing pixmap */ + static gint + expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data) + { + GdkPixmap **ppixmap; + if ((ppixmap=findpixmap(widget))){ + gdk_draw_pixmap(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + *ppixmap, + event->area.x, event->area.y, + event->area.x, event->area.y, + event->area.width, event->area.height); + } + + return FALSE; + } + + + + + + GtkWidget *gpk_plot_new(int width, int height) + { + GtkWidget *pixmapbox; + + pixmapbox = gtk_drawing_area_new(); + gtk_drawing_area_size(GTK_DRAWING_AREA(pixmapbox),width,height); + gtk_signal_connect (GTK_OBJECT (pixmapbox), "expose_event", + (GtkSignalFunc) expose_event, NULL); + gtk_signal_connect (GTK_OBJECT(pixmapbox),"configure_event", + (GtkSignalFunc) configure_event, NULL); + gtk_widget_set_events (pixmapbox, GDK_EXPOSURE_MASK); + + if (num_plotwindows < max_plotwindows) { + pixmapboxes[num_plotwindows] = pixmapbox; + pixmaps[num_plotwindows] = NULL; + num_plotwindows ++; + } else { + g_print("gtk_plotarea_new(): exceeded maximum of 10 plotarea windows\n"); + } + + return pixmapbox; + } + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gpkplotting.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gpkplotting.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gpkplotting.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,27 ---- + #include + + /* allocate a graphing widget */ + GtkWidget *gpk_plot_new(int width,int height); + + /* graph a function in the graphing widged */ + void gpk_graph_draw(GtkWidget *widget, + int n, gdouble *xcord, gdouble *ycord, + gdouble xmn, gdouble ymn,gdouble xmx,gdouble ymx, + int clear, char * title,GdkColor *color); + + /* draw a rectangle in the graphing widget */ + void gpk_rectangle_draw(GtkWidget *widget, /* plot on this widged */ + gdouble xcord[2], gdouble ycord[2], /* corners */ + gdouble xmn,gdouble ymn, /* coordinates of corners */ + gdouble xmx,gdouble ymx, + GdkColor *color); /* color to use */ + + /* make a bar graph in the graphing widged */ + void gpk_bargraph_draw(GtkWidget *widget, + int n, gdouble *xcord, gdouble *ycord, + gdouble xmn, gdouble ymn,gdouble xmx,gdouble ymx, + int clear, char * title, int bwidth,GdkColor *color); + + /* set forground color */ + void setcolor(GtkWidget *widget, GdkColor *color,int red,int green,int blue); + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gtkanal.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gtkanal.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gtkanal.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,1410 ---- + #ifdef HAVEGTK + #include + #include + #include "gpkplotting.h" + #include "util.h" + #include "gtkanal.h" + #include "version.h" + #include "lame.h" + #include "tables.h" + #include "quantize-pvt.h" + #include + + int gtkflag; + + extern int makeframe(void); + + /* global variables for the state of the system */ + static gint idle_keepgoing; /* processing of frames is ON */ + static gint idle_count_max; /* number of frames to process before plotting */ + static gint idle_count; /* pause & plot when idle_count=idel_count_max */ + static gint idle_end=0; /* process all frames, stop at last frame */ + static gint idle_back = 0; /* set when we are displaying the old data */ + static int mp3done = 0; /* last frame has been read */ + static GtkWidget *frameprogress; /* progress bar */ + static GtkWidget *framecounter; /* progress counter */ + + static int subblock_draw[3] = { 1, 1, 1 }; + + /* main window */ + GtkWidget *window; + /* Backing pixmap for drawing areas */ + GtkWidget *pcmbox; /* PCM data plotted here */ + GtkWidget *winbox; /* mpg123 synthesis data plotted here */ + GtkWidget *enerbox[2]; /* spectrum, gr=0,1 plotted here */ + GtkWidget *mdctbox[2]; /* mdct coefficients gr=0,1 plotted here */ + GtkWidget *sfbbox[2]; /* scalefactors gr=0,1 plotted here */ + GtkWidget *headerbox; /* mpg123 header info shown here */ + + plotting_data *pinfo,*pplot; + plotting_data Pinfo[NUMPINFO]; + + struct gtkinfostruct { + int filetype; /* input file type 0=WAV, 1=MP3 */ + int msflag; /* toggle between L&R vs M&S PCM data display */ + int chflag; /* toggle between L & R channels */ + int kbflag; /* toggle between wave # and barks */ + int flag123; /* show mpg123 frame info, OR ISO encoder frame info */ + double avebits; /* running average bits per frame */ + int approxbits; /* (approx) bits per frame */ + int maxbits; /* max bits per frame used so far*/ + int totemph; /* total of frames with de-emphasis */ + int totms; /* total frames with ms_stereo */ + int totis; /* total frames with i_stereo */ + int totshort; /* total granules with short blocks */ + int totmix; /* total granules with mixed blocks */ + int pupdate; /* plot while processing, or only when needed */ + int sfblines; /* plot scalefactor bands in MDCT plot */ + int totalframes; + } gtkinfo; + + + static lame_global_flags *gfp; + + /********************************************************************** + * read one frame and encode it + **********************************************************************/ + int gtkmakeframe(void) + { + int iread = 0; + static int init=0; + static int mpglag; + static short int Buffer[2][1152]; + int ch,j; + int mp3count = 0; + int mp3out = 0; + short mpg123pcm[2][1152]; + char mp3buffer[LAME_MAXMP3BUFFER]; + + + #ifndef HAVEMPGLIB + fprintf(stderr,"Error: GTK frame analyzer requires MPGLIB\n"); + exit(1); + #else + /* even if iread=0, get_audio hit EOF and returned Buffer=all 0's. encode + * and decode to flush any previous buffers from the decoder */ + + pinfo->frameNum = gfp->frameNum; + pinfo->sampfreq=gfp->out_samplerate; + pinfo->framesize=576*gfp->mode_gr; + pinfo->stereo = gfp->stereo; + + if (gfp->input_format == sf_mp3) { + iread=lame_readframe(gfp,Buffer); + gfp->frameNum++; + }else { + while (gfp->frameNum == pinfo->frameNum) { + if (gfp->frameNum==0 && !init) { + mpglag=1; + lame_decode_init(); + } + if (gfp->frameNum==1) init=0; /* reset for next time frameNum==0 */ + iread=lame_readframe(gfp,Buffer); + + + mp3count=lame_encode(gfp,Buffer,mp3buffer,sizeof(mp3buffer)); /* encode frame */ + assert( !(mp3count > 0 && gfp->frameNum == pinfo->frameNum)); + /* not possible to produce mp3 data without encoding at least + * one frame of data which would increment gfp->frameNum */ + } + mp3out=lame_decode(mp3buffer,mp3count,mpg123pcm[0],mpg123pcm[1]); /* re-synthesis to pcm */ + /* mp3out = 0: need more data to decode */ + /* mp3out = -1: error. Lets assume 0 pcm output */ + /* mp3out = number of samples output */ + if (mp3out>0) assert(mp3out==pinfo->framesize); + if (mp3out!=0) { + /* decoded output is for frame pinfo->frameNum123 + * add a delay of framesize-DECDELAY, which will make the total delay + * exactly one frame */ + pinfo->frameNum123=pinfo->frameNum-mpglag; + for ( ch = 0; ch < pinfo->stereo; ch++ ) { + for ( j = 0; j < pinfo->framesize-DECDELAY; j++ ) + pinfo->pcmdata2[ch][j] = pinfo->pcmdata2[ch][j+pinfo->framesize]; + for ( j = 0; j < pinfo->framesize; j++ ) { + pinfo->pcmdata2[ch][j+pinfo->framesize-DECDELAY] = + (mp3out==-1) ? 0 : mpg123pcm[ch][j]; + } + } + }else{ + if (mpglag == MAXMPGLAG) { + fprintf(stderr,"READ_AHEAD set too low - not enough frame buffering.\n"); + fprintf(stderr,"MP3x display of input and output PCM data out of sync.\n"); + } + else mpglag++; + pinfo->frameNum123=-1; /* no frame output */ + } + } + #endif + return iread; + } + + + void plot_frame(void) + { + int i,j,n,ch,gr; + gdouble *xcord,*ycord; + gdouble xmx,xmn,ymx,ymn; + double *data,*data2,*data3; + char title2[80]; + char label[80],label2[80]; + char *title; + plotting_data *pplot1; + plotting_data *pplot2 = NULL; + + double en,samp; + int sampindex,version=0; + static int firstcall=1; + static GdkColor *barcolor,*color,*grcolor[2]; + static GdkColor yellow,gray,cyan,magenta,orange,pink,red,green,blue,black,oncolor,offcolor; + int blocktype[2][2]; + int headbits; + int mode_gr = 2; + + /* find the frame where mpg123 produced output coming from input frame + * pinfo. i.e.: out_frame + out_frame_lag = input_frame */ + for (i=1; i<=MAXMPGLAG; i++ ) { + if ((pplot-i)->frameNum123 == pplot->frameNum ) { + pplot2 = pplot-i; + break; + } + } + if (i > MAXMPGLAG) { + fprintf(stderr,"input/output pcm syncing problem. should not happen!\n"); + pplot2=pplot-1; + } + + + /* however, the PCM data is delayed by 528 samples in the encoder filterbanks. + * We added another 1152-528 delay to this so the PCM data is *exactly* one + * frame behind the header & MDCT information */ + pplot1 =pplot2 +1; /* back one frame for header info, MDCT */ + + /* allocate these GC's only once */ + if (firstcall) { + firstcall=0; + /* grcolor[0] = &magenta; */ + grcolor[0] = &blue; + grcolor[1] = &green; + barcolor = &gray; + + setcolor(headerbox,&oncolor,255,0,0); + setcolor(headerbox,&offcolor,175,175,175); + setcolor(pcmbox,&red,255,0,0); + setcolor(pcmbox,&pink,255,0,255); + setcolor(pcmbox,&magenta,255,0,100); + setcolor(pcmbox,&orange,255,127,0); + setcolor(pcmbox,&cyan,0,255,255); + setcolor(pcmbox,&green,0,255,0); + setcolor(pcmbox,&blue,0,0,255); + setcolor(pcmbox,&black,0,0,0); + setcolor(pcmbox,&gray,100,100,100); + setcolor(pcmbox,&yellow,255,255,0); + + } + + /******************************************************************* + * frame header info + *******************************************************************/ + if (pplot1->sampfreq) + samp=pplot1->sampfreq; + else samp=1; + sampindex = SmpFrqIndex((long)samp, &version); + + ch = gtkinfo.chflag; + + headbits = 32 + ((pplot1->stereo==2) ? 256 : 136); + gtkinfo.approxbits = (pplot1->bitrate*1000*1152.0/samp) - headbits; + /*font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-100-*-*-*-*-*-*");*/ + sprintf(title2,"%3.1fkHz %ikbs ",samp/1000,pplot1->bitrate); + gtk_text_freeze (GTK_TEXT(headerbox)); + gtk_text_backward_delete(GTK_TEXT(headerbox), + gtk_text_get_length(GTK_TEXT(headerbox))); + gtk_text_set_point(GTK_TEXT(headerbox),0); + gtk_text_insert(GTK_TEXT(headerbox),NULL,&oncolor,NULL,title2, -1); + title = " mono "; + if (2==pplot1->stereo) title = pplot1->js ? " js " : " s "; + gtk_text_insert (GTK_TEXT(headerbox), NULL, &oncolor, NULL,title, -1); + color = pplot1->ms_stereo ? &oncolor : &offcolor ; + gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"ms ", -1); + color = pplot1->i_stereo ? &oncolor : &offcolor ; + gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"is ", -1); + + color = pplot1->crc ? &oncolor : &offcolor ; + gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"crc ", -1); + color = pplot1->padding ? &oncolor : &offcolor ; + gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"pad ", -1); + + color = pplot1->emph ? &oncolor : &offcolor ; + gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"em ", -1); + + sprintf(title2,"c1=%i,%i ",pplot1->big_values[0][ch],pplot1->big_values[1][ch]); + gtk_text_insert (GTK_TEXT(headerbox), NULL, &black, NULL,title2, -1); + + color = pplot1->scfsi[ch] ? &oncolor : &offcolor ; + sprintf(title2,"scfsi=%i ",pplot1->scfsi[ch]); + gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,title2, -1); + if (gtkinfo.filetype) + sprintf(title2," mdb=%i %i/NA",pplot1->maindata,pplot1->totbits); + else + sprintf(title2," mdb=%i %i/%i", + pplot1->maindata,pplot1->totbits,pplot->resvsize); + gtk_text_insert (GTK_TEXT(headerbox), NULL, &oncolor, NULL,title2, -1); + gtk_text_thaw (GTK_TEXT(headerbox)); + + + + /******************************************************************* + * block type + *******************************************************************/ + for (gr = 0 ; gr < mode_gr ; gr ++) + if (gtkinfo.flag123) + blocktype[gr][ch]=pplot1->mpg123blocktype[gr][ch]; + else blocktype[gr][ch]=pplot->blocktype[gr][ch]; + + + /******************************************************************* + * draw the PCM data * + *******************************************************************/ + n = 1600; /* PCM frame + FFT window: 224 + 1152 + 224 */ + xcord = g_malloc(n*sizeof(gdouble)); + ycord = g_malloc(n*sizeof(gdouble)); + + + if (gtkinfo.msflag) + title=ch ? "Side Channel" : "Mid Channel"; + else + title=ch ? "Right Channel" : "Left Channel"; + + sprintf(title2,"%s mask_ratio=%3.2f %3.2f ener_ratio=%3.2f %3.2f", + title, + pplot->ms_ratio[0],pplot->ms_ratio[1], + pplot->ms_ener_ratio[0],pplot->ms_ener_ratio[1]); + + + ymn = -32767 ; + ymx = 32767; + xmn = 0; + xmx = 1600-1; + + /* 0 ... 224 draw in black, connecting to 224 pixel + * 1375 .. 1599 draw in black connecting to 1375 pixel + * 224 ... 1375 MP3 frame. draw in blue + */ + + /* draw the title */ + gpk_graph_draw(pcmbox,0,xcord,ycord,xmn,ymn,xmx,ymx,1,title2, + &black); + + + /* draw some hash marks dividing the frames */ + ycord[0] = ymx*.8; ycord[1] = ymn*.8; + for (gr=0 ; gr<=2; gr++) { + xcord[0] = 223.5 + gr*576; xcord[1] = 223.5 +gr*576; + gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow); + } + for (gr = 0 ; gr < mode_gr ; gr++) { + if (blocktype[gr][ch]==2) + for (i=1 ; i<=2; i++) { + xcord[0] = 223.5+gr*576 + i*192; + xcord[1] = 223.5+gr*576 + i*192; + gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow); + } + } + /* bars representing FFT windows */ + xcord[0] = 0; ycord[0] = ymn+3000; + xcord[1] = 1024-1; ycord[1] = ymn+1000; + gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,grcolor[0]); + xcord[0] = 576; ycord[0] = ymn+2000; + xcord[1] = 576+1024-1; ycord[1] = ymn; + gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,grcolor[1]); + + + /* plot PCM data */ + for (i=0; ipcmdata[0][i]-pplot->pcmdata[1][i]) : + .5*(pplot->pcmdata[0][i]+pplot->pcmdata[1][i]); + else + ycord[i]=pplot->pcmdata[ch][i]; + } + + /* skip plot if we are doing an mp3 file */ + if (!gtkinfo.filetype) { + n = 224; /* number of points on end of blue part */ + /* data left of frame */ + gpk_graph_draw(pcmbox,n+1,xcord,ycord,xmn,ymn,xmx,ymx,0,title2,&black); + /* data right of frame */ + gpk_graph_draw(pcmbox,n+1,&xcord[1152+n-1],&ycord[1152+n-1], + xmn,ymn,xmx,ymx,0,title2,&black); + /* the actual frame */ + gpk_graph_draw(pcmbox,1152,&xcord[n],&ycord[n],xmn,ymn,xmx,ymx,0,title2,&black); + } + + + /*******************************************************************/ + /* draw the PCM re-synthesis data */ + /*******************************************************************/ + n = 1152; + /* + sprintf(title2,"Re-synthesis mask_ratio=%3.2f %3.2f ener_ratio=%3.2f %3.2f", + pplot->ms_ratio[0],pplot->ms_ratio[1], + pplot->ms_ener_ratio[0],pplot->ms_ener_ratio[1]); + */ + title="Re-synthesis"; + + + ymn = -32767 ; + ymx = 32767; + xmn = 0; + xmx = 1600-1; + gpk_graph_draw(winbox,0,xcord,ycord, + xmn,ymn,xmx,ymx,1,title,&black); + /* draw some hash marks dividing the frames */ + ycord[0] = ymx*.8; ycord[1] = ymn*.8; + for (gr=0 ; gr<=2; gr++) { + xcord[0] = 223.5 + gr*576; xcord[1] = 223.5 +gr*576; + gpk_rectangle_draw(winbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow); + } + for (gr = 0 ; gr < 2 ; gr++) { + if (blocktype[gr][ch]==2) + for (i=1 ; i<=2; i++) { + xcord[0] = 223.5+gr*576 + i*192; + xcord[1] = 223.5+gr*576 + i*192; + gpk_rectangle_draw(winbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow); + } + } + + + + n = 224; + for (j=1152-n,i=0; i<=n; i++,j++) { + xcord[i] = i; + if (gtkinfo.msflag) + ycord[i] = ch ? .5*(pplot1->pcmdata2[0][j]- + pplot1->pcmdata2[1][j]) : + .5*(pplot1->pcmdata2[0][j]+pplot1->pcmdata2[1][j]); + else + ycord[i]=pplot1->pcmdata2[ch][j]; + } + gpk_graph_draw(winbox,n+1,xcord,ycord, + xmn,ymn,xmx,ymx,0,title,&black); + + n = 1152; + for (i=0; ipcmdata2[0][i]-pplot2->pcmdata2[1][i]) : + .5*(pplot2->pcmdata2[0][i]+pplot2->pcmdata2[1][i]); + else + ycord[i]=pplot2->pcmdata2[ch][i]; + } + gpk_graph_draw(winbox,n,xcord,ycord, + xmn,ymn,xmx,ymx,0,title,&black); + + + + + + /*******************************************************************/ + /* draw the MDCT energy spectrum */ + /*******************************************************************/ + for (gr = 0 ; gr < mode_gr ; gr ++) { + int bits; + char *blockname=""; + switch (blocktype[gr][ch]) { + case 0: blockname = "normal"; break; + case 1: blockname = "start"; break; + case 2: blockname = "short"; break; + case 3: blockname = "end"; break; + } + strcpy(label,blockname); + if (pplot1->mixed[gr][ch]) strcat(label,"(mixed)"); + + + + + n = 576; + if (gtkinfo.flag123) { + data = pplot1->mpg123xr[gr][0]; + data2 = pplot1->mpg123xr[gr][1]; + }else{ + data = pplot->xr[gr][0]; + data2 = pplot->xr[gr][1]; + } + + + xmn = 0; + xmx = n-1; + ymn=0; + ymx=11; + + /* draw title, erase old plot */ + if (gtkinfo.flag123) bits=pplot1->mainbits[gr][ch]; + else bits=pplot->LAMEmainbits[gr][ch]; + sprintf(title2,"MDCT%1i(%s) bits=%i q=%i ",gr,label,bits, + pplot1->qss[gr][ch]); + gpk_bargraph_draw(mdctbox[gr],0,xcord,ycord, + xmn,ymn,xmx,ymx,1,title2,0,barcolor); + + /* draw some hash marks showing scalefactor bands */ + if (gtkinfo.sfblines) { + int fac,nsfb, *scalefac; + if (blocktype[gr][ch]==SHORT_TYPE) { + nsfb=SBMAX_s; + fac=3; + scalefac = scalefac_band.s; + }else{ + nsfb=SBMAX_l; + fac=1; + scalefac = scalefac_band.l; + } + for (i=nsfb-7 ; i ymx) ? ycord[i] : ymx; + ymn=(ycord[i] < ymn) ? ycord[i] : ymn; + } + /* print the min/max + sprintf(title2,"MDCT%1i %5.2f %5.2f bits=%i",gr,ymn,ymx, + pplot1->mainbits[gr][ch]); + */ + if (gtkinfo.flag123) bits=pplot1->mainbits[gr][ch]; + else bits=pplot->LAMEmainbits[gr][ch]; + + + sprintf(title2,"MDCT%1i(%s) bits=%i q=%i ",gr,label,bits, + pplot1->qss[gr][ch]); + + xmn = 0; + xmx = n-1; + ymn=0; + ymx=11; + gpk_bargraph_draw(mdctbox[gr],n,xcord,ycord, + xmn,ymn,xmx,ymx,0,title2,0,barcolor); + } + + + + + /******************************************************************* + * draw the psy model energy spectrum (k space) + * l3psy.c computes pe, en, thm for THIS granule. + *******************************************************************/ + if (gtkinfo.kbflag){ + for (gr = 0 ; gr < mode_gr ; gr ++) { + n = HBLKSIZE; /* only show half the spectrum */ + + data = &pplot->energy[gr][ch][0]; + + ymn=9e20; + ymx=-9e20; + for (i=0; i ymx) ? ycord[i] : ymx; + ymn=(ycord[i] < ymn) ? ycord[i] : ymn; + } + for (en=0 , j=0; jenergy[gr][ch][j]; + + sprintf(title2,"FFT%1i pe=%4.1fK en=%5.2e ",gr, + pplot->pe[gr][ch]/1000,en); + + ymn = 3; + ymx = 15; + xmn = 1; + xmx = n; + gpk_bargraph_draw(enerbox[gr],n,xcord,ycord, + xmn,ymn,xmx,ymx,1,title2,0,barcolor); + + } + }else{ + /******************************************************************* + * draw the psy model energy spectrum (scalefactor bands) + *******************************************************************/ + for (gr = 0 ; gr < mode_gr ; gr ++) { + + if (blocktype[gr][ch]==2) { + n = 3*SBMAX_s; + data = &pplot->en_s[gr][ch][0]; + data2 = &pplot->thr_s[gr][ch][0]; + data3 = &pplot->xfsf_s[gr][ch][0]; + } else { + n = SBMAX_l; + data = &pplot->en[gr][ch][0]; + data2 = &pplot->thr[gr][ch][0]; + data3 = &pplot->xfsf[gr][ch][0]; + } + ymn=9e20; + ymx=-9e20; + for (i=0; i ymx) ? ycord[i] : ymx; + ymn=(ycord[i] < ymn) ? ycord[i] : ymn; + } + + + + /* en = max energy difference amoung the 3 short FFTs for this granule */ + en = pplot->ers[gr][ch]; + sprintf(title2,"FFT%1i pe=%4.1fK/%3.1f n=%i/%3.1f/%3.1f/%3.1f",gr, + pplot->pe[gr][ch]/1000,en,pplot->over[gr][ch], + pplot->max_noise[gr][ch], + pplot->over_noise[gr][ch], + pplot->tot_noise[gr][ch]); + + + ymn = 3; + ymx = 15; + xmn = 1; + xmx = n+1; /* a little extra because of the bar thickness */ + gpk_bargraph_draw(enerbox[gr],n,xcord,ycord, + xmn,ymn,xmx,ymx,1,title2,0,barcolor); + + + for (i=0; i ymx) ? ycord[i] : ymx; + ymn=(ycord[i] < ymn) ? ycord[i] : ymn; + } + gpk_bargraph_draw(enerbox[gr],n,xcord,ycord, + xmn,ymn,xmx,ymx,0,title2,3,&red); + + + for (i=0; i ymx) ? ycord[i] : ymx; + ymn=(ycord[i] < ymn) ? ycord[i] : ymn; + } + gpk_bargraph_draw(enerbox[gr],n,xcord,ycord, + xmn,ymn,xmx,ymx,0,title2,3,grcolor[gr]); + } + } + + /******************************************************************* + * draw scalefactors + *******************************************************************/ + for (gr = 0 ; gr < mode_gr ; gr ++) { + double ggain; + if (blocktype[gr][ch]==2) { + n = 3*SBMAX_s; + if (gtkinfo.flag123) data = pplot1->sfb_s[gr][ch]; + else data = pplot->LAMEsfb_s[gr][ch]; + } else { + n = SBMAX_l; + if (gtkinfo.flag123) data = pplot1->sfb[gr][ch]; + else data = pplot->LAMEsfb[gr][ch]; + } + + ymn=-1; + ymx=10; + for (i=0; i ymx) ? ycord[i] : ymx; + ymn=(ycord[i] < ymn) ? ycord[i] : ymn; + } + + if (blocktype[gr][ch]==2) { + sprintf(label2, + "SFB scale=%i %i%i%i", + pplot1->scalefac_scale[gr][ch], + pplot1->sub_gain[gr][ch][0], + pplot1->sub_gain[gr][ch][1], + pplot1->sub_gain[gr][ch][2]); + }else{ + sprintf(label2,"SFB scale=%i",pplot1->scalefac_scale[gr][ch]); + } + + if (gtkinfo.flag123) ggain = -(pplot1->qss[gr][ch]-210)/4.0; + else ggain = -(pplot->LAMEqss[gr][ch]-210)/4.0; + + sprintf(title2," gain=%4.1f",ggain); + strcat(label2,title2); + + xmn = 1; + xmx = n+1; + gpk_bargraph_draw(sfbbox[gr],n,xcord,ycord, + xmn,ymn,xmx,ymx,1,label2,0,grcolor[gr]); + + ycord[0] = ycord[1] = 0; + xcord[0] = 1; + xcord[1] = n+1; + gpk_rectangle_draw(sfbbox[gr],xcord,ycord,xmn,ymn,xmx,ymx,&yellow); + + + } + + + } + + + + static void update_progress(void) + { + char label[80]; + int tf=gfp->totalframes; + if (gtkinfo.totalframes>0) tf=gtkinfo.totalframes; + + sprintf(label,"Frame:%4i/%4i %6.2fs", + pplot->frameNum,(int)tf-1, pplot->frametime); + gtk_progress_set_value (GTK_PROGRESS (frameprogress), (gdouble) pplot->frameNum); + gtk_label_set_text(GTK_LABEL(framecounter),label); + } + + + + static void analyze(void) + { + if ( idle_keepgoing) { + idle_count = 0; + idle_count_max=0; + idle_keepgoing=0; + idle_end=0; + } + plot_frame(); + update_progress(); + } + + static void plotclick( GtkWidget *widget, gpointer data ) + { analyze(); } + + + + + static int frameadv1(GtkWidget *widget, gpointer data ) + { + int i; + if (idle_keepgoing ){ + if (idle_back) { + /* frame displayed is the old frame. to advance, just swap in new frame */ + idle_back--; + pplot = &Pinfo[READ_AHEAD+idle_back]; + }else{ + /* advance the frame by reading in a new frame */ + pplot = &Pinfo[READ_AHEAD]; + if (mp3done) { + /* dont try to read any more frames, and quit if "finish MP3" was selected */ + /* if (idle_finish) gtk_main_quit(); */ + idle_count_max=0; + idle_end=0; + } else { + /* read in the next frame */ + for (i=NUMPINFO-1 ; i>0 ; i--) + memcpy(&Pinfo[i],&Pinfo[i-1],sizeof(plotting_data)); + pinfo = &Pinfo[0]; + pinfo->num_samples = gtkmakeframe(); + if (pinfo->num_samples==0 && gtkinfo.totalframes==0) + /* allow an extra frame to flush decoder buffers */ + gtkinfo.totalframes = pinfo->frameNum +2; + + if (pinfo->sampfreq) + pinfo->frametime = (pinfo->frameNum)*1152.0/pinfo->sampfreq; + else pinfo->frametime=0; + + /* eof? + if (!pinfo->num_samples) if (idle_finish) gtk_main_quit(); + */ + + pinfo->totbits = 0; + { int gr,ch; + for (gr = 0 ; gr < 2 ; gr ++) + for (ch = 0 ; ch < 2 ; ch ++) { + gtkinfo.totshort += (pinfo->mpg123blocktype[gr][ch]==2); + gtkinfo.totmix += !(pinfo->mixed[gr][ch]==0); + pinfo->totbits += pinfo->mainbits[gr][ch]; + } + } + if (pinfo->frameNum > 0) /* start averaging at second frame */ + gtkinfo.avebits = (gtkinfo.avebits*((pinfo->frameNum)-1) + + pinfo->totbits ) /(pinfo->frameNum); + + gtkinfo.maxbits=MAX(gtkinfo.maxbits,pinfo->totbits); + gtkinfo.totemph += !(pinfo->emph==0); + gtkinfo.totms += !(pinfo->ms_stereo==0); + gtkinfo.totis += !(pinfo->i_stereo==0); + + if (gtkinfo.totalframes>0) + if (pplot->frameNum >= gtkinfo.totalframes-1) mp3done=1; + } + } + + idle_count++; + if (gtkinfo.pupdate) plot_frame(); + update_progress(); + if ((idle_count>=idle_count_max) && (! idle_end)) analyze(); + } + return 1; + } + + + static void frameadv( GtkWidget *widget, gpointer data ) + { + int adv; + + if (!strcmp((char *) data,"-1")) { + /* ignore if we've already gone back as far as possible */ + if (pplot->frameNum==0 || (idle_back==NUMBACK)) return; + idle_back++; + pplot = &Pinfo[READ_AHEAD+idle_back]; + analyze(); + return; + } + + + adv = 1; + if (!strcmp((char *) data,"1")) adv = 1; + if (!strcmp((char *) data,"10")) adv = 10; + if (!strcmp((char *) data,"100")) adv = 100; + if (!strcmp((char *) data,"finish")) idle_end = 1; + + + if (idle_keepgoing) { + /* already running - que up additional frame advance requests */ + idle_count_max += adv; + } + else { + /* turn on idleing */ + idle_count_max = adv; + idle_count = 0; + idle_keepgoing = 1; + } + } + + + + + /* another callback */ + static void delete_event( GtkWidget *widget, + GdkEvent *event, + gpointer data ) + { + gtk_main_quit (); + } + + + + + + + + static void channel_option (GtkWidget *widget, gpointer data) + { + long option; + option = (long) data; + switch (option) { + case 1: + gtkinfo.msflag=0; + gtkinfo.chflag=0; + break; + case 2: + gtkinfo.msflag=0; + gtkinfo.chflag=1; + break; + case 3: + gtkinfo.msflag=1; + gtkinfo.chflag=0; + break; + case 4: + gtkinfo.msflag=1; + gtkinfo.chflag=1; + } + analyze(); + } + static void spec_option (GtkWidget *widget, gpointer data) + { + long option; + option = (long) data; + switch (option) { + case 1: + gtkinfo.kbflag=0; + break; + case 2: + gtkinfo.kbflag=1; + break; + case 3: + gtkinfo.flag123=0; + break; + case 4: + gtkinfo.flag123=1; + break; + case 5: + gtkinfo.pupdate=1; + break; + case 6: + gtkinfo.pupdate=0; + break; + case 7: + gtkinfo.sfblines = !gtkinfo.sfblines; + break; + } + analyze(); + } + + static gint key_press_event (GtkWidget *widget, GdkEventKey *event) + { + if (event->keyval == '1') { + subblock_draw[0] = 1; + subblock_draw[1] = 0; + subblock_draw[2] = 0; + analyze(); + } + else if (event->keyval == '2') { + subblock_draw[0] = 0; + subblock_draw[1] = 1; + subblock_draw[2] = 0; + analyze(); + } + else if (event->keyval == '3') { + subblock_draw[0] = 0; + subblock_draw[1] = 0; + subblock_draw[2] = 1; + analyze(); + } + else if (event->keyval == '0') { + subblock_draw[0] = 1; + subblock_draw[1] = 1; + subblock_draw[2] = 1; + analyze(); + } + /* analyze(); */ /* dont redraw entire window for every key! */ + return 0; + } + + + + static void text_window (GtkWidget *widget, gpointer data) + { + long option; + GtkWidget *hbox,*vbox,*button,*box; + GtkWidget *textwindow,*vscrollbar; + char text[80]; + + option = (long) data; + + textwindow = gtk_window_new(GTK_WINDOW_DIALOG); + gtk_signal_connect_object (GTK_OBJECT (window), "delete_event", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + GTK_OBJECT (textwindow)); + + gtk_container_set_border_width (GTK_CONTAINER (textwindow), 0); + vbox = gtk_vbox_new(FALSE,0); + hbox = gtk_hbox_new(FALSE,0); + + button = gtk_button_new_with_label ("close"); + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + GTK_OBJECT (textwindow)); + + box = gtk_text_new (NULL, NULL); + gtk_text_set_editable (GTK_TEXT (box), FALSE); + vscrollbar = gtk_vscrollbar_new (GTK_TEXT(box)->vadj); + + + switch (option) { + case 0: + gtk_window_set_title (GTK_WINDOW (textwindow), "Documentation"); + gtk_widget_set_usize(box,450,500); + gtk_text_set_word_wrap(GTK_TEXT(box),TRUE); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL, + "Frame header information: "\ + "First the bitrate, sampling frequency and mono, stereo or jstereo "\ + "indicators are displayed . If the bitstream is jstereo, then mid/side "\ + "stereo or intensity stereo may be on (indicated in red). If "\ + "de-emphasis is used, this is also indicated in red. The mdb value is "\ + "main_data_begin. The encoded data starts this many bytes *before* the "\ + "frame header. A large value of mdb means the bitstream has saved some "\ + "bits into the reservoir, which it may allocate for some future frame. "\ + "The two numbers after mdb are the size (in bits) used to encode the "\ + "MDCT coefficients for this frame, followed byt the size of the bit "\ + "resevoir before encoding this frame. The maximum frame size and a "\ + "running average are given in the Stats pull down menu. A large "\ + "maximum frame size indicates the bitstream has made use of the bit "\ + "reservoir. \n\n",-1); + + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL, + "PCM data (top graph): "\ + "The PCM data is plotted in black. The layer3 frame is divided into 2 "\ + "granules of 576 samples (marked with yellow vertical lines). In the "\ + "case of normal, start and stop blocks, the MDCT coefficients for each "\ + "granule are computed using a 1152 sample window centered over the "\ + "granule. In the case of short blocks, the granule is further divided "\ + "into 3 blocks of 192 samples (also marked with yellow vertical lines)."\ + "The MDCT coefficients for these blocks are computed using 384 sample "\ + "windows centered over the 192 sample window. (This info not available "\ + "when analyzing .mp3 files.) For the psycho-acoustic model, a windowed "\ + "FFT is computed for each granule. The range of these windows "\ + "is denoted by the blue and green bars.\n\n",-1); + + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL, + "PCM re-synthesis data (second graph): "\ + "Same as the PCM window described above. The data displayed is the "\ + "result of encoding and then decoding the original sample. \n\n",-1); + + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL, + "MDCT windows: "\ + "Shows the energy in the MDCT spectrum for granule 0 (left window) "\ + "and granule 1 (right window). The text also shows the blocktype "\ + "used, the number of bits used to encode the coefficients and the "\ + "number of extra bits allocated from the reservoir. The MDCT pull down "\ + "window will toggle between the original unquantized MDCT coefficients "\ + "and the compressed (quantized) coefficients.\n\n",-1); + + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL, + "FFT window: "\ + "The gray bars show the energy in the FFT spectrum used by the "\ + "psycho-acoustic model. Granule 0 is in the left window, granule 1 in "\ + "the right window. The green and blue bars show how much distortion is "\ + "allowable, as computed by the psycho-acoustic model. The red bars show "\ + "the actual distortion after encoding. There is one FFT for each "\ + "granule, computed with a 1024 Hann window centered over the "\ + "appropriate granule. (the range of this 1024 sample window is shown "\ + "by the blue and green bars in the PCM data window). The Spectrum pull "\ + "down window will toggle between showing the energy in equally spaced "\ + "frequency domain and the scale factor bands used by layer3. Finally, "\ + "the perceptual entropy, total energy and number of scalefactor bands "\ + "with audible distortion is shown. (This info not available when "\ + "analyzing .mp3 files.)",-1); + + break; + case 1: + /* Set the about box information */ + gtk_window_set_title (GTK_WINDOW (textwindow), "About"); + gtk_widget_set_usize(box,350,260); + + sprintf(text,"LAME version %s \nwww.sulaco.org/mp3\n\n",get_lame_version()); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + + sprintf(text,"psycho-acoustic model: GPSYCHO version %s\n",get_psy_version()); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + + sprintf(text,"frame analyzer: MP3x version %s\n\n",get_mp3x_version()); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL, + "decoder: mpg123/mpglib .59q \nMichael Hipp (www.mpg123.de)\n\n",-1); + + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL, + "Encoder, decoder & psy-models based on ISO\ndemonstration source. ",-1); + break; + + case 2: + gtk_window_set_title (GTK_WINDOW (textwindow), "Statistics"); + gtk_widget_set_usize(box,350,260); + sprintf(text,"frames processed so far: %i \n",Pinfo[0].frameNum+1); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"granules processed so far: %i \n\n",4*(Pinfo[0].frameNum+1)); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"mean bits/frame (approximate): %i\n", + gtkinfo.approxbits); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"mean bits/frame (from LAME): %i\n", + 4*Pinfo[0].mean_bits); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"bitsize of largest frame: %i \n",gtkinfo.maxbits); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"average bits/frame: %3.1f \n\n",gtkinfo.avebits); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"ms_stereo frames: %i \n",gtkinfo.totms); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"i_stereo frames: %i \n",gtkinfo.totis); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"de-emphasis frames: %i \n",gtkinfo.totemph); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"short block granules: %i \n",gtkinfo.totshort); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + sprintf(text,"mixed block granules: %i \n",gtkinfo.totmix); + gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1); + break; + } + + + + gtk_widget_show (vscrollbar); + gtk_widget_show (box); + gtk_widget_show (vbox); + gtk_widget_show (hbox); + gtk_widget_show (button); + + gtk_box_pack_start (GTK_BOX(hbox), box, FALSE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, TRUE, 0); + gtk_container_add (GTK_CONTAINER (textwindow), vbox); + gtk_widget_show(textwindow); + + } + + + + + /* #include */ + + + /* This is the GtkItemFactoryEntry structure used to generate new menus. + Item 1: The menu path. The letter after the underscore indicates an + accelerator key once the menu is open. + Item 2: The accelerator key for the entry + Item 3: The callback function. + Item 4: The callback action. This changes the parameters with + which the function is called. The default is 0. + Item 5: The item type, used to define what kind of an item it is. + Here are the possible values: + + NULL -> "" + "" -> "" + "" -> create a title item + "<Item>" -> create a simple item + "<CheckItem>" -> create a check item + "<ToggleItem>" -> create a toggle item + "<RadioItem>" -> create a radio item + <path> -> path of a radio item to link against + "<Separator>" -> create a separator + "<Branch>" -> create an item to hold sub items + "<LastBranch>" -> create a right justified branch + */ + + static GtkItemFactoryEntry menu_items[] = { + {"/_File", NULL, NULL, 0, "<Branch>"}, + /* + {"/File/_New", "<control>N", print_hello, 0, NULL}, + {"/File/_Open", "<control>O", print_hello, 0, NULL}, + {"/File/_Save", "<control>S", print_hello, 0, NULL}, + {"/File/Save _As", NULL, NULL, 0, NULL}, + {"/File/sep1", NULL, NULL, 0, "<Separator>"}, + {"/File/Quit", "<control>Q", gtk_main_quit, 0, NULL}, + */ + {"/File/_Quit", "<control>Q", delete_event, 0, NULL}, + + {"/_Plotting", NULL, NULL, 0, "<Branch>"}, + {"/Plotting/_While advancing" , NULL, spec_option, 5, NULL}, + {"/Plotting/_After advancing", NULL, spec_option, 6, NULL}, + + {"/_Channel", NULL, NULL, 0, "<Branch>"}, + {"/Channel/show _Left" , NULL, channel_option, 1, NULL}, + {"/Channel/show _Right", NULL, channel_option, 2, NULL}, + {"/Channel/show _Mid" , NULL, channel_option, 3, NULL}, + {"/Channel/show _Side", NULL, channel_option, 4, NULL}, + + {"/_Spectrum", NULL, NULL, 0, "<Branch>"}, + {"/Spectrum/_Scalefactor bands", NULL, spec_option, 1, NULL}, + {"/Spectrum/_Wave number", NULL, spec_option, 2, NULL}, + + {"/_MDCT", NULL, NULL, 0, "<Branch>"}, + {"/MDCT/_Original", NULL, spec_option, 3, NULL}, + {"/MDCT/_Compressed", NULL, spec_option, 4, NULL}, + {"/MDCT/_Toggle SFB lines", NULL, spec_option, 7, NULL}, + + {"/_Stats", NULL, NULL, 0, "<Branch>"}, + {"/Stats/_Show", NULL, text_window, 2, NULL}, + + {"/_Help", NULL, NULL, 0, "<LastBranch>"}, + {"/_Help/_Documentation", NULL, text_window, 0, NULL}, + {"/_Help/_About", NULL, text_window, 1, NULL}, + }; + + + static void get_main_menu(GtkWidget *window, GtkWidget ** menubar) { + int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]); + GtkItemFactory *item_factory; + GtkAccelGroup *accel_group; + + accel_group = gtk_accel_group_new(); + + /* This function initializes the item factory. + Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU, + or GTK_TYPE_OPTION_MENU. + Param 2: The path of the menu. + Param 3: A pointer to a gtk_accel_group. The item factory sets up + the accelerator table while generating menus. + */ + + item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", + accel_group); + + /* This function generates the menu items. Pass the item factory, + the number of items in the array, the array itself, and any + callback data for the the menu items. */ + gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL); + + /* Attach the new accelerator group to the window. */ + gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); + + if (menubar) + /* Finally, return the actual menu bar created by the item factory. */ + *menubar = gtk_item_factory_get_widget(item_factory, "<main>"); + } + + + + + int gtkcontrol(lame_global_flags *gfp2) + { + /* GtkWidget is the storage type for widgets */ + GtkWidget *button; + GtkAdjustment *adj; + GtkWidget *mbox; /* main box */ + GtkWidget *box1; /* frame control buttons go */ + GtkWidget *box2; /* frame counters */ + GtkWidget *box3; /* frame header info */ + GtkWidget *table; /* table for all the plotting areas */ + GtkWidget *menubar; + + gint tableops,graphx,graphy; + char frameinfo[80]; + + graphx = 500; /* minimum allowed size of pixmap */ + graphy = 95; + + gfp=gfp2; + + /* set some global defaults/variables */ + gtkinfo.filetype = (gfp->input_format == sf_mp3); + gtkinfo.msflag=0; + gtkinfo.chflag=0; + gtkinfo.kbflag=0; + gtkinfo.flag123 = (gfp->input_format == sf_mp3); /* MP3 file=use mpg123 output */ + gtkinfo.pupdate=0; + gtkinfo.avebits = 0; + gtkinfo.maxbits = 0; + gtkinfo.approxbits = 0; + gtkinfo.totemph = 0; + gtkinfo.totms = 0; + gtkinfo.totis = 0; + gtkinfo.totshort = 0; + gtkinfo.totmix = 0; + gtkinfo.sfblines= 1; + gtkinfo.totalframes = 0; + + memset((char *) Pinfo, 0, sizeof(Pinfo)); + pplot = &Pinfo[READ_AHEAD]; + + strcpy(frameinfo,"MP3x: "); + strncat(frameinfo,gfp->inPath,70); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), frameinfo); + gtk_signal_connect (GTK_OBJECT (window), "delete_event", + GTK_SIGNAL_FUNC (delete_event), NULL); + + gtk_signal_connect_object (GTK_OBJECT (window), "key_press_event", + GTK_SIGNAL_FUNC(key_press_event), + GTK_OBJECT (window)); + + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + + mbox = gtk_vbox_new(FALSE, 0); + + + /* layout of mbox */ + box1 = gtk_hbox_new(FALSE, 0); + box2 = gtk_hbox_new(FALSE, 0); + box3 = gtk_hbox_new(FALSE, 0); + table = gtk_table_new (5, 2, FALSE); + tableops = GTK_FILL | GTK_EXPAND | GTK_SHRINK; + get_main_menu(window, &menubar); + + gtk_box_pack_start(GTK_BOX(mbox), menubar, FALSE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (mbox), box1, FALSE, TRUE, 0); + gtk_box_pack_end(GTK_BOX (mbox),box2, FALSE, TRUE, 0); + gtk_box_pack_start(GTK_BOX (mbox),box3, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (mbox), table, TRUE, TRUE, 0); + gtk_container_add (GTK_CONTAINER (window), mbox); + + + /*********************************************************************/ + /* stuff in box3 frame header info */ + /*********************************************************************/ + /* + headerbox = gtk_label_new(" "); + gtk_label_set_justify(GTK_LABEL(headerbox),GTK_JUSTIFY_LEFT); + */ + headerbox = gtk_text_new (NULL, NULL); + gtk_text_set_editable (GTK_TEXT (headerbox), FALSE); + gtk_widget_set_usize(headerbox,200,20); + gtk_widget_show (headerbox); + gtk_box_pack_start(GTK_BOX (box3),headerbox, TRUE, TRUE, 0); + + + + /*********************************************************************/ + /* stuff in box2 frame counters */ + /*********************************************************************/ + framecounter = gtk_label_new(""); + gtk_widget_show(framecounter); + gtk_box_pack_start(GTK_BOX (box2),framecounter, FALSE, TRUE, 0); + + adj = (GtkAdjustment *) gtk_adjustment_new (0, 0,(gint) gfp->totalframes-1, 0, 0, 0); + frameprogress = gtk_progress_bar_new_with_adjustment (adj); + /* Set the format of the string that can be displayed in the + * trough of the progress bar: + * %p - percentage + * %v - value + * %l - lower range value + * %u - upper range value */ + gtk_progress_set_format_string (GTK_PROGRESS (frameprogress), + "%p%%"); + gtk_progress_set_value (GTK_PROGRESS (frameprogress), (gdouble) 0); + gtk_progress_set_show_text (GTK_PROGRESS (frameprogress),TRUE); + gtk_widget_show (frameprogress); + gtk_box_pack_end (GTK_BOX (box2), frameprogress, FALSE, TRUE, 0); + + + + /*********************************************************************/ + /* stuff in box1 buttons along bottom */ + /*********************************************************************/ + button = gtk_button_new_with_label ("-1"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (frameadv), (gpointer) "-1"); + gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + button = gtk_button_new_with_label ("+1"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (frameadv), (gpointer) "1"); + gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + button = gtk_button_new_with_label ("+10"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (frameadv), (gpointer) "10"); + gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + button = gtk_button_new_with_label ("+100"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (frameadv), (gpointer) "100"); + gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + button = gtk_button_new_with_label ("last frame"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (frameadv), (gpointer) "finish"); + gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + button = gtk_button_new_with_label ("stop/plot"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (plotclick), NULL); + gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0); + gtk_widget_show(button); + + + /*********************************************************************/ + /* stuff in table. all the plotting windows */ + /*********************************************************************/ + pcmbox = gpk_plot_new(graphx,graphy); + gtk_table_attach (GTK_TABLE(table),pcmbox,0,2,0,1,tableops,tableops,2,2 ); + gtk_widget_show (pcmbox); + + winbox = gpk_plot_new(graphy,graphy); + gtk_table_attach(GTK_TABLE(table),winbox,0,2,1,2,tableops,tableops,2,2); + gtk_widget_show (winbox); + + + mdctbox[0] = gpk_plot_new(graphy,graphy); + gtk_table_attach(GTK_TABLE(table),mdctbox[0],0,1,2,3,tableops,tableops,2,2); + gtk_widget_show (mdctbox[0]); + + mdctbox[1] = gpk_plot_new(graphy,graphy); + gtk_table_attach (GTK_TABLE(table),mdctbox[1],1,2,2,3,tableops,tableops,2,2); + gtk_widget_show (mdctbox[1]); + + enerbox[0] = gpk_plot_new(graphy,graphy); + gtk_table_attach(GTK_TABLE(table),enerbox[0],0,1,3,4,tableops,tableops,2,2); + gtk_widget_show (enerbox[0]); + + enerbox[1] = gpk_plot_new(graphy,graphy); + gtk_table_attach (GTK_TABLE(table),enerbox[1],1,2,3,4,tableops,tableops,2,2); + gtk_widget_show (enerbox[1]); + + sfbbox[0] = gpk_plot_new(graphy,graphy); + gtk_table_attach(GTK_TABLE(table),sfbbox[0],0,1,4,5,tableops,tableops,2,2); + gtk_widget_show (sfbbox[0]); + + sfbbox[1] = gpk_plot_new(graphy,graphy); + gtk_table_attach (GTK_TABLE(table),sfbbox[1],1,2,4,5,tableops,tableops,2,2); + gtk_widget_show (sfbbox[1]); + + + + + gtk_idle_add((GtkFunction) frameadv1, NULL); + gtk_widget_show(menubar); + gtk_widget_show(box2); + gtk_widget_show(box3); + gtk_widget_show(table); + gtk_widget_show(box1); + gtk_widget_show (mbox); + gtk_widget_show (window); /* show smallest allowed window */ + + /* make window bigger. */ + /* now the user will be able to shrink it, if desired */ + /* gtk_widget_set_usize(mbox,500,500); */ + /* gtk_widget_show (window); */ /* show smallest allowed window */ + + + + idle_keepgoing=1; /* processing of frames is ON */ + idle_count_max=READ_AHEAD+1; /* number of frames to process before plotting */ + idle_count=0; /* pause & plot when idle_count=idle_count_max */ + + + gtk_main (); + if (!mp3done) exit(2); + return(0); + } + + #endif + + + + + + + + + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gtkanal.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gtkanal.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/gtkanal.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,68 ---- + #ifndef GTKANAL_DOT_H + #define GTKANAL_DOT_H + #include "lame.h" + #include "encoder.h" + + #define READ_AHEAD 10 /* number of frames to read ahead */ + #define MAXMPGLAG READ_AHEAD /* if the mpg123 lag becomes bigger than this we have to stop */ + #define NUMBACK 6 /* number of frames we can back up */ + #define NUMPINFO (NUMBACK+READ_AHEAD+1) + + + + typedef struct { + int frameNum; /* current frame number */ + int frameNum123; + int num_samples; /* number of pcm samples read for this frame */ + double frametime; /* starting time of frame, in seconds */ + double pcmdata[2][1600]; + double pcmdata2[2][1152+1152-DECDELAY]; + double xr[2][2][576]; + double mpg123xr[2][2][576]; + double ms_ratio[2]; + double ms_ener_ratio[2]; + + /* L,R, M and S values */ + double energy[2][4][BLKSIZE]; + double pe[2][4]; + double thr[2][4][SBMAX_l]; + double en[2][4][SBMAX_l]; + double thr_s[2][4][3*SBMAX_s]; + double en_s[2][4][3*SBMAX_s]; + double ers[2][4]; + + double sfb[2][2][SBMAX_l]; + double sfb_s[2][2][3*SBMAX_s]; + double LAMEsfb[2][2][SBMAX_l]; + double LAMEsfb_s[2][2][3*SBMAX_s]; + + int LAMEqss[2][2]; + int qss[2][2]; + int big_values[2][2]; + int sub_gain[2][2][3]; + + double xfsf[2][2][SBMAX_l]; + double xfsf_s[2][2][3*SBMAX_s]; + + int over[2][2]; + double tot_noise[2][2]; + double max_noise[2][2]; + double over_noise[2][2]; + int blocktype[2][2]; + int scalefac_scale[2][2]; + int mpg123blocktype[2][2]; + int mixed[2][2]; + int mainbits[2][2]; + int LAMEmainbits[2][2]; + int framesize,stereo,js,ms_stereo,i_stereo,emph,bitrate,sampfreq,maindata; + int crc,padding; + int scfsi[2],mean_bits,resvsize; + int totbits; + } plotting_data; + + + int gtkcontrol(lame_global_flags *gfp); + extern plotting_data *pinfo; + extern int gtkflag; + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/huffman.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/huffman.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/huffman.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,332 ---- + /* + * huffman tables ... recalcualted to work with my optimzed + * decoder scheme (MH) + * + * probably we could save a few bytes of memory, because the + * smaller tables are often the part of a bigger table + */ + + struct newhuff + { + unsigned int linbits; + short *table; + }; + + static short tab0[] = + { + 0 + }; + + static short tab1[] = + { + -5, -3, -1, 17, 1, 16, 0 + }; + + static short tab2[] = + { + -15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1, + 16, 0 + }; + + static short tab3[] = + { + -13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1, + 1, 0 + }; + + static short tab5[] = + { + -29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19, + 3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16, + 0 + }; + + static short tab6[] = + { + -25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19, + 49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16, + 0 + }; + + static short tab7[] = + { + -69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83, + -1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1, + 80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7, + -3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18, + -5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0 + }; + + static short tab8[] = + { + -65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83, + -3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52, + 67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4, + 64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1, + 2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0 + }; + + static short tab9[] = + { + -63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1, + 84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67, + -1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5, + -3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2, + 18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0 + }; + + static short tab10[] = + { + -125,-121,-111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118, + 87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3, + -1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1, + 100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23, + -17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81, + -1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7, + -3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1, + 50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1, + 2, 32, 17, -1, 1, 16, 0 + }; + + static short tab11[] = + { + -121,-113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117, + -3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55, + -1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114, + -1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96, + -1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38, + 6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1, + 36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50, + -1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2, + 32, 17, -3, -1, 1, 16, 0 + }; + + static short tab12[] = + { + -115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87, + 117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115, + 85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7, + 112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5, + -1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37, + 82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4, + 36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3, + -1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1, + 2, 32, 0, 17, -1, 1, 16 + }; + + static short tab13[] = + { + -509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13, -9, + -7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238, + 207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1, + 236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249, + 234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158, + -5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1, + 203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245, + 231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1, + 63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15, + -5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1, + 200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1, + 240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1, + 46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3, + -1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1, + 198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5, + -1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167, + 151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76, + 196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137, + 28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106, + -5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43, + -1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178, + -11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1, + 58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161, + -3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88, + -1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1, + 131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25, + 145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100, + 40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113, + -1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38, + -1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6, + 96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81, + -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11, + -5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3, + -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16, + 0 + }; + + static short tab15[] = + { + -495,-445,-355,-263,-183,-115, -77, -43, -27, -13, -7, -3, -1, 255, 239, + -1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237, + 191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3, + -1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219, + -3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173, + -3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246, + -3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9, + -3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243, + 216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1, + 31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1, + 125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3, + -1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5, + -1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124, + 199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1, + 198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183, + -5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76, + -1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1, + 122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15, + -7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106, + -5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5, + -1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74, + -1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1, + 42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134, + 73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29, + -13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7, + -3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7, + -3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86, + -3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100, + 23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69, + -1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9, + -5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1, + 5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20, + 4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48, + 34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16, + 0 + }; + + static short tab16[] = + { + -509,-503,-461,-323,-103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223, + 253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3, + -1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5, + -3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19, + -13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1, + 238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5, + -1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125, + 94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13, + -5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3, + -1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186, + -1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1, + 214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169, + -5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213, + -3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154, + 108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1, + 153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1, + 192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45, + -1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107, + -1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12, + -1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1, + 178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74, + 164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33, + -19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3, + -1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147, + -1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1, + 145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3, + -1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1, + 8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3, + -1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1, + 99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9, + -5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33, + -23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, + -5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1, + 3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16, + 0 + }; + + static short tab24[] = + { + -451,-117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1, + 207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9, + -5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79, + 244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31, + 240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1, + 236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3, + -1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3, + -1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255,-235, + -143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3, + -1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9, + -5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1, + 78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185, + 170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199, + 77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3, + -1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3, + -1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196, + -3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1, + 167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1, + 137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10, + 26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9, + 144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165, + 27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135, + -1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104, + -1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3, + -1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3, + -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7, + -3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86, + 101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15, + -7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84, + -7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1, + 83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5, + 80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5, + -1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1, + 3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16, + 0 + }; + + static short tab_c0[] = + { + -29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5, + 9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8, + 0 + }; + + static short tab_c1[] = + { + -15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9, + 8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1, + 0 + }; + + + + static struct newhuff ht[] = + { + { /* 0 */ 0 , tab0 } , + { /* 2 */ 0 , tab1 } , + { /* 3 */ 0 , tab2 } , + { /* 3 */ 0 , tab3 } , + { /* 0 */ 0 , tab0 } , + { /* 4 */ 0 , tab5 } , + { /* 4 */ 0 , tab6 } , + { /* 6 */ 0 , tab7 } , + { /* 6 */ 0 , tab8 } , + { /* 6 */ 0 , tab9 } , + { /* 8 */ 0 , tab10 } , + { /* 8 */ 0 , tab11 } , + { /* 8 */ 0 , tab12 } , + { /* 16 */ 0 , tab13 } , + { /* 0 */ 0 , tab0 } , + { /* 16 */ 0 , tab15 } , + + { /* 16 */ 1 , tab16 } , + { /* 16 */ 2 , tab16 } , + { /* 16 */ 3 , tab16 } , + { /* 16 */ 4 , tab16 } , + { /* 16 */ 6 , tab16 } , + { /* 16 */ 8 , tab16 } , + { /* 16 */ 10, tab16 } , + { /* 16 */ 13, tab16 } , + { /* 16 */ 4 , tab24 } , + { /* 16 */ 5 , tab24 } , + { /* 16 */ 6 , tab24 } , + { /* 16 */ 7 , tab24 } , + { /* 16 */ 8 , tab24 } , + { /* 16 */ 9 , tab24 } , + { /* 16 */ 11, tab24 } , + { /* 16 */ 13, tab24 } + }; + + static struct newhuff htc[] = + { + { /* 1 , 1 , */ 0 , tab_c0 } , + { /* 1 , 1 , */ 0 , tab_c1 } + }; + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,112 ---- + /* + * functions for writing ID3 tags in LAME + * + * text functions stolen from mp3info by Ricardo Cerqueira <rmc at rccn.net> + * adapted for LAME by Conrad Sanderson <c.sanderson at me.gu.edu.au> + * + * + */ + + #include <stdio.h> + #include <string.h> + #include "id3tag.h" + ID3TAGDATA id3tag; + + /* + * If "string" is shorter than "length", pad it with ' ' (spaces) + */ + + static void id3_pad(char *string, int length) { + int l; l=strlen(string); + + while(l<length) { string[l] = ' '; l++; } + string[l]='\0'; + } + + + /* + * initialize temporary fields + */ + + void id3_inittag(ID3TAGDATA *tag) { + strcpy( tag->title, ""); + strcpy( tag->artist, ""); + strcpy( tag->album, ""); + strcpy( tag->year, ""); + strcpy( tag->comment, ""); + strcpy( tag->genre, "?"); /* unset genre */ + tag->track = 0; + + tag->valid = 0; /* not ready for writing*/ + } + + /* + * build an ID3 tag from temporary fields + */ + + void id3_buildtag(ID3TAGDATA *tag) { + strcpy(tag->tagtext,"TAG"); + + id3_pad( tag->title, 30); strncat( tag->tagtext, tag->title,30); + id3_pad( tag->artist, 30); strncat( tag->tagtext, tag->artist,30); + id3_pad( tag->album, 30); strncat( tag->tagtext, tag->album,30); + id3_pad( tag->year, 4); strncat( tag->tagtext, tag->year,4); + id3_pad( tag->comment, 30); strncat( tag->tagtext, tag->comment,30); + id3_pad( tag->genre, 1); strncat( tag->tagtext, tag->genre,1); + + if( tag->track != 0 ) { + tag->tagtext[125] = '\0'; + tag->tagtext[126] = tag->track; + } + tag->valid = 1; /* ready for writing*/ + } + + /* + * write ID3 tag + */ + + int id3_writetag(char* filename, ID3TAGDATA *tag) { + FILE* f; + if( ! tag->valid ) return -1; + + f=fopen(filename,"rb+"); if(!f) return -1; + + fseek(f,0,SEEK_END); fwrite(tag->tagtext,1,128,f); + fclose(f); return 0; + } + + + + + + int genre_last=147; + char *genre_list[]={ + "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", + "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", + "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", + "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", + "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", + "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", + "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", + "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", + "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", + "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta", + "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret", + "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", + "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", + "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", "Swing", + "Fast-Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", + "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", + "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", + "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", + "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", + "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", + "Punk Rock", "Drum Solo", "A capella", "Euro-House", "Dance Hall", + "Goa", "Drum & Bass", "Club House", "Hardcore", "Terror", + "Indie", "BritPop", "NegerPunk", "Polsk Punk", "Beat", + "Christian Gangsta", "Heavy Metal", "Black Metal", "Crossover", "Contemporary C", + "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop", + "SynthPop", + }; + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,29 ---- + #ifndef ID3TAG_H_INCLUDED + #define ID3TAG_H_INCLUDED + typedef struct + { + int used; + int valid; + char title[31]; + char artist[31]; + char album[31]; + char year[5]; + char comment[31]; + char tagtext[128]; + char genre[1]; + unsigned char track; + + } ID3TAGDATA; + + void id3_inittag(ID3TAGDATA *tag); + void id3_buildtag(ID3TAGDATA *tag); + int id3_writetag(char* filename, ID3TAGDATA *tag); + + + /* + * Array of all possible music genre. Grabbed from id3ed + */ + extern ID3TAGDATA id3tag; /* id3tag info */ + extern int genre_last; + extern char *genre_list[]; + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/ieeefloat.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/ieeefloat.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/ieeefloat.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,962 ---- + /* Copyright (C) 1988-1991 Apple Computer, Inc. + * All Rights Reserved. + * + * Warranty Information + * Even though Apple has reviewed this software, Apple makes no warranty + * or representation, either express or implied, with respect to this + * software, its quality, accuracy, merchantability, or fitness for a + * particular purpose. As a result, this software is provided "as is," + * and you, its user, are assuming the entire risk as to its quality + * and accuracy. + * + * This code may be used and freely distributed as long as it includes + * this copyright notice and the warranty information. + * + * Machine-independent I/O routines for IEEE floating-point numbers. + * + * NaN's and infinities are converted to HUGE_VAL or HUGE, which + * happens to be infinity on IEEE machines. Unfortunately, it is + * impossible to preserve NaN's in a machine-independent way. + * Infinities are, however, preserved on IEEE machines. + * + * These routines have been tested on the following machines: + * Apple Macintosh, MPW 3.1 C compiler + * Apple Macintosh, THINK C compiler + * Silicon Graphics IRIS, MIPS compiler + * Cray X/MP and Y/MP + * Digital Equipment VAX + * Sequent Balance (Multiprocesor 386) + * NeXT + * + * + * Implemented by Malcolm Slaney and Ken Turkowski. + * + * Malcolm Slaney contributions during 1988-1990 include big- and little- + * endian file I/O, conversion to and from Motorola's extended 80-bit + * floating-point format, and conversions to and from IEEE single- + * precision floating-point format. + * + * In 1991, Ken Turkowski implemented the conversions to and from + * IEEE double-precision format, added more precision to the extended + * conversions, and accommodated conversions involving +/- infinity, + * NaN's, and denormalized numbers. + * + * $Id: ieeefloat.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: ieeefloat.c,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:54:36 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.3 2000/02/21 23:05:05 markt + * some 64bit DEC Alpha patches + * + * Revision 1.2 2000/02/19 13:32:30 afaber + * Fixed many warning messages when compiling with MSVC + * + * Revision 1.1.1.1 1999/11/24 08:42:58 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 1.1 1993/06/11 17:45:46 malcolm + * Initial revision + * + */ + + #include <limits.h> + #include <stdio.h> + #include <math.h> + #include "ieeefloat.h" + + + /**************************************************************** + * The following two routines make up for deficiencies in many + * compilers to convert properly between unsigned integers and + * floating-point. Some compilers which have this bug are the + * THINK_C compiler for the Macintosh and the C compiler for the + * Silicon Graphics MIPS-based Iris. + ****************************************************************/ + + #ifdef applec /* The Apple C compiler works */ + # define FloatToUnsigned(f) ((unsigned long)(f)) + # define UnsignedToFloat(u) ((defdouble)(u)) + #else /* applec */ + # define FloatToUnsigned(f) ((unsigned long)(((long)((f) - 2147483648.0)) + 2147483647L + 1)) + # define UnsignedToFloat(u) (((defdouble)((long)((u) - 2147483647L - 1))) + 2147483648.0) + #endif /* applec */ + + + /**************************************************************** + * Single precision IEEE floating-point conversion routines + ****************************************************************/ + + #define SEXP_MAX 255 + #define SEXP_OFFSET 127 + #define SEXP_SIZE 8 + #define SEXP_POSITION (32-SEXP_SIZE-1) + + + defdouble + ConvertFromIeeeSingle(char* bytes) + { + defdouble f; + long mantissa, expon; + long bits; + + bits = ((unsigned long)(bytes[0] & 0xFF) << 24) + | ((unsigned long)(bytes[1] & 0xFF) << 16) + | ((unsigned long)(bytes[2] & 0xFF) << 8) + | (unsigned long)(bytes[3] & 0xFF); /* Assemble bytes into a long */ + + if ((bits & 0x7FFFFFFF) == 0) { + f = 0; + } + + else { + expon = (bits & 0x7F800000) >> SEXP_POSITION; + if (expon == SEXP_MAX) { /* Infinity or NaN */ + f = HUGE_VAL; /* Map NaN's to infinity */ + } + else { + if (expon == 0) { /* Denormalized number */ + mantissa = (bits & 0x7fffff); + f = ldexp((defdouble) mantissa, (int) (expon - SEXP_OFFSET - SEXP_POSITION + 1)); + } + else { /* Normalized number */ + mantissa = (bits & 0x7fffff) + 0x800000; /* Insert hidden bit */ + f = ldexp((defdouble) mantissa, (int) (expon - SEXP_OFFSET - SEXP_POSITION)); + } + } + } + + if (bits & LONG_MIN) + return -f; + else + return f; + } + + + /****************************************************************/ + + + void + ConvertToIeeeSingle(defdouble num, char* bytes) + { + long sign; + register long bits; + + if (num < 0) { /* Can't distinguish a negative zero */ + sign = LONG_MIN; + num *= -1; + } else { + sign = 0; + } + + if (num == 0) { + bits = 0; + } + + else { + defdouble fMant; + int expon; + + fMant = frexp(num, &expon); + + if ((expon > (SEXP_MAX-SEXP_OFFSET+1)) || !(fMant < 1)) { + /* NaN's and infinities fail second test */ + bits = sign | 0x7F800000; /* +/- infinity */ + } + + else { + long mantissa; + + if (expon < -(SEXP_OFFSET-2)) { /* Smaller than normalized */ + int shift = (SEXP_POSITION+1) + (SEXP_OFFSET-2) + expon; + if (shift < 0) { /* Way too small: flush to zero */ + bits = sign; + } + else { /* Nonzero denormalized number */ + mantissa = (long)(fMant * (1L << shift)); + bits = sign | mantissa; + } + } + + else { /* Normalized number */ + mantissa = (long)floor(fMant * (1L << (SEXP_POSITION+1))); + mantissa -= (1L << SEXP_POSITION); /* Hide MSB */ + bits = sign | ((long)((expon + SEXP_OFFSET - 1)) << SEXP_POSITION) | mantissa; + } + } + } + + bytes[0] = (char)(bits >> 24); /* Copy to byte string */ + bytes[1] = (char)(bits >> 16); + bytes[2] = (char)(bits >> 8); + bytes[3] = (char)(bits); + } + + + /**************************************************************** + * Double precision IEEE floating-point conversion routines + ****************************************************************/ + + #define DEXP_MAX 2047 + #define DEXP_OFFSET 1023 + #define DEXP_SIZE 11 + #define DEXP_POSITION (32-DEXP_SIZE-1) + + + defdouble + ConvertFromIeeeDouble(char* bytes) + { + defdouble f; + long mantissa, expon; + unsigned long first, second; + + first = ((unsigned long)(bytes[0] & 0xFF) << 24) + | ((unsigned long)(bytes[1] & 0xFF) << 16) + | ((unsigned long)(bytes[2] & 0xFF) << 8) + | (unsigned long)(bytes[3] & 0xFF); + second= ((unsigned long)(bytes[4] & 0xFF) << 24) + | ((unsigned long)(bytes[5] & 0xFF) << 16) + | ((unsigned long)(bytes[6] & 0xFF) << 8) + | (unsigned long)(bytes[7] & 0xFF); + + if (first == 0 && second == 0) { + f = 0; + } + + else { + expon = (first & 0x7FF00000) >> DEXP_POSITION; + if (expon == DEXP_MAX) { /* Infinity or NaN */ + f = HUGE_VAL; /* Map NaN's to infinity */ + } + else { + if (expon == 0) { /* Denormalized number */ + mantissa = (first & 0x000FFFFF); + f = ldexp((defdouble) mantissa, (int) (expon - DEXP_OFFSET - DEXP_POSITION + 1)); + f += ldexp(UnsignedToFloat(second), (int) (expon - DEXP_OFFSET - DEXP_POSITION + 1 - 32)); + } + else { /* Normalized number */ + mantissa = (first & 0x000FFFFF) + 0x00100000; /* Insert hidden bit */ + f = ldexp((defdouble) mantissa, (int) (expon - DEXP_OFFSET - DEXP_POSITION)); + f += ldexp(UnsignedToFloat(second), (int) (expon - DEXP_OFFSET - DEXP_POSITION - 32)); + } + } + } + + if (first & 0x80000000) + return -f; + else + return f; + } + + + /****************************************************************/ + + + void + ConvertToIeeeDouble(defdouble num, char *bytes) + { + long sign; + long first, second; + + if (num < 0) { /* Can't distinguish a negative zero */ + sign = LONG_MIN; + num *= -1; + } else { + sign = 0; + } + + if (num == 0) { + first = 0; + second = 0; + } + + else { + defdouble fMant, fsMant; + int expon; + + fMant = frexp(num, &expon); + + if ((expon > (DEXP_MAX-DEXP_OFFSET+1)) || !(fMant < 1)) { + /* NaN's and infinities fail second test */ + first = sign | 0x7FF00000; /* +/- infinity */ + second = 0; + } + + else { + long mantissa; + + if (expon < -(DEXP_OFFSET-2)) { /* Smaller than normalized */ + int shift = (DEXP_POSITION+1) + (DEXP_OFFSET-2) + expon; + if (shift < 0) { /* Too small for something in the MS word */ + first = sign; + shift += 32; + if (shift < 0) { /* Way too small: flush to zero */ + second = 0; + } + else { /* Pretty small demorn */ + second = FloatToUnsigned(floor(ldexp(fMant, shift))); + } + } + else { /* Nonzero denormalized number */ + fsMant = ldexp(fMant, shift); + mantissa = (long)floor(fsMant); + first = sign | mantissa; + second = FloatToUnsigned(floor(ldexp(fsMant - mantissa, 32))); + } + } + + else { /* Normalized number */ + fsMant = ldexp(fMant, DEXP_POSITION+1); + mantissa = (long)floor(fsMant); + mantissa -= (1L << DEXP_POSITION); /* Hide MSB */ + fsMant -= (1L << DEXP_POSITION); + first = sign | ((long)((expon + DEXP_OFFSET - 1)) << DEXP_POSITION) | mantissa; + second = FloatToUnsigned(floor(ldexp(fsMant - mantissa, 32))); + } + } + } + + bytes[0] = (char)(first >> 24); + bytes[1] = (char)(first >> 16); + bytes[2] = (char)(first >> 8); + bytes[3] = (char)(first); + bytes[4] = (char)(second >> 24); + bytes[5] = (char)(second >> 16); + bytes[6] = (char)(second >> 8); + bytes[7] = (char)(second); + } + + + /**************************************************************** + * Extended precision IEEE floating-point conversion routines + ****************************************************************/ + + defdouble + ConvertFromIeeeExtended(char* bytes) + { + defdouble f; + long expon; + unsigned long hiMant, loMant; + + #ifdef TEST + printf("ConvertFromIEEEExtended(%lx,%lx,%lx,%lx,%lx,%lx,%lx,%lx,%lx,%lx\r", + (long)bytes[0], (long)bytes[1], (long)bytes[2], (long)bytes[3], + (long)bytes[4], (long)bytes[5], (long)bytes[6], + (long)bytes[7], (long)bytes[8], (long)bytes[9]); + #endif + + expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); + hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24) + | ((unsigned long)(bytes[3] & 0xFF) << 16) + | ((unsigned long)(bytes[4] & 0xFF) << 8) + | ((unsigned long)(bytes[5] & 0xFF)); + loMant = ((unsigned long)(bytes[6] & 0xFF) << 24) + | ((unsigned long)(bytes[7] & 0xFF) << 16) + | ((unsigned long)(bytes[8] & 0xFF) << 8) + | ((unsigned long)(bytes[9] & 0xFF)); + + if (expon == 0 && hiMant == 0 && loMant == 0) { + f = 0; + } + else { + if (expon == 0x7FFF) { /* Infinity or NaN */ + f = HUGE_VAL; + } + else { + expon -= 16383; + f = ldexp(UnsignedToFloat(hiMant), (int) (expon -= 31)); + f += ldexp(UnsignedToFloat(loMant), (int) (expon -= 32)); + } + } + + if (bytes[0] & 0x80) + return -f; + else + return f; + } + + + /****************************************************************/ + + + void + ConvertToIeeeExtended(defdouble num, char *bytes) + { + int sign; + int expon; + defdouble fMant, fsMant; + unsigned long hiMant, loMant; + + if (num < 0) { + sign = 0x8000; + num *= -1; + } else { + sign = 0; + } + + if (num == 0) { + expon = 0; hiMant = 0; loMant = 0; + } + else { + fMant = frexp(num, &expon); + if ((expon > 16384) || !(fMant < 1)) { /* Infinity or NaN */ + expon = sign|0x7FFF; hiMant = 0; loMant = 0; /* infinity */ + } + else { /* Finite */ + expon += 16382; + if (expon < 0) { /* denormalized */ + fMant = ldexp(fMant, expon); + expon = 0; + } + expon |= sign; + fMant = ldexp(fMant, 32); fsMant = floor(fMant); hiMant = FloatToUnsigned(fsMant); + fMant = ldexp(fMant - fsMant, 32); fsMant = floor(fMant); loMant = FloatToUnsigned(fsMant); + } + } + + bytes[0] = expon >> 8; + bytes[1] = expon; + bytes[2] = (char)(hiMant >> 24); + bytes[3] = (char)(hiMant >> 16); + bytes[4] = (char)(hiMant >> 8); + bytes[5] = (char)(hiMant); + bytes[6] = (char)(loMant >> 24); + bytes[7] = (char)(loMant >> 16); + bytes[8] = (char)(loMant >> 8); + bytes[9] = (char)(loMant); + } + + /**************************************************************** + * Testing routines for the floating-point conversions. + ****************************************************************/ + + #ifdef METROWERKS + #define IEEE + #endif + #ifdef applec + # define IEEE + #endif /* applec */ + #ifdef THINK_C + # define IEEE + #endif /* THINK_C */ + #ifdef sgi + # define IEEE + #endif /* sgi */ + #ifdef sequent + # define IEEE + # define LITTLE_ENDIAN + #endif /* sequent */ + #ifdef sun + # define IEEE + #endif /* sun */ + #ifdef NeXT + # define IEEE + #endif /* NeXT */ + + #ifdef MAIN + + union SParts { + Single s; + long i; + }; + union DParts { + Double d; + long i[2]; + }; + union EParts { + defdouble e; + short i[6]; + }; + + + int + GetHexValue(register int x) + { + x &= 0x7F; + + if ('0' <= x && x <= '9') + x -= '0'; + else if ('a' <= x && x <= 'f') + x = x - 'a' + 0xA; + else if ('A' <= x && x <= 'F') + x = x - 'A' + 0xA; + else + x = 0; + + return(x); + } + + + void + Hex2Bytes(register char *hex, register char *bytes) + { + for ( ; *hex; hex += 2) { + *bytes++ = (GetHexValue(hex[0]) << 4) | GetHexValue(hex[1]); + if (hex[1] == 0) + break; /* Guard against odd bytes */ + } + } + + + int + GetHexSymbol(register int x) + { + x &= 0xF; + if (x <= 9) + x += '0'; + else + x += 'A' - 0xA; + return(x); + } + + + void + Bytes2Hex(register char *bytes, register char *hex, register int nBytes) + { + for ( ; nBytes--; bytes++) { + *hex++ = GetHexSymbol(*bytes >> 4); + *hex++ = GetHexSymbol(*bytes); + } + *hex = 0; + } + + + void + MaybeSwapBytes(char* bytes, int nBytes) + { + #ifdef LITTLE_ENDIAN + register char *p, *q, t; + for (p = bytes, q = bytes+nBytes-1; p < q; p++, q--) { + t = *p; + *p = *q; + *q = t; + } + #else + if (bytes, nBytes); /* Just so it's used */ + #endif /* LITTLE_ENDIAN */ + + } + + + float + MachineIEEESingle(char* bytes) + { + float t; + MaybeSwapBytes(bytes, 4); + t = *((float*)(bytes)); + MaybeSwapBytes(bytes, 4); + return (t); + } + + + Double + MachineIEEEDouble(char* bytes) + { + Double t; + MaybeSwapBytes(bytes, 8); + t = *((Double*)(bytes)); + MaybeSwapBytes(bytes, 8); + return (t); + } + + + void + TestFromIeeeSingle(char *hex) + { + defdouble f; + union SParts p; + char bytes[4]; + + Hex2Bytes(hex, bytes); + f = ConvertFromIeeeSingle(bytes); + p.s = f; + + #ifdef IEEE + fprintf(stderr, "IEEE(%g) [%s] --> float(%g) [%08lX]\n", + MachineIEEESingle(bytes), + hex, f, p.i); + #else /* IEEE */ + fprintf(stderr, "IEEE[%s] --> float(%g) [%08lX]\n", hex, f, p.i); + #endif /* IEEE */ + } + + + void + TestToIeeeSingle(defdouble f) + { + union SParts p; + char bytes[4]; + char hex[8+1]; + + p.s = f; + + ConvertToIeeeSingle(f, bytes); + Bytes2Hex(bytes, hex, 4); + #ifdef IEEE + fprintf(stderr, "float(%g) [%08lX] --> IEEE(%g) [%s]\n", + f, p.i, + MachineIEEESingle(bytes), + hex + ); + #else /* IEEE */ + fprintf(stderr, "float(%g) [%08lX] --> IEEE[%s]\n", f, p.i, hex); + #endif /* IEEE */ + } + + + void + TestFromIeeeDouble(char *hex) + { + defdouble f; + union DParts p; + char bytes[8]; + + Hex2Bytes(hex, bytes); + f = ConvertFromIeeeDouble(bytes); + p.d = f; + + #ifdef IEEE + fprintf(stderr, "IEEE(%g) [%.8s %.8s] --> double(%g) [%08lX %08lX]\n", + MachineIEEEDouble(bytes), + hex, hex+8, f, p.i[0], p.i[1]); + #else /* IEEE */ + fprintf(stderr, "IEEE[%.8s %.8s] --> double(%g) [%08lX %08lX]\n", + hex, hex+8, f, p.i[0], p.i[1]); + #endif /* IEEE */ + + } + + void + TestToIeeeDouble(defdouble f) + { + union DParts p; + char bytes[8]; + char hex[16+1]; + + p.d = f; + + ConvertToIeeeDouble(f, bytes); + Bytes2Hex(bytes, hex, 8); + #ifdef IEEE + fprintf(stderr, "double(%g) [%08lX %08lX] --> IEEE(%g) [%.8s %.8s]\n", + f, p.i[0], p.i[1], + MachineIEEEDouble(bytes), + hex, hex+8 + ); + #else /* IEEE */ + fprintf(stderr, "double(%g) [%08lX %08lX] --> IEEE[%.8s %.8s]\n", + f, p.i[0], p.i[1], hex, hex+8 + ); + #endif /* IEEE */ + + } + + + void + TestFromIeeeExtended(char *hex) + { + defdouble f; + union EParts p; + char bytes[12]; + + Hex2Bytes(hex, bytes); + f = ConvertFromIeeeExtended(bytes); + p.e = f; + + bytes[11] = bytes[9]; + bytes[10] = bytes[8]; + bytes[9] = bytes[7]; + bytes[8] = bytes[6]; + bytes[7] = bytes[5]; + bytes[6] = bytes[4]; + bytes[5] = bytes[3]; + bytes[4] = bytes[2]; + bytes[3] = 0; + bytes[2] = 0; + + #if defined(applec) || defined(THINK_C) || defined(METROWERKS) + fprintf(stderr, "IEEE(%g) [%.4s %.8s %.8s] --> extended(%g) [%04X %04X%04X %04X%04X]\n", + *((defdouble*)(bytes)), + hex, hex+4, hex+12, f, + p.i[0]&0xFFFF, p.i[2]&0xFFFF, p.i[3]&0xFFFF, p.i[4]&0xFFFF, p.i[5]&0xFFFF + ); + #else /* !Macintosh */ + fprintf(stderr, "IEEE[%.4s %.8s %.8s] --> extended(%g) [%04X %04X%04X %04X%04X]\n", + hex, hex+4, hex+12, f, + p.i[0]&0xFFFF, p.i[2]&0xFFFF, p.i[3]&0xFFFF, p.i[4]&0xFFFF, p.i[5]&0xFFFF + ); + #endif /* Macintosh */ + } + + + void + TestToIeeeExtended(defdouble f) + { + char bytes[12]; + char hex[24+1]; + + ConvertToIeeeExtended(f, bytes); + Bytes2Hex(bytes, hex, 10); + + bytes[11] = bytes[9]; + bytes[10] = bytes[8]; + bytes[9] = bytes[7]; + bytes[8] = bytes[6]; + bytes[7] = bytes[5]; + bytes[6] = bytes[4]; + bytes[5] = bytes[3]; + bytes[4] = bytes[2]; + bytes[3] = 0; + bytes[2] = 0; + + #if defined(applec) || defined(THINK_C) || defined(METROWERKS) + fprintf(stderr, "extended(%g) --> IEEE(%g) [%.4s %.8s %.8s]\n", + f, *((defdouble*)(bytes)), + hex, hex+4, hex+12 + ); + #else /* !Macintosh */ + fprintf(stderr, "extended(%g) --> IEEE[%.4s %.8s %.8s]\n", + f, + hex, hex+4, hex+12 + ); + #endif /* Macintosh */ + } + + #include <signal.h> + + void SignalFPE(int i, void (*j)()) + { + printf("[Floating Point Interrupt Caught.]\n", i, j); + signal(SIGFPE, SignalFPE); + } + + void + main(void) + { + long d[3]; + char bytes[12]; + + signal(SIGFPE, SignalFPE); + + TestFromIeeeSingle("00000000"); + TestFromIeeeSingle("80000000"); + TestFromIeeeSingle("3F800000"); + TestFromIeeeSingle("BF800000"); + TestFromIeeeSingle("40000000"); + TestFromIeeeSingle("C0000000"); + TestFromIeeeSingle("7F800000"); + TestFromIeeeSingle("FF800000"); + TestFromIeeeSingle("00800000"); + TestFromIeeeSingle("00400000"); + TestFromIeeeSingle("00000001"); + TestFromIeeeSingle("80000001"); + TestFromIeeeSingle("3F8FEDCB"); + TestFromIeeeSingle("7FC00100"); /* Quiet NaN(1) */ + TestFromIeeeSingle("7F800100"); /* Signalling NaN(1) */ + + TestToIeeeSingle(0.0); + TestToIeeeSingle(-0.0); + TestToIeeeSingle(1.0); + TestToIeeeSingle(-1.0); + TestToIeeeSingle(2.0); + TestToIeeeSingle(-2.0); + TestToIeeeSingle(3.0); + TestToIeeeSingle(-3.0); + #if !(defined(sgi) || defined(NeXT)) + TestToIeeeSingle(HUGE_VAL); + TestToIeeeSingle(-HUGE_VAL); + #endif + + #ifdef IEEE + /* These only work on big-endian IEEE machines */ + d[0] = 0x00800000L; MaybeSwapBytes(d,4); TestToIeeeSingle(*((float*)(&d[0]))); /* Smallest normalized */ + d[0] = 0x00400000L; MaybeSwapBytes(d,4); TestToIeeeSingle(*((float*)(&d[0]))); /* Almost largest denormalized */ + d[0] = 0x00000001L; MaybeSwapBytes(d,4); TestToIeeeSingle(*((float*)(&d[0]))); /* Smallest denormalized */ + d[0] = 0x00000001L; MaybeSwapBytes(d,4); TestToIeeeSingle(*((float*)(&d[0])) * 0.5); /* Smaller than smallest denorm */ + d[0] = 0x3F8FEDCBL; MaybeSwapBytes(d,4); TestToIeeeSingle(*((float*)(&d[0]))); + #if !(defined(sgi) || defined(NeXT)) + d[0] = 0x7FC00100L; MaybeSwapBytes(d,4); TestToIeeeSingle(*((float*)(&d[0]))); /* Quiet NaN(1) */ + d[0] = 0x7F800100L; MaybeSwapBytes(d,4); TestToIeeeSingle(*((float*)(&d[0]))); /* Signalling NaN(1) */ + #endif /* sgi */ + #endif /* IEEE */ + + + + TestFromIeeeDouble("0000000000000000"); + TestFromIeeeDouble("8000000000000000"); + TestFromIeeeDouble("3FF0000000000000"); + TestFromIeeeDouble("BFF0000000000000"); + TestFromIeeeDouble("4000000000000000"); + TestFromIeeeDouble("C000000000000000"); + TestFromIeeeDouble("7FF0000000000000"); + TestFromIeeeDouble("FFF0000000000000"); + TestFromIeeeDouble("0010000000000000"); + TestFromIeeeDouble("0008000000000000"); + TestFromIeeeDouble("0000000000000001"); + TestFromIeeeDouble("8000000000000001"); + TestFromIeeeDouble("3FFFEDCBA9876543"); + TestFromIeeeDouble("7FF8002000000000"); /* Quiet NaN(1) */ + TestFromIeeeDouble("7FF0002000000000"); /* Signalling NaN(1) */ + + TestToIeeeDouble(0.0); + TestToIeeeDouble(-0.0); + TestToIeeeDouble(1.0); + TestToIeeeDouble(-1.0); + TestToIeeeDouble(2.0); + TestToIeeeDouble(-2.0); + TestToIeeeDouble(3.0); + TestToIeeeDouble(-3.0); + #if !(defined(sgi) || defined(NeXT)) + TestToIeeeDouble(HUGE_VAL); + TestToIeeeDouble(-HUGE_VAL); + #endif + + #ifdef IEEE + /* These only work on big-endian IEEE machines */ + Hex2Bytes("0010000000000000", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* Smallest normalized */ + Hex2Bytes("0010000080000000", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* Normalized, problem with unsigned */ + Hex2Bytes("0008000000000000", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* Almost largest denormalized */ + Hex2Bytes("0000000080000000", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* Denorm problem with unsigned */ + Hex2Bytes("0000000000000001", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* Smallest denormalized */ + Hex2Bytes("0000000000000001", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes)) * 0.5); /* Smaller than smallest denorm */ + Hex2Bytes("3FFFEDCBA9876543", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* accuracy test */ + #if !(defined(sgi) || defined(NeXT)) + Hex2Bytes("7FF8002000000000", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* Quiet NaN(1) */ + Hex2Bytes("7FF0002000000000", bytes); MaybeSwapBytes(d,8); TestToIeeeDouble(*((Double*)(bytes))); /* Signalling NaN(1) */ + #endif /* sgi */ + #endif /* IEEE */ + + TestFromIeeeExtended("00000000000000000000"); /* +0 */ + TestFromIeeeExtended("80000000000000000000"); /* -0 */ + TestFromIeeeExtended("3FFF8000000000000000"); /* +1 */ + TestFromIeeeExtended("BFFF8000000000000000"); /* -1 */ + TestFromIeeeExtended("40008000000000000000"); /* +2 */ + TestFromIeeeExtended("C0008000000000000000"); /* -2 */ + TestFromIeeeExtended("7FFF0000000000000000"); /* +infinity */ + TestFromIeeeExtended("FFFF0000000000000000"); /* -infinity */ + TestFromIeeeExtended("7FFF8001000000000000"); /* Quiet NaN(1) */ + TestFromIeeeExtended("7FFF0001000000000000"); /* Signalling NaN(1) */ + TestFromIeeeExtended("3FFFFEDCBA9876543210"); /* accuracy test */ + + TestToIeeeExtended(0.0); + TestToIeeeExtended(-0.0); + TestToIeeeExtended(1.0); + TestToIeeeExtended(-1.0); + TestToIeeeExtended(2.0); + TestToIeeeExtended(-2.0); + #if !(defined(sgi) || defined(NeXT)) + TestToIeeeExtended(HUGE_VAL); + TestToIeeeExtended(-HUGE_VAL); + #endif /* sgi */ + + #if defined(applec) || defined(THINK_C) || defined(METROWERKS) + Hex2Bytes("7FFF00008001000000000000", bytes); TestToIeeeExtended(*((long double*)(bytes))); /* Quiet NaN(1) */ + Hex2Bytes("7FFF00000001000000000000", bytes); TestToIeeeExtended(*((long double*)(bytes))); /* Signalling NaN(1) */ + Hex2Bytes("7FFE00008000000000000000", bytes); TestToIeeeExtended(*((long double*)(bytes))); + Hex2Bytes("000000008000000000000000", bytes); TestToIeeeExtended(*((long double*)(bytes))); + Hex2Bytes("000000000000000000000001", bytes); TestToIeeeExtended(*((long double*)(bytes))); + Hex2Bytes("3FFF0000FEDCBA9876543210", bytes); TestToIeeeExtended(*((long double*)(bytes))); + #endif + } + + + /* This is the output of the test program on an IEEE machine: + IEEE(0) [00000000] --> float(0) [00000000] + IEEE(-0) [80000000] --> float(-0) [80000000] + IEEE(1) [3F800000] --> float(1) [3F800000] + IEEE(-1) [BF800000] --> float(-1) [BF800000] + IEEE(2) [40000000] --> float(2) [40000000] + IEEE(-2) [C0000000] --> float(-2) [C0000000] + IEEE(INF) [7F800000] --> float(INF) [7F800000] + IEEE(-INF) [FF800000] --> float(-INF) [FF800000] + IEEE(1.17549e-38) [00800000] --> float(1.17549e-38) [00800000] + IEEE(5.87747e-39) [00400000] --> float(5.87747e-39) [00400000] + IEEE(1.4013e-45) [00000001] --> float(1.4013e-45) [00000001] + IEEE(-1.4013e-45) [80000001] --> float(-1.4013e-45) [80000001] + IEEE(1.12444) [3F8FEDCB] --> float(1.12444) [3F8FEDCB] + IEEE(NAN(001)) [7FC00100] --> float(INF) [7F800000] + IEEE(NAN(001)) [7F800100] --> float(INF) [7F800000] + float(0) [00000000] --> IEEE(0) [00000000] + float(-0) [80000000] --> IEEE(0) [00000000] + float(1) [3F800000] --> IEEE(1) [3F800000] + float(-1) [BF800000] --> IEEE(-1) [BF800000] + float(2) [40000000] --> IEEE(2) [40000000] + float(-2) [C0000000] --> IEEE(-2) [C0000000] + float(3) [40400000] --> IEEE(3) [40400000] + float(-3) [C0400000] --> IEEE(-3) [C0400000] + float(INF) [7F800000] --> IEEE(INF) [7F800000] + float(-INF) [FF800000] --> IEEE(-INF) [FF800000] + float(1.17549e-38) [00800000] --> IEEE(1.17549e-38) [00800000] + float(5.87747e-39) [00400000] --> IEEE(5.87747e-39) [00400000] + float(1.4013e-45) [00000001] --> IEEE(1.4013e-45) [00000001] + float(7.00649e-46) [00000000] --> IEEE(0) [00000000] + float(1.12444) [3F8FEDCB] --> IEEE(1.12444) [3F8FEDCB] + float(NAN(001)) [7FC00100] --> IEEE(INF) [7F800000] + float(NAN(001)) [7FC00100] --> IEEE(INF) [7F800000] + IEEE(0) [00000000 00000000] --> double(0) [00000000 00000000] + IEEE(-0) [80000000 00000000] --> double(-0) [80000000 00000000] + IEEE(1) [3FF00000 00000000] --> double(1) [3FF00000 00000000] + IEEE(-1) [BFF00000 00000000] --> double(-1) [BFF00000 00000000] + IEEE(2) [40000000 00000000] --> double(2) [40000000 00000000] + IEEE(-2) [C0000000 00000000] --> double(-2) [C0000000 00000000] + IEEE(INF) [7FF00000 00000000] --> double(INF) [7FF00000 00000000] + IEEE(-INF) [FFF00000 00000000] --> double(-INF) [FFF00000 00000000] + IEEE(2.22507e-308) [00100000 00000000] --> double(2.22507e-308) [00100000 00000000] + IEEE(1.11254e-308) [00080000 00000000] --> double(1.11254e-308) [00080000 00000000] + IEEE(4.94066e-324) [00000000 00000001] --> double(4.94066e-324) [00000000 00000001] + IEEE(-4.94066e-324) [80000000 00000001] --> double(-4.94066e-324) [80000000 00000001] + IEEE(1.99556) [3FFFEDCB A9876543] --> double(1.99556) [3FFFEDCB A9876543] + IEEE(NAN(001)) [7FF80020 00000000] --> double(INF) [7FF00000 00000000] + IEEE(NAN(001)) [7FF00020 00000000] --> double(INF) [7FF00000 00000000] + double(0) [00000000 00000000] --> IEEE(0) [00000000 00000000] + double(-0) [80000000 00000000] --> IEEE(0) [00000000 00000000] + double(1) [3FF00000 00000000] --> IEEE(1) [3FF00000 00000000] + double(-1) [BFF00000 00000000] --> IEEE(-1) [BFF00000 00000000] + double(2) [40000000 00000000] --> IEEE(2) [40000000 00000000] + double(-2) [C0000000 00000000] --> IEEE(-2) [C0000000 00000000] + double(3) [40080000 00000000] --> IEEE(3) [40080000 00000000] + double(-3) [C0080000 00000000] --> IEEE(-3) [C0080000 00000000] + double(INF) [7FF00000 00000000] --> IEEE(INF) [7FF00000 00000000] + double(-INF) [FFF00000 00000000] --> IEEE(-INF) [FFF00000 00000000] + double(2.22507e-308) [00100000 00000000] --> IEEE(2.22507e-308) [00100000 00000000] + double(2.22507e-308) [00100000 80000000] --> IEEE(2.22507e-308) [00100000 80000000] + double(1.11254e-308) [00080000 00000000] --> IEEE(1.11254e-308) [00080000 00000000] + double(1.061e-314) [00000000 80000000] --> IEEE(1.061e-314) [00000000 80000000] + double(4.94066e-324) [00000000 00000001] --> IEEE(4.94066e-324) [00000000 00000001] + double(4.94066e-324) [00000000 00000001] --> IEEE(4.94066e-324) [00000000 00000001] + double(1.99556) [3FFFEDCB A9876543] --> IEEE(1.99556) [3FFFEDCB A9876543] + double(NAN(001)) [7FF80020 00000000] --> IEEE(INF) [7FF00000 00000000] + double(NAN(001)) [7FF80020 00000000] --> IEEE(INF) [7FF00000 00000000] + IEEE(0) [0000 00000000 00000000] --> extended(0) [0000 00000000 00000000] + IEEE(-0) [8000 00000000 00000000] --> extended(-0) [8000 00000000 00000000] + IEEE(1) [3FFF 80000000 00000000] --> extended(1) [3FFF 80000000 00000000] + IEEE(-1) [BFFF 80000000 00000000] --> extended(-1) [BFFF 80000000 00000000] + IEEE(2) [4000 80000000 00000000] --> extended(2) [4000 80000000 00000000] + IEEE(-2) [C000 80000000 00000000] --> extended(-2) [C000 80000000 00000000] + IEEE(INF) [7FFF 00000000 00000000] --> extended(INF) [7FFF 00000000 00000000] + IEEE(-INF) [FFFF 00000000 00000000] --> extended(-INF) [FFFF 00000000 00000000] + IEEE(NAN(001)) [7FFF 80010000 00000000] --> extended(INF) [7FFF 00000000 00000000] + IEEE(NAN(001)) [7FFF 00010000 00000000] --> extended(INF) [7FFF 00000000 00000000] + IEEE(1.99111) [3FFF FEDCBA98 76543210] --> extended(1.99111) [3FFF FEDCBA98 76543210] + extended(0) --> IEEE(0) [0000 00000000 00000000] + extended(-0) --> IEEE(0) [0000 00000000 00000000] + extended(1) --> IEEE(1) [3FFF 80000000 00000000] + extended(-1) --> IEEE(-1) [BFFF 80000000 00000000] + extended(2) --> IEEE(2) [4000 80000000 00000000] + extended(-2) --> IEEE(-2) [C000 80000000 00000000] + extended(INF) --> IEEE(INF) [7FFF 00000000 00000000] + extended(-INF) --> IEEE(-INF) [FFFF 00000000 00000000] + extended(NAN(001)) --> IEEE(INF) [7FFF 00000000 00000000] + extended(NAN(001)) --> IEEE(INF) [7FFF 00000000 00000000] + extended(5.94866e+4931) --> IEEE(5.94866e+4931) [7FFE 80000000 00000000] + extended(1e-4927) --> IEEE(1e-4927) [0000 80000000 00000000] + extended(1e-4927) --> IEEE(1e-4927) [0000 00000000 00000001] + extended(1.99111) --> IEEE(1.99111) [3FFF FEDCBA98 76543210] + */ + + #endif /* TEST_FP */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/ieeefloat.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/ieeefloat.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/ieeefloat.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,90 ---- + #ifndef IEEE_FLOAT_H__ + #define IEEE_FLOAT_H__ + /* Copyright (C) 1988-1991 Apple Computer, Inc. + * All Rights Reserved. + * + * Warranty Information + * Even though Apple has reviewed this software, Apple makes no warranty + * or representation, either express or implied, with respect to this + * software, its quality, accuracy, merchantability, or fitness for a + * particular purpose. As a result, this software is provided "as is," + * and you, its user, are assuming the entire risk as to its quality + * and accuracy. + * + * This code may be used and freely distributed as long as it includes + * this copyright notice and the warranty information. + * + * Machine-independent I/O routines for IEEE floating-point numbers. + * + * NaN's and infinities are converted to HUGE_VAL or HUGE, which + * happens to be infinity on IEEE machines. Unfortunately, it is + * impossible to preserve NaN's in a machine-independent way. + * Infinities are, however, preserved on IEEE machines. + * + * These routines have been tested on the following machines: + * Apple Macintosh, MPW 3.1 C compiler + * Apple Macintosh, THINK C compiler + * Silicon Graphics IRIS, MIPS compiler + * Cray X/MP and Y/MP + * Digital Equipment VAX + * Sequent Balance (Multiprocesor 386) + * NeXT + * + * + * Implemented by Malcolm Slaney and Ken Turkowski. + * + * Malcolm Slaney contributions during 1988-1990 include big- and little- + * endian file I/O, conversion to and from Motorola's extended 80-bit + * floating-point format, and conversions to and from IEEE single- + * precision floating-point format. + * + * In 1991, Ken Turkowski implemented the conversions to and from + * IEEE double-precision format, added more precision to the extended + * conversions, and accommodated conversions involving +/- infinity, + * NaN's, and denormalized numbers. + * + * $Id: ieeefloat.h,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: ieeefloat.h,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:54:36 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.1.1.1 1999/11/24 08:42:58 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 1.1 1993/06/11 17:45:46 malcolm + * Initial revision + * + */ + + #include <math.h> + + typedef float Single; + + #ifndef applec + typedef double defdouble; + #else /* !applec */ + typedef long double defdouble; + #endif /* applec */ + + #ifndef THINK_C + typedef double Double; + #else /* THINK_C */ + typedef short double Double; + #endif /* THINK_C */ + + #define kFloatLength 4 + #define kDoubleLength 8 + #define kExtendedLength 10 + + extern defdouble ConvertFromIeeeSingle(char *bytes); + extern void ConvertToIeeeSingle(defdouble num, char *bytes); + extern defdouble ConvertFromIeeeDouble(char *bytes); + extern void ConvertToIeeeDouble(defdouble num, char *bytes); + extern defdouble ConvertFromIeeeExtended(char *bytes); + extern void ConvertToIeeeExtended(defdouble num, char *bytes); + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/interface.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/interface.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/interface.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,220 ---- + #ifdef HAVEMPGLIB + #include <stdlib.h> + #include <stdio.h> + + #include "mpg123.h" + #include "mpglib.h" + + + /* Global mp .. it's a hack */ + struct mpstr *gmp; + + + BOOL InitMP3(struct mpstr *mp) + { + memset(mp,0,sizeof(struct mpstr)); + + mp->framesize = 0; + mp->fsizeold = -1; + mp->bsize = 0; + mp->head = mp->tail = NULL; + mp->fr.single = -1; + mp->bsnum = 0; + mp->synth_bo = 1; + + make_decode_tables(32767); + init_layer3(SBLIMIT); + + return !0; + } + + void ExitMP3(struct mpstr *mp) + { + struct buf *b,*bn; + + b = mp->tail; + while(b) { + free(b->pnt); + bn = b->next; + free(b); + b = bn; + } + } + + static struct buf *addbuf(struct mpstr *mp,char *buf,int size) + { + struct buf *nbuf; + + nbuf = (struct buf*) malloc( sizeof(struct buf) ); + if(!nbuf) { + fprintf(stderr,"Out of memory!\n"); + return NULL; + } + nbuf->pnt = (unsigned char*) malloc(size); + if(!nbuf->pnt) { + free(nbuf); + return NULL; + } + nbuf->size = size; + memcpy(nbuf->pnt,buf,size); + nbuf->next = NULL; + nbuf->prev = mp->head; + nbuf->pos = 0; + + if(!mp->tail) { + mp->tail = nbuf; + } + else { + mp->head->next = nbuf; + } + + mp->head = nbuf; + mp->bsize += size; + + return nbuf; + } + + static void remove_buf(struct mpstr *mp) + { + struct buf *buf = mp->tail; + + mp->tail = buf->next; + if(mp->tail) + mp->tail->prev = NULL; + else { + mp->tail = mp->head = NULL; + } + + free(buf->pnt); + free(buf); + + } + + static int read_buf_byte(struct mpstr *mp) + { + unsigned int b; + + int pos; + + pos = mp->tail->pos; + while(pos >= mp->tail->size) { + remove_buf(mp); + pos = mp->tail->pos; + if(!mp->tail) { + fprintf(stderr,"Fatal error!\n"); + exit(1); + } + } + + b = mp->tail->pnt[pos]; + mp->bsize--; + mp->tail->pos++; + + + return b; + } + + static void read_head(struct mpstr *mp) + { + unsigned long head; + + head = read_buf_byte(mp); + head <<= 8; + head |= read_buf_byte(mp); + head <<= 8; + head |= read_buf_byte(mp); + head <<= 8; + head |= read_buf_byte(mp); + + mp->header = head; + } + + int decodeMP3(struct mpstr *mp,char *in,int isize,char *out, + int osize,int *done) + { + int len; + + gmp = mp; + + if(osize < 4608) { + fprintf(stderr,"To less out space\n"); + return MP3_ERR; + } + + if(in) { + if(addbuf(mp,in,isize) == NULL) { + return MP3_ERR; + } + } + + + /* First decode header */ + if(mp->framesize == 0) { + if(mp->bsize < 4) { + return MP3_NEED_MORE; + } + read_head(mp); + decode_header(&mp->fr,mp->header); + mp->framesize = mp->fr.framesize; + } + + /* printf(" fr.framesize = %i \n",mp->fr.framesize); + printf(" bsize = %i \n",mp->bsize); + */ + + if(mp->fr.framesize > mp->bsize) { + return MP3_NEED_MORE; + } + wordpointer = mp->bsspace[mp->bsnum] + 512; + mp->bsnum = (mp->bsnum + 1) & 0x1; + bitindex = 0; + + len = 0; + while(len < mp->framesize) { + int nlen; + int blen = mp->tail->size - mp->tail->pos; + if( (mp->framesize - len) <= blen) { + nlen = mp->framesize-len; + } + else { + nlen = blen; + } + memcpy(wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen); + len += nlen; + mp->tail->pos += nlen; + mp->bsize -= nlen; + if(mp->tail->pos == mp->tail->size) { + remove_buf(mp); + } + } + + *done = 0; + if(mp->fr.error_protection) + getbits(16); + do_layer3(&mp->fr,(unsigned char *) out,done); + + mp->fsizeold = mp->framesize; + mp->framesize = 0; + return MP3_OK; + } + + int set_pointer(long backstep) + { + unsigned char *bsbufold; + if(gmp->fsizeold < 0 && backstep > 0) { + fprintf(stderr,"Can't step back %ld!\n",backstep); + return MP3_ERR; + } + bsbufold = gmp->bsspace[gmp->bsnum] + 512; + wordpointer -= backstep; + if (backstep) + memcpy(wordpointer,bsbufold+gmp->fsizeold-backstep,backstep); + bitindex = 0; + return MP3_OK; + } + + + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream-pvt.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream-pvt.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream-pvt.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,48 ---- + /********************************************************************** + * ISO MPEG Audio Subgroup Software Simulation Group (1996) + * ISO 13818-3 MPEG-2 Audio Encoder - Lower Sampling Frequency Extension + * + * $Id: l3bitstream-pvt.h,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: l3bitstream-pvt.h,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:54:36 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.4 2000/03/21 23:02:17 markt + * replaced all "gf." by gfp-> + * + * Revision 1.3 2000/02/01 11:26:32 takehiro + * scalefactor's structure changed + * + * Revision 1.2 1999/12/09 00:44:34 cisc + * Removed write_ancillary_data() prototype. (No longer used) + * + * Revision 1.1.1.1 1999/11/24 08:42:59 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 1.1 1996/02/14 04:04:23 rowlands + * Initial revision + * + * Received from Mike Coleman + **********************************************************************/ + + #ifndef L3BITSTREAM_PVT_H + #define L3BITSTREAM_PVT_H + + static int encodeSideInfo( lame_global_flags *gfp,III_side_info_t *si ); + + static void encodeMainData( lame_global_flags *gfp, + int l3_enc[2][2][576], + III_side_info_t *si, + III_scalefac_t scalefac[2][2] ); + + static void drain_into_ancillary_data( int lengthInBits ); + + static void Huffmancodebits( BF_PartHolder **pph, int *ix, gr_info *gi ); + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,854 ---- + /********************************************************************** + * ISO MPEG Audio Subgroup Software Simulation Group (1996) + * ISO 13818-3 MPEG-2 Audio Encoder - Lower Sampling Frequency Extension + * + **********************************************************************/ + /* + Revision History: + + Date Programmer Comment + ========== ========================= =============================== + 1995/08/06 mc at fivebats.com created + 1995/09/06 mc at fivebats.com modified to use formatBitstream + */ + + #include <stdlib.h> + #include "lame.h" + #include "l3bitstream.h" /* the public interface */ + #include "encoder.h" + #include "quantize.h" + #include "quantize-pvt.h" + #include "formatBitstream.h" + #include "tables.h" + #include <assert.h> + #include "l3bitstream-pvt.h" + + static Bit_stream_struc *bs = NULL; + + BF_FrameData *frameData = NULL; + BF_FrameResults *frameResults = NULL; + + int PartHoldersInitialized = 0; + + BF_PartHolder *headerPH; + BF_PartHolder *frameSIPH; + BF_PartHolder *channelSIPH[ MAX_CHANNELS ]; + BF_PartHolder *spectrumSIPH[ MAX_GRANULES ][ MAX_CHANNELS ]; + BF_PartHolder *scaleFactorsPH[ MAX_GRANULES ][ MAX_CHANNELS ]; + BF_PartHolder *codedDataPH[ MAX_GRANULES ][ MAX_CHANNELS ]; + BF_PartHolder *userSpectrumPH[ MAX_GRANULES ][ MAX_CHANNELS ]; + BF_PartHolder *userFrameDataPH; + + + void putMyBits( u_int val, u_int len ) + { + putbits( bs, val, len ); + } + + /* + III_format_bitstream() + + This is called after a frame of audio has been quantized and coded. + It will write the encoded audio to the bitstream. Note that + from a layer3 encoder's perspective the bit stream is primarily + a series of main_data() blocks, with header and side information + inserted at the proper locations to maintain framing. (See Figure A.7 + in the IS). + */ + + void + III_format_bitstream( lame_global_flags *gfp, + int bitsPerFrame, + int l3_enc[2][2][576], + III_side_info_t *l3_side, + III_scalefac_t scalefac[2][2], + Bit_stream_struc *in_bs) + { + int gr, ch; + bs = in_bs; + + if ( frameData == NULL ) + { + frameData = calloc( 1,sizeof *frameData); + assert( frameData ); + } + if ( frameResults == NULL ) + { + frameResults = calloc( 1,sizeof *frameResults); + assert( frameResults ); + } + + if ( !PartHoldersInitialized ) + { + headerPH = BF_newPartHolder( 14 ); + frameSIPH = BF_newPartHolder( 12 ); + + for ( ch = 0; ch < MAX_CHANNELS; ch++ ) + channelSIPH[ch] = BF_newPartHolder( 8 ); + + for ( gr = 0; gr < MAX_GRANULES; gr++ ) + for ( ch = 0; ch < MAX_CHANNELS; ch++ ) + { + spectrumSIPH[gr][ch] = BF_newPartHolder( 32 ); + scaleFactorsPH[gr][ch] = BF_newPartHolder( 64 ); + codedDataPH[gr][ch] = BF_newPartHolder( 576 ); + userSpectrumPH[gr][ch] = BF_newPartHolder( 4 ); + } + userFrameDataPH = BF_newPartHolder( 8 ); + PartHoldersInitialized = 1; + } + + encodeSideInfo( gfp,l3_side ); + encodeMainData( gfp,l3_enc, l3_side, scalefac ); + + + + drain_into_ancillary_data( l3_side->resvDrain ); + /* + Put frameData together for the call + to BitstreamFrame() + */ + frameData->frameLength = bitsPerFrame; + frameData->nGranules = gfp->mode_gr; + frameData->nChannels = gfp->stereo; + frameData->header = headerPH->part; + frameData->frameSI = frameSIPH->part; + + for ( ch = 0; ch < gfp->stereo; ch++ ) + frameData->channelSI[ch] = channelSIPH[ch]->part; + + for ( gr = 0; gr < gfp->mode_gr; gr++ ) + for ( ch = 0; ch < gfp->stereo; ch++ ) + { + frameData->spectrumSI[gr][ch] = spectrumSIPH[gr][ch]->part; + frameData->scaleFactors[gr][ch] = scaleFactorsPH[gr][ch]->part; + frameData->codedData[gr][ch] = codedDataPH[gr][ch]->part; + frameData->userSpectrum[gr][ch] = userSpectrumPH[gr][ch]->part; + } + frameData->userFrameData = userFrameDataPH->part; + + BF_BitstreamFrame( frameData, frameResults ); + + /* we set this here -- it will be tested in the next loops iteration */ + l3_side->main_data_begin = frameResults->nextBackPtr; + + } + + void + III_FlushBitstream(void) + { + if (PartHoldersInitialized!=0) + BF_FlushBitstream( frameData, frameResults ); + } + + static unsigned slen1_tab[16] = { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 }; + static unsigned slen2_tab[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 }; + + static void + encodeMainData( lame_global_flags *gfp, + int l3_enc[2][2][576], + III_side_info_t *si, + III_scalefac_t scalefac[2][2] ) + { + int i, gr, ch, sfb, window; + + + for ( gr = 0; gr < gfp->mode_gr; gr++ ) + for ( ch = 0; ch < gfp->stereo; ch++ ) + scaleFactorsPH[gr][ch]->part->nrEntries = 0; + + for ( gr = 0; gr < gfp->mode_gr; gr++ ) + for ( ch = 0; ch < gfp->stereo; ch++ ) + codedDataPH[gr][ch]->part->nrEntries = 0; + + if ( gfp->version == 1 ) + { /* MPEG 1 */ + for ( gr = 0; gr < 2; gr++ ) + { + for ( ch = 0; ch < gfp->stereo; ch++ ) + { + BF_PartHolder **pph = &scaleFactorsPH[gr][ch]; + gr_info *gi = &(si->gr[gr].ch[ch].tt); + unsigned slen1 = slen1_tab[ gi->scalefac_compress ]; + unsigned slen2 = slen2_tab[ gi->scalefac_compress ]; + int *ix = &l3_enc[gr][ch][0]; + + if (gi->block_type == SHORT_TYPE) + { + #ifdef ALLOW_MIXED + if ( gi->mixed_block_flag ) + { + for ( sfb = 0; sfb < 8; sfb++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].l[sfb], slen1 ); + + for ( sfb = 3; sfb < 6; sfb++ ) + for ( window = 0; window < 3; window++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].s[sfb][window], slen1 ); + + for ( sfb = 6; sfb < 12; sfb++ ) + for ( window = 0; window < 3; window++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].s[sfb][window], slen2 ); + + } + else + #endif + { + for ( sfb = 0; sfb < 6; sfb++ ) + for ( window = 0; window < 3; window++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].s[sfb][window], slen1 ); + + for ( sfb = 6; sfb < 12; sfb++ ) + for ( window = 0; window < 3; window++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].s[sfb][window], slen2 ); + } + } + else + { + if ( (gr == 0) || (si->scfsi[ch][0] == 0) ) + for ( sfb = 0; sfb < 6; sfb++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].l[sfb], slen1 ); + + if ( (gr == 0) || (si->scfsi[ch][1] == 0) ) + for ( sfb = 6; sfb < 11; sfb++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].l[sfb], slen1 ); + + if ( (gr == 0) || (si->scfsi[ch][2] == 0) ) + for ( sfb = 11; sfb < 16; sfb++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].l[sfb], slen2 ); + + if ( (gr == 0) || (si->scfsi[ch][3] == 0) ) + for ( sfb = 16; sfb < 21; sfb++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].l[sfb], slen2 ); + } + Huffmancodebits( &codedDataPH[gr][ch], ix, gi ); + } /* for ch */ + } /* for gr */ + } + else + { /* MPEG 2 */ + gr = 0; + for ( ch = 0; ch < gfp->stereo; ch++ ) + { + BF_PartHolder **pph = &scaleFactorsPH[gr][ch]; + gr_info *gi = &(si->gr[gr].ch[ch].tt); + int *ix = &l3_enc[gr][ch][0]; + int sfb_partition; + assert( gi->sfb_partition_table ); + + if (gi->block_type == SHORT_TYPE) + { + #ifdef ALLOW_MIXED + if ( gi->mixed_block_flag ) + { + sfb_partition = 0; + for ( sfb = 0; sfb < 8; sfb++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].l[sfb], gi->slen[sfb_partition] ); + + for ( sfb = 3, sfb_partition = 1; sfb_partition < 4; sfb_partition++ ) + { + int sfbs = gi->sfb_partition_table[ sfb_partition ] / 3; + int slen = gi->slen[ sfb_partition ]; + for ( i = 0; i < sfbs; i++, sfb++ ) + for ( window = 0; window < 3; window++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].s[sfb][window], slen ); + } + } + else + #endif + { + for ( sfb = 0, sfb_partition = 0; sfb_partition < 4; sfb_partition++ ) + { + int sfbs = gi->sfb_partition_table[ sfb_partition ] / 3; + int slen = gi->slen[ sfb_partition ]; + for ( i = 0; i < sfbs; i++, sfb++ ) + for ( window = 0; window < 3; window++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].s[sfb][window], slen ); + } + } + } + else + { + for ( sfb = 0, sfb_partition = 0; sfb_partition < 4; sfb_partition++ ) + { + int sfbs = gi->sfb_partition_table[ sfb_partition ]; + int slen = gi->slen[ sfb_partition ]; + for ( i = 0; i < sfbs; i++, sfb++ ) + *pph = BF_addEntry( *pph, scalefac[gr][ch].l[sfb], slen ); + } + } + + + + Huffmancodebits( &codedDataPH[gr][ch], ix, gi ); + } /* for ch */ + } + } /* main_data */ + + static unsigned int crc = 0; /* (jo) current crc */ + + /* (jo) this wrapper function for BF_addEntry() updates also the crc */ + static BF_PartHolder *CRC_BF_addEntry( BF_PartHolder *thePH, u_int value, u_int length ) + { + u_int bit = 1 << length; + + while((bit >>= 1)){ + crc <<= 1; + if (!(crc & 0x10000) ^ !(value & bit)) + crc ^= CRC16_POLYNOMIAL; + } + crc &= 0xffff; + return BF_addEntry(thePH, value, length); + } + + + + + static int encodeSideInfo( lame_global_flags *gfp,III_side_info_t *si ) + { + int gr, ch, scfsi_band, region, window, bits_sent; + + crc = 0xffff; /* (jo) init crc16 for error_protection */ + + headerPH->part->nrEntries = 0; + headerPH = BF_addEntry( headerPH, 0xfff, 12 ); + headerPH = BF_addEntry( headerPH, gfp->version, 1 ); + headerPH = BF_addEntry( headerPH, 1, 2 ); + headerPH = BF_addEntry( headerPH, !gfp->error_protection, 1 ); + /* (jo) from now on call the CRC_BF_addEntry() wrapper to update crc */ + headerPH = CRC_BF_addEntry( headerPH, gfp->bitrate_index, 4 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->samplerate_index, 2 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->padding, 1 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->extension, 1 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->mode, 2 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->mode_ext, 2 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->copyright, 1 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->original, 1 ); + headerPH = CRC_BF_addEntry( headerPH, gfp->emphasis, 2 ); + + bits_sent = 32; + + /* (jo) see below for BF_addEntry( headerPH, crc, 16 ); */ + + frameSIPH->part->nrEntries = 0; + + for (ch = 0; ch < gfp->stereo; ch++ ) + channelSIPH[ch]->part->nrEntries = 0; + + for ( gr = 0; gr < gfp->mode_gr; gr++ ) + for ( ch = 0; ch < gfp->stereo; ch++ ) + spectrumSIPH[gr][ch]->part->nrEntries = 0; + + if ( gfp->version == 1 ) + { /* MPEG1 */ + frameSIPH = CRC_BF_addEntry( frameSIPH, si->main_data_begin, 9 ); + + if ( gfp->stereo == 2 ) + frameSIPH = CRC_BF_addEntry( frameSIPH, si->private_bits, 3 ); + else + frameSIPH = CRC_BF_addEntry( frameSIPH, si->private_bits, 5 ); + + for ( ch = 0; ch < gfp->stereo; ch++ ) + for ( scfsi_band = 0; scfsi_band < 4; scfsi_band++ ) + { + BF_PartHolder **pph = &channelSIPH[ch]; + *pph = CRC_BF_addEntry( *pph, si->scfsi[ch][scfsi_band], 1 ); + } + + for ( gr = 0; gr < 2; gr++ ) + for ( ch = 0; ch < gfp->stereo; ch++ ) + { + BF_PartHolder **pph = &spectrumSIPH[gr][ch]; + gr_info *gi = &(si->gr[gr].ch[ch].tt); + *pph = CRC_BF_addEntry( *pph, gi->part2_3_length, 12 ); + *pph = CRC_BF_addEntry( *pph, gi->big_values, 9 ); + *pph = CRC_BF_addEntry( *pph, gi->global_gain, 8 ); + *pph = CRC_BF_addEntry( *pph, gi->scalefac_compress, 4 ); + *pph = CRC_BF_addEntry( *pph, gi->window_switching_flag, 1 ); + + if ( gi->window_switching_flag ) + { + *pph = CRC_BF_addEntry( *pph, gi->block_type, 2 ); + *pph = CRC_BF_addEntry( *pph, gi->mixed_block_flag, 1 ); + + for ( region = 0; region < 2; region++ ) + *pph = CRC_BF_addEntry( *pph, gi->table_select[region], 5 ); + for ( window = 0; window < 3; window++ ) + *pph = CRC_BF_addEntry( *pph, gi->subblock_gain[window], 3 ); + } + else + { + assert( gi->block_type == NORM_TYPE ); + for ( region = 0; region < 3; region++ ) + *pph = CRC_BF_addEntry( *pph, gi->table_select[region], 5 ); + + *pph = CRC_BF_addEntry( *pph, gi->region0_count, 4 ); + *pph = CRC_BF_addEntry( *pph, gi->region1_count, 3 ); + } + + *pph = CRC_BF_addEntry( *pph, gi->preflag, 1 ); + *pph = CRC_BF_addEntry( *pph, gi->scalefac_scale, 1 ); + *pph = CRC_BF_addEntry( *pph, gi->count1table_select, 1 ); + } + + if ( gfp->stereo == 2 ) + bits_sent += 256; + else + bits_sent += 136; + } + else + { /* MPEG2 */ + frameSIPH = CRC_BF_addEntry( frameSIPH, si->main_data_begin, 8 ); + + if ( gfp->stereo == 2 ) + frameSIPH = CRC_BF_addEntry( frameSIPH, si->private_bits, 2 ); + else + frameSIPH = CRC_BF_addEntry( frameSIPH, si->private_bits, 1 ); + + gr = 0; + for ( ch = 0; ch < gfp->stereo; ch++ ) + { + BF_PartHolder **pph = &spectrumSIPH[gr][ch]; + gr_info *gi = &(si->gr[gr].ch[ch].tt); + *pph = CRC_BF_addEntry( *pph, gi->part2_3_length, 12 ); + *pph = CRC_BF_addEntry( *pph, gi->big_values, 9 ); + *pph = CRC_BF_addEntry( *pph, gi->global_gain, 8 ); + *pph = CRC_BF_addEntry( *pph, gi->scalefac_compress, 9 ); + *pph = CRC_BF_addEntry( *pph, gi->window_switching_flag, 1 ); + + if ( gi->window_switching_flag ) + { + *pph = CRC_BF_addEntry( *pph, gi->block_type, 2 ); + *pph = CRC_BF_addEntry( *pph, gi->mixed_block_flag, 1 ); + + for ( region = 0; region < 2; region++ ) + *pph = CRC_BF_addEntry( *pph, gi->table_select[region], 5 ); + for ( window = 0; window < 3; window++ ) + *pph = CRC_BF_addEntry( *pph, gi->subblock_gain[window], 3 ); + } + else + { + for ( region = 0; region < 3; region++ ) + *pph = CRC_BF_addEntry( *pph, gi->table_select[region], 5 ); + + *pph = CRC_BF_addEntry( *pph, gi->region0_count, 4 ); + *pph = CRC_BF_addEntry( *pph, gi->region1_count, 3 ); + } + + *pph = CRC_BF_addEntry( *pph, gi->scalefac_scale, 1 ); + *pph = CRC_BF_addEntry( *pph, gi->count1table_select, 1 ); + } + if ( gfp->stereo == 2 ) + bits_sent += 136; + else + bits_sent += 72; + } + + if ( gfp->error_protection ) + { /* (jo) error_protection: add crc16 information to header */ + headerPH = BF_addEntry( headerPH, crc, 16 ); + bits_sent += 16; + } + + return bits_sent; + } + + /* + Some combinations of bitrate, Fs, and stereo make it impossible to stuff + out a frame using just main_data, due to the limited number of bits to + indicate main_data_length. In these situations, we put stuffing bits into + the ancillary data... + */ + static void + drain_into_ancillary_data( int lengthInBits ) + { + /* + */ + int wordsToSend = lengthInBits / 32; + int remainingBits = lengthInBits % 32; + int i; + + /* + userFrameDataPH->part->nrEntries set by call to write_ancillary_data() + */ + + userFrameDataPH->part->nrEntries = 0; + for ( i = 0; i < wordsToSend; i++ ) + userFrameDataPH = BF_addEntry( userFrameDataPH, 0, 32 ); + if ( remainingBits ) + userFrameDataPH = BF_addEntry( userFrameDataPH, 0, remainingBits ); + } + + /* + Note the discussion of huffmancodebits() on pages 28 + and 29 of the IS, as well as the definitions of the side + information on pages 26 and 27. + */ + static void + Huffmancodebits( BF_PartHolder **pph, int *ix, gr_info *gi ) + { + int L3_huffman_coder_count1( BF_PartHolder **pph, struct huffcodetab *h, int v, int w, int x, int y ); + + int region1Start; + int region2Start; + int i, bigvalues, count1End; + int v, w, x, y, bits, cbits, xbits, stuffingBits; + unsigned int code, ext; + #ifdef DEBUG + int bvbits, c1bits; + #endif + int bitsWritten = 0; + + + /* 1: Write the bigvalues */ + bigvalues = gi->big_values * 2; + if ( bigvalues ) + { + if ( !(gi->mixed_block_flag) && (gi->block_type == SHORT_TYPE) ) + { /* Three short blocks */ + /* + Within each scalefactor band, data is given for successive + time windows, beginning with window 0 and ending with window 2. + Within each window, the quantized values are then arranged in + order of increasing frequency... + */ + int sfb, window, line, start, end; + + I192_3 *ix_s; + + ix_s = (I192_3 *) ix; + region1Start = 12; + region2Start = 576; + + for ( sfb = 0; sfb < 13; sfb++ ) + { + unsigned tableindex = 100; + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb+1 ]; + + if ( start < region1Start ) + tableindex = gi->table_select[ 0 ]; + else + tableindex = gi->table_select[ 1 ]; + assert( tableindex < 32 ); + + for ( window = 0; window < 3; window++ ) + for ( line = start; line < end; line += 2 ) + { + x = (*ix_s)[line][window]; + y = (*ix_s)[line + 1][window]; + bits = HuffmanCode( tableindex, x, y, &code, &ext, &cbits, &xbits ); + *pph = BF_addEntry( *pph, code, cbits ); + *pph = BF_addEntry( *pph, ext, xbits ); + bitsWritten += bits; + } + + } + } + else + #ifdef ALLOW_MIXED + if ( gi->mixed_block_flag && gi->block_type == SHORT_TYPE ) + { /* Mixed blocks long, short */ + int sfb, window, line, start, end; + unsigned tableindex; + I192_3 *ix_s; + + ix_s = (I192_3 *) ix; + + /* Write the long block region */ + tableindex = gi->table_select[0]; + if ( tableindex ) + for ( i = 0; i < 36; i += 2 ) + { + x = ix[i]; + y = ix[i + 1]; + bits = HuffmanCode( tableindex, x, y, &code, &ext, &cbits, &xbits ); + *pph = BF_addEntry( *pph, code, cbits ); + *pph = BF_addEntry( *pph, ext, xbits ); + bitsWritten += bits; + + } + /* Write the short block region */ + tableindex = gi->table_select[ 1 ]; + assert( tableindex < 32 ); + + for ( sfb = 3; sfb < 13; sfb++ ) + { + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb+1 ]; + + for ( window = 0; window < 3; window++ ) + for ( line = start; line < end; line += 2 ) + { + x = (*ix_s)[line][window]; + y = (*ix_s)[line + 1][window]; + bits = HuffmanCode( tableindex, x, y, &code, &ext, &cbits, &xbits ); + *pph = BF_addEntry( *pph, code, cbits ); + *pph = BF_addEntry( *pph, ext, xbits ); + bitsWritten += bits; + } + } + + } + else + #endif + { /* Long blocks */ + unsigned scalefac_index = 100; + + if ( gi->mixed_block_flag ) + { + region1Start = 36; + region2Start = 576; + } + else + { + scalefac_index = gi->region0_count + 1; + assert( scalefac_index < 23 ); + region1Start = scalefac_band.l[ scalefac_index ]; + scalefac_index += gi->region1_count + 1; + assert( scalefac_index < 23 ); + region2Start = scalefac_band.l[ scalefac_index ]; + } + + for ( i = 0; i < bigvalues; i += 2 ) + { + unsigned tableindex = 100; + /* get table pointer */ + if ( i < region1Start ) + { + tableindex = gi->table_select[0]; + } + else + if ( i < region2Start ) + { + tableindex = gi->table_select[1]; + } + else + { + tableindex = gi->table_select[2]; + } + assert( tableindex < 32 ); + /* get huffman code */ + x = ix[i]; + y = ix[i + 1]; + + if ( tableindex ) + { + bits = HuffmanCode( tableindex, x, y, &code, &ext, &cbits, &xbits ); + *pph = BF_addEntry( *pph, code, cbits ); + *pph = BF_addEntry( *pph, ext, xbits ); + bitsWritten += bits; + } + } + } + } + #ifdef DEBUG + bvbits = bitsWritten; + #endif + + /* 2: Write count1 area */ + assert( (gi->count1table_select < 2) ); + count1End = bigvalues + (gi->count1 * 4); + + assert( count1End <= 576 ); + + for ( i = bigvalues; i < count1End; i += 4 ) + { + v = ix[i]; + w = ix[i+1]; + x = ix[i+2]; + y = ix[i+3]; + bitsWritten += L3_huffman_coder_count1( pph, &ht[gi->count1table_select + 32], v, w, x, y ); + } + #ifdef DEBUG + c1bits = bitsWritten - bvbits; + #endif + if ( (stuffingBits = gi->part2_3_length - gi->part2_length - bitsWritten) ) + { + int stuffingWords = stuffingBits / 32; + int remainingBits = stuffingBits % 32; + + fprintf(stderr,"opps - adding stuffing bits = %i.\n",stuffingBits); + fprintf(stderr,"this should not happen...\n"); + + /* + Due to the nature of the Huffman code + tables, we will pad with ones + */ + while ( stuffingWords-- ) + *pph = BF_addEntry( *pph, ~(u_int)0, 32 ); + if ( remainingBits ) + *pph = BF_addEntry( *pph, ~(u_int)0, remainingBits ); + bitsWritten += stuffingBits; + } + assert( bitsWritten == (int)(gi->part2_3_length - gi->part2_length) ); + #ifdef DEBUG + fprintf(stderr, "## %d Huffman bits written (%02d + %02d), part2_length = %d, part2_3_length = %d, %d stuffing ##\n", + bitsWritten, bvbits, c1bits, gi->part2_length, gi->part2_3_length, stuffingBits ); + #endif + } + + int + abs_and_sign( int *x ) + { + if ( *x > 0 ) + return 0; + *x *= -1; + return 1; + } + + int + L3_huffman_coder_count1( BF_PartHolder **pph, struct huffcodetab *h, int v, int w, int x, int y ) + { + HUFFBITS huffbits; + unsigned int signv, signw, signx, signy, p; + int len; + int totalBits = 0; + + signv = abs_and_sign( &v ); + signw = abs_and_sign( &w ); + signx = abs_and_sign( &x ); + signy = abs_and_sign( &y ); + + /* bug fix from Leonid A. Kulakov 9/1999:*/ + p = (v << 3) + (w << 2) + (x << 1) + y; + + huffbits = h->table[p]; + len = h->hlen[ p ]; + *pph = BF_addEntry(*pph, huffbits, len); + totalBits= 0; + #if 0 + if ( v ) + { + *pph = BF_addEntry( *pph, signv, 1 ); + totalBits += 1; + } + if ( w ) + { + *pph = BF_addEntry( *pph, signw, 1 ); + totalBits += 1; + } + + if ( x ) + { + *pph = BF_addEntry( *pph, signx, 1 ); + totalBits += 1; + } + if ( y ) + { + *pph = BF_addEntry( *pph, signy, 1 ); + totalBits += 1; + } + #endif + + p=0; + if ( v ) { + p = signv; + ++totalBits; + } + + if ( w ){ + p = 2*p + signw; + ++totalBits; + } + + if ( x ) { + p = 2*p + signx; + ++totalBits; + } + + if ( y ) { + p = 2*p + signy; + ++totalBits; + } + + *pph = BF_addEntry(*pph, p, totalBits); + + return totalBits+len; + } + + /* + Implements the pseudocode of page 98 of the IS + */ + int + HuffmanCode( int table_select, int x, int y, unsigned int *code, unsigned int *ext, int *cbits, int *xbits ) + { + unsigned signx, signy, linbitsx, linbitsy, linbits, idx; + struct huffcodetab *h; + + *cbits = 0; + *xbits = 0; + *code = 0; + *ext = 0; + + if ( table_select == 0 ) + return 0; + + signx = abs_and_sign( &x ); + signy = abs_and_sign( &y ); + h = &(ht[table_select]); + + if ( table_select > 15 ) + { /* ESC-table is used */ + linbits = h->xlen; + linbitsx = linbitsy = 0; + if ( x > 14 ) + { + linbitsx = x - 15; + assert( linbitsx <= h->linmax ); + x = 15; + } + if ( y > 14 ) + { + linbitsy = y - 15; + assert( linbitsy <= h->linmax ); + y = 15; + } + idx = x * 16 + y; + *code = h->table[idx]; + *cbits = h->hlen[ idx ]; + if ( x > 14 ) + { + *ext |= linbitsx; + *xbits += linbits; + } + if ( x != 0 ) + { + *ext <<= 1; + *ext |= signx; + *xbits += 1; + } + if ( y > 14 ) + { + *ext <<= linbits; + *ext |= linbitsy; + *xbits += linbits; + } + if ( y != 0 ) + { + *ext <<= 1; + *ext |= signy; + *xbits += 1; + } + } + else + { /* No ESC-words */ + idx = x * 16 + y; + *code = h->table[idx]; + *cbits += h->hlen[ idx ]; + if ( x != 0 ) + { + *code <<= 1; + *code |= signx; + *cbits += 1; + } + if ( y != 0 ) + { + *code <<= 1; + *code |= signy; + *cbits += 1; + } + } + assert( *cbits <= 32 ); + assert( *xbits <= 32 ); + return *cbits + *xbits; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3bitstream.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,54 ---- + /********************************************************************** + * ISO MPEG Audio Subgroup Software Simulation Group (1996) + * ISO 13818-3 MPEG-2 Audio Encoder - Lower Sampling Frequency Extension + * + * $Id: l3bitstream.h,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: l3bitstream.h,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:54:36 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.5 2000/03/21 23:02:17 markt + * replaced all "gf." by gfp-> + * + * Revision 1.4 2000/03/14 20:45:04 markt + * removed "info" sturct. Removing fr_ps struct + * + * Revision 1.3 2000/02/01 11:26:32 takehiro + * scalefactor's structure changed + * + * Revision 1.2 1999/12/03 09:45:30 takehiro + * little bit cleanup + * + * Revision 1.1.1.1 1999/11/24 08:43:09 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 1.1 1996/02/14 04:04:23 rowlands + * Initial revision + * + * Received from Mike Coleman + **********************************************************************/ + + #ifndef L3_BITSTREAM_H + #define L3_BITSTREAM_H + + #include "util.h" + + void III_format_bitstream( lame_global_flags *gfp, + int bitsPerFrame, + int l3_enc[2][2][576], + III_side_info_t *l3_side, + III_scalefac_t scalefac[2][2], + Bit_stream_struc *in_bs); + + int HuffmanCode( int table_select, int x, int y, unsigned *code, unsigned int *extword, int *codebits, int *extbits ); + void III_FlushBitstream(void); + + int abs_and_sign( int *x ); /* returns signx and changes *x to abs(*x) */ + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3side.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3side.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/l3side.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,78 ---- + /********************************************************************** + * date programmers comment * + * 25. 6.92 Toshiyuki Ishino Ver 1.0 * + * 29.10.92 Masahiro Iwadare Ver 2.0 * + * 17. 4.93 Masahiro Iwadare Updated for IS Modification * + * * + *********************************************************************/ + + #ifndef L3_SIDE_H + #define L3_SIDE_H + #include "encoder.h" + #include "machine.h" + + /* Layer III side information. */ + + typedef FLOAT8 D576[576]; + typedef int I576[576]; + typedef FLOAT8 D192_3[192][3]; + typedef int I192_3[192][3]; + + + typedef struct { + FLOAT8 l[SBPSY_l + 1]; + FLOAT8 s[SBPSY_s + 1][3]; + } III_psy_xmin; + + typedef struct { + III_psy_xmin thm; + III_psy_xmin en; + } III_psy_ratio; + + typedef struct { + unsigned part2_3_length; + unsigned big_values; + unsigned count1; + unsigned global_gain; + unsigned scalefac_compress; + unsigned window_switching_flag; + unsigned block_type; + unsigned mixed_block_flag; + unsigned table_select[3]; + int /* unsigned */ subblock_gain[3]; + unsigned region0_count; + unsigned region1_count; + unsigned preflag; + unsigned scalefac_scale; + unsigned count1table_select; + + unsigned part2_length; + unsigned sfb_lmax; + unsigned sfb_smax; + unsigned count1bits; + /* added for LSF */ + unsigned *sfb_partition_table; + unsigned slen[4]; + } gr_info; + + typedef struct { + int main_data_begin; /* unsigned -> int */ + unsigned private_bits; + int resvDrain; + unsigned scfsi[2][4]; + struct { + struct gr_info_ss { + gr_info tt; + } ch[2]; + } gr[2]; + } III_side_info_t; + + /* Layer III scale factors. */ + /* note: there are only SBPSY_l=(SBMAX_l-1) and SBPSY_s=(SBMAX_s-1) scalefactors. + * Dont know why these would be dimensioned SBMAX_l and SBMAX-s */ + typedef struct { + int l[SBMAX_l]; /* [cb] */ + int s[SBMAX_s][3]; /* [window][cb] */ + } III_scalefac_t; /* [gr][ch] */ + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/lame.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/lame.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/lame.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,1428 ---- + /* + * LAME MP3 encoding engine + * + * Copyright (c) 1999 Mark Taylor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + + #include <assert.h> + + #ifdef HAVEGTK + #include "gtkanal.h" + #include <gtk/gtk.h> + #endif + #include "lame.h" + #include "util.h" + #include "timestatus.h" + #include "psymodel.h" + #include "newmdct.h" + #include "quantize.h" + #include "quantize-pvt.h" + #include "l3bitstream.h" + #include "formatBitstream.h" + #include "version.h" + #include "VbrTag.h" + #include "id3tag.h" + #include "tables.h" + #include "brhist.h" + #include "get_audio.h" + + #ifdef __riscos__ + #include "asmstuff.h" + #endif + + + /* Global variable definitions for lame.c */ + static Bit_stream_struc bs; + static III_side_info_t l3_side; + #define MFSIZE (1152+1152+ENCDELAY-MDCTDELAY) + static short int mfbuf[2][MFSIZE]; + static int mf_size; + static int mf_samples_to_encode; + + + + /******************************************************************** + * initialize internal params based on data in gf + * (globalflags struct filled in by calling program) + * + ********************************************************************/ + void lame_init_params(lame_global_flags *gfp) + { + int i; + FLOAT compression_ratio; + + + memset(&bs, 0, sizeof(Bit_stream_struc)); + memset(&l3_side,0x00,sizeof(III_side_info_t)); + + + gfp->frameNum=0; + InitFormatBitStream(); + if (gfp->num_channels==1) { + gfp->mode = MPG_MD_MONO; + } + gfp->stereo=2; + if (gfp->mode == MPG_MD_MONO) gfp->stereo=1; + + #ifdef BRHIST + if (gfp->silent) { + disp_brhist=0; /* turn of VBR historgram */ + } + if (!gfp->VBR) { + disp_brhist=0; /* turn of VBR historgram */ + } + #endif + + /* set the output sampling rate, and resample options if necessary + samplerate = input sample rate + resamplerate = ouput sample rate + */ + if (gfp->out_samplerate==0) { + /* user did not specify output sample rate */ + gfp->out_samplerate=gfp->in_samplerate; /* default */ + + + /* if resamplerate is not valid, find a valid value */ + if (gfp->out_samplerate>=48000) gfp->out_samplerate=48000; + else if (gfp->out_samplerate>=44100) gfp->out_samplerate=44100; + else if (gfp->out_samplerate>=32000) gfp->out_samplerate=32000; + else if (gfp->out_samplerate>=24000) gfp->out_samplerate=24000; + else if (gfp->out_samplerate>=22050) gfp->out_samplerate=22050; + else gfp->out_samplerate=16000; + + + if (gfp->brate>0) { + /* check if user specified bitrate requires downsampling */ + compression_ratio = gfp->out_samplerate*16*gfp->stereo/(1000.0*gfp->brate); + if (!gfp->VBR && compression_ratio > 13 ) { + /* automatic downsample, if possible */ + gfp->out_samplerate = (10*1000.0*gfp->brate)/(16*gfp->stereo); + if (gfp->out_samplerate<=16000) gfp->out_samplerate=16000; + else if (gfp->out_samplerate<=22050) gfp->out_samplerate=22050; + else if (gfp->out_samplerate<=24000) gfp->out_samplerate=24000; + else if (gfp->out_samplerate<=32000) gfp->out_samplerate=32000; + else if (gfp->out_samplerate<=44100) gfp->out_samplerate=44100; + else gfp->out_samplerate=48000; + } + } + } + + gfp->mode_gr = (gfp->out_samplerate <= 24000) ? 1 : 2; /* mode_gr = 2 */ + gfp->encoder_delay = ENCDELAY; + gfp->framesize = gfp->mode_gr*576; + + if (gfp->brate==0) { /* user didn't specify a bitrate, use default */ + gfp->brate=128; + if (gfp->mode_gr==1) gfp->brate=64; + } + + + gfp->resample_ratio=1; + if (gfp->out_samplerate != gfp->in_samplerate) gfp->resample_ratio = (FLOAT)gfp->in_samplerate/(FLOAT)gfp->out_samplerate; + + /* estimate total frames. must be done after setting sampling rate so + * we know the framesize. */ + gfp->totalframes=0; + gfp->totalframes = 2+ gfp->num_samples/(gfp->resample_ratio*gfp->framesize); + + + + /* 44.1kHz at 56kbs/channel: compression factor of 12.6 + 44.1kHz at 64kbs/channel: compression factor of 11.025 + 44.1kHz at 80kbs/channel: compression factor of 8.82 + 22.05kHz at 24kbs: 14.7 + 22.05kHz at 32kbs: 11.025 + 22.05kHz at 40kbs: 8.82 + 16kHz at 16kbs: 16.0 + 16kHz at 24kbs: 10.7 + + compression_ratio + 11 .70? + 12 sox resample .66 + 14.7 sox resample .45 + + */ + if (gfp->brate >= 320) gfp->VBR=0; /* dont bother with VBR at 320kbs */ + compression_ratio = gfp->out_samplerate*16*gfp->stereo/(1000.0*gfp->brate); + + + /* for VBR, take a guess at the compression_ratio */ + /* VBR_q compression like + 0 4.4 320kbs + 1 5.4 256kbs + 3 7.4 192kbs + 4 8.8 160kbs + 6 10.4 128kbs + */ + if (gfp->VBR && compression_ratio>11) { + compression_ratio = 4.4 + gfp->VBR_q; + } + + + /* At higher quality (lower compression) use STEREO instead of JSTEREO. + * (unless the user explicitly specified a mode ) */ + if ( (!gfp->mode_fixed) && (gfp->mode !=MPG_MD_MONO)) { + if (compression_ratio < 9 ) { + gfp->mode = MPG_MD_STEREO; + } + } + + + + /****************************************************************/ + /* if a filter has not been enabled, see if we should add one: */ + /****************************************************************/ + if (gfp->lowpassfreq == 0) { + /* If the user has not selected their own filter, add a lowpass + * filter based on the compression ratio. Formula based on + 44.1 /160 4.4x + 44.1 /128 5.5x keep all bands + 44.1 /96kbs 7.3x keep band 28 + 44.1 /80kbs 8.8x keep band 25 + 44.1khz/64kbs 11x keep band 21 22? + + 16khz/24kbs 10.7x keep band 21 + 22kHz/32kbs 11x keep band ? + 22kHz/24kbs 14.7x keep band 16 + 16 16 16x keep band 14 + */ + + + /* Should we use some lowpass filters? */ + int band = 1+floor(.5 + 14-18*log(compression_ratio/16.0)); + if (band < 31) { + gfp->lowpass1 = band/31.0; + gfp->lowpass2 = band/31.0; + } + } + + /****************************************************************/ + /* apply user driven filters*/ + /****************************************************************/ + if ( gfp->highpassfreq > 0 ) { + gfp->highpass1 = 2.0*gfp->highpassfreq/gfp->out_samplerate; /* will always be >=0 */ + if ( gfp->highpasswidth >= 0 ) { + gfp->highpass2 = 2.0*(gfp->highpassfreq+gfp->highpasswidth)/gfp->out_samplerate; + } else { + /* 15% above on default */ + /* gfp->highpass2 = 1.15*2.0*gfp->highpassfreq/gfp->out_samplerate; */ + gfp->highpass2 = 1.00*2.0*gfp->highpassfreq/gfp->out_samplerate; + } + gfp->highpass1 = Min( 1, gfp->highpass1 ); + gfp->highpass2 = Min( 1, gfp->highpass2 ); + } + + if ( gfp->lowpassfreq > 0 ) { + gfp->lowpass2 = 2.0*gfp->lowpassfreq/gfp->out_samplerate; /* will always be >=0 */ + if ( gfp->lowpasswidth >= 0 ) { + gfp->lowpass1 = 2.0*(gfp->lowpassfreq-gfp->lowpasswidth)/gfp->out_samplerate; + if ( gfp->lowpass1 < 0 ) { /* has to be >= 0 */ + gfp->lowpass1 = 0; + } + } else { + /* 15% below on default */ + /* gfp->lowpass1 = 0.85*2.0*gfp->lowpassfreq/gfp->out_samplerate; */ + gfp->lowpass1 = 1.00*2.0*gfp->lowpassfreq/gfp->out_samplerate; + } + gfp->lowpass1 = Min( 1, gfp->lowpass1 ); + gfp->lowpass2 = Min( 1, gfp->lowpass2 ); + } + + + /***************************************************************/ + /* compute info needed for polyphase filter */ + /***************************************************************/ + if (gfp->filter_type==0) { + int band,maxband,minband; + FLOAT8 amp,freq; + if (gfp->lowpass1 > 0) { + minband=999; + maxband=-1; + for (band=0; band <=31 ; ++band) { + freq = band/31.0; + amp = 1; + /* this band and above will be zeroed: */ + if (freq >= gfp->lowpass2) { + gfp->lowpass_band= Min(gfp->lowpass_band,band); + amp=0; + } + if (gfp->lowpass1 < freq && freq < gfp->lowpass2) { + minband = Min(minband,band); + maxband = Max(maxband,band); + amp = cos((PI/2)*(gfp->lowpass1-freq)/(gfp->lowpass2-gfp->lowpass1)); + } + /* printf("lowpass band=%i amp=%f \n",band,amp);*/ + } + /* compute the *actual* transition band implemented by the polyphase filter */ + if (minband==999) gfp->lowpass1 = (gfp->lowpass_band-.75)/31.0; + else gfp->lowpass1 = (minband-.75)/31.0; + gfp->lowpass2 = gfp->lowpass_band/31.0; + } + + /* make sure highpass filter is within 90% of whan the effective highpass + * frequency will be */ + if (gfp->highpass2 > 0) + if (gfp->highpass2 < .9*(.75/31.0) ) { + gfp->highpass1=0; gfp->highpass2=0; + fprintf(stderr,"Warning: highpass filter disabled. highpass frequency to small\n"); + } + + + if (gfp->highpass2 > 0) { + minband=999; + maxband=-1; + for (band=0; band <=31; ++band) { + freq = band/31.0; + amp = 1; + /* this band and below will be zereod */ + if (freq <= gfp->highpass1) { + gfp->highpass_band = Max(gfp->highpass_band,band); + amp=0; + } + if (gfp->highpass1 < freq && freq < gfp->highpass2) { + minband = Min(minband,band); + maxband = Max(maxband,band); + amp = cos((PI/2)*(gfp->highpass2-freq)/(gfp->highpass2-gfp->highpass1)); + } + /* printf("highpass band=%i amp=%f \n",band,amp);*/ + } + /* compute the *actual* transition band implemented by the polyphase filter */ + gfp->highpass1 = gfp->highpass_band/31.0; + if (maxband==-1) gfp->highpass2 = (gfp->highpass_band+.75)/31.0; + else gfp->highpass2 = (maxband+.75)/31.0; + } + /* + printf("lowpass band with amp=0: %i \n",gfp->lowpass_band); + printf("highpass band with amp=0: %i \n",gfp->highpass_band); + */ + } + + + + /***************************************************************/ + /* compute info needed for FIR filter */ + /***************************************************************/ + if (gfp->filter_type==1) { + } + + + + + gfp->mode_ext=MPG_MD_LR_LR; + gfp->stereo = (gfp->mode == MPG_MD_MONO) ? 1 : 2; + + + gfp->samplerate_index = SmpFrqIndex((long)gfp->out_samplerate, &gfp->version); + if( gfp->samplerate_index < 0) { + display_bitrates(stderr); + exit(1); + } + if( (gfp->bitrate_index = BitrateIndex(gfp->brate, gfp->version,gfp->out_samplerate)) < 0) { + display_bitrates(stderr); + exit(1); + } + + + /* choose a min/max bitrate for VBR */ + if (gfp->VBR) { + /* if the user didn't specify VBR_max_bitrate: */ + if (0==gfp->VBR_max_bitrate_kbps) { + /* default max bitrate is 256kbs */ + /* we do not normally allow 320bps frams with VBR, unless: */ + gfp->VBR_max_bitrate=13; /* default: allow 256kbs */ + if (gfp->VBR_min_bitrate_kbps>=256) gfp->VBR_max_bitrate=14; + if (gfp->VBR_q == 0) gfp->VBR_max_bitrate=14; /* allow 320kbs */ + if (gfp->VBR_q >= 4) gfp->VBR_max_bitrate=12; /* max = 224kbs */ + if (gfp->VBR_q >= 8) gfp->VBR_max_bitrate=9; /* low quality, max = 128kbs */ + }else{ + if( (gfp->VBR_max_bitrate = BitrateIndex(gfp->VBR_max_bitrate_kbps, gfp->version,gfp->out_samplerate)) < 0) { + display_bitrates(stderr); + exit(1); + } + } + if (0==gfp->VBR_min_bitrate_kbps) { + gfp->VBR_min_bitrate=1; /* 32 kbps */ + }else{ + if( (gfp->VBR_min_bitrate = BitrateIndex(gfp->VBR_min_bitrate_kbps, gfp->version,gfp->out_samplerate)) < 0) { + display_bitrates(stderr); + exit(1); + } + } + + } + + + if (gfp->VBR) gfp->quality=Min(gfp->quality,2); /* always use quality <=2 with VBR */ + /* dont allow forced mid/side stereo for mono output */ + if (gfp->mode == MPG_MD_MONO) gfp->force_ms=0; + + + /* Do not write VBR tag if VBR flag is not specified */ + if (gfp->VBR==0) gfp->bWriteVbrTag=0; + + /* some file options not allowed if output is: not specified or stdout */ + + if (gfp->outPath!=NULL && gfp->outPath[0]=='-' ) { + gfp->bWriteVbrTag=0; /* turn off VBR tag */ + } + + if (gfp->outPath==NULL || gfp->outPath[0]=='-' ) { + id3tag.used=0; /* turn of id3 tagging */ + } + + + + if (gfp->gtkflag) { + gfp->bWriteVbrTag=0; /* disable Xing VBR tag */ + } + + init_bit_stream_w(&bs); + + + + /* set internal feature flags. USER should not access these since + * some combinations will produce strange results */ + + /* no psymodel, no noise shaping */ + if (gfp->quality==9) { + gfp->filter_type=0; + gfp->psymodel=0; + gfp->quantization=0; + gfp->noise_shaping=0; + gfp->noise_shaping_stop=0; + gfp->use_best_huffman=0; + } + + if (gfp->quality==8) gfp->quality=7; + + /* use psymodel (for short block and m/s switching), but no noise shapping */ + if (gfp->quality==7) { + gfp->filter_type=0; + gfp->psymodel=1; + gfp->quantization=0; + gfp->noise_shaping=0; + gfp->noise_shaping_stop=0; + gfp->use_best_huffman=0; + } + + if (gfp->quality==6) gfp->quality=5; + + if (gfp->quality==5) { + /* the default */ + gfp->filter_type=0; + gfp->psymodel=1; + gfp->quantization=0; + gfp->noise_shaping=1; + gfp->noise_shaping_stop=0; + gfp->use_best_huffman=0; + } + + if (gfp->quality==4) gfp->quality=2; + if (gfp->quality==3) gfp->quality=2; + + if (gfp->quality==2) { + gfp->filter_type=0; + gfp->psymodel=1; + gfp->quantization=1; + gfp->noise_shaping=1; + gfp->noise_shaping_stop=0; + gfp->use_best_huffman=1; + } + + if (gfp->quality==1) { + gfp->filter_type=0; + gfp->psymodel=1; + gfp->quantization=1; + gfp->noise_shaping=1; + gfp->noise_shaping_stop=1; + gfp->use_best_huffman=1; + } + + if (gfp->quality==0) { + /* 0..1 quality */ + gfp->filter_type=1; /* not yet coded */ + gfp->psymodel=1; + gfp->quantization=1; + gfp->noise_shaping=3; /* not yet coded */ + gfp->noise_shaping_stop=2; /* not yet coded */ + gfp->use_best_huffman=2; /* not yet coded */ + exit(-99); + } + + + for (i = 0; i < SBMAX_l + 1; i++) { + scalefac_band.l[i] = + sfBandIndex[gfp->samplerate_index + (gfp->version * 3)].l[i]; + } + for (i = 0; i < SBMAX_s + 1; i++) { + scalefac_band.s[i] = + sfBandIndex[gfp->samplerate_index + (gfp->version * 3)].s[i]; + } + + + + if (gfp->bWriteVbrTag) + { + /* Write initial VBR Header to bitstream */ + InitVbrTag(&bs,1-gfp->version,gfp->mode,gfp->samplerate_index); + } + + #ifdef HAVEGTK + gtkflag=gfp->gtkflag; + #endif + + #ifdef BRHIST + if (gfp->VBR) { + if (disp_brhist) + brhist_init(gfp,1, 14); + } else + disp_brhist = 0; + #endif + return; + } + + + + + + + + + + /************************************************************************ + * + * print_config + * + * PURPOSE: Prints the encoding parameters used + * + ************************************************************************/ + void lame_print_config(lame_global_flags *gfp) + { + static const char *mode_names[4] = { "stereo", "j-stereo", "dual-ch", "single-ch" }; + FLOAT out_samplerate=gfp->out_samplerate/1000.0; + FLOAT in_samplerate = gfp->resample_ratio*out_samplerate; + FLOAT compression= + (FLOAT)(gfp->stereo*16*out_samplerate)/(FLOAT)(gfp->brate); + + lame_print_version(stderr); + if (gfp->num_channels==2 && gfp->stereo==1) { + fprintf(stderr, "Autoconverting from stereo to mono. Setting encoding to mono mode.\n"); + } + if (gfp->resample_ratio!=1) { + fprintf(stderr,"Resampling: input=%ikHz output=%ikHz\n", + (int)in_samplerate,(int)out_samplerate); + } + if (gfp->highpass2>0.0) + fprintf(stderr, "Using polyphase highpass filter, transition band: %.0f Hz - %.0f Hz\n", + gfp->highpass1*out_samplerate*500, + gfp->highpass2*out_samplerate*500); + if (gfp->lowpass1>0.0) + fprintf(stderr, "Using polyphase lowpass filter, transition band: %.0f Hz - %.0f Hz\n", + gfp->lowpass1*out_samplerate*500, + gfp->lowpass2*out_samplerate*500); + + if (gfp->gtkflag) { + fprintf(stderr, "Analyzing %s \n",gfp->inPath); + } + else { + fprintf(stderr, "Encoding %s to %s\n", + (strcmp(gfp->inPath, "-")? gfp->inPath : "stdin"), + (strcmp(gfp->outPath, "-")? gfp->outPath : "stdout")); + if (gfp->VBR) + fprintf(stderr, "Encoding as %.1fkHz VBR(q=%i) %s MPEG%i LayerIII qval=%i\n", + gfp->out_samplerate/1000.0, + gfp->VBR_q,mode_names[gfp->mode],2-gfp->version,gfp->quality); + else + fprintf(stderr, "Encoding as %.1f kHz %d kbps %s MPEG%i LayerIII (%4.1fx) qval=%i\n", + gfp->out_samplerate/1000.0,gfp->brate, + mode_names[gfp->mode],2-gfp->version,compression,gfp->quality); + } + fflush(stderr); + } + + + + + + + + + + + + + /************************************************************************ + * + * encodeframe() Layer 3 + * + * encode a single frame + * + ************************************************************************ + lame_encode_frame() + + + gr 0 gr 1 + inbuf: |--------------|---------------|-------------| + MDCT output: |--------------|---------------|-------------| + + FFT's <---------1024----------> + <---------1024--------> + + + + inbuf = buffer of PCM data size=MP3 framesize + encoder acts on inbuf[ch][0], but output is delayed by MDCTDELAY + so the MDCT coefficints are from inbuf[ch][-MDCTDELAY] + + psy-model FFT has a 1 granule day, so we feed it data for the next granule. + FFT is centered over granule: 224+576+224 + So FFT starts at: 576-224-MDCTDELAY + + MPEG2: FFT ends at: BLKSIZE+576-224-MDCTDELAY + MPEG1: FFT ends at: BLKSIZE+2*576-224-MDCTDELAY (1904) + + FFT starts at 576-224-MDCTDELAY (304) = 576-FFTOFFSET + + */ + int lame_encode_frame(lame_global_flags *gfp, + short int inbuf_l[],short int inbuf_r[], + int mf_size,char *mp3buf, int mp3buf_size) + { + static unsigned long frameBits; + static unsigned long bitsPerSlot; + static FLOAT8 frac_SpF; + static FLOAT8 slot_lag; + static unsigned long sentBits = 0; + FLOAT8 xr[2][2][576]; + int l3_enc[2][2][576]; + int mp3count; + III_psy_ratio masking_ratio[2][2]; /*LR ratios */ + III_psy_ratio masking_MS_ratio[2][2]; /*MS ratios */ + III_psy_ratio (*masking)[2][2]; /*LR ratios and MS ratios*/ + III_scalefac_t scalefac[2][2]; + short int *inbuf[2]; + + typedef FLOAT8 pedata[2][2]; + pedata pe,pe_MS; + pedata *pe_use; + + int ch,gr,mean_bits; + int bitsPerFrame; + + int check_ms_stereo; + static FLOAT8 ms_ratio[2]={0,0}; + FLOAT8 ms_ratio_next=0; + FLOAT8 ms_ratio_prev=0; + static FLOAT8 ms_ener_ratio[2]={0,0}; + + memset((char *) masking_ratio, 0, sizeof(masking_ratio)); + memset((char *) masking_MS_ratio, 0, sizeof(masking_MS_ratio)); + memset((char *) scalefac, 0, sizeof(scalefac)); + inbuf[0]=inbuf_l; + inbuf[1]=inbuf_r; + + gfp->mode_ext = MPG_MD_LR_LR; + + if (gfp->frameNum==0 ) { + /* Figure average number of 'slots' per frame. */ + FLOAT8 avg_slots_per_frame; + FLOAT8 sampfreq = gfp->out_samplerate/1000.0; + int bit_rate = gfp->brate; + sentBits = 0; + bitsPerSlot = 8; + avg_slots_per_frame = (bit_rate*gfp->framesize) / + (sampfreq* bitsPerSlot); + /* -f fast-math option causes some strange rounding here, be carefull: */ + frac_SpF = avg_slots_per_frame - floor(avg_slots_per_frame + 1e-9); + if (fabs(frac_SpF) < 1e-9) frac_SpF = 0; + + slot_lag = -frac_SpF; + gfp->padding = 1; + if (frac_SpF==0) gfp->padding = 0; + /* check FFT will not use a negative starting offset */ + assert(576>=FFTOFFSET); + /* check if we have enough data for FFT */ + assert(mf_size>=(BLKSIZE+gfp->framesize-FFTOFFSET)); + } + + + /********************** padding *****************************/ + switch (gfp->padding_type) { + case 0: + gfp->padding=0; + break; + case 1: + gfp->padding=1; + break; + case 2: + default: + if (gfp->VBR) { + gfp->padding=0; + } else { + if (gfp->disable_reservoir) { + gfp->padding = 0; + /* if the user specified --nores, dont very gfp->padding either */ + /* tiny changes in frac_SpF rounding will cause file differences */ + }else{ + if (frac_SpF != 0) { + if (slot_lag > (frac_SpF-1.0) ) { + slot_lag -= frac_SpF; + gfp->padding = 0; + } + else { + gfp->padding = 1; + slot_lag += (1-frac_SpF); + } + } + } + } + } + + + /********************** status display *****************************/ + if (!gfp->gtkflag && !gfp->silent) { + int mod = gfp->version == 0 ? 200 : 50; + if (gfp->frameNum%mod==0) { + timestatus(gfp->out_samplerate,gfp->frameNum,gfp->totalframes,gfp->framesize); + #ifdef BRHIST + if (disp_brhist) + { + brhist_add_count(); + brhist_disp(); + } + #endif + } + } + + + if (gfp->psymodel) { + /* psychoacoustic model + * psy model has a 1 granule (576) delay that we must compensate for + * (mt 6/99). + */ + short int *bufp[2]; /* address of beginning of left & right granule */ + int blocktype[2]; + + ms_ratio_prev=ms_ratio[gfp->mode_gr-1]; + for (gr=0; gr < gfp->mode_gr ; gr++) { + + for ( ch = 0; ch < gfp->stereo; ch++ ) + bufp[ch] = &inbuf[ch][576 + gr*576-FFTOFFSET]; + + L3psycho_anal( gfp,bufp, gr, + &ms_ratio[gr],&ms_ratio_next,&ms_ener_ratio[gr], + masking_ratio, masking_MS_ratio, + pe[gr],pe_MS[gr],blocktype); + + for ( ch = 0; ch < gfp->stereo; ch++ ) + l3_side.gr[gr].ch[ch].tt.block_type=blocktype[ch]; + + } + }else{ + for (gr=0; gr < gfp->mode_gr ; gr++) + for ( ch = 0; ch < gfp->stereo; ch++ ) { + l3_side.gr[gr].ch[ch].tt.block_type=NORM_TYPE; + pe[gr][ch]=700; + } + } + + + /* block type flags */ + for( gr = 0; gr < gfp->mode_gr; gr++ ) { + for ( ch = 0; ch < gfp->stereo; ch++ ) { + gr_info *cod_info = &l3_side.gr[gr].ch[ch].tt; + cod_info->mixed_block_flag = 0; /* never used by this model */ + if (cod_info->block_type == NORM_TYPE ) + cod_info->window_switching_flag = 0; + else + cod_info->window_switching_flag = 1; + } + } + + /* polyphase filtering / mdct */ + mdct_sub48(gfp,inbuf[0], inbuf[1], xr, &l3_side); + + /* use m/s gfp->stereo? */ + check_ms_stereo = (gfp->mode == MPG_MD_JOINT_STEREO); + if (check_ms_stereo) { + /* make sure block type is the same in each channel */ + check_ms_stereo = + (l3_side.gr[0].ch[0].tt.block_type==l3_side.gr[0].ch[1].tt.block_type) && + (l3_side.gr[1].ch[0].tt.block_type==l3_side.gr[1].ch[1].tt.block_type); + } + if (check_ms_stereo) { + /* ms_ratio = is like the ratio of side_energy/total_energy */ + FLOAT8 ms_ratio_ave,ms_ener_ratio_ave; + /* ms_ratio_ave = .5*(ms_ratio[0] + ms_ratio[1]);*/ + ms_ratio_ave = .25*(ms_ratio[0] + ms_ratio[1]+ + ms_ratio_prev + ms_ratio_next); + ms_ener_ratio_ave = .5*(ms_ener_ratio[0]+ms_ener_ratio[1]); + if ( ms_ratio_ave <.35 /*&& ms_ener_ratio_ave<.75*/ ) gfp->mode_ext = MPG_MD_MS_LR; + } + if (gfp->force_ms) gfp->mode_ext = MPG_MD_MS_LR; + + + #ifdef HAVEGTK + if (gfp->gtkflag) { + int j; + for ( gr = 0; gr < gfp->mode_gr; gr++ ) { + for ( ch = 0; ch < gfp->stereo; ch++ ) { + pinfo->ms_ratio[gr]=ms_ratio[gr]; + pinfo->ms_ener_ratio[gr]=ms_ener_ratio[gr]; + pinfo->blocktype[gr][ch]= + l3_side.gr[gr].ch[ch].tt.block_type; + for ( j = 0; j < 576; j++ ) pinfo->xr[gr][ch][j]=xr[gr][ch][j]; + /* if MS stereo, switch to MS psy data */ + if (gfp->mode_ext==MPG_MD_MS_LR) { + pinfo->pe[gr][ch]=pinfo->pe[gr][ch+2]; + pinfo->ers[gr][ch]=pinfo->ers[gr][ch+2]; + memcpy(pinfo->energy[gr][ch],pinfo->energy[gr][ch+2], + sizeof(pinfo->energy[gr][ch])); + } + } + } + } + #endif + + + + + /* bit and noise allocation */ + if (MPG_MD_MS_LR == gfp->mode_ext) { + masking = &masking_MS_ratio; /* use MS masking */ + pe_use=&pe_MS; + } else { + masking = &masking_ratio; /* use LR masking */ + pe_use=&pe; + } + + + /* + VBR_iteration_loop_new( gfp,*pe_use, ms_ratio, xr, masking, &l3_side, l3_enc, + &scalefac); + */ + + + if (gfp->VBR) { + VBR_iteration_loop( gfp,*pe_use, ms_ratio, xr, *masking, &l3_side, l3_enc, + scalefac); + }else{ + iteration_loop( gfp,*pe_use, ms_ratio, xr, *masking, &l3_side, l3_enc, + scalefac); + } + + + + + #ifdef BRHIST + brhist_temp[gfp->bitrate_index]++; + #endif + + + /* write the frame to the bitstream */ + getframebits(gfp,&bitsPerFrame,&mean_bits); + III_format_bitstream( gfp,bitsPerFrame, l3_enc, &l3_side, + scalefac, &bs); + + + frameBits = bs.totbit - sentBits; + + + if ( frameBits % bitsPerSlot ) /* a program failure */ + fprintf( stderr, "Sent %ld bits = %ld slots plus %ld\n", + frameBits, frameBits/bitsPerSlot, + frameBits%bitsPerSlot ); + sentBits += frameBits; + + /* copy mp3 bit buffer into array */ + mp3count = copy_buffer(mp3buf,mp3buf_size,&bs); + + if (gfp->bWriteVbrTag) AddVbrFrame((int)(sentBits/8)); + + #ifdef HAVEGTK + if (gfp->gtkflag) { + int j; + for ( ch = 0; ch < gfp->stereo; ch++ ) { + for ( j = 0; j < FFTOFFSET; j++ ) + pinfo->pcmdata[ch][j] = pinfo->pcmdata[ch][j+gfp->framesize]; + for ( j = FFTOFFSET; j < 1600; j++ ) { + pinfo->pcmdata[ch][j] = inbuf[ch][j-FFTOFFSET]; + } + } + } + #endif + gfp->frameNum++; + + return mp3count; + } + + + + int fill_buffer_resample(lame_global_flags *gfp,short int *outbuf,int desired_len, + short int *inbuf,int len,int *num_used,int ch) { + + static FLOAT8 itime[2]; + #define OLDBUFSIZE 5 + static short int inbuf_old[2][OLDBUFSIZE]; + static int init[2]={0,0}; + int i,j=0,k,linear,value; + + if (gfp->frameNum==0 && !init[ch]) { + init[ch]=1; + itime[ch]=0; + memset((char *) inbuf_old[ch], 0, sizeof(short int)*OLDBUFSIZE); + } + if (gfp->frameNum!=0) init[ch]=0; /* reset, for next time framenum=0 */ + + + /* if downsampling by an integer multiple, use linear resampling, + * otherwise use quadratic */ + linear = ( fabs(gfp->resample_ratio - floor(.5+gfp->resample_ratio)) < .0001 ); + + /* time of j'th element in inbuf = itime + j/ifreq; */ + /* time of k'th element in outbuf = j/ofreq */ + for (k=0;k<desired_len;k++) { + int y0,y1,y2,y3; + FLOAT8 x0,x1,x2,x3; + FLOAT8 time0; + + time0 = k*gfp->resample_ratio; /* time of k'th output sample */ + j = floor( time0 -itime[ch] ); + /* itime[ch] + j; */ /* time of j'th input sample */ + if (j+2 >= len) break; /* not enough data in input buffer */ + + x1 = time0-(itime[ch]+j); + x2 = x1-1; + y1 = (j<0) ? inbuf_old[ch][OLDBUFSIZE+j] : inbuf[j]; + y2 = ((1+j)<0) ? inbuf_old[ch][OLDBUFSIZE+1+j] : inbuf[1+j]; + + /* linear resample */ + if (linear) { + outbuf[k] = floor(.5 + (y2*x1-y1*x2) ); + } else { + /* quadratic */ + x0 = x1+1; + x3 = x1-2; + y0 = ((j-1)<0) ? inbuf_old[ch][OLDBUFSIZE+(j-1)] : inbuf[j-1]; + y3 = ((j+2)<0) ? inbuf_old[ch][OLDBUFSIZE+(j+2)] : inbuf[j+2]; + value = floor(.5 + + -y0*x1*x2*x3/6 + y1*x0*x2*x3/2 - y2*x0*x1*x3/2 +y3*x0*x1*x2/6 + ); + if (value > 32767) outbuf[k]=32767; + else if (value < -32767) outbuf[k]=-32767; + else outbuf[k]=value; + + /* + printf("k=%i new=%i [ %i %i %i %i ]\n",k,outbuf[k], + y0,y1,y2,y3); + */ + } + } + + + /* k = number of samples added to outbuf */ + /* last k sample used data from j,j+1, or j+1 overflowed buffer */ + /* remove num_used samples from inbuf: */ + *num_used = Min(len,j+2); + itime[ch] += *num_used - k*gfp->resample_ratio; + for (i=0;i<OLDBUFSIZE;i++) + inbuf_old[ch][i]=inbuf[*num_used + i -OLDBUFSIZE]; + return k; + } + + + + + int fill_buffer(lame_global_flags *gfp,short int *outbuf,int desired_len,short int *inbuf,int len) { + int j; + j=Min(desired_len,len); + memcpy( (char *) outbuf,(char *)inbuf,sizeof(short int)*j); + return j; + } + + + + + /* + * THE MAIN LAME ENCODING INTERFACE + * mt 3/00 + * + * input pcm data, output (maybe) mp3 frames. + * This routine handles all buffering, resampling and filtering for you. + * The required mp3buffer_size can be computed from num_samples, + * samplerate and encoding rate, but here is a worst case estimate: + * + * mp3buffer_size in bytes = 1.25*num_samples + 7200 + * + * return code = number of bytes output in mp3buffer. can be 0 + */ + int lame_encode_buffer(lame_global_flags *gfp, + short int buffer_l[], short int buffer_r[],int nsamples, + char *mp3buf, int mp3buf_size) + { + static int frame_buffered=0; + int mp3size=0,ret,i,ch,mf_needed; + + short int *in_buffer[2]; + in_buffer[0] = buffer_l; + in_buffer[1] = buffer_r; + + /* some sanity checks */ + assert(ENCDELAY>=MDCTDELAY); + assert(BLKSIZE-FFTOFFSET >= 0); + mf_needed = BLKSIZE+gfp->framesize-FFTOFFSET; + assert(MFSIZE>=mf_needed); + + /* The reason for + * int mf_samples_to_encode = ENCDELAY + 288; + * ENCDELAY = internal encoder delay. And then we have to add 288 + * because of the 50% MDCT overlap. A 576 MDCT granule decodes to + * 1152 samples. To synthesize the 576 samples centered under this granule + * we need the previous granule for the first 288 samples (no problem), and + * the next granule for the next 288 samples (not possible if this is last + * granule). So we need to pad with 288 samples to make sure we can + * encode the 576 samples we are interested in. + */ + if (gfp->frameNum==0 && !frame_buffered) { + memset((char *) mfbuf, 0, sizeof(mfbuf)); + frame_buffered=1; + mf_samples_to_encode = ENCDELAY+288; + mf_size=ENCDELAY-MDCTDELAY; /* we pad input with this many 0's */ + } + if (gfp->frameNum==1) { + /* reset, for the next time frameNum==0 */ + frame_buffered=0; + } + + if (gfp->num_channels==2 && gfp->stereo==1) { + /* downsample to mono */ + for (i=0; i<nsamples; ++i) { + in_buffer[0][i]=((int)in_buffer[0][i]+(int)in_buffer[1][i])/2; + in_buffer[1][i]=0; + } + } + + + while (nsamples > 0) { + int n_in=0; + int n_out=0; + /* copy in new samples */ + for (ch=0; ch<gfp->stereo; ch++) { + if (gfp->resample_ratio!=1) { + n_out=fill_buffer_resample(gfp,&mfbuf[ch][mf_size],gfp->framesize, + in_buffer[ch],nsamples,&n_in,ch); + } else { + n_out=fill_buffer(gfp,&mfbuf[ch][mf_size],gfp->framesize,in_buffer[ch],nsamples); + n_in = n_out; + } + in_buffer[ch] += n_in; + } + + + nsamples -= n_in; + mf_size += n_out; + assert(mf_size<=MFSIZE); + mf_samples_to_encode += n_out; + + if (mf_size >= mf_needed) { + /* encode the frame */ + ret = lame_encode_frame(gfp,mfbuf[0],mfbuf[1],mf_size,mp3buf,mp3buf_size); + if (ret == -1) { + /* fatel error: mp3buffer was too small */ + return -1; + } + mp3buf += ret; + mp3size += ret; + + /* shift out old samples */ + mf_size -= gfp->framesize; + mf_samples_to_encode -= gfp->framesize; + for (ch=0; ch<gfp->stereo; ch++) + for (i=0; i<mf_size; i++) + mfbuf[ch][i]=mfbuf[ch][i+gfp->framesize]; + } + } + assert(nsamples==0); + return mp3size; + } + + + + + int lame_encode_buffer_interleaved(lame_global_flags *gfp, + short int buffer[], int nsamples, char *mp3buf, int mp3buf_size) + { + static int frame_buffered=0; + int mp3size=0,ret,i,ch,mf_needed; + + /* some sanity checks */ + assert(ENCDELAY>=MDCTDELAY); + assert(BLKSIZE-FFTOFFSET >= 0); + mf_needed = BLKSIZE+gfp->framesize-FFTOFFSET; + assert(MFSIZE>=mf_needed); + + if (gfp->num_channels == 1) { + return lame_encode_buffer(gfp,buffer, NULL ,nsamples,mp3buf,mp3buf_size); + } + + if (gfp->resample_ratio!=1) { + short int *buffer_l; + short int *buffer_r; + buffer_l=malloc(sizeof(short int)*nsamples); + buffer_r=malloc(sizeof(short int)*nsamples); + if (buffer_l == NULL || buffer_r == NULL) { + return -1; + } + for (i=0; i<nsamples; i++) { + buffer_l[i]=buffer[2*i]; + buffer_r[i]=buffer[2*i+1]; + } + ret = lame_encode_buffer(gfp,buffer_l,buffer_r,nsamples,mp3buf,mp3buf_size); + free(buffer_l); + free(buffer_r); + return ret; + } + + + if (gfp->frameNum==0 && !frame_buffered) { + memset((char *) mfbuf, 0, sizeof(mfbuf)); + frame_buffered=1; + mf_samples_to_encode = ENCDELAY+288; + mf_size=ENCDELAY-MDCTDELAY; /* we pad input with this many 0's */ + } + if (gfp->frameNum==1) { + /* reset, for the next time frameNum==0 */ + frame_buffered=0; + } + + if (gfp->num_channels==2 && gfp->stereo==1) { + /* downsample to mono */ + for (i=0; i<nsamples; ++i) { + buffer[2*i]=((int)buffer[2*i]+(int)buffer[2*i+1])/2; + buffer[2*i+1]=0; + } + } + + + while (nsamples > 0) { + int n_out; + /* copy in new samples */ + n_out = Min(gfp->framesize,nsamples); + for (i=0; i<n_out; ++i) { + mfbuf[0][mf_size+i]=buffer[2*i]; + mfbuf[1][mf_size+i]=buffer[2*i+1]; + } + buffer += 2*n_out; + + nsamples -= n_out; + mf_size += n_out; + assert(mf_size<=MFSIZE); + mf_samples_to_encode += n_out; + + if (mf_size >= mf_needed) { + /* encode the frame */ + ret = lame_encode_frame(gfp,mfbuf[0],mfbuf[1],mf_size,mp3buf,mp3buf_size); + if (ret == -1) { + /* fatel error: mp3buffer was too small */ + return -1; + } + mp3buf += ret; + mp3size += ret; + + /* shift out old samples */ + mf_size -= gfp->framesize; + mf_samples_to_encode -= gfp->framesize; + for (ch=0; ch<gfp->stereo; ch++) + for (i=0; i<mf_size; i++) + mfbuf[ch][i]=mfbuf[ch][i+gfp->framesize]; + } + } + assert(nsamples==0); + return mp3size; + } + + + + + + + + + + + + + + + /* old LAME interface */ + /* With this interface, it is the users responsibilty to keep track of the + * buffered, unencoded samples. Thus mf_samples_to_encode is not incremented. + * + * lame_encode() is also used to flush the PCM input buffer by + * lame_encode_finish() + */ + int lame_encode(lame_global_flags *gfp, short int in_buffer[2][1152],char *mp3buf,int size){ + int imp3,save; + save = mf_samples_to_encode; + imp3= lame_encode_buffer(gfp,in_buffer[0],in_buffer[1],576*gfp->mode_gr, + mp3buf,size); + mf_samples_to_encode = save; + return imp3; + } + + + + + /* initialize mp3 encoder */ + void lame_init(lame_global_flags *gfp) + { + + /* + * Disable floating point exepctions + */ + #ifdef __FreeBSD__ + # include <floatingpoint.h> + { + /* seet floating point mask to the Linux default */ + fp_except_t mask; + mask=fpgetmask(); + /* if bit is set, we get SIGFPE on that error! */ + fpsetmask(mask & ~(FP_X_INV|FP_X_DZ)); + /* fprintf(stderr,"FreeBSD mask is 0x%x\n",mask); */ + } + #endif + #if defined(__riscos__) && !defined(ABORTFP) + /* Disable FPE's under RISC OS */ + /* if bit is set, we disable trapping that error! */ + /* _FPE_IVO : invalid operation */ + /* _FPE_DVZ : divide by zero */ + /* _FPE_OFL : overflow */ + /* _FPE_UFL : underflow */ + /* _FPE_INX : inexact */ + DisableFPETraps( _FPE_IVO | _FPE_DVZ | _FPE_OFL ); + #endif + + + /* + * Debugging stuff + * The default is to ignore FPE's, unless compiled with -DABORTFP + * so add code below to ENABLE FPE's. + */ + + #if defined(ABORTFP) && !defined(__riscos__) + #if defined(_MSC_VER) + { + #include <float.h> + unsigned int mask; + mask=_controlfp( 0, 0 ); + mask&=~(_EM_OVERFLOW|_EM_UNDERFLOW|_EM_ZERODIVIDE|_EM_INVALID); + mask=_controlfp( mask, _MCW_EM ); + } + #elif defined(__CYGWIN__) + # define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw)) + # define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw)) + + # define _EM_INEXACT 0x00000001 /* inexact (precision) */ + # define _EM_UNDERFLOW 0x00000002 /* underflow */ + # define _EM_OVERFLOW 0x00000004 /* overflow */ + # define _EM_ZERODIVIDE 0x00000008 /* zero divide */ + # define _EM_INVALID 0x00000010 /* invalid */ + { + unsigned int mask; + _FPU_GETCW(mask); + /* Set the FPU control word to abort on most FPEs */ + mask &= ~(_EM_UNDERFLOW | _EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID); + _FPU_SETCW(mask); + } + # else + { + # include <fpu_control.h> + #ifndef _FPU_GETCW + #define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw)) + #endif + #ifndef _FPU_SETCW + #define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw)) + #endif + unsigned int mask; + _FPU_GETCW(mask); + /* Set the Linux mask to abort on most FPE's */ + /* if bit is set, we _mask_ SIGFPE on that error! */ + /* mask &= ~( _FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM );*/ + mask &= ~( _FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM ); + _FPU_SETCW(mask); + } + #endif + #endif /* ABORTFP && !__riscos__ */ + + + + /* Global flags. set defaults here */ + gfp->allow_diff_short=0; + gfp->ATHonly=0; + gfp->noATH=0; + gfp->bWriteVbrTag=1; + gfp->cwlimit=0; + gfp->disable_reservoir=0; + gfp->experimentalX = 0; + gfp->experimentalY = 0; + gfp->experimentalZ = 0; + gfp->frameNum=0; + gfp->gtkflag=0; + gfp->quality=5; + gfp->input_format=sf_unknown; + + gfp->filter_type=0; + gfp->lowpassfreq=0; + gfp->highpassfreq=0; + gfp->lowpasswidth=-1; + gfp->highpasswidth=-1; + gfp->lowpass1=0; + gfp->lowpass2=0; + gfp->highpass1=0; + gfp->highpass2=0; + gfp->lowpass_band=32; + gfp->highpass_band=-1; + + gfp->no_short_blocks=0; + gfp->resample_ratio=1; + gfp->padding_type=2; + gfp->padding=0; + gfp->swapbytes=0; + gfp->silent=0; + gfp->totalframes=0; + gfp->VBR=0; + gfp->VBR_q=4; + gfp->VBR_min_bitrate_kbps=0; + gfp->VBR_max_bitrate_kbps=0; + gfp->VBR_min_bitrate=1; + gfp->VBR_max_bitrate=13; + + + gfp->version = 1; /* =1 Default: MPEG-1 */ + gfp->mode = MPG_MD_JOINT_STEREO; + gfp->mode_fixed=0; + gfp->force_ms=0; + gfp->brate=0; + gfp->copyright=0; + gfp->original=1; + gfp->extension=0; + gfp->error_protection=0; + gfp->emphasis=0; + gfp->in_samplerate=1000*44.1; + gfp->out_samplerate=0; + gfp->num_channels=2; + gfp->num_samples=MAX_U_32_NUM; + + gfp->inPath=NULL; + gfp->outPath=NULL; + id3tag.used=0; + + } + + + + /*****************************************************************/ + /* flush internal mp3 buffers, */ + /*****************************************************************/ + int lame_encode_finish(lame_global_flags *gfp,char *mp3buffer, int mp3buffer_size) + { + int imp3,mp3count,mp3buffer_size_remaining; + short int buffer[2][1152]; + memset((char *)buffer,0,sizeof(buffer)); + mp3count = 0; + + while (mf_samples_to_encode > 0) { + + mp3buffer_size_remaining = mp3buffer_size - mp3count; + /* if user specifed buffer size = 0, dont check size */ + if (mp3buffer_size == 0) mp3buffer_size_remaining=0; + imp3=lame_encode(gfp,buffer,mp3buffer,mp3buffer_size_remaining); + + if (imp3 == -1) { + /* fatel error: mp3buffer too small */ + desalloc_buffer(&bs); /* Deallocate all buffers */ + return -1; + } + mp3buffer += imp3; + mp3count += imp3; + mf_samples_to_encode -= gfp->framesize; + } + + + gfp->frameNum--; + if (!gfp->gtkflag && !gfp->silent) { + timestatus(gfp->out_samplerate,gfp->frameNum,gfp->totalframes,gfp->framesize); + #ifdef BRHIST + if (disp_brhist) + { + brhist_add_count(); + brhist_disp(); + brhist_disp_total(gfp); + } + #endif + fprintf(stderr,"\n"); + fflush(stderr); + } + + + III_FlushBitstream(); + mp3buffer_size_remaining = mp3buffer_size - mp3count; + /* if user specifed buffer size = 0, dont check size */ + if (mp3buffer_size == 0) mp3buffer_size_remaining=0; + + imp3= copy_buffer(mp3buffer,mp3buffer_size_remaining,&bs); + if (imp3 == -1) { + /* fatel error: mp3buffer too small */ + desalloc_buffer(&bs); /* Deallocate all buffers */ + return -1; + } + + mp3count += imp3; + desalloc_buffer(&bs); /* Deallocate all buffers */ + return mp3count; + } + + + /*****************************************************************/ + /* write VBR Xing header, and ID3 tag, if asked for */ + /*****************************************************************/ + void lame_mp3_tags(lame_global_flags *gfp) + { + if (gfp->bWriteVbrTag) + { + /* Calculate relative quality of VBR stream + * 0=best, 100=worst */ + int nQuality=gfp->VBR_q*100/9; + /* Write Xing header again */ + PutVbrTag(gfp->outPath,nQuality,1-gfp->version); + } + + + /* write an ID3 tag */ + if(id3tag.used) { + id3_buildtag(&id3tag); + id3_writetag(gfp->outPath, &id3tag); + } + } + + + void lame_version(lame_global_flags *gfp,char *ostring) { + strncpy(ostring,get_lame_version(),20); + } + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/lame.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/lame.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/lame.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,336 ---- + /* + * Interface to MP3 LAME encoding engine + * + * Copyright (c) 1999 Mark Taylor + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + */ + #ifndef LAME_H_INCLUDE + #define LAME_H_INCLUDE + #include <stdio.h> + + /* maximum size of mp3buffer needed if you encode at most 1152 samples for + each call to lame_encode_buffer. see lame_encode_buffer() below */ + #define LAME_MAXMP3BUFFER 16384 + + + typedef enum sound_file_format_e { + sf_unknown, sf_wave, sf_aiff, sf_mp3, sf_raw + } sound_file_format; + + + /*********************************************************************** + * + * Global Variables. + * + * substantiated in lame.c + * + * Initilized and default values set by gf=lame_init() + * gf is a pointer to this struct, which the user may use to + * override any of the default values + * + * a call to lame_set_params() is also needed + * + ***********************************************************************/ + typedef struct { + /* input file description */ + unsigned long num_samples; /* number of samples. default=2^32-1 */ + int num_channels; /* input number of channels. default=2 */ + int in_samplerate; /* input_samp_rate. default=44.1kHz */ + int out_samplerate; /* output_samp_rate. (usually determined automatically) */ + + + /* general control params */ + int gtkflag; /* run frame analyzer? */ + int bWriteVbrTag; /* add Xing VBR tag? */ + int quality; /* quality setting 0=best, 9=worst */ + int silent; /* disable some status output */ + int mode; /* 0,1,2,3 stereo,jstereo,dual channel,mono */ + int mode_fixed; /* use specified the mode, do not use lame's opinion of the best mode */ + int force_ms; /* force M/S mode. requires mode=1 */ + int brate; /* bitrate */ + + /* frame params */ + int copyright; /* mark as copyright. default=0 */ + int original; /* mark as original. default=1 */ + int error_protection; /* use 2 bytes per frame for a CRC checksum. default=0*/ + int padding_type; /* 0=no padding, 1=always pad, 2=adjust padding */ + int extension; /* the MP3 'private extension' bit. meaningless */ + + /* quantization/noise shaping */ + int disable_reservoir; /* use bit reservoir? */ + int experimentalX; + int experimentalY; + int experimentalZ; + + /* VBR control */ + int VBR; + int VBR_q; + int VBR_min_bitrate_kbps; + int VBR_max_bitrate_kbps; + + + /* resampling and filtering */ + int lowpassfreq; /* freq in Hz. 0=lame choses. -1=no filter */ + int highpassfreq; /* freq in Hz. 0=lame choses. -1=no filter */ + int lowpasswidth; /* freq width of filter, in Hz (default=15%)*/ + int highpasswidth; /* freq width of filter, in Hz (default=15%)*/ + + + /* input file reading - not used if calling program does the i/o */ + sound_file_format input_format; + int swapbytes; /* force byte swapping default=0*/ + char *inPath; /* name of input file */ + char *outPath; /* name of output file. */ + /* Note: outPath must be set if you want Xing VBR or id3 tags + * written */ + + + /* psycho acoustics and other aguments which you should not change + * unless you know what you are doing */ + int ATHonly; /* only use ATH */ + int noATH; /* disable ATH */ + float cwlimit; /* predictability limit */ + int allow_diff_short; /* allow blocktypes to differ between channels ? */ + int no_short_blocks; /* disable short blocks */ + int emphasis; /* obsolete */ + + + + /********************************************************************/ + /* internal variables NOT set by calling program, and should not be */ + /* modified by the calling program */ + /********************************************************************/ + long int frameNum; /* frame counter */ + long totalframes; /* frames: 0..totalframes-1 (estimate)*/ + int encoder_delay; + int framesize; + int version; /* 0=MPEG2 1=MPEG1 */ + int padding; /* padding for the current frame? */ + int mode_gr; /* granules per frame */ + int stereo; /* number of channels */ + int VBR_min_bitrate; /* min bitrate index */ + int VBR_max_bitrate; /* max bitrate index */ + float resample_ratio; /* input_samp_rate/output_samp_rate */ + int bitrate_index; + int samplerate_index; + int mode_ext; + + /* lowpass and highpass filter control */ + float lowpass1,lowpass2; /* normalized frequency bounds of passband */ + float highpass1,highpass2; /* normalized frequency bounds of passband */ + + /* polyphase filter (filter_type=0) */ + int lowpass_band; /* zero bands >= lowpass_band in the polyphase filterbank */ + int highpass_band; /* zero bands <= highpass_band */ + + + + int filter_type; /* 0=polyphase filter, 1= FIR filter 2=MDCT filter(bad)*/ + int quantization; /* 0 = ISO formual, 1=best amplitude */ + int noise_shaping; /* 0 = none + 1 = ISO AAC model + 2 = allow scalefac_select=1 + */ + + int noise_shaping_stop; /* 0 = stop at over=0, all scalefacs amplified or + a scalefac has reached max value + 1 = stop when all scalefacs amplified or + a scalefac has reached max value + 2 = stop when all scalefacs amplified + */ + + int psymodel; /* 0 = none 1=gpsycho */ + int use_best_huffman; /* 0 = no. 1=outside loop 2=inside loop(slow) */ + + + } lame_global_flags; + + + + + + + /* + + The LAME API + + */ + + + /* REQUIRED: initialize the encoder. sets default for all encoder paramters, + * returns pointer to encoder parameters listed above + */ + void lame_init(lame_global_flags *); + + + + + /********************************************************************* + * command line argument parsing & option setting. Only supported + * if libmp3lame compiled with LAMEPARSE defined + *********************************************************************/ + /* OPTIONAL: call this to print an error with a brief command line usage guide and quit + * only supported if libmp3lame compiled with LAMEPARSE defined. + */ + void lame_usage(lame_global_flags *, char *); + + /* OPTIONAL: call this to print a command line interface usage guide and quit */ + void lame_help(lame_global_flags *, char *); + + /* OPTIONAL: get the version number, in a string. of the form: "3.63 (beta)" or + just "3.63". Max allows length is 20 characters */ + void lame_version(lame_global_flags *, char *); + + + /* OPTIONAL: set internal options via command line argument parsing + * You can skip this call if you like the default values, or if + * set the encoder parameters your self + */ + void lame_parse_args(lame_global_flags *, int argc, char **argv); + + + + + + /* REQUIRED: sets more internal configuration based on data provided + * above + */ + void lame_init_params(lame_global_flags *); + + + /* OPTONAL: print internal lame configuration on stderr*/ + void lame_print_config(lame_global_flags *); + + + + + /* input pcm data, output (maybe) mp3 frames. + * This routine handles all buffering, resampling and filtering for you. + * + * leftpcm[] array of 16bit pcm data, left channel + * rightpcm[] array of 16bit pcm data, right channel + * num_samples number of samples in leftpcm[] and rightpcm[] (if stereo) + * mp3buffer pointer to buffer where mp3 output is written + * mp3buffer_size size of mp3buffer, in bytes + * return code number of bytes output in mp3buffer. can be 0 + * if return code = -1: mp3buffer was too small + * + * The required mp3buffer_size can be computed from num_samples, + * samplerate and encoding rate, but here is a worst case estimate: + * + * mp3buffer_size in bytes = 1.25*num_samples + 7200 + * + * I think a tighter bound could be: (mt, March 2000) + * MPEG1: + * num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512 + * MPEG2: + * num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256 + * + * but test first if you use that! + * + * set mp3buffer_size = 0 and LAME will not check if mp3buffer_size is + * large enough. + * + * NOTE: if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels + * will be averaged into the L channel before encoding only the L channel + * This will overwrite the data in leftpcm[] and rightpcm[]. + * + */ + int lame_encode_buffer(lame_global_flags *,short int leftpcm[], short int rightpcm[],int num_samples, + char *mp3buffer,int mp3buffer_size); + + /* as above, but input has L & R channel data interleaved. Note: + * num_samples = number of samples in the L (or R) + * channel, not the total number of samples in pcm[] + */ + int lame_encode_buffer_interleaved(lame_global_flags *,short int pcm[], + int num_samples, char *mp3buffer,int mp3buffer_size); + + + + /* input 1 pcm frame, output (maybe) 1 mp3 frame. + * return code = number of bytes output in mp3buffer. can be 0 + * NOTE: this interface is outdated, please use lame_encode_buffer() instead + * declair mp3buffer with: char mp3buffer[LAME_MAXMP3BUFFER] + * if return code = -1: mp3buffer was too small + */ + int lame_encode(lame_global_flags *,short int Buffer[2][1152],char *mp3buffer,int mp3buffer_size); + + + + /* REQUIRED: lame_encode_finish will flush the buffers and may return a + * final few mp3 frames. mp3buffer should be at least 7200 bytes. + * + * return code = number of bytes output to mp3buffer. can be 0 + */ + int lame_encode_finish(lame_global_flags *,char *mp3buffer, int size); + + + /* OPTIONAL: lame_mp3_tags will append id3 and Xing VBR tags to + the mp3 file with name given by gf->outPath. These calls open the file, + write tags, and close the file, so make sure the the encoding is finished + before calling these routines. + Note: if VBR and id3 tags are turned off by the user, or turned off + by LAME because the output is not a regular file, this call does nothing + */ + void lame_mp3_tags(lame_global_flags *); + + + + + /********************************************************************* + * lame file i/o. Only supported + * if libmp3lame compiled with LAMESNDFILE or LIBSNDFILE + *********************************************************************/ + /* OPTIONAL: open the input file, and parse headers if possible + * you can skip this call if you will do your own PCM input + */ + void lame_init_infile(lame_global_flags *); + + /* OPTIONAL: read one frame of PCM data from audio input file opened by + * lame_init_infile. Input file can be wav, aiff, raw pcm, anything + * supported by libsndfile, or an mp3 file + */ + int lame_readframe(lame_global_flags *,short int Buffer[2][1152]); + + /* OPTIONAL: close the sound input file if lame_init_infile() was used */ + void lame_close_infile(lame_global_flags *); + + + + + + /********************************************************************* + * a simple interface to mpglib, part of mpg123, is also included if + * libmp3lame is compiled with HAVEMPGLIB + * input 1 mp3 frame, output (maybe) 1 pcm frame. + * lame_decode return code: -1: error. 0: need more data. n>0: size of pcm output + *********************************************************************/ + int lame_decode_init(void); + int lame_decode(char *mp3buf,int len,short pcm_l[],short pcm_r[]); + /* read mp3 file until mpglib returns one frame of PCM data */ + #ifdef AMIGA_MPEGA + int lame_decode_initfile(const char *fullname,int *stereo,int *samp,int *bitrate, unsigned long *nsamp); + int lame_decode_fromfile(FILE *fd,short int pcm_l[], short int pcm_r[]); + #else + int lame_decode_initfile(FILE *fd,int *stereo,int *samp,int *bitrate, unsigned long *nsamp); + int lame_decode_fromfile(FILE *fd,short int pcm_l[],short int pcm_r[]); + #endif + + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/large.wav Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/layer3.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/layer3.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/layer3.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,1738 ---- + #ifdef HAVEMPGLIB + /* + * Mpeg Layer-3 audio decoder + * -------------------------- + * copyright (c) 1995,1996,1997 by Michael Hipp. + * All rights reserved. See also 'README' + */ + + #include <stdlib.h> + #include "mpg123.h" + #include "mpglib.h" + #include "huffman.h" + #ifdef HAVEGTK + #include "../gtkanal.h" + #endif + + extern struct mpstr *gmp; + + #define MPEG1 + + + static real ispow[8207]; + static real aa_ca[8],aa_cs[8]; + static real COS1[12][6]; + static real win[4][36]; + static real win1[4][36]; + static real gainpow2[256+118+4]; + static real COS9[9]; + static real COS6_1,COS6_2; + static real tfcos36[9]; + static real tfcos12[3]; + + struct bandInfoStruct { + short longIdx[23]; + short longDiff[22]; + short shortIdx[14]; + short shortDiff[13]; + }; + + int longLimit[9][23]; + int shortLimit[9][14]; + + struct bandInfoStruct bandInfo[9] = { + + /* MPEG 1.0 */ + { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576}, + {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158}, + {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3}, + {4,4,4,4,6,8,10,12,14,18,22,30,56} } , + + { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576}, + {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192}, + {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3}, + {4,4,4,4,6,6,10,12,14,16,20,26,66} } , + + { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} , + {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} , + {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} , + {4,4,4,4,6,8,12,16,20,26,34,42,12} } , + + /* MPEG 2.0 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } , + {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} , + {4,4,4,6,6,8,10,14,18,26,32,42,18 } } , + /* docs: 332. mpg123: 330 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576}, + {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } , + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} , + {4,4,4,6,8,10,12,14,18,24,32,44,12 } } , + + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 }, + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3}, + {4,4,4,6,8,10,12,14,18,24,30,40,18 } } , + /* MPEG 2.5 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}, + {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2}, + {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576}, + {8,8,8,12,16,20,24,28,36,2,2,2,26} } , + }; + + static int mapbuf0[9][152]; + static int mapbuf1[9][156]; + static int mapbuf2[9][44]; + static int *map[9][3]; + static int *mapend[9][3]; + + static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ + static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ + + static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16]; + static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16]; + + static unsigned int get1bit(void) + { + unsigned char rval; + rval = *wordpointer << bitindex; + + bitindex++; + wordpointer += (bitindex>>3); + bitindex &= 7; + + return rval>>7; + } + + + + + /* + * init tables for layer-3 + */ + void init_layer3(int down_sample_sblimit) + { + int i,j,k,l; + + for(i=-256;i<118+4;i++) + gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) ); + + for(i=0;i<8207;i++) + ispow[i] = pow((double)i,(double)4.0/3.0); + + for (i=0;i<8;i++) + { + static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037}; + double sq=sqrt(1.0+Ci[i]*Ci[i]); + aa_cs[i] = 1.0/sq; + aa_ca[i] = Ci[i]/sq; + } + + for(i=0;i<18;i++) + { + win[0][i] = win[1][i] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 ); + win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); + } + for(i=0;i<6;i++) + { + win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); + win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 ); + win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 ); + win[1][i+30] = win[3][i] = 0.0; + win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 ); + } + + for(i=0;i<9;i++) + COS9[i] = cos( M_PI / 18.0 * (double) i); + + for(i=0;i<9;i++) + tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 ); + for(i=0;i<3;i++) + tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 ); + + COS6_1 = cos( M_PI / 6.0 * (double) 1); + COS6_2 = cos( M_PI / 6.0 * (double) 2); + + for(i=0;i<12;i++) + { + win[2][i] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 ); + for(j=0;j<6;j++) + COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) ); + } + + for(j=0;j<4;j++) { + static int len[4] = { 36,36,12,36 }; + for(i=0;i<len[j];i+=2) + win1[j][i] = + win[j][i]; + for(i=1;i<len[j];i+=2) + win1[j][i] = - win[j][i]; + } + + for(i=0;i<16;i++) + { + double t = tan( (double) i * M_PI / 12.0 ); + tan1_1[i] = t / (1.0+t); + tan2_1[i] = 1.0 / (1.0 + t); + tan1_2[i] = M_SQRT2 * t / (1.0+t); + tan2_2[i] = M_SQRT2 / (1.0 + t); + + for(j=0;j<2;j++) { + double base = pow(2.0,-0.25*(j+1.0)); + double p1=1.0,p2=1.0; + if(i > 0) { + if( i & 1 ) + p1 = pow(base,(i+1.0)*0.5); + else + p2 = pow(base,i*0.5); + } + pow1_1[j][i] = p1; + pow2_1[j][i] = p2; + pow1_2[j][i] = M_SQRT2 * p1; + pow2_2[j][i] = M_SQRT2 * p2; + } + } + + for(j=0;j<9;j++) + { + struct bandInfoStruct *bi = &bandInfo[j]; + int *mp; + int cb,lwin; + short *bdf; + + mp = map[j][0] = mapbuf0[j]; + bdf = bi->longDiff; + for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) { + *mp++ = (*bdf) >> 1; + *mp++ = i; + *mp++ = 3; + *mp++ = cb; + } + bdf = bi->shortDiff+3; + for(cb=3;cb<13;cb++) { + int l = (*bdf++) >> 1; + for(lwin=0;lwin<3;lwin++) { + *mp++ = l; + *mp++ = i + lwin; + *mp++ = lwin; + *mp++ = cb; + } + i += 6*l; + } + mapend[j][0] = mp; + + mp = map[j][1] = mapbuf1[j]; + bdf = bi->shortDiff+0; + for(i=0,cb=0;cb<13;cb++) { + int l = (*bdf++) >> 1; + for(lwin=0;lwin<3;lwin++) { + *mp++ = l; + *mp++ = i + lwin; + *mp++ = lwin; + *mp++ = cb; + } + i += 6*l; + } + mapend[j][1] = mp; + + mp = map[j][2] = mapbuf2[j]; + bdf = bi->longDiff; + for(cb = 0; cb < 22 ; cb++) { + *mp++ = (*bdf++) >> 1; + *mp++ = cb; + } + mapend[j][2] = mp; + + } + + for(j=0;j<9;j++) { + for(i=0;i<23;i++) { + longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1; + if(longLimit[j][i] > (down_sample_sblimit) ) + longLimit[j][i] = down_sample_sblimit; + } + for(i=0;i<14;i++) { + shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1; + if(shortLimit[j][i] > (down_sample_sblimit) ) + shortLimit[j][i] = down_sample_sblimit; + } + } + + for(i=0;i<5;i++) { + for(j=0;j<6;j++) { + for(k=0;k<6;k++) { + int n = k + j * 6 + i * 36; + i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12); + } + } + } + for(i=0;i<4;i++) { + for(j=0;j<4;j++) { + for(k=0;k<4;k++) { + int n = k + j * 4 + i * 16; + i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12); + } + } + } + for(i=0;i<4;i++) { + for(j=0;j<3;j++) { + int n = j + i * 3; + i_slen2[n+244] = i|(j<<3) | (5<<12); + n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15); + } + } + + for(i=0;i<5;i++) { + for(j=0;j<5;j++) { + for(k=0;k<4;k++) { + for(l=0;l<4;l++) { + int n = l + k * 4 + j * 16 + i * 80; + n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12); + } + } + } + } + for(i=0;i<5;i++) { + for(j=0;j<5;j++) { + for(k=0;k<4;k++) { + int n = k + j * 4 + i * 20; + n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12); + } + } + } + } + + /* + * read additional side information + */ + #ifdef MPEG1 + static void III_get_side_info_1(struct III_sideinfo *si,int stereo, + int ms_stereo,long sfreq,int single) + { + int ch, gr; + int powdiff = (single == 3) ? 4 : 0; + + si->main_data_begin = getbits(9); + if (stereo == 1) + si->private_bits = getbits_fast(5); + else + si->private_bits = getbits_fast(3); + + for (ch=0; ch<stereo; ch++) { + si->ch[ch].gr[0].scfsi = -1; + si->ch[ch].gr[1].scfsi = getbits_fast(4); + } + + for (gr=0; gr<2; gr++) + { + for (ch=0; ch<stereo; ch++) + { + register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]); + + gr_info->part2_3_length = getbits(12); + gr_info->big_values = getbits_fast(9); + if(gr_info->big_values > 288) { + fprintf(stderr,"big_values too large!\n"); + gr_info->big_values = 288; + } + { + unsigned int qss = getbits_fast(8); + gr_info->pow2gain = gainpow2+256 - qss + powdiff; + #ifdef HAVEGTK + if (gtkflag) { + pinfo->qss[gr][ch]=qss; + pinfo->big_values[gr][ch]=gr_info->big_values; + } + #endif + } + if(ms_stereo) + gr_info->pow2gain += 2; + gr_info->scalefac_compress = getbits_fast(4); + /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */ + if(get1bit()) + { + int i; + gr_info->block_type = getbits_fast(2); + gr_info->mixed_block_flag = get1bit(); + gr_info->table_select[0] = getbits_fast(5); + gr_info->table_select[1] = getbits_fast(5); + + + /* + * table_select[2] not needed, because there is no region2, + * but to satisfy some verifications tools we set it either. + */ + gr_info->table_select[2] = 0; + for(i=0;i<3;i++) { + unsigned int sbg = (getbits_fast(3)<<3); + gr_info->full_gain[i] = gr_info->pow2gain + sbg; + #ifdef HAVEGTK + if (gtkflag) + pinfo->sub_gain[gr][ch][i]=sbg/8; + #endif + } + + + if(gr_info->block_type == 0) { + fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n"); + exit(1); + } + /* region_count/start parameters are implicit in this case. */ + gr_info->region1start = 36>>1; + gr_info->region2start = 576>>1; + } + else + { + int i,r0c,r1c; + for (i=0; i<3; i++) + gr_info->table_select[i] = getbits_fast(5); + r0c = getbits_fast(4); + r1c = getbits_fast(3); + gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; + gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; + gr_info->block_type = 0; + gr_info->mixed_block_flag = 0; + } + gr_info->preflag = get1bit(); + gr_info->scalefac_scale = get1bit(); + gr_info->count1table_select = get1bit(); + #ifdef HAVEGTK + if (gtkflag) + pinfo->scalefac_scale[gr][ch]=gr_info->scalefac_scale; + #endif + } + } + } + #endif + + /* + * Side Info for MPEG 2.0 / LSF + */ + static void III_get_side_info_2(struct III_sideinfo *si,int stereo, + int ms_stereo,long sfreq,int single) + { + int ch; + int powdiff = (single == 3) ? 4 : 0; + + si->main_data_begin = getbits(8); + if (stereo == 1) + si->private_bits = get1bit(); + else + si->private_bits = getbits_fast(2); + + for (ch=0; ch<stereo; ch++) + { + register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]); + unsigned int qss; + + gr_info->part2_3_length = getbits(12); + gr_info->big_values = getbits_fast(9); + if(gr_info->big_values > 288) { + fprintf(stderr,"big_values too large!\n"); + gr_info->big_values = 288; + } + qss=getbits_fast(8); + gr_info->pow2gain = gainpow2+256 - qss + powdiff; + #ifdef HAVEGTK + if (gtkflag) { + pinfo->qss[0][ch]=qss; + pinfo->big_values[0][ch]=gr_info->big_values; + } + #endif + + if(ms_stereo) + gr_info->pow2gain += 2; + gr_info->scalefac_compress = getbits(9); + /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */ + if(get1bit()) + { + int i; + gr_info->block_type = getbits_fast(2); + gr_info->mixed_block_flag = get1bit(); + gr_info->table_select[0] = getbits_fast(5); + gr_info->table_select[1] = getbits_fast(5); + /* + * table_select[2] not needed, because there is no region2, + * but to satisfy some verifications tools we set it either. + */ + gr_info->table_select[2] = 0; + for(i=0;i<3;i++) { + unsigned int sbg = (getbits_fast(3)<<3); + gr_info->full_gain[i] = gr_info->pow2gain + sbg; + #ifdef HAVEGTK + if (gtkflag) + pinfo->sub_gain[0][ch][i]=sbg/8; + #endif + } + + if(gr_info->block_type == 0) { + fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n"); + exit(1); + } + /* region_count/start parameters are implicit in this case. */ + /* check this again! */ + if(gr_info->block_type == 2) + gr_info->region1start = 36>>1; + else if(sfreq == 8) + /* check this for 2.5 and sfreq=8 */ + gr_info->region1start = 108>>1; + else + gr_info->region1start = 54>>1; + gr_info->region2start = 576>>1; + } + else + { + int i,r0c,r1c; + for (i=0; i<3; i++) + gr_info->table_select[i] = getbits_fast(5); + r0c = getbits_fast(4); + r1c = getbits_fast(3); + gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; + gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; + gr_info->block_type = 0; + gr_info->mixed_block_flag = 0; + } + gr_info->scalefac_scale = get1bit(); + gr_info->count1table_select = get1bit(); + #ifdef HAVEGTK + if (gtkflag) + pinfo->scalefac_scale[0][ch]=gr_info->scalefac_scale; + #endif + } + } + + /* + * read scalefactors + */ + #ifdef MPEG1 + static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info) + { + static unsigned char slen[2][16] = { + {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, + {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3} + }; + int numbits; + int num0 = slen[0][gr_info->scalefac_compress]; + int num1 = slen[1][gr_info->scalefac_compress]; + + if (gr_info->block_type == 2) + { + int i=18; + numbits = (num0 + num1) * 18; + + if (gr_info->mixed_block_flag) { + for (i=8;i;i--) + *scf++ = getbits_fast(num0); + i = 9; + numbits -= num0; /* num0 * 17 + num1 * 18 */ + } + + for (;i;i--) + *scf++ = getbits_fast(num0); + for (i = 18; i; i--) + *scf++ = getbits_fast(num1); + *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */ + } + else + { + int i; + int scfsi = gr_info->scfsi; + + if(scfsi < 0) { /* scfsi < 0 => granule == 0 */ + for(i=11;i;i--) + *scf++ = getbits_fast(num0); + for(i=10;i;i--) + *scf++ = getbits_fast(num1); + numbits = (num0 + num1) * 10 + num0; + } + else { + numbits = 0; + if(!(scfsi & 0x8)) { + for (i=6;i;i--) + *scf++ = getbits_fast(num0); + numbits += num0 * 6; + } + else { + scf += 6; + } + + if(!(scfsi & 0x4)) { + for (i=5;i;i--) + *scf++ = getbits_fast(num0); + numbits += num0 * 5; + } + else { + scf += 5; + } + + if(!(scfsi & 0x2)) { + for(i=5;i;i--) + *scf++ = getbits_fast(num1); + numbits += num1 * 5; + } + else { + scf += 5; + } + + if(!(scfsi & 0x1)) { + for (i=5;i;i--) + *scf++ = getbits_fast(num1); + numbits += num1 * 5; + } + else { + scf += 5; + } + } + + *scf++ = 0; /* no l[21] in original sources */ + } + return numbits; + } + #endif + + static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo) + { + unsigned char *pnt; + int i,j; + unsigned int slen; + int n = 0; + int numbits = 0; + + static unsigned char stab[3][6][4] = { + { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} , + { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } , + { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} , + {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } , + { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} , + { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } }; + + if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */ + slen = i_slen2[gr_info->scalefac_compress>>1]; + else + slen = n_slen2[gr_info->scalefac_compress]; + + gr_info->preflag = (slen>>15) & 0x1; + + n = 0; + if( gr_info->block_type == 2 ) { + n++; + if(gr_info->mixed_block_flag) + n++; + } + + pnt = stab[n][(slen>>12)&0x7]; + + for(i=0;i<4;i++) { + int num = slen & 0x7; + slen >>= 3; + if(num) { + for(j=0;j<(int)(pnt[i]);j++) + *scf++ = getbits_fast(num); + numbits += pnt[i] * num; + } + else { + for(j=0;j<(int)(pnt[i]);j++) + *scf++ = 0; + } + } + + n = (n << 1) + 1; + for(i=0;i<n;i++) + *scf++ = 0; + + return numbits; + } + + static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0}; + static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + + /* + * don't forget to apply the same changes to III_dequantize_sample_ms() !!! + */ + static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf, + struct gr_info_s *gr_info,int sfreq,int part2bits) + { + int shift = 1 + gr_info->scalefac_scale; + real *xrpnt = (real *) xr; + int l[3],l3; + int part2remain = gr_info->part2_3_length - part2bits; + int *me; + + { + int bv = gr_info->big_values; + int region1 = gr_info->region1start; + int region2 = gr_info->region2start; + + l3 = ((576>>1)-bv)>>1; + /* + * we may lose the 'odd' bit here !! + * check this later again + */ + if(bv <= region1) { + l[0] = bv; l[1] = 0; l[2] = 0; + } + else { + l[0] = region1; + if(bv <= region2) { + l[1] = bv - l[0]; l[2] = 0; + } + else { + l[1] = region2 - l[0]; l[2] = bv - region2; + } + } + } + + if(gr_info->block_type == 2) { + /* + * decoding with short or mixed mode BandIndex table + */ + int i,max[4]; + int step=0,lwin=0,cb=0; + register real v = 0.0; + register int *m,mc; + + if(gr_info->mixed_block_flag) { + max[3] = -1; + max[0] = max[1] = max[2] = 2; + m = map[sfreq][0]; + me = mapend[sfreq][0]; + } + else { + max[0] = max[1] = max[2] = max[3] = -1; + /* max[3] not really needed in this case */ + m = map[sfreq][1]; + me = mapend[sfreq][1]; + } + + mc = 0; + for(i=0;i<2;i++) { + int lp = l[i]; + struct newhuff *h = ht+gr_info->table_select[i]; + for(;lp;lp--,mc--) { + register int x,y; + if( (!mc) ) { + mc = *m++; + xrpnt = ((real *) xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) { + v = gr_info->pow2gain[(*scf++) << shift]; + step = 1; + } + else { + v = gr_info->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + { + register short *val = h->table; + while((y=*val++)<0) { + if (get1bit()) + val -= y; + part2remain--; + } + x = y >> 4; + y &= 0xf; + } + if(x == 15) { + max[lwin] = cb; + part2remain -= h->linbits+1; + x += getbits(h->linbits); + if(get1bit()) + *xrpnt = -ispow[x] * v; + else + *xrpnt = ispow[x] * v; + } + else if(x) { + max[lwin] = cb; + if(get1bit()) + *xrpnt = -ispow[x] * v; + else + *xrpnt = ispow[x] * v; + part2remain--; + } + else + *xrpnt = 0.0; + xrpnt += step; + if(y == 15) { + max[lwin] = cb; + part2remain -= h->linbits+1; + y += getbits(h->linbits); + if(get1bit()) + *xrpnt = -ispow[y] * v; + else + *xrpnt = ispow[y] * v; + } + else if(y) { + max[lwin] = cb; + if(get1bit()) + *xrpnt = -ispow[y] * v; + else + *xrpnt = ispow[y] * v; + part2remain--; + } + else + *xrpnt = 0.0; + xrpnt += step; + } + } + for(;l3 && (part2remain > 0);l3--) { + struct newhuff *h = htc+gr_info->count1table_select; + register short *val = h->table,a; + + while((a=*val++)<0) { + part2remain--; + if(part2remain < 0) { + part2remain++; + a = 0; + break; + } + if (get1bit()) + val -= a; + } + for(i=0;i<4;i++) { + if(!(i & 1)) { + if(!mc) { + mc = *m++; + xrpnt = ((real *) xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) { + v = gr_info->pow2gain[(*scf++) << shift]; + step = 1; + } + else { + v = gr_info->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + mc--; + } + if( (a & (0x8>>i)) ) { + max[lwin] = cb; + part2remain--; + if(part2remain < 0) { + part2remain++; + break; + } + if(get1bit()) + *xrpnt = -v; + else + *xrpnt = v; + } + else + *xrpnt = 0.0; + xrpnt += step; + } + } + + while( m < me ) { + if(!mc) { + mc = *m++; + xrpnt = ((real *) xr) + *m++; + if( (*m++) == 3) + step = 1; + else + step = 3; + m++; /* cb */ + } + mc--; + *xrpnt = 0.0; + xrpnt += step; + *xrpnt = 0.0; + xrpnt += step; + /* we could add a little opt. here: + * if we finished a band for window 3 or a long band + * further bands could copied in a simple loop without a + * special 'map' decoding + */ + } + + gr_info->maxband[0] = max[0]+1; + gr_info->maxband[1] = max[1]+1; + gr_info->maxband[2] = max[2]+1; + gr_info->maxbandl = max[3]+1; + + { + int rmax = max[0] > max[1] ? max[0] : max[1]; + rmax = (rmax > max[2] ? rmax : max[2]) + 1; + gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1]; + } + + } + else { + /* + * decoding with 'long' BandIndex table (block_type != 2) + */ + int *pretab = gr_info->preflag ? pretab1 : pretab2; + int i,max = -1; + int cb = 0; + register int *m = map[sfreq][2]; + register real v = 0.0; + register int mc = 0; + #if 0 + me = mapend[sfreq][2]; + #endif + + /* + * long hash table values + */ + for(i=0;i<3;i++) { + int lp = l[i]; + struct newhuff *h = ht+gr_info->table_select[i]; + + for(;lp;lp--,mc--) { + int x,y; + + if(!mc) { + mc = *m++; + v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; + cb = *m++; + } + { + register short *val = h->table; + while((y=*val++)<0) { + if (get1bit()) + val -= y; + part2remain--; + } + x = y >> 4; + y &= 0xf; + } + if (x == 15) { + max = cb; + part2remain -= h->linbits+1; + x += getbits(h->linbits); + if(get1bit()) + *xrpnt++ = -ispow[x] * v; + else + *xrpnt++ = ispow[x] * v; + } + else if(x) { + max = cb; + if(get1bit()) + *xrpnt++ = -ispow[x] * v; + else + *xrpnt++ = ispow[x] * v; + part2remain--; + } + else + *xrpnt++ = 0.0; + + if (y == 15) { + max = cb; + part2remain -= h->linbits+1; + y += getbits(h->linbits); + if(get1bit()) + *xrpnt++ = -ispow[y] * v; + else + *xrpnt++ = ispow[y] * v; + } + else if(y) { + max = cb; + if(get1bit()) + *xrpnt++ = -ispow[y] * v; + else + *xrpnt++ = ispow[y] * v; + part2remain--; + } + else + *xrpnt++ = 0.0; + } + } + + /* + * short (count1table) values + */ + for(;l3 && (part2remain > 0);l3--) { + struct newhuff *h = htc+gr_info->count1table_select; + register short *val = h->table,a; + + while((a=*val++)<0) { + part2remain--; + if(part2remain < 0) { + part2remain++; + a = 0; + break; + } + if (get1bit()) + val -= a; + } + for(i=0;i<4;i++) { + if(!(i & 1)) { + if(!mc) { + mc = *m++; + cb = *m++; + v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; + } + mc--; + } + if ( (a & (0x8>>i)) ) { + max = cb; + part2remain--; + if(part2remain < 0) { + part2remain++; + break; + } + if(get1bit()) + *xrpnt++ = -v; + else + *xrpnt++ = v; + } + else + *xrpnt++ = 0.0; + } + } + + /* + * zero part + */ + for(i=(&xr[SBLIMIT][0]-xrpnt)>>1;i;i--) { + *xrpnt++ = 0.0; + *xrpnt++ = 0.0; + } + + gr_info->maxbandl = max+1; + gr_info->maxb = longLimit[sfreq][gr_info->maxbandl]; + } + + while( part2remain > 16 ) { + getbits(16); /* Dismiss stuffing Bits */ + part2remain -= 16; + } + if(part2remain > 0) + getbits(part2remain); + else if(part2remain < 0) { + fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain); + return 1; /* -> error */ + } + return 0; + } + + + /* + * III_stereo: calculate real channel values for Joint-I-Stereo-mode + */ + static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, + struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf) + { + real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf; + struct bandInfoStruct *bi = &bandInfo[sfreq]; + real *tab1,*tab2; + + if(lsf) { + int p = gr_info->scalefac_compress & 0x1; + if(ms_stereo) { + tab1 = pow1_2[p]; tab2 = pow2_2[p]; + } + else { + tab1 = pow1_1[p]; tab2 = pow2_1[p]; + } + } + else { + if(ms_stereo) { + tab1 = tan1_2; tab2 = tan2_2; + } + else { + tab1 = tan1_1; tab2 = tan2_1; + } + } + + if (gr_info->block_type == 2) + { + int lwin,do_l = 0; + if( gr_info->mixed_block_flag ) + do_l = 1; + + for (lwin=0;lwin<3;lwin++) /* process each window */ + { + /* get first band with zero values */ + int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ + if(sfb > 3) + do_l = 0; + + for(;sfb<12;sfb++) + { + is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + sb = bi->shortDiff[sfb]; + idx = bi->shortIdx[sfb] + lwin; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for (; sb > 0; sb--,idx+=3) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } + + #if 1 + /* in the original: copy 10 to 11 , here: copy 11 to 12 + maybe still wrong??? (copy 12 to 13?) */ + is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ + sb = bi->shortDiff[12]; + idx = bi->shortIdx[12] + lwin; + #else + is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ + sb = bi->shortDiff[11]; + idx = bi->shortIdx[11] + lwin; + #endif + if(is_p != 7) + { + real t1,t2; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for ( ; sb > 0; sb--,idx+=3 ) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } /* end for(lwin; .. ; . ) */ + + if (do_l) + { + /* also check l-part, if ALL bands in the three windows are 'empty' + * and mode = mixed_mode + */ + int sfb = gr_info->maxbandl; + int idx = bi->longIdx[sfb]; + + for ( ; sfb<8; sfb++ ) + { + int sb = bi->longDiff[sfb]; + int is_p = scalefac[sfb]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for ( ; sb > 0; sb--,idx++) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + else + idx += sb; + } + } + } + else /* ((gr_info->block_type != 2)) */ + { + int sfb = gr_info->maxbandl; + int is_p,idx = bi->longIdx[sfb]; + for ( ; sfb<21; sfb++) + { + int sb = bi->longDiff[sfb]; + is_p = scalefac[sfb]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for ( ; sb > 0; sb--,idx++) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + else + idx += sb; + } + + is_p = scalefac[20]; /* copy l-band 20 to l-band 21 */ + if(is_p != 7) + { + int sb; + real t1 = tab1[is_p],t2 = tab2[is_p]; + + for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } /* ... */ + } + + static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) + { + int sblim; + + if(gr_info->block_type == 2) + { + if(!gr_info->mixed_block_flag) + return; + sblim = 1; + } + else { + sblim = gr_info->maxb-1; + } + + /* 31 alias-reduction operations between each pair of sub-bands */ + /* with 8 butterflies between each pair */ + + { + int sb; + real *xr1=(real *) xr[1]; + + for(sb=sblim;sb;sb--,xr1+=10) + { + int ss; + real *cs=aa_cs,*ca=aa_ca; + real *xr2 = xr1; + + for(ss=7;ss>=0;ss--) + { /* upper and lower butterfly inputs */ + register real bu = *--xr2,bd = *xr1; + *xr2 = (bu * (*cs) ) - (bd * (*ca) ); + *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) ); + } + } + } + } + + /* + DCT insipired by Jeff Tsay's DCT from the maplay package + this is an optimized version with manual unroll. + + References: + [1] S. Winograd: "On Computing the Discrete Fourier Transform", + Mathematics of Computation, Volume 32, Number 141, January 1978, + Pages 175-199 + */ + + static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf) + { + { + register real *in = inbuf; + + in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; + in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11]; + in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8]; + in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; + in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; + in[2] +=in[1]; in[1] +=in[0]; + + in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; + in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1]; + + + { + + #define MACRO0(v) { \ + real tmp; \ + out2[9+(v)] = (tmp = sum0 + sum1) * w[27+(v)]; \ + out2[8-(v)] = tmp * w[26-(v)]; } \ + sum0 -= sum1; \ + ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \ + ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; + #define MACRO1(v) { \ + real sum0,sum1; \ + sum0 = tmp1a + tmp2a; \ + sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \ + MACRO0(v); } + #define MACRO2(v) { \ + real sum0,sum1; \ + sum0 = tmp2a - tmp1a; \ + sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \ + MACRO0(v); } + + register const real *c = COS9; + register real *out2 = o2; + register real *w = wintab; + register real *out1 = o1; + register real *ts = tsbuf; + + real ta33,ta66,tb33,tb66; + + ta33 = in[2*3+0] * c[3]; + ta66 = in[2*6+0] * c[6]; + tb33 = in[2*3+1] * c[3]; + tb66 = in[2*6+1] * c[6]; + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7]; + tmp1b = in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7]; + tmp2a = in[2*0+0] + in[2*2+0] * c[2] + in[2*4+0] * c[4] + ta66 + in[2*8+0] * c[8]; + tmp2b = in[2*0+1] + in[2*2+1] * c[2] + in[2*4+1] * c[4] + tb66 + in[2*8+1] * c[8]; + + MACRO1(0); + MACRO2(8); + } + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = ( in[2*1+0] - in[2*5+0] - in[2*7+0] ) * c[3]; + tmp1b = ( in[2*1+1] - in[2*5+1] - in[2*7+1] ) * c[3]; + tmp2a = ( in[2*2+0] - in[2*4+0] - in[2*8+0] ) * c[6] - in[2*6+0] + in[2*0+0]; + tmp2b = ( in[2*2+1] - in[2*4+1] - in[2*8+1] ) * c[6] - in[2*6+1] + in[2*0+1]; + + MACRO1(1); + MACRO2(7); + } + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = in[2*1+0] * c[5] - ta33 - in[2*5+0] * c[7] + in[2*7+0] * c[1]; + tmp1b = in[2*1+1] * c[5] - tb33 - in[2*5+1] * c[7] + in[2*7+1] * c[1]; + tmp2a = in[2*0+0] - in[2*2+0] * c[8] - in[2*4+0] * c[2] + ta66 + in[2*8+0] * c[4]; + tmp2b = in[2*0+1] - in[2*2+1] * c[8] - in[2*4+1] * c[2] + tb66 + in[2*8+1] * c[4]; + + MACRO1(2); + MACRO2(6); + } + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = in[2*1+0] * c[7] - ta33 + in[2*5+0] * c[1] - in[2*7+0] * c[5]; + tmp1b = in[2*1+1] * c[7] - tb33 + in[2*5+1] * c[1] - in[2*7+1] * c[5]; + tmp2a = in[2*0+0] - in[2*2+0] * c[4] + in[2*4+0] * c[8] + ta66 - in[2*8+0] * c[2]; + tmp2b = in[2*0+1] - in[2*2+1] * c[4] + in[2*4+1] * c[8] + tb66 - in[2*8+1] * c[2]; + + MACRO1(3); + MACRO2(5); + } + + { + real sum0,sum1; + sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0]; + sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4]; + MACRO0(4); + } + } + + } + } + + /* + * new DCT12 + */ + static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts) + { + #define DCT12_PART1 \ + in5 = in[5*3]; \ + in5 += (in4 = in[4*3]); \ + in4 += (in3 = in[3*3]); \ + in3 += (in2 = in[2*3]); \ + in2 += (in1 = in[1*3]); \ + in1 += (in0 = in[0*3]); \ + \ + in5 += in3; in3 += in1; \ + \ + in2 *= COS6_1; \ + in3 *= COS6_1; \ + + #define DCT12_PART2 \ + in0 += in4 * COS6_2; \ + \ + in4 = in0 + in2; \ + in0 -= in2; \ + \ + in1 += in5 * COS6_2; \ + \ + in5 = (in1 + in3) * tfcos12[0]; \ + in1 = (in1 - in3) * tfcos12[2]; \ + \ + in3 = in4 + in5; \ + in4 -= in5; \ + \ + in2 = in0 + in1; \ + in0 -= in1; + + + { + real in0,in1,in2,in3,in4,in5; + register real *out1 = rawout1; + ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2]; + ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5]; + + DCT12_PART1 + + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = (in1 - in5) * tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1]; + ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1]; + ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1]; + ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1]; + } + + DCT12_PART2 + + ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0]; + ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0]; + ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2]; + ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2]; + + ts[(6+0)*SBLIMIT] = out1[6+0] + in0 * wi[0]; + ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0]; + ts[(6+2)*SBLIMIT] = out1[6+2] + in4 * wi[2]; + ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2]; + } + + in++; + + { + real in0,in1,in2,in3,in4,in5; + register real *out2 = rawout2; + + DCT12_PART1 + + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = (in1 - in5) * tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[5-1] = tmp0 * wi[11-1]; + out2[0+1] = tmp0 * wi[6+1]; + ts[(12+1)*SBLIMIT] += tmp1 * wi[1]; + ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1]; + } + + DCT12_PART2 + + out2[5-0] = in2 * wi[11-0]; + out2[0+0] = in2 * wi[6+0]; + out2[0+2] = in3 * wi[6+2]; + out2[5-2] = in3 * wi[11-2]; + + ts[(12+0)*SBLIMIT] += in0 * wi[0]; + ts[(17-0)*SBLIMIT] += in0 * wi[5-0]; + ts[(12+2)*SBLIMIT] += in4 * wi[2]; + ts[(17-2)*SBLIMIT] += in4 * wi[5-2]; + } + + in++; + + { + real in0,in1,in2,in3,in4,in5; + register real *out2 = rawout2; + out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0; + + DCT12_PART1 + + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = (in1 - in5) * tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[11-1] = tmp0 * wi[11-1]; + out2[6 +1] = tmp0 * wi[6+1]; + out2[0+1] += tmp1 * wi[1]; + out2[5-1] += tmp1 * wi[5-1]; + } + + DCT12_PART2 + + out2[11-0] = in2 * wi[11-0]; + out2[6 +0] = in2 * wi[6+0]; + out2[6 +2] = in3 * wi[6+2]; + out2[11-2] = in3 * wi[11-2]; + + out2[0+0] += in0 * wi[0]; + out2[5-0] += in0 * wi[5-0]; + out2[0+2] += in4 * wi[2]; + out2[5-2] += in4 * wi[5-2]; + } + } + + /* + * III_hybrid + */ + static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT], + int ch,struct gr_info_s *gr_info) + { + real *tspnt = (real *) tsOut; + real (*block)[2][SBLIMIT*SSLIMIT] = gmp->hybrid_block; + int *blc = gmp->hybrid_blc; + real *rawout1,*rawout2; + int bt; + int sb = 0; + + { + int b = blc[ch]; + rawout1=block[b][ch]; + b=-b+1; + rawout2=block[b][ch]; + blc[ch] = b; + } + + + if(gr_info->mixed_block_flag) { + sb = 2; + dct36(fsIn[0],rawout1,rawout2,win[0],tspnt); + dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1); + rawout1 += 36; rawout2 += 36; tspnt += 2; + } + + bt = gr_info->block_type; + if(bt == 2) { + for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { + dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt); + dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1); + } + } + else { + for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { + dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt); + dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1); + } + } + + for(;sb<SBLIMIT;sb++,tspnt++) { + int i; + for(i=0;i<SSLIMIT;i++) { + tspnt[i*SBLIMIT] = *rawout1++; + *rawout2++ = 0.0; + } + } + } + + /* + * main layer3 handler + */ + int do_layer3(struct frame *fr,unsigned char *pcm_sample,int *pcm_point) + { + int gr, ch, ss,clip=0; + int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ + struct III_sideinfo sideinfo; + int stereo = fr->stereo; + int single = fr->single; + int ms_stereo,i_stereo; + int sfreq = fr->sampling_frequency; + int stereo1,granules; + + + + if(stereo == 1) { /* stream is mono */ + stereo1 = 1; + single = 0; + } + else if(single >= 0) /* stream is stereo, but force to mono */ + stereo1 = 1; + else + stereo1 = 2; + + if(fr->mode == MPG_MD_JOINT_STEREO) { + ms_stereo = fr->mode_ext & 0x2; + i_stereo = fr->mode_ext & 0x1; + } + else + ms_stereo = i_stereo = 0; + + + if(fr->lsf) { + granules = 1; + III_get_side_info_2(&sideinfo,stereo,ms_stereo,sfreq,single); + } + else { + granules = 2; + #ifdef MPEG1 + III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single); + #else + fprintf(stderr,"Not supported\n"); + #endif + } + + if(set_pointer(sideinfo.main_data_begin) == MP3_ERR) + return 0; + + + for (gr=0;gr<granules;gr++) + { + static real hybridIn[2][SBLIMIT][SSLIMIT]; + static real hybridOut[2][SSLIMIT][SBLIMIT]; + + { + struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]); + long part2bits; + if(fr->lsf) + part2bits = III_get_scale_factors_2(scalefacs[0],gr_info,0); + else { + #ifdef MPEG1 + part2bits = III_get_scale_factors_1(scalefacs[0],gr_info); + #else + fprintf(stderr,"Not supported\n"); + #endif + } + #ifdef HAVEGTK + if (gtkflag) { + int i; + for (i=0; i<39; i++) + pinfo->sfb_s[gr][0][i]=scalefacs[0][i]; + } + #endif + if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits)) + return clip; + } + if(stereo == 2) { + struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]); + long part2bits; + if(fr->lsf) + part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo); + else { + #ifdef MPEG1 + part2bits = III_get_scale_factors_1(scalefacs[1],gr_info); + #else + fprintf(stderr,"Not supported\n"); + #endif + } + #ifdef HAVEGTK + if (gtkflag) { + int i; + for (i=0; i<39; i++) + pinfo->sfb_s[gr][1][i]=scalefacs[1][i]; + } + #endif + + if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits)) + return clip; + + if(ms_stereo) { + int i; + for(i=0;i<SBLIMIT*SSLIMIT;i++) { + real tmp0,tmp1; + tmp0 = ((real *) hybridIn[0])[i]; + tmp1 = ((real *) hybridIn[1])[i]; + ((real *) hybridIn[1])[i] = tmp0 - tmp1; + ((real *) hybridIn[0])[i] = tmp0 + tmp1; + } + } + + if(i_stereo) + III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf); + + if(ms_stereo || i_stereo || (single == 3) ) { + if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) + sideinfo.ch[0].gr[gr].maxb = gr_info->maxb; + else + gr_info->maxb = sideinfo.ch[0].gr[gr].maxb; + } + + switch(single) { + case 3: + { + register int i; + register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; + for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++) + *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ + } + break; + case 1: + { + register int i; + register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; + for(i=0;i<SSLIMIT*gr_info->maxb;i++) + *in0++ = *in1++; + } + break; + } + } + + #ifdef HAVEGTK + if (gtkflag) { + extern int tabsel_123[2][3][16]; + extern int pretab[21]; + int i,j,sb; + float ifqstep; + + for (ch=0;ch<stereo1;ch++) { + struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); + ifqstep = ( pinfo->scalefac_scale[gr][ch] == 0 ) ? .5 : 1.0; + if (2==gr_info->block_type) { + for (i=0; i<3; i++) { + for (sb=0; sb<12; sb++) { + j = 3*sb+i; + /* + is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; + */ + /* scalefac was copied into pinfo->sfb_s[] above */ + pinfo->sfb_s[gr][ch][j] = -ifqstep*pinfo->sfb_s[gr][ch][j-gr_info->mixed_block_flag]; + pinfo->sfb_s[gr][ch][j] -= 2*(pinfo->sub_gain[gr][ch][i]); + } + pinfo->sfb_s[gr][ch][3*sb+i] = - 2*(pinfo->sub_gain[gr][ch][i]); + } + }else{ + for (sb=0; sb<21; sb++) { + /* scalefac was copied into pinfo->sfb[] above */ + pinfo->sfb[gr][ch][sb] = pinfo->sfb_s[gr][ch][sb]; + if (gr_info->preflag) pinfo->sfb[gr][ch][sb] += pretab[sb]; + pinfo->sfb[gr][ch][sb] *= -ifqstep; + } + } + } + + + + pinfo->bitrate = + tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index]; + pinfo->sampfreq = freqs[sfreq]; + pinfo->emph = fr->emphasis; + pinfo->crc = fr->error_protection; + pinfo->padding = fr->padding; + pinfo->stereo = fr->stereo; + pinfo->js = (fr->mode == MPG_MD_JOINT_STEREO); + pinfo->ms_stereo = ms_stereo; + pinfo->i_stereo = i_stereo; + pinfo->maindata = sideinfo.main_data_begin; + + for(ch=0;ch<stereo1;ch++) { + struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); + pinfo->mixed[gr][ch] = gr_info->mixed_block_flag; + pinfo->mpg123blocktype[gr][ch]=gr_info->block_type; + pinfo->mainbits[gr][ch] = gr_info->part2_3_length; + if (gr==1) pinfo->scfsi[ch] = gr_info->scfsi; + } + for(ch=0;ch<stereo1;ch++) { + int j=0; + for (sb=0;sb<SBLIMIT;sb++) + for(ss=0;ss<SSLIMIT;ss++,j++) + pinfo->mpg123xr[gr][ch][j]=hybridIn[ch][sb][ss]; + } + } + + #endif + + for(ch=0;ch<stereo1;ch++) { + struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); + III_antialias(hybridIn[ch],gr_info); + III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info); + } + + for(ss=0;ss<SSLIMIT;ss++) { + if(single >= 0) { + clip += synth_1to1_mono(hybridOut[0][ss],pcm_sample,pcm_point); + } + else { + int p1 = *pcm_point; + clip += synth_1to1(hybridOut[0][ss],0,pcm_sample,&p1); + clip += synth_1to1(hybridOut[1][ss],1,pcm_sample,pcm_point); + } + } + } + + return clip; + } + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/machine.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/machine.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/machine.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,112 ---- + /* + * Machine dependent defines/includes for LAME. + * + * Copyright (c) 1999 A.L. Faber + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + + #ifndef MACHINE_H_INCLUDED + #define MACHINE_H_INCLUDED + + #include <stdio.h> + #include <string.h> + #include <math.h> + #include <stdlib.h> + #include <ctype.h> + #include <signal.h> + #include <sys/types.h> + #include <sys/stat.h> + #include <fcntl.h> + #include <errno.h> + + + /* three different types of pow() functions: + 1. table lookup + 2. pow() + 3. exp() on some machines this is claimed to be faster than pow() + */ + + + #define POW20(x) pow20[x] + /* + #define POW20(x) pow(2.0,((double)(x)-210)*.25) + #define POW20(x) exp( ((double)(x)-210)*(.25*LOG2) ) + */ + + #define IPOW20(x) ipow20[x] + /* + #define IPOW20(x) exp( -((double)(x)-210)*.1875*LOG2 ) + #define IPOW20(x) pow(2.0,-((double)(x)-210)*.1875) + */ + + + + #if ( defined(_MSC_VER) && !defined(INLINE)) + # define INLINE _inline + #elif defined(__SASC) || defined(__GNUC__) + # define INLINE __inline + #else + # define INLINE + #endif + + #if ( defined(_MSC_VER)) + # pragma warning( disable : 4244 ) + # pragma warning( disable : 4305 ) + #endif + + #if ( defined(_MSC_VER) || defined(__BORLANDC__) ) + # define WIN32_LEAN_AND_MEAN + # include <windows.h> + #else + typedef float FLOAT; + #endif + + + /* MH: the x86 asm quantization routines in quantize-pvt.c + are designed to work only with 8-byte doubles or 4-byte + floats. if you use a different type (e.g. 10-byte extended + precision long doubles, as supported by ICL), you will need + to disable the ASM routines (or fix them :) */ + + #define FLOAT8_is_double + typedef double FLOAT8; + + /*#define FLOAT8_is_float*/ + /*typedef float FLOAT8; */ + + + + + #if defined _WIN32 && !defined __CYGWIN__ + typedef unsigned long u_long; + typedef unsigned int u_int; + typedef unsigned short u_short; + typedef unsigned char u_char; + #elif defined __DECALPHA__ + # do nothing + #elif !defined __GNUC__ || defined __STRICT_ANSI__ + typedef unsigned long u_long; + typedef unsigned int u_int; + typedef unsigned short u_short; + typedef unsigned char u_char; + #endif + + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/main.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/main.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/main.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,142 ---- + #include <stdlib.h> + #include <string.h> + #include <stdio.h> + #include <fcntl.h> + #ifdef _WIN32 + /* needed to set stdout to binary */ + #include <io.h> + #endif + #include "lame.h" + + + #ifdef HAVEGTK + #include "gtkanal.h" + #include <gtk/gtk.h> + #endif + + #ifdef __riscos__ + #include "asmstuff.h" + #endif + + + + + /************************************************************************ + * + * main + * + * PURPOSE: MPEG-1,2 Layer III encoder with GPSYCHO + * psychoacoustic model. + * + ************************************************************************/ + + + int main(int argc, char **argv) + { + + char mp3buffer[LAME_MAXMP3BUFFER]; + short int Buffer[2][1152]; + int iread,imp3; + lame_global_flags gf; + FILE *outf; + #ifdef __riscos__ + int i; + #endif + + + lame_init(&gf); /* initialize libmp3lame */ + if(argc==1) lame_usage(&gf,argv[0]); /* no command-line args, print usage, exit */ + + /* parse the command line arguments, setting various flags in the + * struct 'gf'. If you want to parse your own arguments, + * or call libmp3lame from a program which uses a GUI to set arguments, + * skip this call and set the values of interest in the gf struct. + * (see lame.h for documentation about these parameters) + */ + lame_parse_args(&gf,argc, argv); + + if (!gf.gtkflag) { + /* open the MP3 output file */ + if (!strcmp(gf.outPath, "-")) { + #ifdef __EMX__ + _fsetmode(stdout,"b"); + #elif (defined __BORLANDC__) + setmode(_fileno(stdout), O_BINARY); + #elif (defined __CYGWIN__) + setmode(fileno(stdout), _O_BINARY); + #elif (defined _WIN32) + _setmode(_fileno(stdout), _O_BINARY); + #endif + outf = stdout; + } else { + if ((outf = fopen(gf.outPath, "wb")) == NULL) { + fprintf(stderr,"Could not create \"%s\".\n", gf.outPath); + exit(1); + } + } + #ifdef __riscos__ + /* Assign correct file type */ + for (i = 0; gf.outPath[i]; i++) + if (gf.outPath[i] == '.') gf.outPath[i] = '/'; + SetFiletype(gf.outPath, 0x1ad); + #endif + } + + + /* open the wav/aiff/raw pcm or mp3 input file. This call will + * open the file with name gf.inFile, try to parse the headers and + * set gf.samplerate, gf.num_channels, gf.num_samples. + * if you want to do your own file input, skip this call and set + * these values yourself. + */ + lame_init_infile(&gf); + + /* Now that all the options are set, lame needs to analyze them and + * set some more options + */ + lame_init_params(&gf); + lame_print_config(&gf); /* print usefull information about options being used */ + + + + + #ifdef HAVEGTK + if (gf.gtkflag) gtk_init (&argc, &argv); + if (gf.gtkflag) gtkcontrol(&gf); + else + #endif + { + + /* encode until we hit eof */ + do { + /* read in 'iread' samples */ + iread=lame_readframe(&gf,Buffer); + + + /* encode */ + imp3=lame_encode_buffer(&gf,Buffer[0],Buffer[1],iread, + mp3buffer,(int)sizeof(mp3buffer)); + + /* was our output buffer big enough? */ + if (imp3==-1) { + fprintf(stderr,"mp3 buffer is not big enough... \n"); + exit(1); + } + + if (fwrite(mp3buffer,1,imp3,outf) != imp3) { + fprintf(stderr,"Error writing mp3 output"); + exit(1); + } + } while (iread); + } + + imp3=lame_encode_finish(&gf,mp3buffer,(int)sizeof(mp3buffer)); /* may return one more mp3 frame */ + fwrite(mp3buffer,1,imp3,outf); + fclose(outf); + lame_close_infile(&gf); /* close the input file */ + lame_mp3_tags(&gf); /* add id3 or VBR tags to mp3 file */ + return 0; + } + + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpg123.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpg123.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpg123.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,174 ---- + #include <stdio.h> + #include <string.h> + #include <signal.h> + + + #include <math.h> + + #ifndef M_PI + #define M_PI 3.14159265358979323846 + #endif + #ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880 + #endif + + #ifdef _MSC_VER + #pragma warning( disable : 4244 ) + #pragma warning( disable : 4305 ) + # define REAL_IS_FLOAT + # define NEW_DCT9 + + # define random rand + # define srandom srand + + #endif + + #ifdef REAL_IS_FLOAT + # define real float + #elif defined(REAL_IS_LONG_DOUBLE) + # define real long double + #else + # define real double + #endif + + /* AUDIOBUFSIZE = n*64 with n=1,2,3 ... */ + #define AUDIOBUFSIZE 16384 + + #define FALSE 0 + #define TRUE 1 + + #define SBLIMIT 32 + #define SSLIMIT 18 + + #define MPG_MD_STEREO 0 + #define MPG_MD_JOINT_STEREO 1 + #define MPG_MD_DUAL_CHANNEL 2 + #define MPG_MD_MONO 3 + + #define MAXFRAMESIZE 1792 + + + /* Pre Shift fo 16 to 8 bit converter table */ + #define AUSHIFT (3) + + struct frame { + int stereo; + int jsbound; + int single; + int lsf; + int mpeg25; + int header_change; + int lay; + int error_protection; + int bitrate_index; + int sampling_frequency; + int padding; + int extension; + int mode; + int mode_ext; + int copyright; + int original; + int emphasis; + int framesize; /* computed framesize */ + }; + + struct parameter { + int quiet; /* shut up! */ + int tryresync; /* resync stream after error */ + int verbose; /* verbose level */ + int checkrange; + }; + + /* extern unsigned int get1bit(void); */ + extern unsigned int getbits(int); + extern unsigned int getbits_fast(int); + extern int set_pointer(long); + + extern unsigned char *wordpointer; + extern int bitindex; + + extern void make_decode_tables(long scaleval); + extern int do_layer3(struct frame *fr,unsigned char *,int *); + extern int decode_header(struct frame *fr,unsigned long newhead); + + + + struct gr_info_s { + int scfsi; + unsigned part2_3_length; + unsigned big_values; + unsigned scalefac_compress; + unsigned block_type; + unsigned mixed_block_flag; + unsigned table_select[3]; + unsigned subblock_gain[3]; + unsigned maxband[3]; + unsigned maxbandl; + unsigned maxb; + unsigned region1start; + unsigned region2start; + unsigned preflag; + unsigned scalefac_scale; + unsigned count1table_select; + real *full_gain[3]; + real *pow2gain; + }; + + struct III_sideinfo + { + unsigned main_data_begin; + unsigned private_bits; + struct { + struct gr_info_s gr[2]; + } ch[2]; + }; + + extern int synth_1to1 (real *,int,unsigned char *,int *); + extern int synth_1to1_8bit (real *,int,unsigned char *,int *); + extern int synth_1to1_mono (real *,unsigned char *,int *); + extern int synth_1to1_mono2stereo (real *,unsigned char *,int *); + extern int synth_1to1_8bit_mono (real *,unsigned char *,int *); + extern int synth_1to1_8bit_mono2stereo (real *,unsigned char *,int *); + + extern int synth_2to1 (real *,int,unsigned char *,int *); + extern int synth_2to1_8bit (real *,int,unsigned char *,int *); + extern int synth_2to1_mono (real *,unsigned char *,int *); + extern int synth_2to1_mono2stereo (real *,unsigned char *,int *); + extern int synth_2to1_8bit_mono (real *,unsigned char *,int *); + extern int synth_2to1_8bit_mono2stereo (real *,unsigned char *,int *); + + extern int synth_4to1 (real *,int,unsigned char *,int *); + extern int synth_4to1_8bit (real *,int,unsigned char *,int *); + extern int synth_4to1_mono (real *,unsigned char *,int *); + extern int synth_4to1_mono2stereo (real *,unsigned char *,int *); + extern int synth_4to1_8bit_mono (real *,unsigned char *,int *); + extern int synth_4to1_8bit_mono2stereo (real *,unsigned char *,int *); + + extern int synth_ntom (real *,int,unsigned char *,int *); + extern int synth_ntom_8bit (real *,int,unsigned char *,int *); + extern int synth_ntom_mono (real *,unsigned char *,int *); + extern int synth_ntom_mono2stereo (real *,unsigned char *,int *); + extern int synth_ntom_8bit_mono (real *,unsigned char *,int *); + extern int synth_ntom_8bit_mono2stereo (real *,unsigned char *,int *); + + extern void rewindNbits(int bits); + extern int hsstell(void); + extern int get_songlen(struct frame *fr,int no); + + extern void init_layer3(int); + extern void init_layer2(void); + extern void make_decode_tables(long scale); + extern void make_conv16to8_table(int); + extern void dct64(real *,real *,real *); + + extern void synth_ntom_set_step(long,long); + + extern unsigned char *conv16to8; + extern long freqs[9]; + extern real muls[27][64]; + extern real decwin[512+32]; + extern real *pnts[5]; + + extern struct parameter param; + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpglib.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpglib.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpglib.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,49 ---- + + struct buf { + unsigned char *pnt; + long size; + long pos; + struct buf *next; + struct buf *prev; + }; + + struct framebuf { + struct buf *buf; + long pos; + struct frame *next; + struct frame *prev; + }; + + struct mpstr { + struct buf *head,*tail; + int bsize; + int framesize; + int fsizeold; + struct frame fr; + unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */ + real hybrid_block[2][2][SBLIMIT*SSLIMIT]; + int hybrid_blc[2]; + unsigned long header; + int bsnum; + real synth_buffs[2][2][0x110]; + int synth_bo; + + }; + + + #if ( defined(_MSC_VER) || defined(__BORLANDC__) ) + typedef int BOOL; /* windef.h contains the same definition */ + #else + #define BOOL int + #endif + + #define MP3_ERR -1 + #define MP3_OK 0 + #define MP3_NEED_MORE 1 + + + BOOL InitMP3(struct mpstr *mp); + int decodeMP3(struct mpstr *mp,char *inmemory,int inmemsize, + char *outmemory,int outmemsize,int *done); + void ExitMP3(struct mpstr *mp); + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpglib_main.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpglib_main.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/mpglib_main.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,203 ---- + #ifdef HAVEMPGLIB + + #include "mpg123.h" + #include "mpglib.h" + + #ifdef OS_AMIGAOS + #include "/lame.h" + #include "/util.h" + #include "/VbrTag.h" + #else + #include "lame.h" + #include "util.h" + #include "VbrTag.h" + #endif /* OS_AMIGAOS */ + + #include <stdlib.h> + + static char buf[16384]; + #define FSIZE 8192 + static char out[FSIZE]; + struct mpstr mp; + + + int is_syncword(char *header) + { + + /* + unsigned int s0,s1; + s0 = (unsigned char) header[0]; + s1 = (unsigned char) header[1] ; + printf(" syncword: %2X %2X \n ",s0, s1); + */ + + /* + printf(" integer %i \n",(int) ( header[0] == (char) 0xFF)); + printf(" integer %i \n",(int) ( (header[1] & (char) 0xF0) == (char) 0xF0)); + */ + + return + ((int) ( header[0] == (char) 0xFF)) && + ((int) ( (header[1] & (char) 0xF0) == (char) 0xF0)); + + + } + + + int lame_decode_initfile(FILE *fd, int *stereo, int *samp, int *bitrate, + unsigned long *num_samples) + { + extern int tabsel_123[2][3][16]; + VBRTAGDATA pTagData; + int ret,size,framesize; + unsigned long num_frames=0; + size_t len; + int xing_header; + + + InitMP3(&mp); + memset(buf, 0, sizeof(buf)); + + /* skip RIFF type proprietary headers */ + /* look for sync word FFF */ + while (!is_syncword(buf)) { + buf[0]=buf[1]; + if (fread(&buf[1],1,1,fd) == 0) return -1; /* failed */ + } + /* ret = decodeMP3(&mp,buf,2,out,FSIZE,&size); */ + + /* read the header */ + len = fread(&buf[2],1,46,fd); + if (len ==0 ) return -1; + len +=2; + + /* check for Xing header */ + xing_header = GetVbrTag(&pTagData,(unsigned char*)buf); + if (xing_header) { + num_frames=pTagData.frames; + } + + size=0; + ret = decodeMP3(&mp,buf,len,out,FSIZE,&size); + if (size>0 && !xing_header) { + fprintf(stderr,"Opps: first frame of mpglib output will be lost \n"); + } + + *stereo = mp.fr.stereo; + *samp = freqs[mp.fr.sampling_frequency]; + *bitrate = tabsel_123[mp.fr.lsf][mp.fr.lay-1][mp.fr.bitrate_index]; + framesize = (mp.fr.lsf == 0) ? 1152 : 576; + *num_samples=MAX_U_32_NUM; + if (xing_header && num_frames) { + *num_samples=framesize * num_frames; + } + + /* + printf("ret = %i NEED_MORE=%i \n",ret,MP3_NEED_MORE); + printf("stereo = %i \n",mp.fr.stereo); + printf("samp = %i \n",(int)freqs[mp.fr.sampling_frequency]); + printf("framesize = %i \n",framesize); + printf("num frames = %i \n",(int)num_frames); + printf("num samp = %i \n",(int)*num_samples); + */ + return 0; + } + + + int lame_decode_init(void) + { + InitMP3(&mp); + memset(buf, 0, sizeof(buf)); + return 0; + } + + + /* + For lame_decode_fromfile: return code + -1 error + 0 ok, but need more data before outputing any samples + n number of samples output. either 576 or 1152 depending on MP3 file. + */ + int lame_decode_fromfile(FILE *fd, short pcm_l[], short pcm_r[]) + { + int size,stereo; + int outsize=0,j,i,ret; + size_t len; + + size=0; + len = fread(buf,1,64,fd); + if (len ==0 ) return 0; + ret = decodeMP3(&mp,buf,len,out,FSIZE,&size); + + /* read more until we get a valid output frame */ + while((ret == MP3_NEED_MORE) || !size) { + len = fread(buf,1,100,fd); + if (len ==0 ) return -1; + ret = decodeMP3(&mp,buf,len,out,FSIZE,&size); + /* if (ret ==MP3_ERR) return -1; lets ignore errors and keep reading... */ + /* + printf("ret = %i size= %i %i %i %i \n",ret,size, + MP3_NEED_MORE,MP3_ERR,MP3_OK); + */ + } + + stereo=mp.fr.stereo; + + if (ret == MP3_OK) + { + /* write(1,out,size); */ + outsize = size/(2*(stereo)); + if ((outsize!=576) && (outsize!=1152)) { + fprintf(stderr,"Opps: mpg123 returned more than one frame! Cant handle this... \n"); + exit(-50); + } + + for (j=0; j<stereo; j++) + for (i=0; i<outsize; i++) + if (j==0) pcm_l[i] = ((short *) out)[mp.fr.stereo*i+j]; + else pcm_r[i] = ((short *) out)[mp.fr.stereo*i+j]; + + } + if (ret==MP3_ERR) return -1; + else return outsize; + } + + + + + /* + For lame_decode: return code + -1 error + 0 ok, but need more data before outputing any samples + n number of samples output. either 576 or 1152 depending on MP3 file. + */ + int lame_decode(char *buf,int len,short pcm_l[],short pcm_r[]) + { + int size; + int outsize=0,j,i,ret; + + ret = decodeMP3(&mp,buf,len,out,FSIZE,&size); + if (ret==MP3_OK) { + /* printf("mpg123 output one frame out=%i \n",size/4); */ + outsize = size/(2*mp.fr.stereo); + if (outsize > 1152) { + fprintf(stderr,"Opps: mpg123 returned more than one frame! shouldn't happen... \n"); + exit(-50); + } + + for (j=0; j<mp.fr.stereo; j++) + for (i=0; i<outsize; i++) + if (j==0) pcm_l[i] = ((short *) out)[mp.fr.stereo*i+j]; + else pcm_r[i] = ((short *) out)[mp.fr.stereo*i+j]; + + } + /* + printf("ok, more, err: %i %i %i \n",MP3_OK, MP3_NEED_MORE, MP3_ERR); + printf("ret = %i out=%i \n",ret,outsize); + */ + if (ret==MP3_ERR) return -1; + else return outsize; + } + + #endif /* HAVEMPGLIB */ + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/newmdct.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/newmdct.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/newmdct.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,631 ---- + /* + * MP3 window subband -> subband filtering -> mdct routine + * + * Copyright (c) 1999 Takehiro TOMINAGA + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + /* + * Special Thanks to Patrick De Smet for your advices. + */ + + + #include "util.h" + #include "l3side.h" + #include "newmdct.h" + + #define SCALE 32768 + + static FLOAT8 enwindow[] = + { + 3.5780907e-02,1.7876148e-02,3.134727e-03,2.457142e-03, + 9.71317e-04, 2.18868e-04, 1.01566e-04, 1.3828e-05, + + 3.5758972e-02, 3.401756e-03, 9.83715e-04, 9.9182e-05, + -4.77e-07, 1.03951e-04, 9.53674e-04, 2.841473e-03, + 1.2398e-05, 1.91212e-04, 2.283096e-03,1.6994476e-02, + 1.8756866e-02, 2.630711e-03, 2.47478e-04, 1.4782e-05, + + 3.5694122e-02, 3.643036e-03, 9.91821e-04, 9.6321e-05, + -4.77e-07, 1.05858e-04, 9.30786e-04, 2.521515e-03, + 1.1444e-05, 1.65462e-04, 2.110004e-03,1.6112804e-02, + 1.9634247e-02, 2.803326e-03, 2.77042e-04, 1.6689e-05, + + 3.5586357e-02, 3.858566e-03, 9.95159e-04, 9.3460e-05, + -4.77e-07, 1.07288e-04, 9.02653e-04, 2.174854e-03, + 1.0014e-05, 1.40190e-04, 1.937389e-03,1.5233517e-02, + 2.0506859e-02, 2.974033e-03, 3.07560e-04, 1.8120e-05, + + 3.5435200e-02, 4.049301e-03, 9.94205e-04, 9.0599e-05, + -4.77e-07, 1.08242e-04, 8.68797e-04, 1.800537e-03, + 9.060e-06, 1.16348e-04, 1.766682e-03,1.4358521e-02, + 2.1372318e-02, 3.14188e-03, 3.39031e-04, 1.9550e-05, + + 3.5242081e-02, 4.215240e-03, 9.89437e-04, 8.7261e-05, + -4.77e-07, 1.08719e-04, 8.29220e-04, 1.399517e-03, + 8.106e-06, 9.3937e-05, 1.597881e-03,1.3489246e-02, + 2.2228718e-02, 3.306866e-03, 3.71456e-04, 2.1458e-05, + + 3.5007000e-02, 4.357815e-03, 9.80854e-04, 8.3923e-05, + -4.77e-07, 1.08719e-04, 7.8392e-04, 9.71317e-04, + 7.629e-06, 7.2956e-05, 1.432419e-03,1.2627602e-02, + 2.3074150e-02, 3.467083e-03, 4.04358e-04, 2.3365e-05, + + 3.4730434e-02, 4.477024e-03, 9.68933e-04, 8.0585e-05, + -9.54e-07, 1.08242e-04, 7.31945e-04, 5.15938e-04, + 6.676e-06, 5.2929e-05, 1.269817e-03,1.1775017e-02, + 2.3907185e-02, 3.622532e-03, 4.38213e-04, 2.5272e-05, + + 3.4412861e-02, 4.573822e-03, 9.54151e-04, 7.6771e-05, + -9.54e-07, 1.06812e-04, 6.74248e-04, 3.3379e-05, + 6.199e-06, 3.4332e-05, 1.111031e-03,1.0933399e-02, + 2.4725437e-02, 3.771782e-03, 4.72546e-04, 2.7657e-05, + + 3.4055710e-02, 4.649162e-03, 9.35555e-04, 7.3433e-05, + -9.54e-07, 1.05381e-04, 6.10352e-04, -4.75883e-04, + 5.245e-06, 1.7166e-05, 9.56535e-04,1.0103703e-02, + 2.5527000e-02, 3.914356e-03, 5.07355e-04, 3.0041e-05, + + 3.3659935e-02, 4.703045e-03, 9.15051e-04, 7.0095e-05, + -9.54e-07, 1.02520e-04, 5.39303e-04,-1.011848e-03, + 4.768e-06, 9.54e-07, 8.06808e-04, 9.287834e-03, + 2.6310921e-02, 4.048824e-03, 5.42164e-04, 3.2425e-05, + + 3.3225536e-02, 4.737377e-03, 8.91685e-04, 6.6280e-05, + -1.431e-06, 9.9182e-05, 4.62532e-04,-1.573563e-03, + 4.292e-06, -1.3828e-05, 6.61850e-04, 8.487225e-03, + 2.7073860e-02, 4.174709e-03, 5.76973e-04, 3.4809e-05, + + 3.2754898e-02, 4.752159e-03, 8.66413e-04, 6.2943e-05, + -1.431e-06, 9.5367e-05, 3.78609e-04,-2.161503e-03, + 3.815e-06, -2.718e-05, 5.22137e-04, 7.703304e-03, + 2.7815342e-02, 4.290581e-03, 6.11782e-04, 3.7670e-05, + + 3.2248020e-02, 4.748821e-03, 8.38757e-04, 5.9605e-05, + -1.907e-06, 9.0122e-05, 2.88486e-04,-2.774239e-03, + 3.338e-06, -3.9577e-05, 3.88145e-04, 6.937027e-03, + 2.8532982e-02, 4.395962e-03, 6.46591e-04, 4.0531e-05, + + 3.1706810e-02, 4.728317e-03, 8.09669e-04, 5.579e-05, + -1.907e-06, 8.4400e-05, 1.91689e-04,-3.411293e-03, + 3.338e-06, -5.0545e-05, 2.59876e-04, 6.189346e-03, + 2.9224873e-02, 4.489899e-03, 6.80923e-04, 4.3392e-05, + + 3.1132698e-02, 4.691124e-03, 7.79152e-04, 5.2929e-05, + -2.384e-06, 7.7724e-05, 8.8215e-05,-4.072189e-03, + 2.861e-06, -6.0558e-05, 1.37329e-04, 5.462170e-03, + 2.9890060e-02, 4.570484e-03, 7.14302e-04, 4.6253e-05, + + 3.0526638e-02, 4.638195e-03, 7.47204e-04, 4.9591e-05, + 4.756451e-03, 2.1458e-05, -6.9618e-05, 2.384e-06 + }; + + static FLOAT8 sb_sample[2][2][18][SBLIMIT]; + static FLOAT8 mm[16][SBLIMIT - 1]; + + #define NS 12 + #define NL 36 + + static const int all[] = {0,2,3,5,6,8,9,11,12,14,15,17}; + static FLOAT8 ca[8], cs[8]; + static FLOAT8 cos_s[NS / 2][NS / 2]; + static FLOAT8 cos_l[(NL / 2) * 12 + (NL / 6) * 4 + (NL / 18) * 2]; + static FLOAT8 win[4][36]; + + #define work (&win[2][4]) + + /************************************************************************ + * + * window_subband() + * + * PURPOSE: Overlapping window on PCM samples + * + * SEMANTICS: + * 32 16-bit pcm samples are scaled to fractional 2's complement and + * concatenated to the end of the window buffer #x#. The updated window + * buffer #x# is then windowed by the analysis window #c# to produce the + * windowed sample #z# + * + ************************************************************************/ + + static void window_subband(short *xk, FLOAT8 d[SBLIMIT], FLOAT8 *in) + { + int i; + FLOAT8 s, t, *wp; + wp = enwindow; + { + t = xk[255]; + t += (xk[223] - xk[287]) * *wp++; + t += (xk[191] + xk[319]) * *wp++; + t += (xk[159] - xk[351]) * *wp++; + t += (xk[127] + xk[383]) * *wp++; + t += (xk[ 95] - xk[415]) * *wp++; + t += (xk[ 63] + xk[447]) * *wp++; + t += (xk[ 31] - xk[479]) * *wp++; + in[15] = t; + } + + for (i = 14; i >= 0; --i) { + short *x1 = &xk[i]; + short *x2 = &xk[-i]; + FLOAT8 w; + + s = x2[270]; t = x1[240]; + w = *wp++; s += x2[334] * w; t += x1[176] * w; + w = *wp++; s += x2[398] * w; t += x1[112] * w; + w = *wp++; s += x2[462] * w; t += x1[ 48] * w; + w = *wp++; s += x2[ 14] * w; t += x1[496] * w; + w = *wp++; s += x2[ 78] * w; t += x1[432] * w; + w = *wp++; s += x2[142] * w; t += x1[368] * w; + w = *wp++; s += x2[206] * w; t += x1[304] * w; + + w = *wp++; s += x1[ 16] * w; t -= x2[494] * w; + w = *wp++; s += x1[ 80] * w; t -= x2[430] * w; + w = *wp++; s += x1[144] * w; t -= x2[366] * w; + w = *wp++; s += x1[208] * w; t -= x2[302] * w; + w = *wp++; s -= x1[272] * w; t += x2[238] * w; + w = *wp++; s -= x1[336] * w; t += x2[174] * w; + w = *wp++; s -= x1[400] * w; t += x2[110] * w; + w = *wp++; s -= x1[464] * w; t += x2[ 46] * w; + + in[30 - i] = s; + in[i] = t; + } + + { + s = xk[239]; + s += xk[175] * *wp++; + s += xk[111] * *wp++; + s += xk[ 47] * *wp++; + s -= xk[303] * *wp++; + s -= xk[367] * *wp++; + s -= xk[431] * *wp++; + s -= xk[495] * *wp++; + /* in[-1] = s; */ + } + + in++; + wp = &mm[0][0]; + for (i = 15; i >= 0; --i) { + int j; + FLOAT8 s0 = s; /* mm[i][0] is always 1 */ + FLOAT8 s1 = t * *wp++; + for (j = 14; j >= 0; j--) { + s0 += *wp++ * *in++; + s1 += *wp++ * *in++; + } + in -= 30; + d[i ] = s0 + s1; + d[31 - i] = s0 - s1; + } + } + + + /*-------------------------------------------------------------------*/ + /* */ + /* Function: Calculation of the MDCT */ + /* In the case of long blocks (type 0,1,3) there are */ + /* 36 coefficents in the time domain and 18 in the frequency */ + /* domain. */ + /* In the case of short blocks (type 2) there are 3 */ + /* transformations with short length. This leads to 12 coefficents */ + /* in the time and 6 in the frequency domain. In this case the */ + /* results are stored side by side in the vector out[]. */ + /* */ + /* New layer3 */ + /* */ + /*-------------------------------------------------------------------*/ + + static void mdct_short(FLOAT8 *out, FLOAT8 *in) + { + int m; + for (m = NS / 2 - 1; m >= 0; --m) { + int l; + FLOAT8 a0, a1, a2, a3, a4, a5; + a0 = cos_s[m][0]; + a1 = cos_s[m][1]; + a2 = cos_s[m][2]; + a3 = cos_s[m][3]; + a4 = cos_s[m][4]; + a5 = cos_s[m][5]; + for (l = 2; l >= 0; l--) { + out[3 * m + l] = + a0 * in[6 * l ] + + a1 * in[6 * l + 1] + + a2 * in[6 * l + 2] + + a3 * in[6 * l + 3] + + a4 * in[6 * l + 4] + + a5 * in[6 * l + 5]; + } + } + } + + static void mdct_long(FLOAT8 *out, FLOAT8 *in) + { + FLOAT8 s0, s1, s2, s3, s4, s5; + int j = sizeof(all) / sizeof(int) - 1; + FLOAT8 *cos_l0 = cos_l; + do { + out[all[j]] = + in[ 0] * cos_l0[ 0] + + in[ 1] * cos_l0[ 1] + + in[ 2] * cos_l0[ 2] + + in[ 3] * cos_l0[ 3] + + in[ 4] * cos_l0[ 4] + + in[ 5] * cos_l0[ 5] + + in[ 6] * cos_l0[ 6] + + in[ 7] * cos_l0[ 7] + + in[ 8] * cos_l0[ 8] + + in[ 9] * cos_l0[ 9] + + in[10] * cos_l0[10] + + in[11] * cos_l0[11] + + in[12] * cos_l0[12] + + in[13] * cos_l0[13] + + in[14] * cos_l0[14] + + in[15] * cos_l0[15] + + in[16] * cos_l0[16] + + in[17] * cos_l0[17]; + cos_l0 += 18; + } while (--j >= 0); + + s0 = in[0] + in[ 5] + in[15]; + s1 = in[1] + in[ 4] + in[16]; + s2 = in[2] + in[ 3] + in[17]; + s3 = in[6] - in[ 9] + in[14]; + s4 = in[7] - in[10] + in[13]; + s5 = in[8] - in[11] + in[12]; + + /* 16 */ + out[16] = + s0 * cos_l0[0] + s1 * cos_l0[1] + s2 * cos_l0[2] + + s3 * cos_l0[3] + s4 * cos_l0[4] + s5 * cos_l0[5]; + cos_l0 += 6; + + /* 10 */ + out[10] = + s0 * cos_l0[0] + s1 * cos_l0[1] + s2 * cos_l0[2] + + s3 * cos_l0[3] + s4 * cos_l0[4] + s5 * cos_l0[5]; + cos_l0 += 6; + + /* 7 */ + out[7] = + s0 * cos_l0[0] + s1 * cos_l0[1] + s2 * cos_l0[2] + + s3 * cos_l0[3] + s4 * cos_l0[4] + s5 * cos_l0[5]; + cos_l0 += 6; + + /* 1 */ + out[1] = + s0 * cos_l0[0] + s1 * cos_l0[1] + s2 * cos_l0[2] + + s3 * cos_l0[3] + s4 * cos_l0[4] + s5 * cos_l0[5]; + cos_l0 += 6; + + s0 = s0 - s1 + s5; + s2 = s2 - s3 - s4; + /* 13 */ + out[13] = s0 * cos_l0[0] + s2 * cos_l0[1]; + + /* 4 */ + out[4] = s0 * cos_l0[2] + s2 * cos_l0[3]; + } + + + void mdct_sub48(lame_global_flags *gfp, + short *w0, short *w1, + FLOAT8 mdct_freq[2][2][576], + III_side_info_t *l3_side) + { + int gr, k, ch; + short *wk; + static int init = 0; + + if ( init == 0 ) { + void mdct_init48(void); + mdct_init48(); + init++; + } + + wk = w0; + /* thinking cache performance, ch->gr loop is better than gr->ch loop */ + for (ch = 0; ch < gfp->stereo; ch++) { + for (gr = 0; gr < gfp->mode_gr; gr++) { + int band; + FLOAT8 *mdct_enc = mdct_freq[gr][ch]; + gr_info *gi = &(l3_side->gr[gr].ch[ch].tt); + FLOAT8 *samp = sb_sample[ch][1 - gr][0]; + + for (k = 0; k < 18 / 2; k++) { + window_subband(wk, samp, work); + window_subband(wk + 32, samp + 32, work); + /* + * Compensate for inversion in the analysis filter + */ + for (band = 1; band < 32; band += 2) + samp[band + 32] *= -1.0; + samp += 64; + wk += 64; + } + + + /* apply filters on the polyphase filterbank outputs */ + /* bands <= gfp->highpass_band will be zeroed out below */ + /* bands >= gfp->lowpass_band will be zeroed out below */ + if (gfp->filter_type==0) { + FLOAT8 amp,freq; + for (band=gfp->highpass_band+1; band < gfp->lowpass_band ; band++) { + freq = band/31.0; + if (gfp->lowpass1 < freq && freq < gfp->lowpass2) { + amp = cos((PI/2)*(gfp->lowpass1-freq)/(gfp->lowpass2-gfp->lowpass1)); + for (k=0; k<18; k++) + sb_sample[ch][1-gr][k][band]*=amp; + } + if (gfp->highpass1 < freq && freq < gfp->highpass2) { + amp = cos((PI/2)*(gfp->highpass2-freq)/(gfp->highpass2-gfp->highpass1)); + for (k=0; k<18; k++) + sb_sample[ch][1-gr][k][band]*=amp; + } + } + } + + + + /* + * Perform imdct of 18 previous subband samples + * + 18 current subband samples + */ + for (band = 0; band < 32; band++, mdct_enc += 18) + { + int type = gi->block_type; + #ifdef ALLOW_MIXED + if (gi->mixed_block_flag && band < 2) + type = 0; + #endif + if (band >= gfp->lowpass_band || band <= gfp->highpass_band) { + memset((char *)mdct_enc,0,18*sizeof(FLOAT8)); + }else { + if (type == SHORT_TYPE) { + for (k = 2; k >= 0; --k) { + FLOAT8 w1 = win[SHORT_TYPE][k]; + work[k] = + sb_sample[ch][gr][k+6][band] * w1 - + sb_sample[ch][gr][11-k][band]; + work[k+3] = + sb_sample[ch][gr][k+12][band] + + sb_sample[ch][gr][17-k][band] * w1; + + work[k+6] = + sb_sample[ch][gr][k+12][band] * w1 - + sb_sample[ch][gr][17-k][band]; + work[k+9] = + sb_sample[ch][1-gr][k][band] + + sb_sample[ch][1-gr][5-k][band] * w1; + + work[k+12] = + sb_sample[ch][1-gr][k][band] * w1 - + sb_sample[ch][1-gr][5-k][band]; + work[k+15] = + sb_sample[ch][1-gr][k+6][band] + + sb_sample[ch][1-gr][11-k][band] * w1; + } + mdct_short(mdct_enc, work); + } else { + for (k = 8; k >= 0; --k) { + work[k] = + win[type][k ] * sb_sample[ch][gr][k ][band] + - win[type][k+9] * sb_sample[ch][gr][17-k][band]; + + work[9+k] = + win[type][k+18] * sb_sample[ch][1-gr][k ][band] + + win[type][k+27] * sb_sample[ch][1-gr][17-k][band]; + } + mdct_long(mdct_enc, work); + } + } + + + /* + Perform aliasing reduction butterfly + */ + if (type != SHORT_TYPE) { + if (band == 0) + continue; + for (k = 7; k >= 0; --k) { + FLOAT8 bu,bd; + bu = mdct_enc[k] * ca[k] + mdct_enc[-1-k] * cs[k]; + bd = mdct_enc[k] * cs[k] - mdct_enc[-1-k] * ca[k]; + + mdct_enc[-1-k] = bu; + mdct_enc[k] = bd; + } + } + } + } + wk = w1; + if (gfp->mode_gr == 1) { + memcpy(sb_sample[ch][0], sb_sample[ch][1], 576 * sizeof(FLOAT8)); + } + } + } + + + + void mdct_init48(void) + { + int i, k, m; + FLOAT8 sq; + FLOAT8 max; + + /* prepare the aliasing reduction butterflies */ + for (k = 0; k < 8; k++) { + /* + This is table B.9: coefficients for aliasing reduction + */ + static const FLOAT8 c[8] = { + -0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142, -0.0037 + }; + sq = 1.0 + c[k] * c[k]; + sq = sqrt(sq); + ca[k] = c[k] / sq; + cs[k] = 1.0 / sq; + } + + /* type 0*/ + for (i = 0; i < 36; i++) + win[0][i] = sin(PI/36 * (i + 0.5)); + /* type 1*/ + for (i = 0; i < 18; i++) + win[1][i] = win[0][i]; + for (; i < 24; i++) + win[1][i] = 1.0; + for (; i < 30; i++) + win[1][i] = cos(PI/12 * (i + 0.5)); + for (; i < 36; i++) + win[1][i] = 0.0; + /* type 3*/ + for (i = 0; i < 36; i++) + win[3][i] = win[1][35 - i]; + + sq = 4.0 / NL; + { + FLOAT8 *cos_l0 = cos_l; + static const int d3[] = {1,7,10,16}; + static const int d9[] = {4,13}; + + int j = sizeof(all) / sizeof(int) - 1; + do { + m = all[j]; + for (k = 0; k < NL / 4; k++) { + *cos_l0++ = sq * + cos((PI / (4 * NL)) * (2 * m + 1) * (4 * k + 2 + NL)); + } + for (k = 0; k < NL / 4; k++) { + *cos_l0++ = sq * + cos((PI / (4 * NL)) * (2 * m + 1) * (4 * k + 2 + NL * 3)); + } + } while (--j >= 0); + + j = sizeof(d3) / sizeof(int) - 1; + do { + m = d3[j]; + for (k = 0; k < 3; k++) { + *cos_l0++ = sq * + cos((PI / (4 * NL)) * (2 * m + 1) * (4 * k + 2 + NL)); + } + for (k = 6; k < 9; k++) { + *cos_l0++ = sq * + cos((PI / (4 * NL)) * (2 * m + 1) * (4 * k + 2 + NL)); + } + } while (--j >= 0); + + j = sizeof(d9) / sizeof(int) - 1; + do { + m = d9[j]; + *cos_l0++ = sq * + cos((PI / (4 * NL)) * (2 * m + 1) * (2 + NL)); + *cos_l0++ = sq * + cos((PI / (4 * NL)) * (2 * m + 1) * (4 * 2 + 2 + NL)); + } while (--j >= 0); + } + + max = enwindow[256 - 8]; + { + FLOAT8 *wp = enwindow; + FLOAT8 *wr = enwindow; + FLOAT8 mmax[32 - 1]; + + { + FLOAT8 w = *wp++; + mmax[15] = w / max; + + for (k = 0; k < 7; k++) { + *wr++ = *wp++ / w; + } + } + + for (i = 14; i >= 0; --i) { + FLOAT8 w = *wp++; + mmax[i] = mmax[30 - i] = w / max; + + for (k = 0; k < 15; k++) { + *wr++ = *wp++ / w; + } + } + + { + wp++; + for (k = 0; k < 7; k++) { + *wr++ = *wp++ / max; + } + } + + wp = &mm[0][0]; + for (i = 15; i >= 0; --i) { + for (k = 1; k < 32; k++) { + *wp++ = cos((2 * i + 1) * k * PI/64) * mmax[k - 1]; + } + } + } + + /* swap window data*/ + for (k = 0; k < 4; k++) { + FLOAT8 a; + + a = win[0][17-k]; + win[0][17-k] = win[0][9+k]; + win[0][9+k] = a; + + a = win[0][35-k]; + win[0][35-k] = win[0][27+k]; + win[0][27+k] = a; + + a = win[1][17-k]; + win[1][17-k] = win[1][9+k]; + win[1][9+k] = a; + + a = win[1][35-k]; + win[1][35-k] = win[1][27+k]; + win[1][27+k] = a; + + a = win[3][17-k]; + win[3][17-k] = win[3][9+k]; + win[3][9+k] = a; + + a = win[3][35-k]; + win[3][35-k] = win[3][27+k]; + win[3][27+k] = a; + } + + for (i = 0; i < 36; i++) { + win[0][i] *= max / SCALE; + win[1][i] *= max / SCALE; + win[3][i] *= max / SCALE; + } + + /* type 2(short)*/ + sq = 4.0 / NS; + for (i = 0; i < NS / 4; i++) { + FLOAT8 w2 = cos(PI/12 * (i + 0.5)) * max / SCALE * sq; + win[SHORT_TYPE][i] = tan(PI/12 * (i + 0.5)); + + for (m = 0; m < NS / 2; m++) { + cos_s[m][i] = w2 * + cos((PI / (4 * NS)) * (2 * m + 1) * (4 * i + 2 + NS)); + cos_s[m][i + NS / 4] = w2 * + cos((PI / (4 * NS)) * (2 * m + 1) * (4 * i + 2 + NS * 3)); + } + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/newmdct.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/newmdct.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/newmdct.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,6 ---- + #ifndef MDCT_DOT_H + #define MDCT_DOT_H + void mdct_sub48(lame_global_flags *gfp,short *w0, short *w1, + FLOAT8 mdct_freq[2][2][576], + III_side_info_t *l3_side); + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/output_large.mp3 Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/parse.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/parse.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/parse.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,724 ---- + #ifdef LAMEPARSE + + #include "util.h" + #include "id3tag.h" + #include "get_audio.h" + #include "brhist.h" + #include "version.h" + + + + #define MAX_NAME_SIZE 300 + char inPath[MAX_NAME_SIZE]; + char outPath[MAX_NAME_SIZE]; + + + /************************************************************************ + * + * usage + * + * PURPOSE: Writes command line syntax to the file specified by #stderr# + * + ************************************************************************/ + + void lame_usage(lame_global_flags *gfp,char *name) /* print syntax & exit */ + { + lame_print_version(stderr); + fprintf(stderr,"\n"); + fprintf(stderr,"USAGE : %s [options] <infile> [outfile]\n",name); + fprintf(stderr,"\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"); + fprintf(stderr,"\n"); + fprintf(stderr,"Try \"%s --help\" for more information\n",name); + exit(1); + } + + + + /************************************************************************ + * + * usage + * + * PURPOSE: Writes command line syntax to the file specified by #stdout# + * + ************************************************************************/ + + void lame_help(lame_global_flags *gfp,char *name) /* print syntax & exit */ + { + lame_print_version(stdout); + fprintf(stdout,"\n"); + fprintf(stdout,"USAGE : %s [options] <infile> [outfile]\n",name); + fprintf(stdout,"\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"OPTIONS :\n"); + fprintf(stdout," Input options:\n"); + fprintf(stdout," -r input is raw pcm\n"); + fprintf(stdout," -x force byte-swapping of input\n"); + fprintf(stdout," -s sfreq sampling frequency of input file(kHz) - default 44.1kHz\n"); + fprintf(stdout," --mp3input input file is a MP3 file\n"); + fprintf(stdout,"\n"); + fprintf(stdout," Filter options:\n"); + fprintf(stdout," -k keep ALL frequencies (disables all filters)\n"); + fprintf(stdout," --lowpass freq frequency(kHz), lowpass filter cutoff above freq\n"); + fprintf(stdout," --lowpass-width freq frequency(kHz) - default 15%% of lowpass freq\n"); + fprintf(stdout," --highpass freq frequency(kHz), highpass filter cutoff below freq\n"); + fprintf(stdout," --highpass-width freq frequency(kHz) - default 15%% of highpass freq\n"); + fprintf(stdout," --resample sfreq sampling frequency of output file(kHz)- default=input sfreq\n"); + fprintf(stdout," --cwlimit freq compute tonality up to freq (in kHz) default 8.8717\n"); + fprintf(stdout,"\n"); + fprintf(stdout," Operational options:\n"); + fprintf(stdout," -m mode (s)tereo, (j)oint, (f)orce or (m)ono (default j)\n"); + fprintf(stdout," force = force ms_stereo on all frames. Faster\n"); + fprintf(stdout," -a downmix from stereo to mono file for mono encoding\n"); + fprintf(stdout," -d allow channels to have different blocktypes\n"); + fprintf(stdout," -S don't print progress report, VBR histograms\n"); + fprintf(stdout," --athonly only use the ATH for masking\n"); + fprintf(stdout," --noath disable the ATH for masking\n"); + fprintf(stdout," --noshort do not use short blocks\n"); + fprintf(stdout," --voice experimental voice mode\n"); + fprintf(stdout," --preset type type must be phone, voice, fm, tape, hifi, cd or studio\n"); + fprintf(stdout," help gives some more infos on these\n"); + fprintf(stdout,"\n"); + fprintf(stdout," CBR (constant bitrate, the default) options:\n"); + fprintf(stdout," -h higher quality, but a little slower. Recommended.\n"); + fprintf(stdout," -f fast mode (very low quality)\n"); + fprintf(stdout," -b bitrate set the bitrate, default 128kbps\n"); + fprintf(stdout,"\n"); + fprintf(stdout," VBR options:\n"); + fprintf(stdout," -v use variable bitrate (VBR)\n"); + fprintf(stdout," -V n quality setting for VBR. default n=%i\n",gfp->VBR_q); + fprintf(stdout," 0=high quality,bigger files. 9=smaller files\n"); + fprintf(stdout," -b bitrate specify minimum allowed bitrate, default 32kbs\n"); + fprintf(stdout," -B bitrate specify maximum allowed bitrate, default 256kbs\n"); + fprintf(stdout," -t disable Xing VBR informational tag\n"); + fprintf(stdout," --nohist disable VBR histogram display\n"); + fprintf(stdout,"\n"); + fprintf(stdout," MP3 header/stream options:\n"); + fprintf(stdout," -e emp de-emphasis n/5/c (obsolete)\n"); + fprintf(stdout," -c mark as copyright\n"); + fprintf(stdout," -o mark as non-original\n"); + fprintf(stdout," -p error protection. adds 16bit checksum to every frame\n"); + fprintf(stdout," (the checksum is computed correctly)\n"); + fprintf(stdout," --nores disable the bit reservoir\n"); + fprintf(stdout,"\n"); + fprintf(stdout," Specifying any of the following options will add an ID3 tag:\n"); + fprintf(stdout," --tt \"title\" title of song (max 30 chars)\n"); + fprintf(stdout," --ta \"artist\" artist who did the song (max 30 chars)\n"); + fprintf(stdout," --tl \"album\" album where it came from (max 30 chars)\n"); + fprintf(stdout," --ty \"year\" year in which the song/album was made (max 4 chars)\n"); + fprintf(stdout," --tc \"comment\" additional info (max 30 chars)\n"); + fprintf(stdout," (or max 28 chars if using the \"track\" option)\n"); + fprintf(stdout," --tn \"track\" track number of the song on the CD (1 to 99)\n"); + fprintf(stdout," (using this option will add an ID3v1.1 tag)\n"); + fprintf(stdout," --tg \"genre\" genre of song (name or number)\n"); + fprintf(stdout,"\n"); + #ifdef HAVEGTK + fprintf(stdout," -g run graphical analysis on <infile>\n"); + #endif + display_bitrates(stdout); + exit(0); + } + + + + /************************************************************************ + * + * usage + * + * PURPOSE: Writes presetting info to #stdout# + * + ************************************************************************/ + + void lame_presets_info(lame_global_flags *gfp,char *name) /* print syntax & exit */ + { + lame_print_version(stdout); + fprintf(stdout,"\n"); + fprintf(stdout,"Presets are some shortcuts for common settings.\n"); + fprintf(stdout,"They can be combined with -v if you want VBR MP3s.\n"); + fprintf(stdout,"\n"); + fprintf(stdout," --preset phone => --resample 16\n"); + fprintf(stdout," --highpass 0.260\n"); + fprintf(stdout," --highpasswidth 0.040\n"); + fprintf(stdout," --lowpass 3.700\n"); + fprintf(stdout," --lowpasswidth 0.300\n"); + fprintf(stdout," --noshort\n"); + fprintf(stdout," -m m\n"); + fprintf(stdout," -b 16\n"); + fprintf(stdout," plus -b 8 \\\n"); + fprintf(stdout," -B 56 > in combination with -v\n"); + fprintf(stdout," -V 5 /\n"); + fprintf(stdout,"\n"); + fprintf(stdout," --preset voice: => --resample 24\n"); + fprintf(stdout," --highpass 0.100\n"); + fprintf(stdout," --highpasswidth 0.020\n"); + fprintf(stdout," --lowpass 11\n"); + fprintf(stdout," --lowpasswidth 2\n"); + fprintf(stdout," --noshort\n"); + fprintf(stdout," -m m\n"); + fprintf(stdout," -b 32\n"); + fprintf(stdout," plus -b 8 \\\n"); + fprintf(stdout," -B 96 > in combination with -v\n"); + fprintf(stdout," -V 4 /\n"); + fprintf(stdout,"\n"); + fprintf(stdout," --preset fm: => --resample 32\n"); + fprintf(stdout," --highpass 0.030\n"); + fprintf(stdout," --highpasswidth 0\n"); + fprintf(stdout," --lowpass 11.4\n"); + fprintf(stdout," --lowpasswidth 0\n"); + fprintf(stdout," -m j\n"); + fprintf(stdout," -b 96\n"); + fprintf(stdout," plus -b 32 \\\n"); + fprintf(stdout," -B 192 > in combination with -v\n"); + fprintf(stdout," -V 4 /\n"); + fprintf(stdout,"\n"); + fprintf(stdout," --preset tape: => --lowpass 17\n"); + fprintf(stdout," --lowpasswidth 2\n"); + fprintf(stdout," --highpass 0.015\n"); + fprintf(stdout," --highpasswidth 0.015\n"); + fprintf(stdout," -m j\n"); + fprintf(stdout," -b 128\n"); + fprintf(stdout," plus -b 32 \\\n"); + fprintf(stdout," -B 192 > in combination with -v\n"); + fprintf(stdout," -V 4 /\n"); + fprintf(stdout,"\n"); + fprintf(stdout," --preset hifi: => --lowpass 20\n"); + fprintf(stdout," --lowpasswidth 3\n"); + fprintf(stdout," --highpass 0.015\n"); + fprintf(stdout," --highpasswidth 0.015\n"); + fprintf(stdout," -h\n"); + fprintf(stdout," -m j\n"); + fprintf(stdout," -b 160\n"); + fprintf(stdout," plus -b 32 \\\n"); + fprintf(stdout," -B 224 > in combination with -v\n"); + fprintf(stdout," -V 3 /\n"); + fprintf(stdout,"\n"); + fprintf(stdout," --preset cd: => -k\n"); + fprintf(stdout," -h\n"); + fprintf(stdout," -m s\n"); + fprintf(stdout," -b 192\n"); + fprintf(stdout," plus -b 80 \\\n"); + fprintf(stdout," -B 256 > in combination with -v\n"); + fprintf(stdout," -V 2 /\n"); + fprintf(stdout,"\n"); + fprintf(stdout," --preset studio: => -k\n"); + fprintf(stdout," -h\n"); + fprintf(stdout," -m s\n"); + fprintf(stdout," -b 256\n"); + fprintf(stdout," plus -b 112 \\\n"); + fprintf(stdout," -B 320 > in combination with -v\n"); + fprintf(stdout," -V 0 /\n"); + fprintf(stdout,"\n"); + + exit(0); + } + + + + /************************************************************************ + * + * parse_args + * + * PURPOSE: Sets encoding parameters to the specifications of the + * command line. Default settings are used for parameters + * not specified in the command line. + * + * If the input file is in WAVE or AIFF format, the sampling frequency is read + * from the AIFF header. + * + * The input and output filenames are read into #inpath# and #outpath#. + * + ************************************************************************/ + void lame_parse_args(lame_global_flags *gfp,int argc, char **argv) + { + FLOAT srate; + int err = 0, i = 0; + int autoconvert=0; + int user_quality=0; + + char *programName = argv[0]; + int track = 0; + + inPath[0] = '\0'; + outPath[0] = '\0'; + gfp->inPath=inPath; + gfp->outPath=outPath; + + id3_inittag(&id3tag); + id3tag.used = 0; + + /* process args */ + while(++i<argc && err == 0) { + char c, *token, *arg, *nextArg; + int argUsed; + + token = argv[i]; + if(*token++ == '-') { + if(i+1 < argc) nextArg = argv[i+1]; + else nextArg = ""; + argUsed = 0; + if (! *token) { + /* The user wants to use stdin and/or stdout. */ + if(inPath[0] == '\0') strncpy(inPath, argv[i],MAX_NAME_SIZE); + else if(outPath[0] == '\0') strncpy(outPath, argv[i],MAX_NAME_SIZE); + } + if (*token == '-') { + /* GNU style */ + token++; + + if (strcmp(token, "resample")==0) { + argUsed=1; + srate = atof( nextArg ); + /* samplerate = rint( 1000.0 * srate ); $A */ + gfp->out_samplerate = (( 1000.0 * srate ) + 0.5); + if (srate < 1) { + fprintf(stderr,"Must specify a samplerate with --resample\n"); + exit(1); + } + } + else if (strcmp(token, "mp3input")==0) { + gfp->input_format=sf_mp3; + } + else if (strcmp(token, "voice")==0) { + gfp->lowpassfreq=12000; + gfp->VBR_max_bitrate_kbps=160; + gfp->no_short_blocks=1; + } + else if (strcmp(token, "noshort")==0) { + gfp->no_short_blocks=1; + } + else if (strcmp(token, "noath")==0) { + gfp->noATH=1; + } + else if (strcmp(token, "nores")==0) { + gfp->disable_reservoir=1; + gfp->padding=0; + } + else if (strcmp(token, "athonly")==0) { + gfp->ATHonly=1; + } + else if (strcmp(token, "nohist")==0) { + #ifdef BRHIST + disp_brhist = 0; + #endif + } + /* options for ID3 tag */ + else if (strcmp(token, "tt")==0) { + id3tag.used=1; argUsed = 1; + strncpy(id3tag.title, nextArg, 30); + } + else if (strcmp(token, "ta")==0) { + id3tag.used=1; argUsed = 1; + strncpy(id3tag.artist, nextArg, 30); + } + else if (strcmp(token, "tl")==0) { + id3tag.used=1; argUsed = 1; + strncpy(id3tag.album, nextArg, 30); + } + else if (strcmp(token, "ty")==0) { + id3tag.used=1; argUsed = 1; + strncpy(id3tag.year, nextArg, 4); + } + else if (strcmp(token, "tc")==0) { + id3tag.used=1; argUsed = 1; + strncpy(id3tag.comment, nextArg, 30); + } + else if (strcmp(token, "tn")==0) { + id3tag.used=1; argUsed = 1; + track = atoi(nextArg); + if (track < 1) { track = 1; } + if (track > 99) { track = 99; } + id3tag.track = track; + } + else if (strcmp(token, "tg")==0) { + argUsed = strtol (nextArg, &token, 10); + if (nextArg==token) { + /* Genere was given as a string, so it's number*/ + for (argUsed=0; argUsed<=genre_last; argUsed++) { + if (!strcmp (genre_list[argUsed], nextArg)) { break; } + } + } + if (argUsed>genre_last) { + argUsed=255; + fprintf(stderr,"Unknown genre: %s. Specifiy genre number \n", nextArg); + } + argUsed &= 255; c=(char)(argUsed); + + id3tag.used=1; argUsed = 1; + strncpy(id3tag.genre, &c, 1); + } + else if (strcmp(token, "lowpass")==0) { + argUsed=1; + gfp->lowpassfreq = (( 1000.0 * atof( nextArg ) ) + 0.5); + if (gfp->lowpassfreq < 1) { + fprintf(stderr,"Must specify lowpass with --lowpass freq, freq >= 0.001 kHz\n"); + exit(1); + } + } + else if (strcmp(token, "lowpass-width")==0) { + argUsed=1; + gfp->lowpasswidth = (( 1000.0 * atof( nextArg ) ) + 0.5); + if (gfp->lowpasswidth < 0) { + fprintf(stderr,"Must specify lowpass width with --lowpass-width freq, freq >= 0 kHz\n"); + exit(1); + } + } + else if (strcmp(token, "highpass")==0) { + argUsed=1; + gfp->highpassfreq = (( 1000.0 * atof( nextArg ) ) + 0.5); + if (gfp->highpassfreq < 1) { + fprintf(stderr,"Must specify highpass with --highpass freq, freq >= 0.001 kHz\n"); + exit(1); + } + } + else if (strcmp(token, "highpass-width")==0) { + argUsed=1; + gfp->highpasswidth = (( 1000.0 * atof( nextArg ) ) + 0.5); + if (gfp->highpasswidth < 0) { + fprintf(stderr,"Must specify highpass width with --highpass-width freq, freq >= 0 kHz\n"); + exit(1); + } + } + else if (strcmp(token, "cwlimit")==0) { + argUsed=1; + gfp->cwlimit = atof( nextArg ); + if (gfp->cwlimit <= 0 ) { + fprintf(stderr,"Must specify cwlimit in kHz\n"); + exit(1); + } + } /* some more GNU-ish options could be added + * version => complete name, version and license info (normal exit) + * quiet/silent => no messages on screen + * brief => few messages on screen (name, status report) + * verbose => all infos to screen (brhist, internal flags/filters) + * o/output file => specifies output filename + * O => stdout + * i/input file => specifies input filename + * I => stdin + */ + else if (strcmp(token, "help") ==0 + ||strcmp(token, "usage")==0){ + lame_help(gfp,programName); /* doesn't return */ + } + else if (strcmp(token, "preset")==0) { + argUsed=1; + if (strcmp(nextArg,"phone")==0) + { /* when making changes, please update help text too */ + gfp->brate = 16; + gfp->highpassfreq=260; + gfp->highpasswidth=40; + gfp->lowpassfreq=3700; + gfp->lowpasswidth=300; + gfp->VBR_q=5; + gfp->VBR_min_bitrate_kbps=8; + gfp->VBR_max_bitrate_kbps=56; + gfp->no_short_blocks=1; + gfp->out_samplerate = 16000; + gfp->mode = MPG_MD_MONO; + gfp->mode_fixed = 1; + gfp->quality = 5; + } + else if (strcmp(nextArg,"voice")==0) + { /* when making changes, please update help text too */ + gfp->brate = 56; + gfp->highpassfreq=100; + gfp->highpasswidth=20; + gfp->lowpasswidth=2000; + gfp->lowpassfreq=11000; + gfp->VBR_q=4; + gfp->VBR_min_bitrate_kbps=8; + gfp->VBR_max_bitrate_kbps=96; + gfp->no_short_blocks=1; + gfp->mode = MPG_MD_MONO; + gfp->mode_fixed = 1; + gfp->out_samplerate = 24000; + gfp->quality = 5; + } + else if (strcmp(nextArg,"fm")==0) + { /* when making changes, please update help text too */ + gfp->brate = 96; + gfp->highpassfreq=30; + gfp->highpasswidth=0; + gfp->lowpassfreq=15000; + gfp->lowpasswidth=0; + gfp->VBR_q=4; + gfp->VBR_min_bitrate_kbps=32; + gfp->VBR_max_bitrate_kbps=192; + gfp->mode = MPG_MD_JOINT_STEREO; + gfp->mode_fixed = 1; + /*gfp->out_samplerate = 32000; */ /* determined automatically based on bitrate & sample freq. */ + gfp->quality = 5; + } + else if (strcmp(nextArg,"tape")==0) + { /* when making changes, please update help text too */ + gfp->brate = 128; + gfp->highpassfreq=15; + gfp->highpasswidth=15; + gfp->lowpassfreq=17000; + gfp->lowpasswidth=2000; + gfp->VBR_q=4; + gfp->VBR_min_bitrate_kbps=32; + gfp->VBR_max_bitrate_kbps=192; + gfp->mode = MPG_MD_JOINT_STEREO; + gfp->mode_fixed = 1; + gfp->quality = 5; + } + else if (strcmp(nextArg,"hifi")==0) + { /* when making changes, please update help text too */ + gfp->brate = 160; + gfp->highpassfreq=15; + gfp->highpasswidth=15; + gfp->lowpassfreq=20000; + gfp->lowpasswidth=3000; + gfp->VBR_q=3; + gfp->VBR_min_bitrate_kbps=32; + gfp->VBR_max_bitrate_kbps=224; + gfp->mode = MPG_MD_JOINT_STEREO; + gfp->mode_fixed = 1; + gfp->quality = 2; + } + else if (strcmp(nextArg,"cd")==0) + { /* when making changes, please update help text too */ + gfp->brate = 192; + gfp->lowpassfreq=-1; + gfp->highpassfreq=-1; + gfp->VBR_q=2; + gfp->VBR_min_bitrate_kbps=80; + gfp->VBR_max_bitrate_kbps=256; + gfp->mode = MPG_MD_STEREO; + gfp->mode_fixed = 1; + gfp->quality = 2; + } + else if (strcmp(nextArg,"studio")==0) + { /* when making changes, please update help text too */ + gfp->brate = 256; + gfp->lowpassfreq=-1; + gfp->highpassfreq=-1; + gfp->VBR_q=0; + gfp->VBR_min_bitrate_kbps=112; + gfp->VBR_max_bitrate_kbps=320; + gfp->mode = MPG_MD_STEREO; + gfp->mode_fixed = 1; + gfp->quality = 2; /* should be 0, but does not work now */ + } + else if (strcmp(nextArg,"help")==0) + { + lame_presets_info(gfp,programName); /* doesn't return */ + } + else + { + fprintf(stderr,"%s: --preset type, type must be phone, voice, fm, tape, hifi, cd or studio, not %s\n", + programName, nextArg); + exit(1); + } + } /* --preset */ + else + { + fprintf(stderr,"%s: unrec option --%s\n", + programName, token); + } + i += argUsed; + + } else while( (c = *token++) ) { + if(*token ) arg = token; + else arg = nextArg; + switch(c) { + case 'm': argUsed = 1; gfp->mode_fixed = 1; + if (*arg == 's') + { gfp->mode = MPG_MD_STEREO; } + else if (*arg == 'd') + { gfp->mode = MPG_MD_DUAL_CHANNEL; } + else if (*arg == 'j') + { gfp->mode = MPG_MD_JOINT_STEREO; } + else if (*arg == 'f') + { gfp->mode = MPG_MD_JOINT_STEREO; gfp->force_ms=1; } + else if (*arg == 'm') + { gfp->mode = MPG_MD_MONO; } + else { + fprintf(stderr,"%s: -m mode must be s/d/j/f/m not %s\n", + programName, arg); + err = 1; + } + break; + case 'V': argUsed = 1; gfp->VBR = 1; + gfp->VBR_q = atoi(arg); + if (gfp->VBR_q <0) gfp->VBR_q=0; + if (gfp->VBR_q >9) gfp->VBR_q=9; + break; + case 'q': argUsed = 1; + user_quality = atoi(arg); + if (user_quality<0) user_quality=0; + if (user_quality>9) user_quality=9; + break; + case 's': + argUsed = 1; + srate = atof( arg ); + /* samplerate = rint( 1000.0 * srate ); $A */ + gfp->in_samplerate = (( 1000.0 * srate ) + 0.5); + break; + case 'b': + argUsed = 1; + gfp->brate = atoi(arg); + gfp->VBR_min_bitrate_kbps=gfp->brate; + break; + case 'B': + argUsed = 1; + gfp->VBR_max_bitrate_kbps=atoi(arg); + break; + case 't': /* dont write VBR tag */ + gfp->bWriteVbrTag=0; + break; + case 'r': /* force raw pcm input file */ + #ifdef LIBSNDFILE + fprintf(stderr,"WARNING: libsndfile may ignore -r and perform fseek's on the input.\n"); + fprintf(stderr,"Compile without libsndfile if this is a problem.\n"); + #endif + gfp->input_format=sf_raw; + break; + case 'x': /* force byte swapping */ + gfp->swapbytes=TRUE; + break; + case 'p': /* (jo) error_protection: add crc16 information to stream */ + gfp->error_protection = 1; + break; + case 'a': /* autoconvert input file from stereo to mono - for mono mp3 encoding */ + autoconvert=1; + gfp->mode=MPG_MD_MONO; + gfp->mode_fixed=1; + break; + case 'h': + gfp->quality = 2; + break; + case 'k': + gfp->lowpassfreq=-1; + gfp->highpassfreq=-1; + break; + case 'd': + gfp->allow_diff_short = 1; + break; + case 'v': + gfp->VBR = 1; + break; + case 'S': + gfp->silent = TRUE; + break; + case 'X': argUsed = 1; gfp->experimentalX = 0; + if (*arg == '0') + { gfp->experimentalX=0; } + else if (*arg == '1') + { gfp->experimentalX=1; } + else if (*arg == '2') + { gfp->experimentalX=2; } + else if (*arg == '3') + { gfp->experimentalX=3; } + else if (*arg == '4') + { gfp->experimentalX=4; } + else if (*arg == '5') + { gfp->experimentalX=5; } + else if (*arg == '6') + { gfp->experimentalX=6; } + else { + fprintf(stderr,"%s: -X n must be 0-6, not %s\n", + programName, arg); + err = 1; + } + break; + + + case 'Y': + gfp->experimentalY = TRUE; + break; + case 'Z': + gfp->experimentalZ = TRUE; + break; + case 'f': + gfp->quality= 9; + break; + case 'g': /* turn on gtk analysis */ + #ifdef HAVEGTK + gfp->gtkflag = TRUE; + #else + fprintf(stderr,"LAME not compiled with GTK support, -g not supported.\n", + programName, arg); + #endif + break; + + case 'e': argUsed = 1; + if (*arg == 'n') gfp->emphasis = 0; + else if (*arg == '5') gfp->emphasis = 1; + else if (*arg == 'c') gfp->emphasis = 3; + else { + fprintf(stderr,"%s: -e emp must be n/5/c not %s\n", + programName, arg); + err = 1; + } + break; + case 'c': gfp->copyright = 1; break; + case 'o': gfp->original = 0; break; + + case '?': lame_help(gfp,programName); /* doesn't return */ + default: fprintf(stderr,"%s: unrec option %c\n", + programName, c); + err = 1; break; + } + if(argUsed) { + if(arg == token) token = ""; /* no more from token */ + else ++i; /* skip arg we used */ + arg = ""; argUsed = 0; + } + } + } else { + if(inPath[0] == '\0') strncpy(inPath, argv[i], MAX_NAME_SIZE); + else if(outPath[0] == '\0') strncpy(outPath, argv[i], MAX_NAME_SIZE); + else { + fprintf(stderr,"%s: excess arg %s\n", programName, argv[i]); + err = 1; + } + } + } /* loop over args */ + + + + if(err || inPath[0] == '\0') lame_usage(gfp,programName); /* never returns */ + if (inPath[0]=='-') gfp->silent=1; /* turn off status - it's broken for stdin */ + if(outPath[0] == '\0') { + if (inPath[0]=='-') { + /* if input is stdin, default output is stdout */ + strcpy(outPath,"-"); + }else { + strncpy(outPath, inPath, MAX_NAME_SIZE - 4); + strncat(outPath, ".mp3", 4 ); + } + } + /* some file options not allowed with stdout */ + if (outPath[0]=='-') { + gfp->bWriteVbrTag=0; /* turn off VBR tag */ + if (id3tag.used) { + id3tag.used=0; /* turn of id3 tagging */ + fprintf(stderr,"id3tag ignored: id3 tagging not supported for stdout.\n"); + } + } + + + /* if user did not explicitly specify input is mp3, check file name */ + if (gfp->input_format != sf_mp3) + if (!(strcmp((char *) &inPath[strlen(inPath)-4],".mp3"))) + gfp->input_format = sf_mp3; + + #if !(defined HAVEMPGLIB || defined AMIGA_MPEGA) + if (gfp->input_format == sf_mp3) { + fprintf(stderr,"Error: libmp3lame not compiled with mp3 *decoding* support \n"); + exit(1); + } + #endif + /* default guess for number of channels */ + if (autoconvert) gfp->num_channels=2; + else if (gfp->mode == MPG_MD_MONO) gfp->num_channels=1; + else gfp->num_channels=2; + + /* user specified a quality value. override any defaults set above */ + if (user_quality) gfp->quality=user_quality; + + } + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/portableio.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/portableio.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/portableio.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,358 ---- + /* Copyright (C) 1988-1991 Apple Computer, Inc. + * All Rights Reserved. + * + * Warranty Information + * Even though Apple has reviewed this software, Apple makes no warranty + * or representation, either express or implied, with respect to this + * software, its quality, accuracy, merchantability, or fitness for a + * particular purpose. As a result, this software is provided "as is," + * and you, its user, are assuming the entire risk as to its quality + * and accuracy. + * + * This code may be used and freely distributed as long as it includes + * this copyright notice and the warranty information. + * + * + * Motorola processors (Macintosh, Sun, Sparc, MIPS, etc) + * pack bytes from high to low (they are big-endian). + * Use the HighLow routines to match the native format + * of these machines. + * + * Intel-like machines (PCs, Sequent) + * pack bytes from low to high (the are little-endian). + * Use the LowHigh routines to match the native format + * of these machines. + * + * These routines have been tested on the following machines: + * Apple Macintosh, MPW 3.1 C compiler + * Apple Macintosh, THINK C compiler + * Silicon Graphics IRIS, MIPS compiler + * Cray X/MP and Y/MP + * Digital Equipment VAX + * + * + * Implemented by Malcolm Slaney and Ken Turkowski. + * + * Malcolm Slaney contributions during 1988-1990 include big- and little- + * endian file I/O, conversion to and from Motorola's extended 80-bit + * floating-point format, and conversions to and from IEEE single- + * precision floating-point format. + * + * In 1991, Ken Turkowski implemented the conversions to and from + * IEEE double-precision format, added more precision to the extended + * conversions, and accommodated conversions involving +/- infinity, + * NaN's, and denormalized numbers. + * + * $Id: portableio.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: portableio.c,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:55:51 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.1.1.1 1999/11/24 08:43:35 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 2.6 91/04/30 17:06:02 malcolm + */ + + #include <stdio.h> + #include <math.h> + #include "portableio.h" + + /**************************************************************** + * Big/little-endian independent I/O routines. + ****************************************************************/ + + + int + ReadByte(FILE *fp) + { + int result; + + result = getc(fp) & 0xff; + if (result & 0x80) + result = result - 0x100; + return result; + } + + + int + Read16BitsLowHigh(FILE *fp) + { + int first, second, result; + + first = 0xff & getc(fp); + second = 0xff & getc(fp); + + result = (second << 8) + first; + #ifndef THINK_C42 + if (result & 0x8000) + result = result - 0x10000; + #endif /* THINK_C */ + return(result); + } + + + int + Read16BitsHighLow(FILE *fp) + { + int first, second, result; + + first = 0xff & getc(fp); + second = 0xff & getc(fp); + + result = (first << 8) + second; + #ifndef THINK_C42 + if (result & 0x8000) + result = result - 0x10000; + #endif /* THINK_C */ + return(result); + } + + + void + Write8Bits(FILE *fp, int i) + { + putc(i&0xff,fp); + } + + + void + Write16BitsLowHigh(FILE *fp, int i) + { + putc(i&0xff,fp); + putc((i>>8)&0xff,fp); + } + + + void + Write16BitsHighLow(FILE *fp, int i) + { + putc((i>>8)&0xff,fp); + putc(i&0xff,fp); + } + + + int + Read24BitsHighLow(FILE *fp) + { + int first, second, third; + int result; + + first = 0xff & getc(fp); + second = 0xff & getc(fp); + third = 0xff & getc(fp); + + result = (first << 16) + (second << 8) + third; + if (result & 0x800000) + result = result - 0x1000000; + return(result); + } + + #define Read32BitsLowHigh(f) Read32Bits(f) + + + int + Read32Bits(FILE *fp) + { + int first, second, result; + + first = 0xffff & Read16BitsLowHigh(fp); + second = 0xffff & Read16BitsLowHigh(fp); + + result = (second << 16) + first; + #ifdef CRAY + if (result & 0x80000000) + result = result - 0x100000000; + #endif /* CRAY */ + return(result); + } + + + int + Read32BitsHighLow(FILE *fp) + { + int first, second, result; + + first = 0xffff & Read16BitsHighLow(fp); + second = 0xffff & Read16BitsHighLow(fp); + + result = (first << 16) + second; + #ifdef CRAY + if (result & 0x80000000) + result = result - 0x100000000; + #endif + return(result); + } + + + void + Write32Bits(FILE *fp, int i) + { + Write16BitsLowHigh(fp,(int)(i&0xffffL)); + Write16BitsLowHigh(fp,(int)((i>>16)&0xffffL)); + } + + + void + Write32BitsLowHigh(FILE *fp, int i) + { + Write16BitsLowHigh(fp,(int)(i&0xffffL)); + Write16BitsLowHigh(fp,(int)((i>>16)&0xffffL)); + } + + + void + Write32BitsHighLow(FILE *fp, int i) + { + Write16BitsHighLow(fp,(int)((i>>16)&0xffffL)); + Write16BitsHighLow(fp,(int)(i&0xffffL)); + } + + void ReadBytes(FILE *fp, char *p, int n) + { + while (!feof(fp) & (n-- > 0)) + *p++ = getc(fp); + } + + void ReadBytesSwapped(FILE *fp, char *p, int n) + { + register char *q = p; + + while (!feof(fp) & (n-- > 0)) + *q++ = getc(fp); + + for (q--; p < q; p++, q--){ + n = *p; + *p = *q; + *q = n; + } + } + + void WriteBytes(FILE *fp, char *p, int n) + { + while (n-- > 0) + putc(*p++, fp); + } + + void WriteBytesSwapped(FILE *fp, char *p, int n) + { + p += n-1; + while (n-- > 0) + putc(*p--, fp); + } + + defdouble + ReadIeeeFloatHighLow(FILE *fp) + { + char bits[kFloatLength]; + + ReadBytes(fp, bits, kFloatLength); + return ConvertFromIeeeSingle(bits); + } + + defdouble + ReadIeeeFloatLowHigh(FILE *fp) + { + char bits[kFloatLength]; + + ReadBytesSwapped(fp, bits, kFloatLength); + return ConvertFromIeeeSingle(bits); + } + + defdouble + ReadIeeeDoubleHighLow(FILE *fp) + { + char bits[kDoubleLength]; + + ReadBytes(fp, bits, kDoubleLength); + return ConvertFromIeeeDouble(bits); + } + + defdouble + ReadIeeeDoubleLowHigh(FILE *fp) + { + char bits[kDoubleLength]; + + ReadBytesSwapped(fp, bits, kDoubleLength); + return ConvertFromIeeeDouble(bits); + } + + defdouble + ReadIeeeExtendedHighLow(FILE *fp) + { + char bits[kExtendedLength]; + + ReadBytes(fp, bits, kExtendedLength); + return ConvertFromIeeeExtended(bits); + } + + defdouble + ReadIeeeExtendedLowHigh(FILE *fp) + { + char bits[kExtendedLength]; + + ReadBytesSwapped(fp, bits, kExtendedLength); + return ConvertFromIeeeExtended(bits); + } + + void + WriteIeeeFloatLowHigh(FILE *fp, defdouble num) + { + char bits[kFloatLength]; + + ConvertToIeeeSingle(num,bits); + WriteBytesSwapped(fp,bits,kFloatLength); + } + + void + WriteIeeeFloatHighLow(FILE *fp, defdouble num) + { + char bits[kFloatLength]; + + ConvertToIeeeSingle(num,bits); + WriteBytes(fp,bits,kFloatLength); + } + + void + WriteIeeeDoubleLowHigh(FILE *fp, defdouble num) + { + char bits[kDoubleLength]; + + ConvertToIeeeDouble(num,bits); + WriteBytesSwapped(fp,bits,kDoubleLength); + } + + void + WriteIeeeDoubleHighLow(FILE *fp, defdouble num) + { + char bits[kDoubleLength]; + + ConvertToIeeeDouble(num,bits); + WriteBytes(fp,bits,kDoubleLength); + } + + void + WriteIeeeExtendedLowHigh(FILE *fp, defdouble num) + { + char bits[kExtendedLength]; + + ConvertToIeeeExtended(num,bits); + WriteBytesSwapped(fp,bits,kExtendedLength); + } + + + void + WriteIeeeExtendedHighLow(FILE *fp, defdouble num) + { + char bits[kExtendedLength]; + + ConvertToIeeeExtended(num,bits); + WriteBytes(fp,bits,kExtendedLength); + } + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/portableio.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/portableio.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/portableio.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,105 ---- + #ifndef PORTABLEIO_H__ + #define PORTABLEIO_H__ + /* Copyright (C) 1988-1991 Apple Computer, Inc. + * All Rights Reserved. + * + * Warranty Information + * Even though Apple has reviewed this software, Apple makes no warranty + * or representation, either express or implied, with respect to this + * software, its quality, accuracy, merchantability, or fitness for a + * particular purpose. As a result, this software is provided "as is," + * and you, its user, are assuming the entire risk as to its quality + * and accuracy. + * + * This code may be used and freely distributed as long as it includes + * this copyright notice and the warranty information. + * + * Machine-independent I/O routines for 8-, 16-, 24-, and 32-bit integers. + * + * Motorola processors (Macintosh, Sun, Sparc, MIPS, etc) + * pack bytes from high to low (they are big-endian). + * Use the HighLow routines to match the native format + * of these machines. + * + * Intel-like machines (PCs, Sequent) + * pack bytes from low to high (the are little-endian). + * Use the LowHigh routines to match the native format + * of these machines. + * + * These routines have been tested on the following machines: + * Apple Macintosh, MPW 3.1 C compiler + * Apple Macintosh, THINK C compiler + * Silicon Graphics IRIS, MIPS compiler + * Cray X/MP and Y/MP + * Digital Equipment VAX + * + * + * Implemented by Malcolm Slaney and Ken Turkowski. + * + * Malcolm Slaney contributions during 1988-1990 include big- and little- + * endian file I/O, conversion to and from Motorola's extended 80-bit + * floating-point format, and conversions to and from IEEE single- + * precision floating-point format. + * + * In 1991, Ken Turkowski implemented the conversions to and from + * IEEE double-precision format, added more precision to the extended + * conversions, and accommodated conversions involving +/- infinity, + * NaN's, and denormalized numbers. + * + * $Id: portableio.h,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: portableio.h,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:55:51 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.1.1.1 1999/11/24 08:43:37 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 2.6 91/04/30 17:06:02 malcolm + */ + + #include <stdio.h> + #include "ieeefloat.h" + + #ifndef __cplusplus + # define CLINK + #else + # define CLINK "C" + #endif + + extern CLINK int ReadByte(FILE *fp); + extern CLINK int Read16BitsLowHigh(FILE *fp); + extern CLINK int Read16BitsHighLow(FILE *fp); + extern CLINK void Write8Bits(FILE *fp, int i); + extern CLINK void Write16BitsLowHigh(FILE *fp, int i); + extern CLINK void Write16BitsHighLow(FILE *fp, int i); + extern CLINK int Read24BitsHighLow(FILE *fp); + extern CLINK int Read32Bits(FILE *fp); + extern CLINK int Read32BitsHighLow(FILE *fp); + extern CLINK void Write32Bits(FILE *fp, int i); + extern CLINK void Write32BitsLowHigh(FILE *fp, int i); + extern CLINK void Write32BitsHighLow(FILE *fp, int i); + extern CLINK void ReadBytes(FILE *fp, char *p, int n); + extern CLINK void ReadBytesSwapped(FILE *fp, char *p, int n); + extern CLINK void WriteBytes(FILE *fp, char *p, int n); + extern CLINK void WriteBytesSwapped(FILE *fp, char *p, int n); + extern CLINK defdouble ReadIeeeFloatHighLow(FILE *fp); + extern CLINK defdouble ReadIeeeFloatLowHigh(FILE *fp); + extern CLINK defdouble ReadIeeeDoubleHighLow(FILE *fp); + extern CLINK defdouble ReadIeeeDoubleLowHigh(FILE *fp); + extern CLINK defdouble ReadIeeeExtendedHighLow(FILE *fp); + extern CLINK defdouble ReadIeeeExtendedLowHigh(FILE *fp); + extern CLINK void WriteIeeeFloatLowHigh(FILE *fp, defdouble num); + extern CLINK void WriteIeeeFloatHighLow(FILE *fp, defdouble num); + extern CLINK void WriteIeeeDoubleLowHigh(FILE *fp, defdouble num); + extern CLINK void WriteIeeeDoubleHighLow(FILE *fp, defdouble num); + extern CLINK void WriteIeeeExtendedLowHigh(FILE *fp, defdouble num); + extern CLINK void WriteIeeeExtendedHighLow(FILE *fp, defdouble num); + + #define Read32BitsLowHigh(f) Read32Bits(f) + #define WriteString(f,s) fwrite(s,strlen(s),sizeof(char),f) + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/psymodel.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/psymodel.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/psymodel.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,1253 ---- + /********************************************************************** + * date programmers comment * + * 2/25/91 Davis Pan start of version 1.0 records * + * 5/10/91 W. Joseph Carter Ported to Macintosh and Unix. * + * 7/10/91 Earle Jennings Ported to MsDos. * + * replace of floats with FLOAT * + * 2/11/92 W. Joseph Carter Fixed mem_alloc() arg for "absthr". * + * 3/16/92 Masahiro Iwadare Modification for Layer III * + * 17/4/93 Masahiro Iwadare Updated for IS Modification * + **********************************************************************/ + + #include "util.h" + #include "encoder.h" + #include "psymodel.h" + #include "l3side.h" + #include <assert.h> + #ifdef HAVEGTK + #include "gtkanal.h" + #endif + #include "tables.h" + #include "fft.h" + + #ifdef M_LN10 + #define LN_TO_LOG10 (M_LN10/10) + #else + #define LN_TO_LOG10 0.2302585093 + #endif + + + void L3para_read( FLOAT8 sfreq, int numlines[CBANDS],int numlines_s[CBANDS], int partition_l[HBLKSIZE], + FLOAT8 minval[CBANDS], FLOAT8 qthr_l[CBANDS], + FLOAT8 s3_l[CBANDS + 1][CBANDS + 1], + FLOAT8 s3_s[CBANDS + 1][CBANDS + 1], + FLOAT8 qthr_s[CBANDS], + FLOAT8 SNR_s[CBANDS], + int bu_l[SBPSY_l], int bo_l[SBPSY_l], + FLOAT8 w1_l[SBPSY_l], FLOAT8 w2_l[SBPSY_l], + int bu_s[SBPSY_s], int bo_s[SBPSY_s], + FLOAT8 w1_s[SBPSY_s], FLOAT8 w2_s[SBPSY_s] ); + + + + + + + + + + + void L3psycho_anal( lame_global_flags *gfp, + short int *buffer[2],int gr_out , + FLOAT8 *ms_ratio, + FLOAT8 *ms_ratio_next, + FLOAT8 *ms_ener_ratio, + III_psy_ratio masking_ratio[2][2], + III_psy_ratio masking_MS_ratio[2][2], + FLOAT8 percep_entropy[2],FLOAT8 percep_MS_entropy[2], + int blocktype_d[2]) + { + + /* to get a good cache performance, one has to think about + * the sequence, in which the variables are used + */ + + /* The static variables "r", "phi_sav", "new", "old" and "oldest" have */ + /* to be remembered for the unpredictability measure. For "r" and */ + /* "phi_sav", the first index from the left is the channel select and */ + /* the second index is the "age" of the data. */ + static FLOAT8 minval[CBANDS],qthr_l[CBANDS]; + static FLOAT8 qthr_s[CBANDS]; + static FLOAT8 nb_1[4][CBANDS], nb_2[4][CBANDS]; + static FLOAT8 s3_s[CBANDS + 1][CBANDS + 1]; + static FLOAT8 s3_l[CBANDS + 1][CBANDS + 1]; + + static III_psy_xmin thm[4]; + static III_psy_xmin en[4]; + + /* unpredictability calculation + */ + static int cw_upper_index; + static int cw_lower_index; + static FLOAT ax_sav[4][2][HBLKSIZE]; + static FLOAT bx_sav[4][2][HBLKSIZE]; + static FLOAT rx_sav[4][2][HBLKSIZE]; + static FLOAT cw[HBLKSIZE]; + + /* fft and energy calculation + */ + FLOAT (*wsamp_l)[BLKSIZE]; + FLOAT (*wsamp_s)[3][BLKSIZE_s]; + FLOAT tot_ener[4]; + static FLOAT wsamp_L[2][BLKSIZE]; + static FLOAT energy[HBLKSIZE]; + static FLOAT wsamp_S[2][3][BLKSIZE_s]; + static FLOAT energy_s[3][HBLKSIZE_s]; + + /* convolution + */ + static FLOAT8 eb[CBANDS]; + static FLOAT8 cb[CBANDS]; + static FLOAT8 thr[CBANDS]; + + /* Scale Factor Bands + */ + static FLOAT8 w1_l[SBPSY_l], w2_l[SBPSY_l]; + static FLOAT8 w1_s[SBPSY_s], w2_s[SBPSY_s]; + static FLOAT8 mld_l[SBPSY_l],mld_s[SBPSY_s]; + static int bu_l[SBPSY_l],bo_l[SBPSY_l] ; + static int bu_s[SBPSY_s],bo_s[SBPSY_s] ; + static int npart_l,npart_s; + static int npart_l_orig,npart_s_orig; + + static int s3ind[CBANDS][2]; + static int s3ind_s[CBANDS][2]; + + static int numlines_s[CBANDS] ; + static int numlines_l[CBANDS]; + static int partition_l[HBLKSIZE]; + + /* frame analyzer + */ + #ifdef HAVEGTK + static FLOAT energy_save[4][HBLKSIZE]; + static FLOAT8 pe_save[4]; + static FLOAT8 ers_save[4]; + #endif + + /* ratios + */ + static FLOAT8 pe[4]={0,0,0,0}; + static FLOAT8 ms_ratio_s_old=0,ms_ratio_l_old=0; + static FLOAT8 ms_ener_ratio_old=.25; + FLOAT8 ms_ratio_l=0,ms_ratio_s=0; + + /* block type + */ + static int blocktype_old[2]; + int blocktype[2],uselongblock[2]; + + /* usual variables like loop indices, etc.. + */ + int numchn, chn; + int b, i, j, k; + int sb,sblock; + FLOAT cwlimit; + + + /* initialization of static variables + */ + if((gfp->frameNum==0) && (gr_out==0)){ + FLOAT8 SNR_s[CBANDS]; + + blocktype_old[0]=STOP_TYPE; + blocktype_old[1]=STOP_TYPE; + i = gfp->out_samplerate; + switch(i){ + case 32000: break; + case 44100: break; + case 48000: break; + case 16000: break; + case 22050: break; + case 24000: break; + default: fprintf(stderr,"error, invalid sampling frequency: %d Hz\n",i); + exit(-1); + } + + /* reset states used in unpredictability measure */ + memset (rx_sav,0, sizeof(rx_sav)); + memset (ax_sav,0, sizeof(ax_sav)); + memset (bx_sav,0, sizeof(bx_sav)); + memset (en,0, sizeof(en)); + memset (thm,0, sizeof(thm)); + + + /* gfp->cwlimit = sfreq*j/1024.0; */ + cw_lower_index=6; + if (gfp->cwlimit>0) + cwlimit=gfp->cwlimit; + else + cwlimit=8.8717; + cw_upper_index = cwlimit*1000.0*1024.0/((FLOAT8) gfp->out_samplerate); + cw_upper_index=Min(HBLKSIZE-4,cw_upper_index); /* j+3 < HBLKSIZE-1 */ + cw_upper_index=Max(6,cw_upper_index); + + for ( j = 0; j < HBLKSIZE; j++ ) + cw[j] = 0.4; + + /* setup stereo demasking thresholds */ + /* formula reverse enginerred from plot in paper */ + for ( sb = 0; sb < SBPSY_s; sb++ ) { + FLOAT8 mld = 1.25*(1-cos(PI*sb/SBPSY_s))-2.5; + mld_s[sb] = pow(10.0,mld); + } + for ( sb = 0; sb < SBPSY_l; sb++ ) { + FLOAT8 mld = 1.25*(1-cos(PI*sb/SBPSY_l))-2.5; + mld_l[sb] = pow(10.0,mld); + } + + for (i=0;i<HBLKSIZE;i++) partition_l[i]=-1; + + L3para_read( (FLOAT8) gfp->out_samplerate,numlines_l,numlines_s,partition_l,minval,qthr_l,s3_l,s3_s, + qthr_s,SNR_s, + bu_l,bo_l,w1_l,w2_l, bu_s,bo_s,w1_s,w2_s ); + + + /* npart_l_orig = number of partition bands before convolution */ + /* npart_l = number of partition bands after convolution */ + npart_l_orig=0; npart_s_orig=0; + for (i=0;i<HBLKSIZE;i++) + if (partition_l[i]>npart_l_orig) npart_l_orig=partition_l[i]; + npart_l_orig++; + + for (i=0;numlines_s[i]>=0;i++) + ; + npart_s_orig = i; + + npart_l=bo_l[SBPSY_l-1]+1; + npart_s=bo_s[SBPSY_s-1]+1; + + /* MPEG2 tables are screwed up + * the mapping from paritition bands to scalefactor bands will use + * more paritition bands than we have. + * So we will not compute these fictitious partition bands by reducing + * npart_l below. */ + if (npart_l > npart_l_orig) { + npart_l=npart_l_orig; + bo_l[SBPSY_l-1]=npart_l-1; + w2_l[SBPSY_l-1]=1.0; + } + if (npart_s > npart_s_orig) { + npart_s=npart_s_orig; + bo_s[SBPSY_s-1]=npart_s-1; + w2_s[SBPSY_s-1]=1.0; + } + + + + for (i=0; i<npart_l; i++) { + for (j = 0; j < npart_l_orig; j++) { + if (s3_l[i][j] != 0.0) + break; + } + s3ind[i][0] = j; + + for (j = npart_l_orig - 1; j > 0; j--) { + if (s3_l[i][j] != 0.0) + break; + } + s3ind[i][1] = j; + } + + + for (i=0; i<npart_s; i++) { + for (j = 0; j < npart_s_orig; j++) { + if (s3_s[i][j] != 0.0) + break; + } + s3ind_s[i][0] = j; + + for (j = npart_s_orig - 1; j > 0; j--) { + if (s3_s[i][j] != 0.0) + break; + } + s3ind_s[i][1] = j; + } + + + /* + #include "debugscalefac.c" + */ + + + #define AACS3 + #define NEWS3XX + + #ifdef AACS3 + /* AAC values, results in more masking over MP3 values */ + # define TMN 18 + # define NMT 6 + #else + /* MP3 values */ + # define TMN 29 + # define NMT 6 + #endif + + #define rpelev 2 + #define rpelev2 16 + + /* compute norm_l, norm_s instead of relying on table data */ + for ( b = 0;b < npart_l; b++ ) { + FLOAT8 norm=0; + for ( k = s3ind[b][0]; k <= s3ind[b][1]; k++ ) { + norm += s3_l[b][k]; + } + for ( k = s3ind[b][0]; k <= s3ind[b][1]; k++ ) { + s3_l[b][k] *= exp(-LN_TO_LOG10 * NMT) / norm; + } + /*printf("%i norm=%f norm_l=%f \n",b,1/norm,norm_l[b]);*/ + } + + /* MPEG1 SNR_s data is given in db, convert to energy */ + if (gfp->version == 1) { + for ( b = 0;b < npart_s; b++ ) { + SNR_s[b]=exp( (FLOAT8) SNR_s[b] * LN_TO_LOG10 ); + } + } + + for ( b = 0;b < npart_s; b++ ) { + FLOAT8 norm=0; + for ( k = s3ind_s[b][0]; k <= s3ind_s[b][1]; k++ ) { + norm += s3_s[b][k]; + } + for ( k = s3ind_s[b][0]; k <= s3ind_s[b][1]; k++ ) { + s3_s[b][k] *= SNR_s[b] / norm; + } + /*printf("%i norm=%f norm_s=%f \n",b,1/norm,norm_l[b]);*/ + } + + init_fft(); + } + /************************* End of Initialization *****************************/ + + + + + + numchn = gfp->stereo; + /* chn=2 and 3 = Mid and Side channels */ + if (gfp->mode == MPG_MD_JOINT_STEREO) numchn=4; + for (chn=0; chn<numchn; chn++) { + + wsamp_s = wsamp_S+(chn & 1); + wsamp_l = wsamp_L+(chn & 1); + + + if (chn<2) { + /********************************************************************** + * compute FFTs + **********************************************************************/ + fft_long ( *wsamp_l, chn, buffer); + fft_short( *wsamp_s, chn, buffer); + + /* LR maskings */ + percep_entropy[chn] = pe[chn]; + masking_ratio[gr_out][chn].thm = thm[chn]; + masking_ratio[gr_out][chn].en = en[chn]; + }else{ + /* MS maskings */ + percep_MS_entropy[chn-2] = pe[chn]; + masking_MS_ratio[gr_out][chn-2].en = en[chn]; + masking_MS_ratio[gr_out][chn-2].thm = thm[chn]; + + if (chn == 2) + { + for (j = BLKSIZE-1; j >=0 ; --j) + { + FLOAT l = wsamp_L[0][j]; + FLOAT r = wsamp_L[1][j]; + wsamp_L[0][j] = (l+r)*(FLOAT)(SQRT2*0.5); + wsamp_L[1][j] = (l-r)*(FLOAT)(SQRT2*0.5); + } + for (b = 2; b >= 0; --b) + { + for (j = BLKSIZE_s-1; j >= 0 ; --j) + { + FLOAT l = wsamp_S[0][b][j]; + FLOAT r = wsamp_S[1][b][j]; + wsamp_S[0][b][j] = (l+r)*(FLOAT)(SQRT2*0.5); + wsamp_S[1][b][j] = (l-r)*(FLOAT)(SQRT2*0.5); + } + } + } + } + + /********************************************************************** + * compute energies + **********************************************************************/ + + + + energy[0] = (*wsamp_l)[0]; + energy[0] *= energy[0]; + + tot_ener[chn] = energy[0]; /* sum total energy at nearly no extra cost */ + + for (j=BLKSIZE/2-1; j >= 0; --j) + { + FLOAT re = (*wsamp_l)[BLKSIZE/2-j]; + FLOAT im = (*wsamp_l)[BLKSIZE/2+j]; + energy[BLKSIZE/2-j] = (re * re + im * im) * (FLOAT)0.5; + + tot_ener[chn] += energy[BLKSIZE/2-j]; + } + for (b = 2; b >= 0; --b) + { + energy_s[b][0] = (*wsamp_s)[b][0]; + energy_s[b][0] *= energy_s [b][0]; + for (j=BLKSIZE_s/2-1; j >= 0; --j) + { + FLOAT re = (*wsamp_s)[b][BLKSIZE_s/2-j]; + FLOAT im = (*wsamp_s)[b][BLKSIZE_s/2+j]; + energy_s[b][BLKSIZE_s/2-j] = (re * re + im * im) * (FLOAT)0.5; + } + } + + + #ifdef HAVEGTK + if(gfp->gtkflag) { + for (j=0; j<HBLKSIZE ; j++) { + pinfo->energy[gr_out][chn][j]=energy_save[chn][j]; + energy_save[chn][j]=energy[j]; + } + } + #endif + + /********************************************************************** + * compute unpredicatability of first six spectral lines * + **********************************************************************/ + for ( j = 0; j < cw_lower_index; j++ ) + { /* calculate unpredictability measure cw */ + FLOAT an, a1, a2; + FLOAT bn, b1, b2; + FLOAT rn, r1, r2; + FLOAT numre, numim, den; + + a2 = ax_sav[chn][1][j]; + b2 = bx_sav[chn][1][j]; + r2 = rx_sav[chn][1][j]; + a1 = ax_sav[chn][1][j] = ax_sav[chn][0][j]; + b1 = bx_sav[chn][1][j] = bx_sav[chn][0][j]; + r1 = rx_sav[chn][1][j] = rx_sav[chn][0][j]; + an = ax_sav[chn][0][j] = (*wsamp_l)[j]; + bn = bx_sav[chn][0][j] = j==0 ? (*wsamp_l)[0] : (*wsamp_l)[BLKSIZE-j]; + rn = rx_sav[chn][0][j] = sqrt(energy[j]); + + { /* square (x1,y1) */ + if( r1 != 0 ) { + numre = (a1*b1); + numim = (a1*a1-b1*b1)*(FLOAT)0.5; + den = r1*r1; + } else { + numre = 1; + numim = 0; + den = 1; + } + } + + { /* multiply by (x2,-y2) */ + if( r2 != 0 ) { + FLOAT tmp2 = (numim+numre)*(a2+b2)*(FLOAT)0.5; + FLOAT tmp1 = -a2*numre+tmp2; + numre = -b2*numim+tmp2; + numim = tmp1; + den *= r2; + } else { + /* do nothing */ + } + } + + { /* r-prime factor */ + FLOAT tmp = (2*r1-r2)/den; + numre *= tmp; + numim *= tmp; + } + den=rn+fabs(2*r1-r2); + if( den != 0 ) { + numre = (an+bn)*(FLOAT)0.5-numre; + numim = (an-bn)*(FLOAT)0.5-numim; + den = sqrt(numre*numre+numim*numim)/den; + } + cw[j] = den; + } + + + + /********************************************************************** + * compute unpredicatibility of next 200 spectral lines * + **********************************************************************/ + for ( j = cw_lower_index; j < cw_upper_index; j += 4 ) + {/* calculate unpredictability measure cw */ + FLOAT rn, r1, r2; + FLOAT numre, numim, den; + + k = (j+2) / 4; + + { /* square (x1,y1) */ + r1 = energy_s[0][k]; + if( r1 != 0 ) { + FLOAT a1 = (*wsamp_s)[0][k]; + FLOAT b1 = (*wsamp_s)[0][BLKSIZE_s-k]; /* k is never 0 */ + numre = (a1*b1); + numim = (a1*a1-b1*b1)*(FLOAT)0.5; + den = r1; + r1 = sqrt(r1); + } else { + numre = 1; + numim = 0; + den = 1; + } + } + + + { /* multiply by (x2,-y2) */ + r2 = energy_s[2][k]; + if( r2 != 0 ) { + FLOAT a2 = (*wsamp_s)[2][k]; + FLOAT b2 = (*wsamp_s)[2][BLKSIZE_s-k]; + + + FLOAT tmp2 = (numim+numre)*(a2+b2)*(FLOAT)0.5; + FLOAT tmp1 = -a2*numre+tmp2; + numre = -b2*numim+tmp2; + numim = tmp1; + + r2 = sqrt(r2); + den *= r2; + } else { + /* do nothing */ + } + } + + { /* r-prime factor */ + FLOAT tmp = (2*r1-r2)/den; + numre *= tmp; + numim *= tmp; + } + + rn = sqrt(energy_s[1][k]); + den=rn+fabs(2*r1-r2); + if( den != 0 ) { + FLOAT an = (*wsamp_s)[1][k]; + FLOAT bn = (*wsamp_s)[1][BLKSIZE_s-k]; + numre = (an+bn)*(FLOAT)0.5-numre; + numim = (an-bn)*(FLOAT)0.5-numim; + den = sqrt(numre*numre+numim*numim)/den; + } + + cw[j+1] = cw[j+2] = cw[j+3] = cw[j] = den; + } + + #if 0 + for ( j = 14; j < HBLKSIZE-4; j += 4 ) + {/* calculate energy from short ffts */ + FLOAT8 tot,ave; + k = (j+2) / 4; + for (tot=0, sblock=0; sblock < 3; sblock++) + tot+=energy_s[sblock][k]; + ave = energy[j+1]+ energy[j+2]+ energy[j+3]+ energy[j]; + ave /= 4.; + /* + printf("energy / tot %i %5.2f %e %e\n",j,ave/(tot*16./3.), + ave,tot*16./3.); + */ + energy[j+1] = energy[j+2] = energy[j+3] = energy[j]=tot; + } + #endif + + + + + + + + + /********************************************************************** + * Calculate the energy and the unpredictability in the threshold * + * calculation partitions * + **********************************************************************/ + #if 0 + for ( b = 0; b < CBANDS; b++ ) + { + eb[b] = 0; + cb[b] = 0; + } + for ( j = 0; j < HBLKSIZE; j++ ) + { + int tp = partition_l[j]; + + if ( tp >= 0 ) + { + eb[tp] += energy[j]; + cb[tp] += cw[j] * energy[j]; + } + assert(tp<npart_l_orig); + } + #else + b = 0; + for (j = 0; j < cw_upper_index;) + { + FLOAT8 ebb, cbb; + int i; + + ebb = energy[j]; + cbb = energy[j] * cw[j]; + j++; + + for (i = numlines_l[b] - 1; i > 0; i--) + { + ebb += energy[j]; + cbb += energy[j] * cw[j]; + j++; + } + eb[b] = ebb; + cb[b] = cbb; + b++; + } + + for (; b < npart_l_orig; b++ ) + { + int i; + FLOAT8 ebb = energy[j++]; + + for (i = numlines_l[b] - 1; i > 0; i--) + { + ebb += energy[j++]; + } + eb[b] = ebb; + cb[b] = ebb * 0.4; + } + #endif + + /********************************************************************** + * convolve the partitioned energy and unpredictability * + * with the spreading function, s3_l[b][k] * + ******************************************************************** */ + pe[chn] = 0; /* calculate percetual entropy */ + for ( b = 0;b < npart_l; b++ ) + { + FLOAT8 tbb,ecb,ctb; + FLOAT8 temp_1; /* BUG of IS */ + + ecb = 0; + ctb = 0; + for ( k = s3ind[b][0]; k <= s3ind[b][1]; k++ ) + { + ecb += s3_l[b][k] * eb[k]; /* sprdngf for Layer III */ + ctb += s3_l[b][k] * cb[k]; + } + + /* calculate the tonality of each threshold calculation partition */ + /* calculate the SNR in each threshhold calculation partition */ + + tbb = ecb; + if (tbb != 0) + { + tbb = ctb / tbb; + if (tbb <= 0.04875584301) + { + tbb = exp(-LN_TO_LOG10 * (TMN - NMT)); + } + else if (tbb > 0.4989003827) + { + tbb = 1; + } + else + { + tbb = log(tbb); + tbb = exp(((TMN - NMT)*(LN_TO_LOG10*0.299)) + + ((TMN - NMT)*(LN_TO_LOG10*0.43 ))*tbb); /* conv1=-0.299, conv2=-0.43 */ + } + } + + tbb = Min(minval[b], tbb); + ecb *= tbb; + + /* pre-echo control */ + /* rpelev=2.0, rpelev2=16.0 */ + temp_1 = Min(ecb, Min(rpelev*nb_1[chn][b],rpelev2*nb_2[chn][b]) ); + thr[b] = Max( qthr_l[b], temp_1 ); + nb_2[chn][b] = nb_1[chn][b]; + nb_1[chn][b] = ecb; + + /* note: all surges in PE are because of the above pre-echo formula + * for temp_1. it this is not used, PE is always around 600 + */ + + if (thr[b] < eb[b]) + { + /* there's no non sound portition, because thr[b] is + maximum of qthr_l and temp_1 */ + pe[chn] -= numlines_l[b] * log(thr[b] / eb[b]); + } + } + + + #ifdef HAVEGTK + if (gfp->gtkflag) { + FLOAT mn,mx,ma=0,mb=0,mc=0; + + for ( j = HBLKSIZE_s/2; j < HBLKSIZE_s; j ++) + { + ma += energy_s[0][j]; + mb += energy_s[1][j]; + mc += energy_s[2][j]; + } + mn = Min(ma,mb); + mn = Min(mn,mc); + mx = Max(ma,mb); + mx = Max(mx,mc); + + pinfo->ers[gr_out][chn]=ers_save[chn]; + ers_save[chn]=mx/(1e-12+mn); + pinfo->pe[gr_out][chn]=pe_save[chn]; + pe_save[chn]=pe[chn]; + } + #endif + + /*************************************************************** + * determine the block type (window type) based on L & R channels + * + ***************************************************************/ + if (chn<2) { + if (gfp->no_short_blocks){ + uselongblock[chn]=1; + } else { + /* tuned for t1.wav. doesnt effect most other samples */ + if (pe[chn] > 3000) { + uselongblock[chn]=0; + } else { + FLOAT mn,mx,ma=0,mb=0,mc=0; + + for ( j = HBLKSIZE_s/2; j < HBLKSIZE_s; j ++) + { + ma += energy_s[0][j]; + mb += energy_s[1][j]; + mc += energy_s[2][j]; + } + mn = Min(ma,mb); + mn = Min(mn,mc); + mx = Max(ma,mb); + mx = Max(mx,mc); + + uselongblock[chn] = 1; + + if ( mx > 30*mn ) + {/* big surge of energy - always use short blocks */ + uselongblock[chn] = 0; + } + else if ((mx > 10*mn) && (pe[chn] > 1000)) + {/* medium surge, medium pe - use short blocks */ + uselongblock[chn] = 0; + } + } + } + } + + + + /*************************************************************** + * compute masking thresholds for both short and long blocks + ***************************************************************/ + /* longblock threshold calculation (part 2) */ + for ( sb = 0; sb < SBPSY_l; sb++ ) + { + FLOAT8 enn = w1_l[sb] * eb[bu_l[sb]] + w2_l[sb] * eb[bo_l[sb]]; + FLOAT8 thmm = w1_l[sb] *thr[bu_l[sb]] + w2_l[sb] * thr[bo_l[sb]]; + for ( b = bu_l[sb]+1; b < bo_l[sb]; b++ ) + { + enn += eb[b]; + thmm += thr[b]; + } + en[chn].l[sb] = enn; + thm[chn].l[sb] = thmm; + } + + + /* threshold calculation for short blocks */ + for ( sblock = 0; sblock < 3; sblock++ ) + { + j = 0; + for ( b = 0; b < npart_s_orig; b++ ) + { + int i; + FLOAT ecb = energy_s[sblock][j++]; + for (i = numlines_s[b]; i > 0; i--) + { + ecb += energy_s[sblock][j++]; + } + eb[b] = ecb; + } + + for ( b = 0; b < npart_s; b++ ) + { + FLOAT8 ecb = 0; + for ( k = s3ind_s[b][0]; k <= s3ind_s[b][1]; k++ ) + { + ecb += s3_s[b][k] * eb[k]; + } + thr[b] = Max (qthr_s[b], ecb); + } + + for ( sb = 0; sb < SBPSY_s; sb++ ) + { + FLOAT8 enn = w1_s[sb] * eb[bu_s[sb]] + w2_s[sb] * eb[bo_s[sb]]; + FLOAT8 thmm = w1_s[sb] *thr[bu_s[sb]] + w2_s[sb] * thr[bo_s[sb]]; + for ( b = bu_s[sb]+1; b < bo_s[sb]; b++ ) + { + enn += eb[b]; + thmm += thr[b]; + } + en[chn].s[sb][sblock] = enn; + thm[chn].s[sb][sblock] = thmm; + } + } + } /* end loop over chn */ + + + /* compute M/S thresholds from Johnston & Ferreira 1992 ICASSP paper */ + if ( numchn==4 /* mid/side and r/l */) { + FLOAT8 rside,rmid,mld; + int chmid=2,chside=3; + + for ( sb = 0; sb < SBPSY_l; sb++ ) { + /* use this fix if L & R masking differs by 2db or less */ + /* if db = 10*log10(x2/x1) < 2 */ + /* if (x2 < 1.58*x1) { */ + if (thm[0].l[sb] <= 1.58*thm[1].l[sb] + && thm[1].l[sb] <= 1.58*thm[0].l[sb]) { + + mld = mld_l[sb]*en[chside].l[sb]; + rmid = Max(thm[chmid].l[sb], Min(thm[chside].l[sb],mld)); + + mld = mld_l[sb]*en[chmid].l[sb]; + rside = Max(thm[chside].l[sb],Min(thm[chmid].l[sb],mld)); + + thm[chmid].l[sb]=rmid; + thm[chside].l[sb]=rside; + } + } + for ( sb = 0; sb < SBPSY_s; sb++ ) { + for ( sblock = 0; sblock < 3; sblock++ ) { + if (thm[0].s[sb][sblock] <= 1.58*thm[1].s[sb][sblock] + && thm[1].s[sb][sblock] <= 1.58*thm[0].s[sb][sblock]) { + + mld = mld_s[sb]*en[chside].s[sb][sblock]; + rmid = Max(thm[chmid].s[sb][sblock],Min(thm[chside].s[sb][sblock],mld)); + + mld = mld_s[sb]*en[chmid].s[sb][sblock]; + rside = Max(thm[chside].s[sb][sblock],Min(thm[chmid].s[sb][sblock],mld)); + + thm[chmid].s[sb][sblock]=rmid; + thm[chside].s[sb][sblock]=rside; + } + } + } + } + + + + + + + if (gfp->mode == MPG_MD_JOINT_STEREO) { + /* determin ms_ratio from masking thresholds*/ + /* use ms_stereo (ms_ratio < .35) if average thresh. diff < 5 db */ + FLOAT8 db,x1,x2,sidetot=0,tot=0; + for (sb= SBPSY_l/4 ; sb< SBPSY_l; sb ++ ) { + x1 = Min(thm[0].l[sb],thm[1].l[sb]); + x2 = Max(thm[0].l[sb],thm[1].l[sb]); + /* thresholds difference in db */ + if (x2 >= 1000*x1) db=3; + else db = log10(x2/x1); + /* printf("db = %f %e %e \n",db,thm[0].l[sb],thm[1].l[sb]);*/ + sidetot += db; + tot++; + } + ms_ratio_l= (sidetot/tot)*0.7; /* was .35*(sidetot/tot)/5.0*10 */ + ms_ratio_l = Min(ms_ratio_l,0.5); + + sidetot=0; tot=0; + for ( sblock = 0; sblock < 3; sblock++ ) + for ( sb = SBPSY_s/4; sb < SBPSY_s; sb++ ) { + x1 = Min(thm[0].s[sb][sblock],thm[1].s[sb][sblock]); + x2 = Max(thm[0].s[sb][sblock],thm[1].s[sb][sblock]); + /* thresholds difference in db */ + if (x2 >= 1000*x1) db=3; + else db = log10(x2/x1); + sidetot += db; + tot++; + } + ms_ratio_s = (sidetot/tot)*0.7; /* was .35*(sidetot/tot)/5.0*10 */ + ms_ratio_s = Min(ms_ratio_s,.5); + } + + /*************************************************************** + * determin final block type + ***************************************************************/ + + for (chn=0; chn<gfp->stereo; chn++) { + blocktype[chn] = NORM_TYPE; + } + + + if (gfp->stereo==2) { + if (!gfp->allow_diff_short || gfp->mode==MPG_MD_JOINT_STEREO) { + /* force both channels to use the same block type */ + /* this is necessary if the frame is to be encoded in ms_stereo. */ + /* But even without ms_stereo, FhG does this */ + int bothlong= (uselongblock[0] && uselongblock[1]); + if (!bothlong) { + uselongblock[0]=0; + uselongblock[1]=0; + } + } + } + + + + /* update the blocktype of the previous granule, since it depends on what + * happend in this granule */ + for (chn=0; chn<gfp->stereo; chn++) { + if ( uselongblock[chn]) + { /* no attack : use long blocks */ + switch( blocktype_old[chn] ) + { + case NORM_TYPE: + case STOP_TYPE: + blocktype[chn] = NORM_TYPE; + break; + case SHORT_TYPE: + blocktype[chn] = STOP_TYPE; + break; + case START_TYPE: + fprintf( stderr, "Error in block selecting\n" ); + abort(); + break; /* problem */ + } + } else { + /* attack : use short blocks */ + blocktype[chn] = SHORT_TYPE; + if ( blocktype_old[chn] == NORM_TYPE ) { + blocktype_old[chn] = START_TYPE; + } + if ( blocktype_old[chn] == STOP_TYPE ) { + blocktype_old[chn] = SHORT_TYPE ; + } + } + + blocktype_d[chn] = blocktype_old[chn]; /* value returned to calling program */ + blocktype_old[chn] = blocktype[chn]; /* save for next call to l3psy_anal */ + } + + if (blocktype_d[0]==2) + *ms_ratio = ms_ratio_s_old; + else + *ms_ratio = ms_ratio_l_old; + + ms_ratio_s_old = ms_ratio_s; + ms_ratio_l_old = ms_ratio_l; + + /* we dont know the block type of this frame yet - assume long */ + *ms_ratio_next = ms_ratio_l; + + + + /*********************************************************************/ + /* compute side_energy / (side+mid)_energy */ + /* 0 = no energy in side channel */ + /* .5 = half of total energy in side channel */ + /*********************************************************************/ + if (numchn==4) { + FLOAT tmp = tot_ener[3]+tot_ener[2]; + *ms_ener_ratio = ms_ener_ratio_old; + ms_ener_ratio_old=0; + if (tmp>0) ms_ener_ratio_old=tot_ener[3]/tmp; + } else + /* we didn't compute ms_ener_ratios */ + *ms_ener_ratio = 0; + + } + + + + + + + void L3para_read(FLOAT8 sfreq, int *numlines_l,int *numlines_s, int *partition_l, FLOAT8 *minval, + FLOAT8 *qthr_l, FLOAT8 s3_l[64][64], FLOAT8 s3_s[CBANDS + 1][CBANDS + 1], + FLOAT8 *qthr_s, FLOAT8 *SNR, + int *bu_l, int *bo_l, FLOAT8 *w1_l, FLOAT8 *w2_l, + int *bu_s, int *bo_s, FLOAT8 *w1_s, FLOAT8 *w2_s) + { + FLOAT8 freq_tp; + FLOAT8 bval_l[CBANDS], bval_s[CBANDS]; + int cbmax=0, cbmax_tp; + FLOAT8 *p = psy_data; + + int sbmax ; + int i,j,k,k2,loop, part_max ; + int freq_scale=1; + + + /* use MPEG1 tables. The MPEG2 tables in tables.c appear to be + * junk. MPEG2 doc claims data for these tables is the same as the + * MPEG1 data for 2x sampling frequency */ + /* if (sfreq<32000) freq_scale=2; */ + + + + /* Read long block data */ + + for(loop=0;loop<6;loop++) + { + freq_tp = *p++; + cbmax_tp = (int) *p++; + cbmax_tp++; + + if (sfreq == freq_tp/freq_scale ) + { + cbmax = cbmax_tp; + for(i=0,k2=0;i<cbmax_tp;i++) + { + j = (int) *p++; + numlines_l[i] = (int) *p++; + minval[i] = exp(-((*p++) - NMT) * LN_TO_LOG10); + qthr_l[i] = *p++; + /* norm_l[i] = *p++*/ p++; + bval_l[i] = *p++; + if (j!=i) + { + fprintf(stderr,"1. please check \"psy_data\""); + exit(-1); + } + for(k=0;k<numlines_l[i];k++) + partition_l[k2++] = i ; + } + } + else + p += cbmax_tp * 6; + } + + #define NEWBARKXXX + #ifdef NEWBARK + /* compute bark values of each critical band */ + j = 0; + for(i=0;i<cbmax;i++) + { + FLOAT8 ji, freq, bark; + + ji = j + (numlines_l[i]-1)/2.0; + freq = sfreq*ji/1024000.0; + bark = 13*atan(.76*freq) + 3.5*atan(freq*freq/(7.5*7.5)); + + printf("%i %i bval_l table=%f f=%f formaula=%f \n",i,j,bval_l[i],freq,bark); + bval_l[i]=bark; + j += numlines_l[i]; + } + #endif + + /************************************************************************ + * Now compute the spreading function, s[j][i], the value of the spread-* + * ing function, centered at band j, for band i, store for later use * + ************************************************************************/ + /* i.e.: sum over j to spread into signal barkval=i + NOTE: i and j are used opposite as in the ISO docs */ + part_max = cbmax ; + for(i=0;i<part_max;i++) + { + FLOAT8 tempx,x,tempy,temp; + for(j=0;j<part_max;j++) + { + /*tempx = (bval_l[i] - bval_l[j])*1.05;*/ + if (j>=i) tempx = (bval_l[i] - bval_l[j])*3.0; + else tempx = (bval_l[i] - bval_l[j])*1.5; + + #ifdef AACS3 + if (i>=j) tempx = (bval_l[i] - bval_l[j])*3.0; + else tempx = (bval_l[i] - bval_l[j])*1.5; + #endif + + if(tempx>=0.5 && tempx<=2.5) + { + temp = tempx - 0.5; + x = 8.0 * (temp*temp - 2.0 * temp); + } + else x = 0.0; + tempx += 0.474; + tempy = 15.811389 + 7.5*tempx - 17.5*sqrt(1.0+tempx*tempx); + + #ifdef NEWS3 + if (j>=i) tempy = (bval_l[j] - bval_l[i])*(-15); + else tempy = (bval_l[j] - bval_l[i])*25; + x=0; + #endif + /* + if ((i==part_max/2) && (fabs(bval_l[j] - bval_l[i])) < 3) { + printf("bark=%f x+tempy = %f \n",bval_l[j] - bval_l[i],x+tempy); + } + */ + + if (tempy <= -60.0) s3_l[i][j] = 0.0; + else s3_l[i][j] = exp( (x + tempy)*LN_TO_LOG10 ); + } + } + + /* Read short block data */ + for(loop=0;loop<6;loop++) + { + freq_tp = *p++; + cbmax_tp = (int) *p++; + cbmax_tp++; + + if (sfreq == freq_tp/freq_scale ) + { + cbmax = cbmax_tp; + for(i=0,k2=0;i<cbmax_tp;i++) + { + j = (int) *p++; + numlines_s[i] = (int) *p++; + qthr_s[i] = *p++; + /* norm_s[i] =*p++ */ p++; + SNR[i] = *p++; + bval_s[i] = *p++; + if (j!=i) + { + fprintf(stderr,"3. please check \"psy_data\""); + exit(-1); + } + numlines_s[i]--; + } + numlines_s[i] = -1; + } + else + p += cbmax_tp * 6; + } + + + #ifdef NEWBARK + /* compute bark values of each critical band */ + j = 0; + for(i=0;i<cbmax;i++) + { + FLOAT8 ji, freq, bark; + ji = (j * 2 + numlines_s[i]) / 2.0; + freq = sfreq*ji/256000.0; + bark = 13*atan(.76*freq) + 3.5*atan(freq*freq/(7.5*7.5)); + printf("%i %i bval_s = %f %f %f \n",i,j,bval_s[i],freq,bark); + bval_s[i]=bark; + j += numlines_s[i] + 1; + } + #endif + + + + /************************************************************************ + * Now compute the spreading function, s[j][i], the value of the spread-* + * ing function, centered at band j, for band i, store for later use * + ************************************************************************/ + part_max = cbmax ; + for(i=0;i<part_max;i++) + { + FLOAT8 tempx,x,tempy,temp; + for(j=0;j<part_max;j++) + { + /* tempx = (bval_s[i] - bval_s[j])*1.05;*/ + if (j>=i) tempx = (bval_s[i] - bval_s[j])*3.0; + else tempx = (bval_s[i] - bval_s[j])*1.5; + #ifdef AACS3 + if (i>=j) tempx = (bval_s[i] - bval_s[j])*3.0; + else tempx = (bval_s[i] - bval_s[j])*1.5; + #endif + if(tempx>=0.5 && tempx<=2.5) + { + temp = tempx - 0.5; + x = 8.0 * (temp*temp - 2.0 * temp); + } + else x = 0.0; + tempx += 0.474; + tempy = 15.811389 + 7.5*tempx - 17.5*sqrt(1.0+tempx*tempx); + #ifdef NEWS3 + if (j>=i) tempy = (bval_s[j] - bval_s[i])*(-15); + else tempy = (bval_s[j] - bval_s[i])*25; + x=0; + #endif + if (tempy <= -60.0) s3_s[i][j] = 0.0; + else s3_s[i][j] = exp( (x + tempy)*LN_TO_LOG10 ); + } + } + /* Read long block data for converting threshold calculation + partitions to scale factor bands */ + + for(loop=0;loop<6;loop++) + { + freq_tp = *p++; + sbmax = (int) *p++; + sbmax++; + + if (sfreq == freq_tp/freq_scale) + { + for(i=0;i<sbmax;i++) + { + j = (int) *p++; + p++; + bu_l[i] = (int) *p++; + bo_l[i] = (int) *p++; + w1_l[i] = (FLOAT8) *p++; + w2_l[i] = (FLOAT8) *p++; + if (j!=i) + { fprintf(stderr,"30:please check \"psy_data\"\n"); + exit(-1); + } + + if (i!=0) + if ( (fabs(1.0-w1_l[i]-w2_l[i-1]) > 0.01 ) ) + { + fprintf(stderr,"31l: please check \"psy_data.\"\n"); + fprintf(stderr,"w1,w2: %f %f \n",w1_l[i],w2_l[i-1]); + exit(-1); + } + } + } + else + p += sbmax * 6; + } + + /* Read short block data for converting threshold calculation + partitions to scale factor bands */ + + for(loop=0;loop<6;loop++) + { + freq_tp = *p++; + sbmax = (int) *p++; + sbmax++; + + if (sfreq == freq_tp/freq_scale) + { + for(i=0;i<sbmax;i++) + { + j = (int) *p++; + p++; + bu_s[i] = (int) *p++; + bo_s[i] = (int) *p++; + w1_s[i] = *p++; + w2_s[i] = *p++; + if (j!=i) + { fprintf(stderr,"30:please check \"psy_data\"\n"); + exit(-1); + } + + if (i!=0) + if ( (fabs(1.0-w1_s[i]-w2_s[i-1]) > 0.01 ) ) + { + fprintf(stderr,"31s: please check \"psy_data.\"\n"); + fprintf(stderr,"w1,w2: %f %f \n",w1_s[i],w2_s[i-1]); + exit(-1); + } + } + } + else + p += sbmax * 6; + } + + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/psymodel.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/psymodel.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/psymodel.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,15 ---- + #ifndef L3PSY_DOT_H_ + #define L3PSY_DOT_H_ + + /* l3psy.c */ + #include "l3side.h" + void L3psycho_anal( lame_global_flags *gfp, + short int *buffer[2], int gr , + FLOAT8 *ms_ratio, + FLOAT8 *ms_ratio_next, + FLOAT8 *ms_ener_ratio, + III_psy_ratio ratio[2][2], + III_psy_ratio MS_ratio[2][2], + FLOAT8 pe[2], FLOAT8 pe_MS[2], + int blocktype_d[2]); + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize-pvt.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize-pvt.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize-pvt.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,1320 ---- + #include <assert.h> + #include "util.h" + #include "tables.h" + #include "reservoir.h" + #include "quantize-pvt.h" + + FLOAT masking_lower=1; + int convert_mdct, reduce_sidechannel; + /* + mt 5/99. These global flags denote 4 possibilities: + mode l3_xmin + 1 MDCT input L/R, quantize L/R, psy-model thresholds: L/R -m s either + 2 MDCT input L/R, quantize M/S, psy-model thresholds: L/R -m j orig + 3 MDCT input M/S, quantize M/S, psy-model thresholds: M/S -m f either + 4 MDCT input L/R, quantize M/S, psy-model thresholds: M/S -m j -h m/s + + 1: convert_mdct = 0, convert_psy=0, reduce_sidechannel=0 + 2: convert_mdct = 1, convert_psy=1, reduce_sidechannel=1 + 3: convert_mdct = 0, convert_psy=0, reduce_sidechannel=1 (this mode no longer used) + 4: convert_mdct = 1, convert_psy=0, reduce_sidechannel=1 + + if (convert_mdct), then iteration_loop will quantize M/S data from + the L/R input MDCT coefficients. + + if (convert_psy), then calc_noise will compute the noise for the L/R + channels from M/S MDCT data and L/R psy-model threshold information. + Distortion in ether L or R channel will be marked as distortion in + both Mid and Side channels. + NOTE: 3/00: this mode has been removed. + + if (reduce_sidechannel) then outer_loop will allocate less bits + to the side channel and more bits to the mid channel based on relative + energies. + */ + + + + /* + The following table is used to implement the scalefactor + partitioning for MPEG2 as described in section + 2.4.3.2 of the IS. The indexing corresponds to the + way the tables are presented in the IS: + + [table_number][row_in_table][column of nr_of_sfb] + */ + unsigned nr_of_sfb_block[6][3][4] = + { + { + {6, 5, 5, 5}, + {9, 9, 9, 9}, + {6, 9, 9, 9} + }, + { + {6, 5, 7, 3}, + {9, 9, 12, 6}, + {6, 9, 12, 6} + }, + { + {11, 10, 0, 0}, + {18, 18, 0, 0}, + {15,18,0,0} + }, + { + {7, 7, 7, 0}, + {12, 12, 12, 0}, + {6, 15, 12, 0} + }, + { + {6, 6, 6, 3}, + {12, 9, 9, 6}, + {6, 12, 9, 6} + }, + { + {8, 8, 5, 0}, + {15,12,9,0}, + {6,18,9,0} + } + }; + + + /* Table B.6: layer3 preemphasis */ + int pretab[21] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 2, 2, 3, 3, 3, 2 + }; + + /* + Here are MPEG1 Table B.8 and MPEG2 Table B.1 + -- Layer III scalefactor bands. + Index into this using a method such as: + idx = fr_ps->header->sampling_frequency + + (fr_ps->header->version * 3) + */ + + struct scalefac_struct sfBandIndex[6] = + { + { /* Table B.2.b: 22.05 kHz */ + {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {0,4,8,12,18,24,32,42,56,74,100,132,174,192} + }, + { /* Table B.2.c: 24 kHz */ /* docs: 332. mpg123: 330 */ + {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278, 332, 394,464,540,576}, + {0,4,8,12,18,26,36,48,62,80,104,136,180,192} + }, + { /* Table B.2.a: 16 kHz */ + {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {0,4,8,12,18,26,36,48,62,80,104,134,174,192} + }, + { /* Table B.8.b: 44.1 kHz */ + {0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576}, + {0,4,8,12,16,22,30,40,52,66,84,106,136,192} + }, + { /* Table B.8.c: 48 kHz */ + {0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576}, + {0,4,8,12,16,22,28,38,50,64,80,100,126,192} + }, + { /* Table B.8.a: 32 kHz */ + {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576}, + {0,4,8,12,16,22,30,42,58,78,104,138,180,192} + } + }; + + struct scalefac_struct scalefac_band; + + + FLOAT8 pow20[Q_MAX]; + FLOAT8 ipow20[Q_MAX]; + FLOAT8 pow43[PRECALC_SIZE]; + static FLOAT8 adj43[PRECALC_SIZE]; + static FLOAT8 adj43asm[PRECALC_SIZE]; + static FLOAT8 ATH_l[SBPSY_l]; + static FLOAT8 ATH_s[SBPSY_l]; + + FLOAT8 ATH_mdct_long[576]; + FLOAT8 ATH_mdct_short[192]; + + + /************************************************************************/ + /* initialization for iteration_loop */ + /************************************************************************/ + void + iteration_init( lame_global_flags *gfp,III_side_info_t *l3_side, int l3_enc[2][2][576]) + { + gr_info *cod_info; + int ch, gr, i; + + l3_side->resvDrain = 0; + + if ( gfp->frameNum==0 ) { + for (i = 0; i < SBMAX_l + 1; i++) { + scalefac_band.l[i] = + sfBandIndex[gfp->samplerate_index + (gfp->version * 3)].l[i]; + } + for (i = 0; i < SBMAX_s + 1; i++) { + scalefac_band.s[i] = + sfBandIndex[gfp->samplerate_index + (gfp->version * 3)].s[i]; + } + + l3_side->main_data_begin = 0; + compute_ath(gfp,ATH_l,ATH_s); + + for(i=0;i<PRECALC_SIZE;i++) + pow43[i] = pow((FLOAT8)i, 4.0/3.0); + + for (i = 0; i < PRECALC_SIZE-1; i++) + adj43[i] = (i + 1) - pow(0.5 * (pow43[i] + pow43[i + 1]), 0.75); + adj43[i] = 0.5; + + + adj43asm[0] = 0.0; + for (i = 1; i < PRECALC_SIZE; i++) + adj43asm[i] = i - 0.5 - pow(0.5 * (pow43[i - 1] + pow43[i]),0.75); + + for (i = 0; i < Q_MAX; i++) { + ipow20[i] = pow(2.0, (double)(i - 210) * -0.1875); + pow20[i] = pow(2.0, (double)(i - 210) * 0.25); + } + } + + + convert_mdct=0; + reduce_sidechannel=0; + if (gfp->mode_ext==MPG_MD_MS_LR) { + convert_mdct = 1; + reduce_sidechannel=1; + } + + /* some intializations. */ + for ( gr = 0; gr < gfp->mode_gr; gr++ ){ + for ( ch = 0; ch < gfp->stereo; ch++ ){ + cod_info = (gr_info *) &(l3_side->gr[gr].ch[ch]); + + if (cod_info->block_type == SHORT_TYPE) + { + cod_info->sfb_lmax = 0; /* No sb*/ + cod_info->sfb_smax = 0; + } + else + { + /* MPEG 1 doesnt use last scalefactor band */ + cod_info->sfb_lmax = SBPSY_l; + cod_info->sfb_smax = SBPSY_s; /* No sb */ + } + + } + } + + + /* dont bother with scfsi. */ + for ( ch = 0; ch < gfp->stereo; ch++ ) + for ( i = 0; i < 4; i++ ) + l3_side->scfsi[ch][i] = 0; + } + + + + + + /* + compute the ATH for each scalefactor band + cd range: 0..96db + + Input: 3.3kHz signal 32767 amplitude (3.3kHz is where ATH is smallest = -5db) + longblocks: sfb=12 en0/bw=-11db max_en0 = 1.3db + shortblocks: sfb=5 -9db 0db + + Input: 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 (repeated) + longblocks: amp=1 sfb=12 en0/bw=-103 db max_en0 = -92db + amp=32767 sfb=12 -12 db -1.4db + + Input: 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 (repeated) + shortblocks: amp=1 sfb=5 en0/bw= -99 -86 + amp=32767 sfb=5 -9 db 4db + + + MAX energy of largest wave at 3.3kHz = 1db + AVE energy of largest wave at 3.3kHz = -11db + Let's take AVE: -11db = maximum signal in sfb=12. + Dynamic range of CD: 96db. Therefor energy of smallest audible wave + in sfb=12 = -11 - 96 = -107db = ATH at 3.3kHz. + + ATH formula for this wave: -5db. To adjust to LAME scaling, we need + ATH = ATH_formula - 103 (db) + ATH = ATH * 2.5e-10 (ener) + + */ + FLOAT8 ATHformula(lame_global_flags *gfp,FLOAT8 f) + { + FLOAT8 ath; + f = Max(0.02, f); + /* from Painter & Spanias, 1997 */ + /* minimum: (i=77) 3.3kHz = -5db */ + ath=(3.640 * pow(f,-0.8) + - 6.500 * exp(-0.6*pow(f-3.3,2.0)) + + 0.001 * pow(f,4.0)); + /* convert to energy */ + if (gfp->noATH) + ath -= 200; /* disables ATH */ + else { + ath -= 114; /* MDCT scaling. From tests by macik and MUS420 code */ + /* ath -= 109; */ + } + #ifdef RH_QUALITY_CONTROL + /* purpose of RH_QUALITY_CONTROL: + * at higher quality lower ATH masking abilities => needs more bits + * at lower quality increase ATH masking abilities => needs less bits + * works together with adjusted masking lowering of GPSYCHO thresholds + * (Robert.Hegemann at gmx.de 2000-01-30) + */ + ath -= (4-gfp->VBR_q)*4.0; + #endif + ath = pow( 10.0, ath/10.0 ); + return ath; + } + + + void compute_ath(lame_global_flags *gfp,FLOAT8 ATH_l[SBPSY_l],FLOAT8 ATH_s[SBPSY_l]) + { + int sfb,i,start,end; + FLOAT8 ATH_f; + FLOAT8 samp_freq = gfp->out_samplerate/1000.0; + #ifdef RH_ATH + /* going from average to peak level ATH masking + */ + FLOAT8 adjust_mdct_scaling = 10.0; + #endif + + + /* last sfb is not used */ + for ( sfb = 0; sfb < SBPSY_l; sfb++ ) { + start = scalefac_band.l[ sfb ]; + end = scalefac_band.l[ sfb+1 ]; + ATH_l[sfb]=1e99; + for (i=start ; i < end; i++) { + ATH_f = ATHformula(gfp,samp_freq*i/(2*576)); /* freq in kHz */ + ATH_l[sfb]=Min(ATH_l[sfb],ATH_f); + #ifdef RH_ATH + ATH_mdct_long[i] = ATH_f*adjust_mdct_scaling; + #endif + } + /* + printf("sfb=%i %f ATH=%f %f %f \n",sfb,samp_freq*start/(2*576), + 10*log10(ATH_l[sfb]), + 10*log10( ATHformula(samp_freq*start/(2*576))) , + 10*log10(ATHformula(samp_freq*end/(2*576)))); + */ + } + + for ( sfb = 0; sfb < SBPSY_s; sfb++ ){ + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb+1 ]; + ATH_s[sfb]=1e99; + for (i=start ; i < end; i++) { + ATH_f = ATHformula(gfp,samp_freq*i/(2*192)); /* freq in kHz */ + ATH_s[sfb]=Min(ATH_s[sfb],ATH_f); + #ifdef RH_ATH + ATH_mdct_short[i] = ATH_f*adjust_mdct_scaling; + #endif + } + } + } + + + + + + /* convert from L/R <-> Mid/Side */ + void ms_convert(FLOAT8 xr[2][576],FLOAT8 xr_org[2][576]) + { + int i; + for ( i = 0; i < 576; i++ ) { + FLOAT8 l = xr_org[0][i]; + FLOAT8 r = xr_org[1][i]; + xr[0][i] = (l+r)*(SQRT2*0.5); + xr[1][i] = (l-r)*(SQRT2*0.5); + } + } + + + + /************************************************************************ + * allocate bits among 2 channels based on PE + * mt 6/99 + ************************************************************************/ + void on_pe(lame_global_flags *gfp,FLOAT8 pe[2][2],III_side_info_t *l3_side, + int targ_bits[2],int mean_bits, int gr) + { + gr_info *cod_info; + int extra_bits,tbits,bits; + int add_bits[2]; + int ch; + + /* allocate targ_bits for granule */ + ResvMaxBits( mean_bits, &tbits, &extra_bits, gr); + + + for (ch=0 ; ch < gfp->stereo ; ch ++) { + /****************************************************************** + * allocate bits for each channel + ******************************************************************/ + cod_info = &l3_side->gr[gr].ch[ch].tt; + + targ_bits[ch]=tbits/gfp->stereo; + + /* allocate extra bits from reservoir based on PE */ + bits=0; + + /* extra bits based on PE > 700 */ + add_bits[ch]=(pe[gr][ch]-750)/1.55; /* 1.4; */ + + /* short blocks need extra, no matter what the pe */ + if (cod_info->block_type==SHORT_TYPE) + if (add_bits[ch]<500) add_bits[ch]=500; + + if (add_bits[ch] < 0) add_bits[ch]=0; + bits += add_bits[ch]; + + if (bits > extra_bits) add_bits[ch] = (extra_bits*add_bits[ch])/bits; + if ((targ_bits[ch]+add_bits[ch]) > 4095) + add_bits[ch]=4095-targ_bits[ch]; + + targ_bits[ch] = targ_bits[ch] + add_bits[ch]; + extra_bits -= add_bits[ch]; + } + } + + void reduce_side(int targ_bits[2],FLOAT8 ms_ener_ratio,int mean_bits) + { + int ch; + int numchn=2; + /* ms_ener_ratio = 0: allocate 66/33 mid/side fac=.33 + * ms_ener_ratio =.5: allocate 50/50 mid/side fac= 0 */ + /* 75/25 split is fac=.5 */ + /* float fac = .50*(.5-ms_ener_ratio[gr])/.5;*/ + float fac = .33*(.5-ms_ener_ratio)/.5; + if (fac<0) fac=0; + + if (targ_bits[1] >= 125) { + /* dont reduce side channel below 125 bits */ + if (targ_bits[1]-targ_bits[1]*fac > 125) { + targ_bits[0] += targ_bits[1]*fac; + targ_bits[1] -= targ_bits[1]*fac; + } else { + targ_bits[0] += targ_bits[1] - 125; + targ_bits[1] = 125; + } + } + + /* dont allow to many bits per channel */ + for (ch=0; ch<numchn; ch++) { + int max_bits = Min(4095,mean_bits/2 + 1200); + if (targ_bits[ch] > max_bits) { + targ_bits[ch] = max_bits; + } + } + + } + + /*************************************************************************** + * inner_loop * + *************************************************************************** + * The code selects the best global gain for a particular set of scalefacs */ + + int + inner_loop( lame_global_flags *gfp,FLOAT8 xrpow[576], + int l3_enc[576], int max_bits, + gr_info *cod_info) + { + int bits; + assert( max_bits >= 0 ); + cod_info->global_gain--; + do + { + cod_info->global_gain++; + bits = count_bits(gfp,l3_enc, xrpow, cod_info); + } + while ( bits > max_bits ); + return bits; + } + + + + /*************************************************************************/ + /* scale_bitcount */ + /*************************************************************************/ + + /* Also calculates the number of bits necessary to code the scalefactors. */ + + int scale_bitcount( III_scalefac_t *scalefac, gr_info *cod_info) + { + int i, k, sfb, max_slen1 = 0, max_slen2 = 0, /*a, b, */ ep = 2; + + static int slen1[16] = { 1, 1, 1, 1, 8, 2, 2, 2, 4, 4, 4, 8, 8, 8,16,16 }; + static int slen2[16] = { 1, 2, 4, 8, 1, 2, 4, 8, 2, 4, 8, 2, 4, 8, 4, 8 }; + + static int slen1_tab[16] = {0, + 18, 36, 54, 54, 36, 54, 72, 54, 72, 90, 72, 90,108,108,126 + }; + static int slen2_tab[16] = {0, + 10, 20, 30, 33, 21, 31, 41, 32, 42, 52, 43, 53, 63, 64, 74 + }; + int *tab; + + + if ( cod_info->block_type == SHORT_TYPE ) + { + tab = slen1_tab; + /* a = 18; b = 18; */ + for ( i = 0; i < 3; i++ ) + { + for ( sfb = 0; sfb < 6; sfb++ ) + if (scalefac->s[sfb][i] > max_slen1 ) + max_slen1 = scalefac->s[sfb][i]; + for (sfb = 6; sfb < SBPSY_s; sfb++ ) + if ( scalefac->s[sfb][i] > max_slen2 ) + max_slen2 = scalefac->s[sfb][i]; + } + } + else + { /* block_type == 1,2,or 3 */ + tab = slen2_tab; + /* a = 11; b = 10; */ + for ( sfb = 0; sfb < 11; sfb++ ) + if ( scalefac->l[sfb] > max_slen1 ) + max_slen1 = scalefac->l[sfb]; + + if (!cod_info->preflag) { + for ( sfb = 11; sfb < SBPSY_l; sfb++ ) + if (scalefac->l[sfb] < pretab[sfb]) + break; + + if (sfb == SBPSY_l) { + cod_info->preflag = 1; + for ( sfb = 11; sfb < SBPSY_l; sfb++ ) + scalefac->l[sfb] -= pretab[sfb]; + } + } + + for ( sfb = 11; sfb < SBPSY_l; sfb++ ) + if ( scalefac->l[sfb] > max_slen2 ) + max_slen2 = scalefac->l[sfb]; + } + + + + /* from Takehiro TOMINAGA <tominaga at isoternet.org> 10/99 + * loop over *all* posible values of scalefac_compress to find the + * one which uses the smallest number of bits. ISO would stop + * at first valid index */ + cod_info->part2_length = LARGE_BITS; + for ( k = 0; k < 16; k++ ) + { + if ( (max_slen1 < slen1[k]) && (max_slen2 < slen2[k]) && + ((int)cod_info->part2_length > tab[k])) { + cod_info->part2_length=tab[k]; + cod_info->scalefac_compress=k; + ep=0; /* we found a suitable scalefac_compress */ + } + } + return ep; + } + + + + /* + table of largest scalefactors (number of bits) for MPEG2 + */ + /* + static unsigned max_sfac_tab[6][4] = + { + {4, 4, 3, 3}, + {4, 4, 3, 0}, + {3, 2, 0, 0}, + {4, 5, 5, 0}, + {3, 3, 3, 0}, + {2, 2, 0, 0} + }; + */ + /* + table of largest scalefactor values for MPEG2 + */ + static unsigned max_range_sfac_tab[6][4] = + { + { 15, 15, 7, 7}, + { 15, 15, 7, 0}, + { 7, 3, 0, 0}, + { 15, 31, 31, 0}, + { 7, 7, 7, 0}, + { 3, 3, 0, 0} + }; + + + + + + /*************************************************************************/ + /* scale_bitcount_lsf */ + /*************************************************************************/ + + /* Also counts the number of bits to encode the scalefacs but for MPEG 2 */ + /* Lower sampling frequencies (24, 22.05 and 16 kHz.) */ + + /* This is reverse-engineered from section 2.4.3.2 of the MPEG2 IS, */ + /* "Audio Decoding Layer III" */ + + int scale_bitcount_lsf(III_scalefac_t *scalefac, gr_info *cod_info) + { + int table_number, row_in_table, partition, nr_sfb, window, over; + int i, sfb, max_sfac[ 4 ]; + unsigned *partition_table; + + /* + Set partition table. Note that should try to use table one, + but do not yet... + */ + if ( cod_info->preflag ) + table_number = 2; + else + table_number = 0; + + for ( i = 0; i < 4; i++ ) + max_sfac[i] = 0; + + if ( cod_info->block_type == SHORT_TYPE ) + { + row_in_table = 1; + partition_table = &nr_of_sfb_block[table_number][row_in_table][0]; + for ( sfb = 0, partition = 0; partition < 4; partition++ ) + { + nr_sfb = partition_table[ partition ] / 3; + for ( i = 0; i < nr_sfb; i++, sfb++ ) + for ( window = 0; window < 3; window++ ) + if ( scalefac->s[sfb][window] > max_sfac[partition] ) + max_sfac[partition] = scalefac->s[sfb][window]; + } + } + else + { + row_in_table = 0; + partition_table = &nr_of_sfb_block[table_number][row_in_table][0]; + for ( sfb = 0, partition = 0; partition < 4; partition++ ) + { + nr_sfb = partition_table[ partition ]; + for ( i = 0; i < nr_sfb; i++, sfb++ ) + if ( scalefac->l[sfb] > max_sfac[partition] ) + max_sfac[partition] = scalefac->l[sfb]; + } + } + + for ( over = 0, partition = 0; partition < 4; partition++ ) + { + if ( max_sfac[partition] > (int)max_range_sfac_tab[table_number][partition] ) + over++; + } + if ( !over ) + { + /* + Since no bands have been over-amplified, we can set scalefac_compress + and slen[] for the formatter + */ + static int log2tab[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; + + unsigned slen1, slen2, slen3, slen4; + + cod_info->sfb_partition_table = &nr_of_sfb_block[table_number][row_in_table][0]; + for ( partition = 0; partition < 4; partition++ ) + cod_info->slen[partition] = log2tab[max_sfac[partition]]; + + /* set scalefac_compress */ + slen1 = cod_info->slen[ 0 ]; + slen2 = cod_info->slen[ 1 ]; + slen3 = cod_info->slen[ 2 ]; + slen4 = cod_info->slen[ 3 ]; + + switch ( table_number ) + { + case 0: + cod_info->scalefac_compress = (((slen1 * 5) + slen2) << 4) + + (slen3 << 2) + + slen4; + break; + + case 1: + cod_info->scalefac_compress = 400 + + (((slen1 * 5) + slen2) << 2) + + slen3; + break; + + case 2: + cod_info->scalefac_compress = 500 + (slen1 * 3) + slen2; + break; + + default: + fprintf( stderr, "intensity stereo not implemented yet\n" ); + exit( EXIT_FAILURE ); + break; + } + } + #ifdef DEBUG + if ( over ) + printf( "---WARNING !! Amplification of some bands over limits\n" ); + #endif + if (!over) { + assert( cod_info->sfb_partition_table ); + cod_info->part2_length=0; + for ( partition = 0; partition < 4; partition++ ) + cod_info->part2_length += cod_info->slen[partition] * cod_info->sfb_partition_table[partition]; + } + return over; + } + + + + + + /*************************************************************************/ + /* calc_xmin */ + /*************************************************************************/ + + /* + Calculate the allowed distortion for each scalefactor band, + as determined by the psychoacoustic model. + xmin(sb) = ratio(sb) * en(sb) / bw(sb) + + returns number of sfb's with energy > ATH + */ + int calc_xmin( lame_global_flags *gfp,FLOAT8 xr[576], III_psy_ratio *ratio, + gr_info *cod_info, III_psy_xmin *l3_xmin) + { + int start, end, bw,l, b, ath_over=0; + u_int sfb; + FLOAT8 en0, xmin, ener; + + if (gfp->ATHonly) { + for ( sfb = cod_info->sfb_smax; sfb < SBPSY_s; sfb++ ) + for ( b = 0; b < 3; b++ ) + l3_xmin->s[sfb][b]=ATH_s[sfb]; + for ( sfb = 0; sfb < cod_info->sfb_lmax; sfb++ ) + l3_xmin->l[sfb]=ATH_l[sfb]; + + }else{ + + for ( sfb = cod_info->sfb_smax; sfb < SBPSY_s; sfb++ ) { + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb + 1 ]; + bw = end - start; + for ( b = 0; b < 3; b++ ) { + for (en0 = 0.0, l = start; l < end; l++) { + ener = xr[l * 3 + b]; + ener = ener * ener; + en0 += ener; + } + en0 /= bw; + + xmin = ratio->en.s[sfb][b]; + if (xmin > 0.0) + xmin = en0 * ratio->thm.s[sfb][b] * masking_lower / xmin; + + #ifdef RH_ATH + /* do not mix up ATH masking with GPSYCHO thresholds + */ + l3_xmin->s[sfb][b] = Max(1e-20, xmin); + #else + l3_xmin->s[sfb][b] = Max(ATH_s[sfb], xmin); + #endif + if (en0 > ATH_s[sfb]) ath_over++; + } + } + + for ( sfb = 0; sfb < cod_info->sfb_lmax; sfb++ ){ + start = scalefac_band.l[ sfb ]; + end = scalefac_band.l[ sfb+1 ]; + bw = end - start; + + for (en0 = 0.0, l = start; l < end; l++ ) { + ener = xr[l] * xr[l]; + en0 += ener; + } + en0 /= bw; + + xmin = ratio->en.l[sfb]; + if (xmin > 0.0) + xmin = en0 * ratio->thm.l[sfb] * masking_lower / xmin; + + + #ifdef RH_ATH + /* do not mix up ATH masking with GPSYCHO thresholds + */ + l3_xmin->l[sfb]=Max(1e-20, xmin); + #else + l3_xmin->l[sfb]=Max(ATH_l[sfb], xmin); + #endif + if (en0 > ATH_l[sfb]) ath_over++; + } + } + return ath_over; + } + + + + /*************************************************************************/ + /* loop_break */ + /*************************************************************************/ + + /* Function: Returns zero if there is a scalefac which has not been + amplified. Otherwise it returns one. + */ + + int loop_break( III_scalefac_t *scalefac, gr_info *cod_info) + { + int i; + u_int sfb; + + for ( sfb = 0; sfb < cod_info->sfb_lmax; sfb++ ) + if ( scalefac->l[sfb] == 0 ) + return 0; + + for ( sfb = cod_info->sfb_smax; sfb < SBPSY_s; sfb++ ) + for ( i = 0; i < 3; i++ ) + if ( scalefac->s[sfb][i] == 0 ) + return 0; + + return 1; + } + + + + + + + + + + + + + + /* + ---------------------------------------------------------------------- + if someone wants to try to find a faster step search function, + here is some code which gives a lower bound for the step size: + + for (max_xrspow = 0, i = 0; i < 576; ++i) + { + max_xrspow = Max(max_xrspow, xrspow[i]); + } + lowerbound = 210+log10(max_xrspow/IXMAX_VAL)/(0.1875*LOG2); + + + Robert.Hegemann at gmx.de + ---------------------------------------------------------------------- + */ + + + typedef enum { + BINSEARCH_NONE, + BINSEARCH_UP, + BINSEARCH_DOWN + } binsearchDirection_t; + + /*-------------------------------------------------------------------------*/ + int + bin_search_StepSize2 (lame_global_flags *gfp,int desired_rate, int start, int *ix, + FLOAT8 xrspow[576], gr_info *cod_info) + /*-------------------------------------------------------------------------*/ + { + static int CurrentStep = 4; + int nBits; + int flag_GoneOver = 0; + int StepSize = start; + binsearchDirection_t Direction = BINSEARCH_NONE; + + do + { + cod_info->global_gain = StepSize; + nBits = count_bits(gfp,ix, xrspow, cod_info); + + if (CurrentStep == 1 ) + { + break; /* nothing to adjust anymore */ + } + if (flag_GoneOver) + { + CurrentStep /= 2; + } + if (nBits > desired_rate) /* increase Quantize_StepSize */ + { + if (Direction == BINSEARCH_DOWN && !flag_GoneOver) + { + flag_GoneOver = 1; + CurrentStep /= 2; /* late adjust */ + } + Direction = BINSEARCH_UP; + StepSize += CurrentStep; + if (StepSize > 255) break; + } + else if (nBits < desired_rate) + { + if (Direction == BINSEARCH_UP && !flag_GoneOver) + { + flag_GoneOver = 1; + CurrentStep /= 2; /* late adjust */ + } + Direction = BINSEARCH_DOWN; + StepSize -= CurrentStep; + if (StepSize < 0) break; + } + else break; /* nBits == desired_rate;; most unlikely to happen.*/ + } while (1); /* For-ever, break is adjusted. */ + + CurrentStep = abs(start - StepSize); + + if (CurrentStep >= 4) { + CurrentStep = 4; + } else { + CurrentStep = 2; + } + + return nBits; + } + + + + + + + + + #if 0 + #if (defined(__GNUC__) && defined(__i386__)) + #define USE_GNUC_ASM + #endif + #ifdef _MSC_VER + #define USE_MSC_ASM + #endif + #endif + + + + /********************************************************************* + * XRPOW_FTOI is a macro to convert floats to ints. + * if XRPOW_FTOI(x) = nearest_int(x), then QUANTFAC(x)=adj43asm[x] + * ROUNDFAC= -0.0946 + * + * if XRPOW_FTOI(x) = floor(x), then QUANTFAC(x)=asj43[x] + * ROUNDFAC=0.4054 + *********************************************************************/ + #ifdef USE_GNUC_ASM + # define QUANTFAC(rx) adj43asm[rx] + # define ROUNDFAC -0.0946 + # define XRPOW_FTOI(src, dest) \ + asm ("fistpl %0 " : "=m"(dest) : "t"(src) : "st") + #elif defined (USE_MSC_ASM) + # define QUANTFAC(rx) adj43asm[rx] + # define ROUNDFAC -0.0946 + # define XRPOW_FTOI(src, dest) do { \ + FLOAT8 src_ = (src); \ + int dest_; \ + { \ + __asm fld src_ \ + __asm fistp dest_ \ + } \ + (dest) = dest_; \ + } while (0) + #else + # define QUANTFAC(rx) adj43[rx] + # define ROUNDFAC 0.4054 + # define XRPOW_FTOI(src,dest) ((dest) = (int)(src)) + #endif + + #ifdef USE_MSC_ASM + /* define F8type and F8size according to type of FLOAT8 */ + # if defined FLOAT8_is_double + # define F8type qword + # define F8size 8 + # elif defined FLOAT8_is_float + # define F8type dword + # define F8size 4 + # else + /* only float and double supported */ + # error invalid FLOAT8 type for USE_MSC_ASM + # endif + #endif + + #ifdef USE_GNUC_ASM + /* define F8type and F8size according to type of FLOAT8 */ + # if defined FLOAT8_is_double + # define F8type "l" + # define F8size "8" + # elif defined FLOAT8_is_float + # define F8type "s" + # define F8size "4" + # else + /* only float and double supported */ + # error invalid FLOAT8 type for USE_GNUC_ASM + # endif + #endif + + /********************************************************************* + * nonlinear quantization of xr + * More accurate formula than the ISO formula. Takes into account + * the fact that we are quantizing xr -> ix, but we want ix^4/3 to be + * as close as possible to x^4/3. (taking the nearest int would mean + * ix is as close as possible to xr, which is different.) + * From Segher Boessenkool <segher at eastsite.nl> 11/1999 + * ASM optimization from + * Mathew Hendry <scampi at dial.pipex.com> 11/1999 + * Acy Stapp <AStapp at austin.rr.com> 11/1999 + * Takehiro Tominaga <tominaga at isoternet.org> 11/1999 + *********************************************************************/ + + void quantize_xrpow(FLOAT8 xr[576], int ix[576], gr_info *cod_info) { + /* quantize on xr^(3/4) instead of xr */ + const FLOAT8 istep = IPOW20(cod_info->global_gain); + + #if defined (USE_GNUC_ASM) + { + int rx[4]; + __asm__ __volatile__( + "\n\nloop1:\n\t" + + "fld" F8type " 0*" F8size "(%1)\n\t" + "fld" F8type " 1*" F8size "(%1)\n\t" + "fld" F8type " 2*" F8size "(%1)\n\t" + "fld" F8type " 3*" F8size "(%1)\n\t" + + "fxch %%st(3)\n\t" + "fmul %%st(4)\n\t" + "fxch %%st(2)\n\t" + "fmul %%st(4)\n\t" + "fxch %%st(1)\n\t" + "fmul %%st(4)\n\t" + "fxch %%st(3)\n\t" + "fmul %%st(4)\n\t" + + "addl $4*" F8size ", %1\n\t" + "addl $16, %3\n\t" + + "fxch %%st(2)\n\t" + "fistl %5\n\t" + "fxch %%st(1)\n\t" + "fistl 4+%5\n\t" + "fxch %%st(3)\n\t" + "fistl 8+%5\n\t" + "fxch %%st(2)\n\t" + "fistl 12+%5\n\t" + + "dec %4\n\t" + + "movl %5, %%eax\n\t" + "movl 4+%5, %%ebx\n\t" + "fxch %%st(1)\n\t" + "fadd" F8type " (%2,%%eax," F8size ")\n\t" + "fxch %%st(3)\n\t" + "fadd" F8type " (%2,%%ebx," F8size ")\n\t" + + "movl 8+%5, %%eax\n\t" + "movl 12+%5, %%ebx\n\t" + "fxch %%st(2)\n\t" + "fadd" F8type " (%2,%%eax," F8size ")\n\t" + "fxch %%st(1)\n\t" + "fadd" F8type " (%2,%%ebx," F8size ")\n\t" + + "fxch %%st(3)\n\t" + "fistpl -16(%3)\n\t" + "fxch %%st(1)\n\t" + "fistpl -12(%3)\n\t" + "fistpl -8(%3)\n\t" + "fistpl -4(%3)\n\t" + + "jnz loop1\n\n" + : /* no outputs */ + : "t" (istep), "r" (xr), "r" (adj43asm), "r" (ix), "r" (576 / 4), "m" (rx) + : "%eax", "%ebx", "memory", "cc" + ); + } + #elif defined (USE_MSC_ASM) + { + /* asm from Acy Stapp <AStapp at austin.rr.com> */ + int rx[4]; + _asm { + fld F8type ptr [istep] + mov esi, dword ptr [xr] + lea edi, dword ptr [adj43asm] + mov edx, dword ptr [ix] + mov ecx, 576/4 + } loop1: _asm { + fld F8type ptr [esi+(0*F8size)] // 0 + fld F8type ptr [esi+(1*F8size)] // 1 0 + fld F8type ptr [esi+(2*F8size)] // 2 1 0 + fld F8type ptr [esi+(3*F8size)] // 3 2 1 0 + fxch st(3) // 0 2 1 3 + fmul st(0), st(4) + fxch st(2) // 1 2 0 3 + fmul st(0), st(4) + fxch st(1) // 2 1 0 3 + fmul st(0), st(4) + fxch st(3) // 3 1 0 2 + fmul st(0), st(4) + + add esi, 4*F8size + add edx, 16 + + fxch st(2) // 0 1 3 2 + fist dword ptr [rx] + fxch st(1) // 1 0 3 2 + fist dword ptr [rx+4] + fxch st(3) // 2 0 3 1 + fist dword ptr [rx+8] + fxch st(2) // 3 0 2 1 + fist dword ptr [rx+12] + + dec ecx + + mov eax, dword ptr [rx] + mov ebx, dword ptr [rx+4] + fxch st(1) // 0 3 2 1 + fadd F8type ptr [edi+eax*F8size] + fxch st(3) // 1 3 2 0 + fadd F8type ptr [edi+ebx*F8size] + + mov eax, dword ptr [rx+8] + mov ebx, dword ptr [rx+12] + fxch st(2) // 2 3 1 0 + fadd F8type ptr [edi+eax*F8size] + fxch st(1) // 3 2 1 0 + fadd F8type ptr [edi+ebx*F8size] + fxch st(3) // 0 2 1 3 + fistp dword ptr [edx-16] // 2 1 3 + fxch st(1) // 1 2 3 + fistp dword ptr [edx-12] // 2 3 + fistp dword ptr [edx-8] // 3 + fistp dword ptr [edx-4] + + jnz loop1 + + mov dword ptr [xr], esi + mov dword ptr [ix], edx + fstp st(0) + } + } + #else + #if 0 + { /* generic code if you write ASM for XRPOW_FTOI() */ + FLOAT8 x; + int j, rx; + for (j = 576 / 4; j > 0; --j) { + x = *xr++ * istep; + XRPOW_FTOI(x, rx); + XRPOW_FTOI(x + QUANTFAC(rx), *ix++); + + x = *xr++ * istep; + XRPOW_FTOI(x, rx); + XRPOW_FTOI(x + QUANTFAC(rx), *ix++); + + x = *xr++ * istep; + XRPOW_FTOI(x, rx); + XRPOW_FTOI(x + QUANTFAC(rx), *ix++); + + x = *xr++ * istep; + XRPOW_FTOI(x, rx); + XRPOW_FTOI(x + QUANTFAC(rx), *ix++); + } + } + #endif + {/* from Wilfried.Behne at t-online.de. Reported to be 2x faster than + the above code (when not using ASM) on PowerPC */ + int j; + + for ( j = 576/8; j > 0; --j) + { + FLOAT8 x1, x2, x3, x4, x5, x6, x7, x8; + int rx1, rx2, rx3, rx4, rx5, rx6, rx7, rx8; + x1 = *xr++ * istep; + x2 = *xr++ * istep; + XRPOW_FTOI(x1, rx1); + x3 = *xr++ * istep; + XRPOW_FTOI(x2, rx2); + x4 = *xr++ * istep; + XRPOW_FTOI(x3, rx3); + x5 = *xr++ * istep; + XRPOW_FTOI(x4, rx4); + x6 = *xr++ * istep; + XRPOW_FTOI(x5, rx5); + x7 = *xr++ * istep; + XRPOW_FTOI(x6, rx6); + x8 = *xr++ * istep; + XRPOW_FTOI(x7, rx7); + x1 += QUANTFAC(rx1); + XRPOW_FTOI(x8, rx8); + x2 += QUANTFAC(rx2); + XRPOW_FTOI(x1,*ix++); + x3 += QUANTFAC(rx3); + XRPOW_FTOI(x2,*ix++); + x4 += QUANTFAC(rx4); + XRPOW_FTOI(x3,*ix++); + x5 += QUANTFAC(rx5); + XRPOW_FTOI(x4,*ix++); + x6 += QUANTFAC(rx6); + XRPOW_FTOI(x5,*ix++); + x7 += QUANTFAC(rx7); + XRPOW_FTOI(x6,*ix++); + x8 += QUANTFAC(rx8); + XRPOW_FTOI(x7,*ix++); + XRPOW_FTOI(x8,*ix++); + } + } + #endif + } + + + + + + + void quantize_xrpow_ISO( FLOAT8 xr[576], int ix[576], gr_info *cod_info ) + { + /* quantize on xr^(3/4) instead of xr */ + const FLOAT8 istep = IPOW20(cod_info->global_gain); + + #if defined(USE_GNUC_ASM) + { + __asm__ __volatile__ ( + "\n\nloop0:\n\t" + + "fld" F8type " 0*" F8size "(%3)\n\t" + "fld" F8type " 1*" F8size "(%3)\n\t" + "fld" F8type " 2*" F8size "(%3)\n\t" + "fld" F8type " 3*" F8size "(%3)\n\t" + + "addl $4*" F8size ", %3\n\t" + "addl $16, %4\n\t" + + "fxch %%st(3)\n\t" + "fmul %%st(4)\n\t" + "fxch %%st(2)\n\t" + "fmul %%st(4)\n\t" + "fxch %%st(1)\n\t" + "fmul %%st(4)\n\t" + "fxch %%st(3)\n\t" + "fmul %%st(4)\n\t" + + "dec %0\n\t" + + "fxch %%st(2)\n\t" + "fadd %%st(5)\n\t" + "fxch %%st(1)\n\t" + "fadd %%st(5)\n\t" + "fxch %%st(3)\n\t" + "fadd %%st(5)\n\t" + "fxch %%st(2)\n\t" + "fadd %%st(5)\n\t" + + "fxch %%st(1)\n\t" + "fistpl -16(%4)\n\t" + "fxch %%st(2)\n\t" + "fistpl -12(%4)\n\t" + "fistpl -8(%4)\n\t" + "fistpl -4(%4)\n\t" + + "jnz loop0\n\n" + + : /* no outputs */ + : "r" (576 / 4), "u" ((FLOAT8)(0.4054 - 0.5)), "t" (istep), "r" (xr), "r" (ix) + : "memory", "cc" + ); + } + #elif defined(USE_MSC_ASM) + { + /* asm from Acy Stapp <AStapp at austin.rr.com> */ + const FLOAT8 temp0 = 0.4054 - 0.5; + _asm { + mov ecx, 576/4; + fld F8type ptr [temp0]; + fld F8type ptr [istep]; + mov eax, dword ptr [xr]; + mov edx, dword ptr [ix]; + } loop0: _asm { + fld F8type ptr [eax+0*F8size]; // 0 + fld F8type ptr [eax+1*F8size]; // 1 0 + fld F8type ptr [eax+2*F8size]; // 2 1 0 + fld F8type ptr [eax+3*F8size]; // 3 2 1 0 + + add eax, 4*F8size; + add edx, 16; + + fxch st(3); // 0 2 1 3 + fmul st(0), st(4); + fxch st(2); // 1 2 0 3 + fmul st(0), st(4); + fxch st(1); // 2 1 0 3 + fmul st(0), st(4); + fxch st(3); // 3 1 0 2 + fmul st(0), st(4); + + dec ecx; + + fxch st(2); // 0 1 3 2 + fadd st(0), st(5); + fxch st(1); // 1 0 3 2 + fadd st(0), st(5); + fxch st(3); // 2 0 3 1 + fadd st(0), st(5); + fxch st(2); // 3 0 2 1 + fadd st(0), st(5); + + fxch st(1); // 0 3 2 1 + fistp dword ptr [edx-16]; // 3 2 1 + fxch st(2); // 1 2 3 + fistp dword ptr [edx-12]; + fistp dword ptr [edx-8]; + fistp dword ptr [edx-4]; + + jnz loop0; + + mov dword ptr [xr], eax; + mov dword ptr [ix], edx; + fstp st(0); + fstp st(0); + } + } + #else + #if 0 + /* generic ASM */ + register int j; + for (j=576/4;j>0;j--) { + XRPOW_FTOI(istep * (*xr++) + ROUNDFAC, *ix++); + XRPOW_FTOI(istep * (*xr++) + ROUNDFAC, *ix++); + XRPOW_FTOI(istep * (*xr++) + ROUNDFAC, *ix++); + XRPOW_FTOI(istep * (*xr++) + ROUNDFAC, *ix++); + } + #endif + { + register int j; + const FLOAT8 compareval0 = (1.0 - 0.4054)/istep; + /* depending on architecture, it may be worth calculating a few more compareval's. + eg. compareval1 = (2.0 - 0.4054/istep); + .. and then after the first compare do this ... + if compareval1>*xr then ix = 1; + On a pentium166, it's only worth doing the one compare (as done here), as the second + compare becomes more expensive than just calculating the value. Architectures with + slow FP operations may want to add some more comparevals. try it and send your diffs + statistically speaking + 73% of all xr*istep values give ix=0 + 16% will give 1 + 4% will give 2 + */ + for (j=576;j>0;j--) + { + if (compareval0 > *xr) { + *(ix++) = 0; + xr++; + } else + /* *(ix++) = (int)( istep*(*(xr++)) + 0.4054); */ + XRPOW_FTOI( istep*(*(xr++)) + ROUNDFAC , *(ix++) ); + } + } + #endif + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize-pvt.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize-pvt.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize-pvt.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,124 ---- + #ifndef LOOP_PVT_H + #define LOOP_PVT_H + + #define IXMAX_VAL 8206 /* ix always <= 8191+15. see count_bits() */ + #define PRECALC_SIZE (IXMAX_VAL+2) + + extern FLOAT masking_lower; + extern int convert_mdct, convert_psy, reduce_sidechannel; + extern unsigned nr_of_sfb_block[6][3][4]; + extern int pretab[21]; + + struct scalefac_struct + { + int l[1+SBMAX_l]; + int s[1+SBMAX_s]; + }; + + extern struct scalefac_struct scalefac_band; + extern struct scalefac_struct sfBandIndex[6]; + + extern FLOAT8 pow43[PRECALC_SIZE]; + + #define Q_MAX 256 + + extern FLOAT8 pow20[Q_MAX]; + extern FLOAT8 ipow20[Q_MAX]; + + #ifdef RH_ATH + extern FLOAT8 ATH_mdct_long[576], ATH_mdct_short[192]; + #endif + + FLOAT8 ATHformula(lame_global_flags *gfp,FLOAT8 f); + void compute_ath(lame_global_flags *gfp,FLOAT8 ATH_l[SBPSY_l],FLOAT8 ATH_s[SBPSY_l]); + void ms_convert(FLOAT8 xr[2][576],FLOAT8 xr_org[2][576]); + void on_pe(lame_global_flags *gfp,FLOAT8 pe[2][2],III_side_info_t *l3_side, + int targ_bits[2],int mean_bits, int gr); + void reduce_side(int targ_bits[2],FLOAT8 ms_ener_ratio,int mean_bits); + + + void outer_loop( lame_global_flags *gfp, + FLOAT8 xr[576], /*vector of the magnitudees of the spectral values */ + int bits, + FLOAT8 noise[4], + III_psy_xmin *l3_xmin, /* the allowed distortion of the scalefactor */ + int l3_enc[576], /* vector of quantized values ix(0..575) */ + III_scalefac_t *scalefac, /* scalefactors */ + gr_info *, + FLOAT8 xfsf[4][SBPSY_l], + int ch); + + + + void iteration_init( lame_global_flags *gfp,III_side_info_t *l3_side, int l3_enc[2][2][576]); + + int inner_loop( lame_global_flags *gfp,FLOAT8 xrpow[576], + int l3_enc[576], + int max_bits, + gr_info *cod_info); + + int calc_xmin( lame_global_flags *gfp,FLOAT8 xr[576], + III_psy_ratio *ratio, + gr_info *cod_info, + III_psy_xmin *l3_xmin); + + + int scale_bitcount( III_scalefac_t *scalefac, gr_info *cod_info); + int scale_bitcount_lsf( III_scalefac_t *scalefac, gr_info *cod_info); + int calc_noise1( FLOAT8 xr[576], + int ix[576], + gr_info *cod_info, + FLOAT8 xfsf[4][SBPSY_l], + FLOAT8 distort[4][SBPSY_l], + III_psy_xmin *l3_xmin, + III_scalefac_t *, + FLOAT8 *noise, FLOAT8 *tot_noise, FLOAT8 *max_noise); + + int loop_break( III_scalefac_t *scalefac, gr_info *cod_info); + + void amp_scalefac_bands(FLOAT8 xrpow[576], + gr_info *cod_info, + III_scalefac_t *scalefac, + FLOAT8 distort[4][SBPSY_l]); + + void quantize_xrpow( FLOAT8 xr[576], + int ix[576], + gr_info *cod_info ); + void quantize_xrpow_ISO( FLOAT8 xr[576], + int ix[576], + gr_info *cod_info ); + + int + new_choose_table( int ix[576], + unsigned int begin, + unsigned int end, int * s ); + + int bin_search_StepSize2(lame_global_flags *gfp,int desired_rate, int start, int ix[576], + FLOAT8 xrspow[576], gr_info * cod_info); + int count_bits(lame_global_flags *gfp,int *ix, FLOAT8 xr[576], gr_info *cod_info); + + + int quant_compare(int type, + int best_over,FLOAT8 best_tot_noise,FLOAT8 best_over_noise,FLOAT8 best_max_over, + int over,FLOAT8 tot_noise, FLOAT8 over_noise,FLOAT8 max_noise); + + int VBR_compare( + int best_over,FLOAT8 best_tot_noise,FLOAT8 best_over_noise,FLOAT8 best_max_over, + int over,FLOAT8 tot_noise, FLOAT8 over_noise,FLOAT8 max_noise); + + void best_huffman_divide(int gr, int ch, gr_info *cod_info, int *ix); + + void best_scalefac_store(lame_global_flags *gfp,int gr, int ch, + int l3_enc[2][2][576], + III_side_info_t *l3_side, + III_scalefac_t scalefac[2][2]); + + int init_outer_loop( + lame_global_flags *gfp, + FLOAT8 xr[576], /* could be L/R OR MID/SIDE */ + gr_info *cod_info); + + #define LARGE_BITS 100000 + + #endif + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,1201 ---- + #define MAXNOISEXX + /* + * MP3 quantization + * + * Copyright (c) 1999 Mark Taylor + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + + + #include <assert.h> + #include "util.h" + #include "l3side.h" + #include "quantize.h" + #include "l3bitstream.h" + #include "reservoir.h" + #include "quantize-pvt.h" + #ifdef HAVEGTK + #include "gtkanal.h" + #endif + + + + #ifdef HAVEGTK + + /************************************************************************/ + /* updates plotting data */ + /************************************************************************/ + void + set_pinfo ( + gr_info *cod_info, + III_psy_ratio *ratio, + III_scalefac_t *scalefac, + FLOAT8 xr[576], + FLOAT8 xfsf[4][SBPSY_l], + FLOAT8 noise[4], + int gr, + int ch + ) + { + int sfb; + FLOAT ifqstep; + int i,l,start,end,bw; + FLOAT8 en0; + D192_3 *xr_s = (D192_3 *)xr; + ifqstep = ( cod_info->scalefac_scale == 0 ) ? .5 : 1.0; + + if (cod_info->block_type == SHORT_TYPE) { + for ( i = 0; i < 3; i++ ) { + for ( sfb = 0; sfb < SBPSY_s; sfb++ ) { + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb + 1 ]; + bw = end - start; + for ( en0 = 0.0, l = start; l < end; l++ ) + en0 += (*xr_s)[l][i] * (*xr_s)[l][i]; + en0=Max(en0/bw,1e-20); + + /* conversion to FFT units */ + en0 = ratio->en.s[sfb][i]/en0; + + pinfo->xfsf_s[gr][ch][3*sfb+i] = xfsf[i+1][sfb]*en0; + pinfo->thr_s[gr][ch][3*sfb+i] = ratio->thm.s[sfb][i]; + pinfo->en_s[gr][ch][3*sfb+i] = ratio->en.s[sfb][i]; + + pinfo->LAMEsfb_s[gr][ch][3*sfb+i]= + -2*cod_info->subblock_gain[i]-ifqstep*scalefac->s[sfb][i]; + } + } + }else{ + for ( sfb = 0; sfb < SBPSY_l; sfb++ ) { + start = scalefac_band.l[ sfb ]; + end = scalefac_band.l[ sfb+1 ]; + bw = end - start; + for ( en0 = 0.0, l = start; l < end; l++ ) + en0 += xr[l] * xr[l]; + en0=Max(en0/bw,1e-20); + /* + printf("diff = %f \n",10*log10(Max(ratio[gr][ch].en.l[sfb],1e-20)) + -(10*log10(en0)+150)); + */ + + /* convert to FFT units */ + en0 = ratio->en.l[sfb]/en0; + + pinfo->xfsf[gr][ch][sfb] = xfsf[0][sfb]*en0; + pinfo->thr[gr][ch][sfb] = ratio->thm.l[sfb]; + pinfo->en[gr][ch][sfb] = ratio->en.l[sfb]; + + pinfo->LAMEsfb[gr][ch][sfb]=-ifqstep*scalefac->l[sfb]; + if (cod_info->preflag && sfb>=11) + pinfo->LAMEsfb[gr][ch][sfb]-=ifqstep*pretab[sfb]; + } + } + pinfo->LAMEqss[gr][ch] = cod_info->global_gain; + pinfo->LAMEmainbits[gr][ch] = cod_info->part2_3_length; + + pinfo->over [gr][ch] = noise[0]; + pinfo->max_noise [gr][ch] = noise[1]; + pinfo->over_noise[gr][ch] = noise[2]; + pinfo->tot_noise [gr][ch] = noise[3]; + } + + #endif + + + + /************************************************************************/ + /* iteration_loop() */ + /************************************************************************/ + void + iteration_loop( lame_global_flags *gfp, + FLOAT8 pe[2][2], FLOAT8 ms_ener_ratio[2], + FLOAT8 xr[2][2][576], III_psy_ratio ratio[2][2], + III_side_info_t *l3_side, int l3_enc[2][2][576], + III_scalefac_t scalefac[2][2]) + { + FLOAT8 xfsf[4][SBPSY_l]; + FLOAT8 noise[4]; /* over,max_noise,over_noise,tot_noise; */ + III_psy_xmin l3_xmin[2]; + gr_info *cod_info; + int bitsPerFrame; + int mean_bits; + int ch, gr, i, bit_rate; + + + iteration_init(gfp,l3_side,l3_enc); + bit_rate = bitrate_table[gfp->version][gfp->bitrate_index]; + + + getframebits(gfp,&bitsPerFrame, &mean_bits); + ResvFrameBegin(gfp, l3_side, mean_bits, bitsPerFrame ); + + /* quantize! */ + + + + for ( gr = 0; gr < gfp->mode_gr; gr++ ) { + int targ_bits[2]; + + if (convert_mdct) + ms_convert(xr[gr], xr[gr]); + + on_pe(gfp,pe,l3_side,targ_bits,mean_bits, gr); + #ifdef RH_SIDE_CBR + #else + if (reduce_sidechannel) + reduce_side(targ_bits,ms_ener_ratio[gr],mean_bits); + #endif + + for (ch=0 ; ch < gfp->stereo ; ch ++) { + cod_info = &l3_side->gr[gr].ch[ch].tt; + if (!init_outer_loop(gfp,xr[gr][ch], cod_info)) + { + /* xr contains no energy + * cod_info was set in init_outer_loop above + */ + memset(&scalefac[gr][ch],0,sizeof(III_scalefac_t)); + memset(l3_enc[gr][ch],0,576*sizeof(int)); + noise[0]=noise[1]=noise[2]=noise[3]=0; + } + else + { + calc_xmin(gfp,xr[gr][ch], &ratio[gr][ch], cod_info, &l3_xmin[ch]); + outer_loop( gfp,xr[gr][ch], targ_bits[ch], noise, + &l3_xmin[ch], l3_enc[gr][ch], + &scalefac[gr][ch], cod_info, xfsf, ch); + } + best_scalefac_store(gfp,gr, ch, l3_enc, l3_side, scalefac); + if (gfp->use_best_huffman==1 && cod_info->block_type == NORM_TYPE) { + best_huffman_divide(gr, ch, cod_info, l3_enc[gr][ch]); + } + #ifdef HAVEGTK + if (gfp->gtkflag) + set_pinfo (cod_info, &ratio[gr][ch], &scalefac[gr][ch], xr[gr][ch], xfsf, noise, gr, ch); + #endif + + /*#define NORES_TEST */ + #ifndef NORES_TEST + ResvAdjust(gfp,cod_info, l3_side, mean_bits ); + #endif + /* set the sign of l3_enc */ + for ( i = 0; i < 576; i++) { + if (xr[gr][ch][i] < 0) + l3_enc[gr][ch][i] *= -1; + } + } + } /* loop over gr */ + + #ifdef NORES_TEST + /* replace ResvAdjust above with this code if you do not want + the second granule to use bits saved by the first granule. + when combined with --nores, this is usefull for testing only */ + for ( gr = 0; gr < gfp->mode_gr; gr++ ) { + for ( ch = 0; ch < gfp->stereo; ch++ ) { + cod_info = &l3_side->gr[gr].ch[ch].tt; + ResvAdjust(gfp, cod_info, l3_side, mean_bits ); + } + } + #endif + + + + ResvFrameEnd(gfp,l3_side, mean_bits ); + } + + + void + set_masking_lower (int VBR_q,int nbits) + { + FLOAT masking_lower_db, adjust; + + /* quality setting */ + /* Adjust allowed masking based on quality setting */ + + #ifdef RH_QUALITY_CONTROL + /* - lower masking depending on Quality setting + * - quality control together with adjusted ATH MDCT scaling + * on lower quality setting allocate more noise from + * ATH masking, and on higher quality setting allocate + * less noise from ATH masking. + * - experiments show that going more than 2dB over GPSYCHO's + * limits ends up in very annoying artefacts + */ + static FLOAT dbQ[10]={-6.0,-4.5,-3.0,-1.5,0,0.3,0.6,1.0,1.5,2.0}; + + assert( VBR_q <= 9 ); + assert( VBR_q >= 0 ); + + masking_lower_db = dbQ[VBR_q]; + adjust = 0; + #else + /* masking_lower varies from -8 to +10 db */ + masking_lower_db = -6 + 2*VBR_q; + /* adjust by -6(min)..0(max) depending on bitrate */ + adjust = (nbits-125)/(2500.0-125.0); + adjust = 4*(adjust-1); + #endif + masking_lower_db += adjust; + masking_lower = pow(10.0,masking_lower_db/10); + } + + /************************************************************************ + * + * VBR_iteration_loop() + * + * tries to find out how many bits are needed for each granule and channel + * to get an acceptable quantization. An appropriate bitrate will then be + * choosed for quantization. rh 8/99 + * + ************************************************************************/ + void + VBR_iteration_loop (lame_global_flags *gfp, + FLOAT8 pe[2][2], FLOAT8 ms_ener_ratio[2], + FLOAT8 xr[2][2][576], III_psy_ratio ratio[2][2], + III_side_info_t * l3_side, int l3_enc[2][2][576], + III_scalefac_t scalefac[2][2]) + { + #ifdef HAVEGTK + plotting_data bst_pinfo; + #endif + gr_info bst_cod_info, clean_cod_info; + III_scalefac_t bst_scalefac; + int bst_l3_enc[576]; + + III_psy_xmin l3_xmin; + gr_info *cod_info = NULL; + int save_bits[2][2]; + FLOAT8 noise[4]; /* over,max_noise,over_noise,tot_noise; */ + FLOAT8 targ_noise[4]; /* over,max_noise,over_noise,tot_noise; */ + FLOAT8 xfsf[4][SBPSY_l]; + int this_bits, dbits; + int used_bits=0; + int min_bits,max_bits,min_mean_bits=0; + int frameBits[15]; + int bitsPerFrame; + int bits; + int mean_bits; + int i,ch, gr, analog_silence; + int reparted = 0; + + iteration_init(gfp,l3_side,l3_enc); + + #ifdef RH_QUALITY_CONTROL + /* with RH_QUALITY_CONTROL we have to set masking_lower only once */ + set_masking_lower(gfp->VBR_q, 0 ); + #endif + + /******************************************************************* + * how many bits are available for each bitrate? + *******************************************************************/ + for( gfp->bitrate_index = 1; + gfp->bitrate_index <= gfp->VBR_max_bitrate; + gfp->bitrate_index++ ) { + getframebits (gfp,&bitsPerFrame, &mean_bits); + if (gfp->bitrate_index == gfp->VBR_min_bitrate) { + /* always use at least this many bits per granule per channel */ + /* unless we detect analog silence, see below */ + min_mean_bits=mean_bits/gfp->stereo; + } + frameBits[gfp->bitrate_index]= + ResvFrameBegin (gfp,l3_side, mean_bits, bitsPerFrame); + } + + gfp->bitrate_index=gfp->VBR_max_bitrate; + + + /******************************************************************* + * how many bits would we use of it? + *******************************************************************/ + analog_silence=0; + for (gr = 0; gr < gfp->mode_gr; gr++) { + int num_chan=gfp->stereo; + #ifdef RH_SIDE_VBR + /* my experiences are, that side channel reduction + * does more harm than good when VBR encoding + * (Robert.Hegemann at gmx.de 2000-02-18) + */ + #else + /* determine quality based on mid channel only */ + if (reduce_sidechannel) num_chan=1; + #endif + + /* copy data to be quantized into xr */ + if (convert_mdct) + ms_convert(xr[gr],xr[gr]); + + for (ch = 0; ch < num_chan; ch++) { + int real_bits; + + /****************************************************************** + * find smallest number of bits for an allowable quantization + ******************************************************************/ + cod_info = &l3_side->gr[gr].ch[ch].tt; + min_bits = Max(125,min_mean_bits); + + if (!init_outer_loop(gfp,xr[gr][ch], cod_info)) + { + /* xr contains no energy + * cod_info was set in init_outer_loop above + */ + memset(&scalefac[gr][ch],0,sizeof(III_scalefac_t)); + memset(l3_enc[gr][ch],0,576*sizeof(int)); + save_bits[gr][ch] = 0; + #ifdef HAVEGTK + if (gfp->gtkflag) + set_pinfo(cod_info, &ratio[gr][ch], &scalefac[gr][ch], xr[gr][ch], xfsf, noise, gr, ch); + #endif + analog_silence=1; + continue; /* with next channel */ + } + + memcpy( &clean_cod_info, cod_info, sizeof(gr_info) ); + + #ifdef RH_QUALITY_CONTROL + /* + * masking lower already set in the beginning + */ + #else + /* + * has to be set before calculating l3_xmin + */ + set_masking_lower( gfp->VBR_q,2500 ); + #endif + /* check for analolg silence */ + /* if energy < ATH, set min_bits = 125 */ + if (0==calc_xmin(gfp,xr[gr][ch], &ratio[gr][ch], cod_info, &l3_xmin)) { + analog_silence=1; + min_bits=125; + } + + if (cod_info->block_type==SHORT_TYPE) { + min_bits += Max(1100,pe[gr][ch]); + min_bits=Min(min_bits,1800); + } + + max_bits = 1200 + frameBits[gfp->VBR_max_bitrate]/(gfp->stereo*gfp->mode_gr); + max_bits=Min(max_bits,2500); + max_bits=Max(max_bits,min_bits); + + dbits = (max_bits-min_bits)/4; + this_bits = (max_bits+min_bits)/2; + real_bits = max_bits+1; + + /* bin search to within +/- 10 bits of optimal */ + do { + int better; + assert(this_bits>=min_bits); + assert(this_bits<=max_bits); + + if( this_bits >= real_bits ){ + /* + * we already found a quantization with fewer bits + * so we can skip this try + */ + this_bits -= dbits; + dbits /= 2; + continue; /* skips the rest of this do-while loop */ + } + + /* VBR will look for a quantization which has better values + * then those specified below.*/ + targ_noise[0]=0; /* over */ + targ_noise[1]=0; /* max_noise */ + targ_noise[2]=0; /* over_noise */ + targ_noise[3]=0; /* tot_noise */ + + targ_noise[0]=Max(0,targ_noise[0]); + targ_noise[2]=Max(0,targ_noise[2]); + + /* + * OK, start with a fresh setting + * - scalefac will be set up by outer_loop + * - l3_enc will be set up by outer_loop + * + cod_info we will restore our initialized one, see below + */ + memcpy( cod_info, &clean_cod_info, sizeof(gr_info) ); + + #ifdef RH_QUALITY_CONTROL + /* + * there is no need for a recalculation of l3_xmin, + * because masking_lower did not change within this do-while + */ + #else + /* quality setting */ + set_masking_lower( gfp->VBR_q,this_bits ); + /* + * compute max allowed distortion, masking lower has changed + */ + calc_xmin(gfp,xr[gr][ch], &ratio[gr][ch], cod_info, &l3_xmin); + #endif + outer_loop( gfp,xr[gr][ch], this_bits, noise, + &l3_xmin, l3_enc[gr][ch], + &scalefac[gr][ch], cod_info, xfsf, + ch); + + /* is quantization as good as we are looking for ? */ + better=VBR_compare((int)targ_noise[0],targ_noise[3],targ_noise[2], + targ_noise[1],(int)noise[0],noise[3],noise[2], + noise[1]); + #ifdef HAVEGTK + if (gfp->gtkflag) + set_pinfo(cod_info, &ratio[gr][ch], &scalefac[gr][ch], xr[gr][ch], xfsf, noise, gr, ch); + #endif + if (better) { + /* + * we now know it can be done with "real_bits" + * and maybe we can skip some iterations + */ + real_bits = cod_info->part2_3_length; + /* + * save best quantization so far + */ + memcpy( &bst_scalefac, &scalefac[gr][ch], sizeof(III_scalefac_t) ); + memcpy( bst_l3_enc, l3_enc [gr][ch], sizeof(int)*576 ); + memcpy( &bst_cod_info, cod_info, sizeof(gr_info) ); + #ifdef HAVEGTK + if (gfp->gtkflag) + memcpy( &bst_pinfo, pinfo, sizeof(plotting_data) ); + #endif + /* + * try with fewer bits + */ + this_bits -= dbits; + } else { + /* + * try with more bits + */ + this_bits += dbits; + } + dbits /= 2; + } while (dbits>10) ; + + if (real_bits <= max_bits) + { + /* restore best quantization found */ + memcpy( cod_info, &bst_cod_info, sizeof(gr_info) ); + memcpy( &scalefac[gr][ch], &bst_scalefac, sizeof(III_scalefac_t) ); + memcpy( l3_enc [gr][ch], bst_l3_enc, sizeof(int)*576 ); + #ifdef HAVEGTK + if (gfp->gtkflag) + memcpy( pinfo, &bst_pinfo, sizeof(plotting_data) ); + #endif + } + assert((int)cod_info->part2_3_length <= max_bits); + save_bits[gr][ch] = cod_info->part2_3_length; + used_bits += save_bits[gr][ch]; + + } /* for ch */ + } /* for gr */ + + + #ifdef RH_SIDE_VBR + /* my experiences are, that side channel reduction + * does more harm than good when VBR encoding + * (Robert.Hegemann at gmx.de 2000-02-18) + */ + #else + if (reduce_sidechannel) { + /* number of bits needed was found for MID channel above. Use formula + * (fixed bitrate code) to set the side channel bits */ + for (gr = 0; gr < gfp->mode_gr; gr++) { + FLOAT8 fac = .33*(.5-ms_ener_ratio[gr])/.5; + save_bits[gr][1]=((1-fac)/(1+fac))*save_bits[gr][0]; + save_bits[gr][1]=Max(125,save_bits[gr][1]); + used_bits += save_bits[gr][1]; + } + } + #endif + + /****************************************************************** + * find lowest bitrate able to hold used bits + ******************************************************************/ + for( gfp->bitrate_index = (analog_silence ? 1 : gfp->VBR_min_bitrate ); + gfp->bitrate_index < gfp->VBR_max_bitrate; + gfp->bitrate_index++ ) + if( used_bits <= frameBits[gfp->bitrate_index] ) break; + + /******************************************************************* + * calculate quantization for this bitrate + *******************************************************************/ + getframebits (gfp,&bitsPerFrame, &mean_bits); + bits=ResvFrameBegin (gfp,l3_side, mean_bits, bitsPerFrame); + + /* repartion available bits in same proportion */ + if (used_bits > bits ) { + reparted = 1; + for( gr = 0; gr < gfp->mode_gr; gr++) { + for(ch = 0; ch < gfp->stereo; ch++) { + save_bits[gr][ch]=(save_bits[gr][ch]*frameBits[gfp->bitrate_index])/used_bits; + } + } + used_bits=0; + for( gr = 0; gr < gfp->mode_gr; gr++) { + for(ch = 0; ch < gfp->stereo; ch++) { + used_bits += save_bits[gr][ch]; + } + } + } + assert(used_bits <= bits); + + for(gr = 0; gr < gfp->mode_gr; gr++) { + for(ch = 0; ch < gfp->stereo; ch++) { + #ifdef RH_SIDE_VBR + if (reparted) + #else + if (reparted || (reduce_sidechannel && ch == 1)) + #endif + { + cod_info = &l3_side->gr[gr].ch[ch].tt; + + if (!init_outer_loop(gfp,xr[gr][ch], cod_info)) + { + /* xr contains no energy + * cod_info was set in init_outer_loop above + */ + memset(&scalefac[gr][ch],0,sizeof(III_scalefac_t)); + memset(l3_enc[gr][ch],0,576*sizeof(int)); + noise[0]=noise[1]=noise[2]=noise[3]=0; + } + else + { + #ifdef RH_QUALITY_CONTROL + /* + * masking lower already set in the beginning + */ + #else + /* quality setting */ + set_masking_lower( gfp->VBR_q,save_bits[gr][ch] ); + #endif + calc_xmin(gfp,xr[gr][ch], &ratio[gr][ch], cod_info, &l3_xmin); + + outer_loop( gfp,xr[gr][ch], save_bits[gr][ch], noise, + &l3_xmin, l3_enc[gr][ch], + &scalefac[gr][ch], cod_info, xfsf, ch); + } + #ifdef HAVEGTK + if (gfp->gtkflag) + set_pinfo(cod_info, &ratio[gr][ch], &scalefac[gr][ch], xr[gr][ch], xfsf, noise, gr, ch); + #endif + } + } + } + + /******************************************************************* + * update reservoir status after FINAL quantization/bitrate + *******************************************************************/ + for (gr = 0; gr < gfp->mode_gr; gr++) + for (ch = 0; ch < gfp->stereo; ch++) { + cod_info = &l3_side->gr[gr].ch[ch].tt; + best_scalefac_store(gfp,gr, ch, l3_enc, l3_side, scalefac); + if (cod_info->block_type == NORM_TYPE) { + best_huffman_divide(gr, ch, cod_info, l3_enc[gr][ch]); + } + #ifdef HAVEGTK + if (gfp->gtkflag) + pinfo->LAMEmainbits[gr][ch]=cod_info->part2_3_length; + #endif + ResvAdjust (gfp,cod_info, l3_side, mean_bits); + } + + /******************************************************************* + * set the sign of l3_enc + *******************************************************************/ + for (gr = 0; gr < gfp->mode_gr; gr++) + for (ch = 0; ch < gfp->stereo; ch++) { + /* + * is the following code correct? + * + int *pi = &l3_enc[gr][ch][0]; + + for (i = 0; i < 576; i++) { + FLOAT8 pr = xr[gr][ch][i]; + + if ((pr < 0) && (pi[i] > 0)) + pi[i] *= -1; + } + * + * or is the code used for CBR correct? + */ + for ( i = 0; i < 576; i++) { + if (xr[gr][ch][i] < 0) l3_enc[gr][ch][i] *= -1; + } + } + + ResvFrameEnd (gfp,l3_side, mean_bits); + } + + + + + /************************************************************************/ + /* init_outer_loop mt 6/99 */ + /* returns 0 if all energies in xr are zero, else 1 */ + /************************************************************************/ + int init_outer_loop(lame_global_flags *gfp, + FLOAT8 xr[576], /* could be L/R OR MID/SIDE */ + gr_info *cod_info) + { + int i; + + + for ( i = 0; i < 4; i++ ) + cod_info->slen[i] = 0; + cod_info->sfb_partition_table = &nr_of_sfb_block[0][0][0]; + + cod_info->part2_3_length = 0; + cod_info->big_values = 0; + cod_info->count1 = 0; + cod_info->scalefac_compress = 0; + cod_info->table_select[0] = 0; + cod_info->table_select[1] = 0; + cod_info->table_select[2] = 0; + cod_info->subblock_gain[0] = 0; + cod_info->subblock_gain[1] = 0; + cod_info->subblock_gain[2] = 0; + cod_info->region0_count = 0; + cod_info->region1_count = 0; + cod_info->part2_length = 0; + cod_info->preflag = 0; + cod_info->scalefac_scale = 0; + cod_info->global_gain = 210; + cod_info->count1table_select= 0; + cod_info->count1bits = 0; + + + if (gfp->experimentalZ) { + /* compute subblock gains */ + int j,b; FLOAT8 en[3],mx; + if ((cod_info->block_type==SHORT_TYPE) ) { + /* estimate energy within each subblock */ + for (b=0; b<3; b++) en[b]=0; + for ( i=0,j = 0; j < 192; j++ ) { + for (b=0; b<3; b++) { + en[b]+=xr[i] * xr[i]; + i++; + } + } + mx = 1e-12; + for (b=0; b<3; b++) mx=Max(mx,en[b]); + for (b=0; b<3; b++) en[b] = Max(en[b],1e-12)/mx; + /*printf("ener = %4.2f %4.2f %4.2f \n",en[0],en[1],en[2]);*/ + /* pick gain so that 2^(2gain)*en[0] = 1 */ + /* gain = .5* log( 1/en[0] )/LOG2 = -.5*log(en[])/LOG2 */ + for (b=0; b<3; b++) { + cod_info->subblock_gain[b] = (int)(-.5*log(en[b])/LOG2 + 0.5); + if (cod_info->subblock_gain[b] > 2) + cod_info->subblock_gain[b]=2; + if (cod_info->subblock_gain[b] < 0) + cod_info->subblock_gain[b]=0; + } + /* + * check if there is some energy we have to quantize + * if so, then return 1 else 0 + */ + if (1e-99 < en[0]+en[1]+en[2]) + return 1; + else + return 0; + } + } + /* + * check if there is some energy we have to quantize + * if so, then return 1 else 0 + */ + for (i=0; i<576; i++) + if ( 1e-99 < fabs (xr[i]) ) + return 1; + + return 0; + } + + + + + /************************************************************************/ + /* outer_loop */ + /************************************************************************/ + /* Function: The outer iteration loop controls the masking conditions */ + /* of all scalefactorbands. It computes the best scalefac and */ + /* global gain. This module calls the inner iteration loop + * + * mt 5/99 completely rewritten to allow for bit reservoir control, + * mid/side channels with L/R or mid/side masking thresholds, + * and chooses best quantization instead of last quantization when + * no distortion free quantization can be found. + * + * added VBR support mt 5/99 + ************************************************************************/ + void outer_loop( + lame_global_flags *gfp, + FLOAT8 xr[576], + int targ_bits, + FLOAT8 best_noise[4], + III_psy_xmin *l3_xmin, /* the allowed distortion of the scalefactor */ + int l3_enc[576], /* vector of quantized values ix(0..575) */ + III_scalefac_t *scalefac, /* scalefactors */ + gr_info *cod_info, + FLOAT8 xfsf[4][SBPSY_l], + int ch) + { + III_scalefac_t scalefac_w; + gr_info save_cod_info; + int l3_enc_w[576]; + int i, iteration; + int status,bits_found=0; + int huff_bits; + FLOAT8 xrpow[576],temp; + int better; + int over=0; + FLOAT8 max_noise; + FLOAT8 over_noise; + FLOAT8 tot_noise; + int best_over=100; + FLOAT8 best_max_noise=0; + FLOAT8 best_over_noise=0; + FLOAT8 best_tot_noise=0; + FLOAT8 xfsf_w[4][SBPSY_l]; + FLOAT8 distort[4][SBPSY_l]; + + int compute_stepsize=1; + int notdone=1; + + /* BEGIN MAIN LOOP */ + iteration = 0; + while ( notdone ) { + static int OldValue[2] = {180, 180}; + int try_scale=0; + iteration ++; + + if (compute_stepsize) { + /* init and compute initial quantization step */ + compute_stepsize=0; + /* reset of iteration variables */ + memset(&scalefac_w, 0, sizeof(III_scalefac_t)); + for (i=0;i<576;i++) { + temp=fabs(xr[i]); + xrpow[i]=sqrt(sqrt(temp)*temp); + } + bits_found=bin_search_StepSize2(gfp,targ_bits,OldValue[ch], + l3_enc_w,xrpow,cod_info); + OldValue[ch] = cod_info->global_gain; + } + + + /* inner_loop starts with the initial quantization step computed above + * and slowly increases until the bits < huff_bits. + * Thus it is important not to start with too large of an inital + * quantization step. Too small is ok, but inner_loop will take longer + */ + huff_bits = targ_bits - cod_info->part2_length; + if (huff_bits < 0) { + assert(iteration != 1); + /* scale factors too large, not enough bits. use previous quantizaton */ + notdone=0; + } else { + /* if this is the first iteration, see if we can reuse the quantization + * computed in bin_search_StepSize above */ + int real_bits; + if (iteration==1) { + if(bits_found>huff_bits) { + cod_info->global_gain++; + real_bits = inner_loop(gfp,xrpow, l3_enc_w, huff_bits, cod_info); + } else real_bits=bits_found; + } + else + real_bits=inner_loop(gfp,xrpow, l3_enc_w, huff_bits, cod_info); + cod_info->part2_3_length = real_bits; + + /* compute the distortion in this quantization */ + if (gfp->noise_shaping==0) { + over=0; + }else{ + /* coefficients and thresholds both l/r (or both mid/side) */ + over=calc_noise1( xr, l3_enc_w, cod_info, + xfsf_w,distort, l3_xmin, &scalefac_w, &over_noise, + &tot_noise, &max_noise); + + } + + /* check if this quantization is better the our saved quantization */ + if (iteration == 1) better=1; + else + better=quant_compare(gfp->experimentalX, + best_over,best_tot_noise,best_over_noise,best_max_noise, + over, tot_noise, over_noise, max_noise); + + /* save data so we can restore this quantization later */ + if (better) { + best_over=over; + best_max_noise=max_noise; + best_over_noise=over_noise; + best_tot_noise=tot_noise; + + memcpy(scalefac, &scalefac_w, sizeof(III_scalefac_t)); + memcpy(l3_enc,l3_enc_w,sizeof(int)*576); + memcpy(&save_cod_info,cod_info,sizeof(save_cod_info)); + + #ifdef HAVEGTK + if (gfp->gtkflag) { + memcpy(xfsf, xfsf_w, sizeof(xfsf_w)); + } + #endif + } + } + + /* if no bands with distortion, we are done */ + if (gfp->noise_shaping_stop==0) + if (over==0) notdone=0; + + if (notdone) { + amp_scalefac_bands( xrpow, cod_info, &scalefac_w, distort); + /* check to make sure we have not amplified too much */ + /* loop_break returns 0 if there is an unamplified scalefac */ + /* scale_bitcount returns 0 if no scalefactors are too large */ + if ( (status = loop_break(&scalefac_w, cod_info)) == 0 ) { + if ( gfp->version == 1 ) { + status = scale_bitcount(&scalefac_w, cod_info); + }else{ + status = scale_bitcount_lsf(&scalefac_w, cod_info); + } + if (status && (cod_info->scalefac_scale==0)) try_scale=1; + } + notdone = !status; + } + + if (try_scale && gfp->experimentalY) { + init_outer_loop(gfp,xr, cod_info); + compute_stepsize=1; /* compute a new global gain */ + notdone=1; + cod_info->scalefac_scale=1; + } + } /* done with main iteration */ + + memcpy(cod_info,&save_cod_info,sizeof(save_cod_info)); + cod_info->part2_3_length += cod_info->part2_length; + + /* finish up */ + assert( cod_info->global_gain < 256 ); + + best_noise[0]=best_over; + best_noise[1]=best_max_noise; + best_noise[2]=best_over_noise; + best_noise[3]=best_tot_noise; + } + + + + + + + + + + + + + + + + + /*************************************************************************/ + /* calc_noise */ + /*************************************************************************/ + /* mt 5/99: Function: Improved calc_noise for a single channel */ + int calc_noise1( FLOAT8 xr[576], int ix[576], gr_info *cod_info, + FLOAT8 xfsf[4][SBPSY_l], FLOAT8 distort[4][SBPSY_l], + III_psy_xmin *l3_xmin, III_scalefac_t *scalefac, + FLOAT8 *over_noise, + FLOAT8 *tot_noise, FLOAT8 *max_noise) + { + int start, end, l, i, over=0; + u_int sfb; + FLOAT8 sum,step,bw; + #ifdef RH_ATH + FLOAT8 ath_max; + #endif + + int count=0; + FLOAT8 noise; + *over_noise=0; + *tot_noise=0; + *max_noise = -999; + + for ( sfb = 0; sfb < cod_info->sfb_lmax; sfb++ ) { + FLOAT8 step; + int s = scalefac->l[sfb]; + + if (cod_info->preflag) + s += pretab[sfb]; + + s = cod_info->global_gain - (s << (cod_info->scalefac_scale + 1)); + assert(s<Q_MAX); + assert(s>=0); + step = POW20(s); + + start = scalefac_band.l[ sfb ]; + end = scalefac_band.l[ sfb+1 ]; + bw = end - start; + + #ifdef RH_ATH + ath_max = 0; + #endif + for ( sum = 0.0, l = start; l < end; l++ ) + { + FLOAT8 temp; + temp = fabs(xr[l]) - pow43[ix[l]] * step; + #ifdef MAXNOISE + temp = bw*temp*temp; + sum = Max(sum,temp); + #elif RH_ATH + temp = temp*temp; + sum += temp; + ath_max = Max( ath_max, temp/ATH_mdct_long[l] ); + #else + sum += temp * temp; + #endif + + } + xfsf[0][sfb] = sum / bw; + + /* max -30db noise below threshold */ + #ifdef RH_ATH + noise = 10*log10(Max(.001,Min(ath_max,xfsf[0][sfb]/l3_xmin->l[sfb]))); + #else + noise = 10*log10(Max(.001,xfsf[0][sfb] / l3_xmin->l[sfb])); + #endif + distort[0][sfb] = noise; + if (noise>0) { + over++; + *over_noise += noise; + } + *tot_noise += noise; + *max_noise=Max(*max_noise,noise); + count++; + + } + + + for ( i = 0; i < 3; i++ ) { + for ( sfb = cod_info->sfb_smax; sfb < SBPSY_s; sfb++ ) { + int s; + + s = (scalefac->s[sfb][i] << (cod_info->scalefac_scale + 1)) + + cod_info->subblock_gain[i] * 8; + s = cod_info->global_gain - s; + + assert(s<Q_MAX); + assert(s>=0); + step = POW20(s); + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb+1 ]; + bw = end - start; + #ifdef RH_ATH + ath_max = 0; + #endif + for ( sum = 0.0, l = start; l < end; l++ ) { + FLOAT8 temp; + temp = fabs(xr[l * 3 + i]) - pow43[ix[l * 3 + i]] * step; + #ifdef MAXNOISE + temp = bw*temp*temp; + sum = Max(sum,temp); + #elif RH_ATH + temp = temp*temp; + sum += temp; + ath_max = Max( ath_max, temp/ATH_mdct_short[l] ); + #else + sum += temp * temp; + #endif + } + xfsf[i+1][sfb] = sum / bw; + /* max -30db noise below threshold */ + #ifdef RH_ATH + noise = 10*log10(Max(.001,Min(ath_max,xfsf[i+1][sfb]/l3_xmin->s[sfb][i]))); + #else + noise = 10*log10(Max(.001,xfsf[i+1][sfb] / l3_xmin->s[sfb][i] )); + #endif + distort[i+1][sfb] = noise; + if (noise > 0) { + over++; + *over_noise += noise; + } + *tot_noise += noise; + *max_noise=Max(*max_noise,noise); + count++; + } + } + + if (count>1) *tot_noise /= count; + if (over>1) *over_noise /= over; + + return over; + } + + + + + + + + /*************************************************************************/ + /* amp_scalefac_bands */ + /*************************************************************************/ + + /* + Amplify the scalefactor bands that violate the masking threshold. + See ISO 11172-3 Section C.1.5.4.3.5 + */ + void amp_scalefac_bands(FLOAT8 xrpow[576], + gr_info *cod_info, + III_scalefac_t *scalefac, + FLOAT8 distort[4][SBPSY_l]) + { + int start, end, l,i; + u_int sfb; + FLOAT8 ifqstep34; + FLOAT8 distort_thresh; + + if ( cod_info->scalefac_scale == 0 ) + ifqstep34 = 1.29683955465100964055; + else + ifqstep34 = 1.68179283050742922612; + + /* distort_thresh = 0, unless all bands have distortion + * less than masking. In that case, just amplify bands with distortion + * within 95% of largest distortion/masking ratio */ + distort_thresh = -900; + for ( sfb = 0; sfb < cod_info->sfb_lmax; sfb++ ) { + distort_thresh = Max(distort[0][sfb],distort_thresh); + } + + for ( sfb = cod_info->sfb_smax; sfb < 12; sfb++ ) { + for ( i = 0; i < 3; i++ ) { + distort_thresh = Max(distort[i+1][sfb],distort_thresh); + } + } + distort_thresh=Min(distort_thresh * 1.05, 0.0); + + + + for ( sfb = 0; sfb < cod_info->sfb_lmax; sfb++ ) { + if ( distort[0][sfb]>distort_thresh ) { + scalefac->l[sfb]++; + start = scalefac_band.l[sfb]; + end = scalefac_band.l[sfb+1]; + for ( l = start; l < end; l++ ) + xrpow[l] *= ifqstep34; + } + } + + + for ( i = 0; i < 3; i++ ) { + for ( sfb = cod_info->sfb_smax; sfb < 12; sfb++ ) { + if ( distort[i+1][sfb]>distort_thresh) { + scalefac->s[sfb][i]++; + start = scalefac_band.s[sfb]; + end = scalefac_band.s[sfb+1]; + for (l = start; l < end; l++) + xrpow[l * 3 + i] *= ifqstep34; + } + } + } + } + + + + int quant_compare(int experimentalX, + int best_over,FLOAT8 best_tot_noise,FLOAT8 best_over_noise,FLOAT8 best_max_noise, + int over,FLOAT8 tot_noise, FLOAT8 over_noise, FLOAT8 max_noise) + { + /* + noise is given in decibals (db) relative to masking thesholds. + + over_noise: sum of quantization noise > masking + tot_noise: sum of all quantization noise + max_noise: max quantization noise + + */ + int better=0; + + if (experimentalX==0) { + better = ((over < best_over) || + ((over==best_over) && (over_noise<=best_over_noise)) ) ; + } + + if (experimentalX==1) + better = max_noise < best_max_noise; + + if (experimentalX==2) { + better = tot_noise < best_tot_noise; + } + if (experimentalX==3) { + better = (tot_noise < best_tot_noise) && + (max_noise < best_max_noise + 2); + } + if (experimentalX==4) { + better = ( ( (0>=max_noise) && (best_max_noise>2)) || + ( (0>=max_noise) && (best_max_noise<0) && ((best_max_noise+2)>max_noise) && (tot_noise<best_tot_noise) ) || + ( (0>=max_noise) && (best_max_noise>0) && ((best_max_noise+2)>max_noise) && (tot_noise<(best_tot_noise+best_over_noise)) ) || + ( (0<max_noise) && (best_max_noise>-0.5) && ((best_max_noise+1)>max_noise) && ((tot_noise+over_noise)<(best_tot_noise+best_over_noise)) ) || + ( (0<max_noise) && (best_max_noise>-1) && ((best_max_noise+1.5)>max_noise) && ((tot_noise+over_noise+over_noise)<(best_tot_noise+best_over_noise+best_over_noise)) ) ); + } + if (experimentalX==5) { + better = (over_noise < best_over_noise) + || ((over_noise == best_over_noise)&&(tot_noise < best_tot_noise)); + } + if (experimentalX==6) { + better = (over_noise < best_over_noise) + ||( (over_noise == best_over_noise) + &&( (max_noise < best_max_noise) + ||( (max_noise == best_max_noise) + &&(tot_noise <= best_tot_noise) + ) + ) + ); + } + + return better; + } + + + int VBR_compare( + int best_over,FLOAT8 best_tot_noise,FLOAT8 best_over_noise,FLOAT8 best_max_noise, + int over,FLOAT8 tot_noise, FLOAT8 over_noise, FLOAT8 max_noise) + { + /* + noise is given in decibals (db) relative to masking thesholds. + + over_noise: sum of quantization noise > masking + tot_noise: sum of all quantization noise + max_noise: max quantization noise + + */ + int better=0; + + better = ((over <= best_over) && + (over_noise<=best_over_noise) && + (tot_noise<=best_tot_noise) && + (max_noise<=best_max_noise)); + return better; + } + + + + + + + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/quantize.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,76 ---- + /********************************************************************** + * ISO MPEG Audio Subgroup Software Simulation Group (1996) + * ISO 13818-3 MPEG-2 Audio Encoder - Lower Sampling Frequency Extension + * + * $Id: quantize.h,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: quantize.h,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:55:54 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.5 2000/03/21 23:02:17 markt + * replaced all "gf." by gfp-> + * + * Revision 1.4 2000/03/14 21:01:47 markt + * removed fr_ps struct + * + * Revision 1.3 2000/02/01 14:09:14 takehiro + * code clean up. changed definition of structure to optimize array index calculation + * + * Revision 1.2 2000/02/01 11:26:32 takehiro + * scalefactor's structure changed + * + * Revision 1.1.1.1 1999/11/24 08:43:45 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 1.1 1996/02/14 04:04:23 rowlands + * Initial revision + * + * Received from Mike Coleman + **********************************************************************/ + + #ifndef LOOP_DOT_H + #define LOOP_DOT_H + #include "util.h" + #include "l3side.h" + + /********************************************************************** + * date programmers comment * + * 25. 6.92 Toshiyuki Ishino Ver 1.0 * + * 29.10.92 Masahiro Iwadare Ver 2.0 * + * 17. 4.93 Masahiro Iwadare Updated for IS Modification * + * * + *********************************************************************/ + + extern int cont_flag; + + + extern int pretab[]; + + void iteration_loop( lame_global_flags *gfp, + FLOAT8 pe[2][2], FLOAT8 ms_ratio[2], + FLOAT8 xr_org[2][2][576], III_psy_ratio ratio[2][2], + III_side_info_t *l3_side, int l3_enc[2][2][576], + III_scalefac_t scalefac[2][2]); + + void VBR_iteration_loop( lame_global_flags *gfp, + FLOAT8 pe[2][2], FLOAT8 ms_ratio[2], + FLOAT8 xr_org[2][2][576], III_psy_ratio ratio[2][2], + III_side_info_t *l3_side, int l3_enc[2][2][576], + III_scalefac_t scalefac[2][2]); + + + + + #define maximum(A,B) ( (A) > (B) ? (A) : (B) ) + #define minimum(A,B) ( (A) < (B) ? (A) : (B) ) + #define signum( A ) ( (A) > 0 ? 1 : -1 ) + + + extern int bit_buffer[50000]; + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/reservoir.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/reservoir.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/reservoir.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,183 ---- + /********************************************************************** + * ISO MPEG Audio Subgroup Software Simulation Group (1996) + * ISO 13818-3 MPEG-2 Audio Encoder - Lower Sampling Frequency Extension + * + **********************************************************************/ + /* + Revision History: + + Date Programmer Comment + ========== ========================= =============================== + 1995/09/06 mc at fivebats.com created + + */ + #include <stdio.h> + #include <stdlib.h> + #include <math.h> + #include <assert.h> + #include "util.h" + #ifdef HAVEGTK + #include "gtkanal.h" + #endif + + + /* + Layer3 bit reservoir: + Described in C.1.5.4.2.2 of the IS + */ + + static int ResvSize = 0; /* in bits */ + static int ResvMax = 0; /* in bits */ + + /* + ResvFrameBegin: + Called (repeatedly) at the beginning of a frame. Updates the maximum + size of the reservoir, and checks to make sure main_data_begin + was set properly by the formatter + */ + int + ResvFrameBegin(lame_global_flags *gfp,III_side_info_t *l3_side, int mean_bits, int frameLength ) + { + int fullFrameBits; + int resvLimit; + + if (gfp->frameNum==0) { + ResvSize=0; + } + + + if ( gfp->version == 1 ) + { + resvLimit = 4088; /* main_data_begin has 9 bits in MPEG 1 */ + } + else + { + resvLimit = 2040; /* main_data_begin has 8 bits in MPEG 2 */ + } + + /* + main_data_begin was set by the formatter to the + expected value for the next call -- this should + agree with our reservoir size + */ + + #ifdef DEBUG + fprintf( stderr, ">>> ResvSize = %d\n", ResvSize ); + #endif + /* check expected resvsize */ + assert( (l3_side->main_data_begin * 8) == ResvSize ); + fullFrameBits = mean_bits * gfp->mode_gr + ResvSize; + + /* + determine maximum size of reservoir: + ResvMax + frameLength <= 7680; + */ + if ( frameLength > 7680 ) + ResvMax = 0; + else + ResvMax = 7680 - frameLength; + if (gfp->disable_reservoir) ResvMax=0; + + + /* + limit max size to resvLimit bits because + main_data_begin cannot indicate a + larger value + */ + if ( ResvMax > resvLimit ) + ResvMax = resvLimit; + + #ifdef HAVEGTK + if (gfp->gtkflag){ + pinfo->mean_bits=mean_bits/2; /* expected bits per channel per granule */ + pinfo->resvsize=ResvSize; + } + #endif + + return fullFrameBits; + } + + + /* + ResvMaxBits2: + As above, but now it *really* is bits per granule (both channels). + Mark Taylor 4/99 + */ + void ResvMaxBits(int mean_bits, int *targ_bits, int *extra_bits, int gr) + { + int add_bits; + *targ_bits = mean_bits ; + /* extra bits if the reservoir is almost full */ + if (ResvSize > ((ResvMax * 9) / 10)) { + add_bits= ResvSize-((ResvMax * 9) / 10); + *targ_bits += add_bits; + }else { + add_bits =0 ; + /* build up reservoir. this builds the reservoir a little slower + * than FhG. It could simple be mean_bits/15, but this was rigged + * to always produce 100 (the old value) at 128kbs */ + *targ_bits -= (int) (mean_bits/15.2); + } + + + /* amount from the reservoir we are allowed to use. ISO says 6/10 */ + *extra_bits = + (ResvSize < (ResvMax*6)/10 ? ResvSize : (ResvMax*6)/10); + *extra_bits -= add_bits; + + if (*extra_bits < 0) *extra_bits=0; + + + } + + /* + ResvAdjust: + Called after a granule's bit allocation. Readjusts the size of + the reservoir to reflect the granule's usage. + */ + void + ResvAdjust(lame_global_flags *gfp,gr_info *gi, III_side_info_t *l3_side, int mean_bits ) + { + ResvSize += (mean_bits / gfp->stereo) - gi->part2_3_length; + } + + + /* + ResvFrameEnd: + Called after all granules in a frame have been allocated. Makes sure + that the reservoir size is within limits, possibly by adding stuffing + bits. Note that stuffing bits are added by increasing a granule's + part2_3_length. The bitstream formatter will detect this and write the + appropriate stuffing bits to the bitstream. + */ + void + ResvFrameEnd(lame_global_flags *gfp,III_side_info_t *l3_side, int mean_bits) + { + int stuffingBits; + int over_bits; + + /* just in case mean_bits is odd, this is necessary... */ + if ( gfp->stereo == 2 && mean_bits & 1) + ResvSize += 1; + + over_bits = ResvSize - ResvMax; + if ( over_bits < 0 ) + over_bits = 0; + + ResvSize -= over_bits; + stuffingBits = over_bits; + + /* we must be byte aligned */ + if ( (over_bits = ResvSize % 8) ) + { + stuffingBits += over_bits; + ResvSize -= over_bits; + } + + + l3_side->resvDrain = stuffingBits; + return; + + } + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/reservoir.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/reservoir.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/reservoir.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,49 ---- + /********************************************************************** + * ISO MPEG Audio Subgroup Software Simulation Group (1996) + * ISO 13818-3 MPEG-2 Audio Encoder - Lower Sampling Frequency Extension + * + * $Id: reservoir.h,v 1.1 2007/01/09 23:44:35 lattner Exp $ + * + * $Log: reservoir.h,v $ + * Revision 1.1 2007/01/09 23:44:35 lattner + * Readd mibench + * + * Revision 1.1.1.1 2007/01/09 02:55:54 evancheng + * Add selected tests from MiBench 1.0 to LLVM test suite. + * + * Revision 1.4 2000/03/21 23:02:17 markt + * replaced all "gf." by gfp-> + * + * Revision 1.3 2000/03/14 21:01:47 markt + * removed fr_ps struct + * + * Revision 1.2 2000/01/13 16:26:50 takehiro + * moved info.stereo into gf.stereo + * + * Revision 1.1.1.1 1999/11/24 08:43:40 markt + * initial checkin of LAME + * Starting with LAME 3.57beta with some modifications + * + * Revision 1.1 1996/02/14 04:04:23 rowlands + * Initial revision + * + * Received from Mike Coleman + **********************************************************************/ + /* + Revision History: + + Date Programmer Comment + ========== ========================= =============================== + 1995/09/06 mc at fivebats.com created + + */ + + #ifndef RESERVOIR_H + #define RESERVOIR_H + + int ResvFrameBegin( lame_global_flags *gfp,III_side_info_t *l3_side, int mean_bits, int frameLength ); + void ResvMaxBits( int mean_bits, int *targ_bits, int *max_bits, int gr); + void ResvAdjust(lame_global_flags *gfp,gr_info *gi, III_side_info_t *l3_side, int mean_bits ); + void ResvFrameEnd(lame_global_flags *gfp,III_side_info_t *l3_side, int mean_bits ); + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/rtp.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/rtp.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/rtp.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,102 ---- + #include <stdlib.h> + #include <string.h> + #include <netinet/in.h> + #include <unistd.h> + #include <stdlib.h> + #include <stdio.h> + #include <sys/types.h> + #include <sys/socket.h> + #include <arpa/inet.h> + + struct rtpbits { + int sequence:16; /* sequence number: random */ + int pt:7; /* payload type: 14 for MPEG audio */ + int m:1; /* marker: 0 */ + int cc:4; /* number of CSRC identifiers: 0 */ + int x:1; /* number of extension headers: 0 */ + int p:1; /* is there padding appended: 0 */ + int v:2; /* version: 2 */ + }; + + struct rtpheader { /* in network byte order */ + struct rtpbits b; + int timestamp; /* start: random */ + int ssrc; /* random */ + int iAudioHeader; /* =0?! */ + }; + + void initrtp(struct rtpheader *foo) { + foo->b.v=2; + foo->b.p=0; + foo->b.x=0; + foo->b.cc=0; + foo->b.m=0; + foo->b.pt=14; /* MPEG Audio */ + #ifdef FEFE + foo->b.sequence=42; + foo->timestamp=0; + #else + foo->b.sequence=rand() & 65535; + foo->timestamp=rand(); + #endif + foo->ssrc=rand(); + foo->iAudioHeader=0; + } + + int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, void *data, int len) { + char *buf=alloca(len+sizeof(struct rtpheader)); + int *cast=(int *)foo; + int *outcast=(int *)buf; + outcast[0]=htonl(cast[0]); + outcast[1]=htonl(cast[1]); + outcast[2]=htonl(cast[2]); + outcast[3]=htonl(cast[3]); + memmove(buf+sizeof(struct rtpheader),data,len); + return sendto(fd,buf,len+sizeof(*foo),0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr)); + /* return write(fd,buf,len+sizeof(*foo))==len+sizeof(*foo); */ + } + + /* create a sender socket. */ + int makesocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr) { + int iRet, iLoop = 1; + struct sockaddr_in sin; + char cTtl = (char)TTL; + char cLoop=0; + unsigned int tempaddr; + + int iSocket = socket( AF_INET, SOCK_DGRAM, 0 ); + if (iSocket < 0) { + fprintf(stderr,"socket() failed.\n"); + exit(1); + } + + tempaddr=inet_addr(szAddr); + sSockAddr->sin_family = sin.sin_family = AF_INET; + sSockAddr->sin_port = sin.sin_port = htons(port); + sSockAddr->sin_addr.s_addr = tempaddr; + + iRet = setsockopt(iSocket, SOL_SOCKET, SO_REUSEADDR, &iLoop, sizeof(int)); + if (iRet < 0) { + fprintf(stderr,"setsockopt SO_REUSEADDR failed\n"); + exit(1); + } + + if ((ntohl(tempaddr) >> 28) == 0xe) { + /* only set multicast parameters for multicast destination IPs */ + iRet = setsockopt(iSocket, IPPROTO_IP, IP_MULTICAST_TTL, &cTtl, sizeof(char)); + if (iRet < 0) { + fprintf(stderr,"setsockopt IP_MULTICAST_TTL failed. multicast in kernel?\n"); + exit(1); + } + + cLoop = 1; /* !? */ + iRet = setsockopt(iSocket, IPPROTO_IP, IP_MULTICAST_LOOP, + &cLoop, sizeof(char)); + if (iRet < 0) { + fprintf(stderr,"setsockopt IP_MULTICAST_LOOP failed. multicast in kernel?\n"); + exit(1); + } + } + + return iSocket; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/rtp.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/rtp.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/rtp.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,24 ---- + #include <sys/socket.h> + #include <netinet/in.h> + + struct rtpbits { + int sequence:16; /* sequence number: random */ + int pt:7; /* payload type: 14 for MPEG audio */ + int m:1; /* marker: 0 */ + int cc:4; /* number of CSRC identifiers: 0 */ + int x:1; /* number of extension headers: 0 */ + int p:1; /* is there padding appended: 0 */ + int v:2; /* version: 2 */ + }; + + struct rtpheader { /* in network byte order */ + struct rtpbits b; + int timestamp; /* start: random */ + int ssrc; /* random */ + int iAudioHeader; /* =0?! */ + }; + + void initrtp(struct rtpheader *foo); + int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, void *data, int len); + int makesocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr); + void rtp_output(char *mp3buffer,int mp3size); Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/small.wav Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tabinit.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tabinit.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tabinit.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,82 ---- + #ifdef HAVEMPGLIB + #include <stdlib.h> + + #include "mpg123.h" + + real decwin[512+32]; + static real cos64[16],cos32[8],cos16[4],cos8[2],cos4[1]; + real *pnts[] = { cos64,cos32,cos16,cos8,cos4 }; + + #if 0 + static unsigned char *conv16to8_buf = NULL; + unsigned char *conv16to8; + #endif + + static long intwinbase[] = { + 0, -1, -1, -1, -1, -1, -1, -2, -2, -2, + -2, -3, -3, -4, -4, -5, -5, -6, -7, -7, + -8, -9, -10, -11, -13, -14, -16, -17, -19, -21, + -24, -26, -29, -31, -35, -38, -41, -45, -49, -53, + -58, -63, -68, -73, -79, -85, -91, -97, -104, -111, + -117, -125, -132, -139, -147, -154, -161, -169, -176, -183, + -190, -196, -202, -208, -213, -218, -222, -225, -227, -228, + -228, -227, -224, -221, -215, -208, -200, -189, -177, -163, + -146, -127, -106, -83, -57, -29, 2, 36, 72, 111, + 153, 197, 244, 294, 347, 401, 459, 519, 581, 645, + 711, 779, 848, 919, 991, 1064, 1137, 1210, 1283, 1356, + 1428, 1498, 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962, + 2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063, 2037, 2000, + 1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970, + 794, 605, 402, 185, -45, -288, -545, -814, -1095, -1388, + -1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788, + -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209, + -8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959, + -9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092, + -7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082, + -70, 998, 2122, 3300, 4533, 5818, 7154, 8540, 9975, 11455, + 12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289, + 30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617, + 48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684, + 64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835, + 73415, 73908, 74313, 74630, 74856, 74992, 75038 }; + + void make_decode_tables(long scaleval) + { + int i,j,k,kr,divv; + real *table,*costab; + + + for(i=0;i<5;i++) + { + kr=0x10>>i; divv=0x40>>i; + costab = pnts[i]; + for(k=0;k<kr;k++) + costab[k] = 1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv)); + } + + table = decwin; + scaleval = -scaleval; + for(i=0,j=0;i<256;i++,j++,table+=32) + { + if(table < decwin+512+16) + table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval; + if(i % 32 == 31) + table -= 1023; + if(i % 64 == 63) + scaleval = - scaleval; + } + + for( /* i=256 */ ;i<512;i++,j--,table+=32) + { + if(table < decwin+512+16) + table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval; + if(i % 32 == 31) + table -= 1023; + if(i % 64 == 63) + scaleval = - scaleval; + } + } + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tables.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tables.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tables.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,1215 ---- + #include "util.h" + #include "tables.h" + + /* + Here are MPEG1 Table B.8 and MPEG2 Table B.1 + -- Layer III scalefactor bands. + Index into this using a method such as: + idx = fr_ps->header->sampling_frequency + + (fr_ps->header->version * 3) + */ + + + + + unsigned int hs = sizeof(HUFFBITS)*8; + + static HUFFBITS t1HB[] = { + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0}; + + static HUFFBITS t2HB[] = { + 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 2, 0}; + + static HUFFBITS t3HB[] = { + 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 2, 0}; + + static HUFFBITS t5HB[] = { + 1, 2, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 1, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 5, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 1, 1, 0}; + + static HUFFBITS t6HB[] = { + 7, 3, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 2, 0}; + + static HUFFBITS t7HB[] = { + 1, 2,10,19,16,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 7,10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 11, 4,13,17, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 12,11,18,15,11, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 6, 9,14, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 4, 5, 3, 2, 0}; + + static HUFFBITS t8HB[] = { + 3, 4, 6, 18,12, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 1, 2, 16, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 3, 5, 14, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 19,17,15, 13,10, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 13, 5, 8, 11, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 12, 4, 4, 1, 1, 0}; + + static HUFFBITS t9HB[] = { + 7, 5, 9, 14, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 4, 5, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 6, 8, 8, 8, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 15, 6, 9, 10, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 11, 7, 9, 6, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 14, 4, 6, 2, 6, 0}; + + static HUFFBITS t10HB[] = { + 1, 2, 10, 23, 35, 30, 12, 17, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 8, 12, 18, 21, 12, 7, 0, 0, 0, 0, 0, 0, 0, 0, + 11, 9, 15, 21, 32, 40, 19, 6, 0, 0, 0, 0, 0, 0, 0, 0, + 14,13, 22, 34, 46, 23, 18, 7, 0, 0, 0, 0, 0, 0, 0, 0, + 20,19, 33, 47, 27, 22, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, + 31,22, 41, 26, 21, 20, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, + 14,13, 10, 11, 16, 6, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 9, 8, 7, 8, 4, 4, 2, 0}; + + static HUFFBITS t11HB[] = { + 3, 4, 10, 24, 34, 33, 21, 15, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 3, 4, 10, 32, 17, 11, 10, 0, 0, 0, 0, 0, 0, 0, 0, + 11, 7, 13, 18, 30, 31, 20, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 25,11, 19, 59, 27, 18, 12, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 35,33, 31, 58, 30, 16, 7, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 28,26, 32, 19, 17, 15, 8, 14, 0, 0, 0, 0, 0, 0, 0, 0, + 14,12, 9, 13, 14, 9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 11, 4, 6, 6, 6, 3, 2, 0}; + + static HUFFBITS t12HB[] = { + 9, 6, 16, 33, 41, 39, 38,26, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 5, 6, 9, 23, 16, 26,11, 0, 0, 0, 0, 0, 0, 0, 0, + 17, 7, 11, 14, 21, 30, 10, 7, 0, 0, 0, 0, 0, 0, 0, 0, + 17, 10, 15, 12, 18, 28, 14, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 32, 13, 22, 19, 18, 16, 9, 5, 0, 0, 0, 0, 0, 0, 0, 0, + 40, 17, 31, 29, 17, 13, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, + 27, 12, 11, 15, 10, 7, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 27, 12, 8, 12, 6, 3, 1, 0}; + + static HUFFBITS t13HB[] = { + 1, 5, 14, 21, 34, 51, 46, 71, 42, 52, 68, 52, 67, 44, 43, 19, + 3, 4, 12, 19, 31, 26, 44, 33, 31, 24, 32, 24, 31, 35, 22, 14, + 15, 13, 23, 36, 59, 49, 77, 65, 29, 40, 30, 40, 27, 33, 42, 16, + 22, 20, 37, 61, 56, 79, 73, 64, 43, 76, 56, 37, 26, 31, 25, 14, + 35, 16, 60, 57, 97, 75,114, 91, 54, 73, 55, 41, 48, 53, 23, 24, + 58, 27, 50, 96, 76, 70, 93, 84, 77, 58, 79, 29, 74, 49, 41, 17, + 47, 45, 78, 74,115, 94, 90, 79, 69, 83, 71, 50, 59, 38, 36, 15, + 72, 34, 56, 95, 92, 85, 91, 90, 86, 73, 77, 65, 51, 44, 43, 42, + 43, 20, 30, 44, 55, 78, 72, 87, 78, 61, 46, 54, 37, 30, 20, 16, + 53, 25, 41, 37, 44, 59, 54, 81, 66, 76, 57, 54, 37, 18, 39, 11, + 35, 33, 31, 57, 42, 82, 72, 80, 47, 58, 55, 21, 22, 26, 38, 22, + 53, 25, 23, 38, 70, 60, 51, 36, 55, 26, 34, 23, 27, 14, 9, 7, + 34, 32, 28, 39, 49, 75, 30, 52, 48, 40, 52, 28, 18, 17, 9, 5, + 45, 21, 34, 64, 56, 50, 49, 45, 31, 19, 12, 15, 10, 7, 6, 3, + 48, 23, 20, 39, 36, 35, 53, 21, 16, 23, 13, 10, 6, 1, 4, 2, + 16, 15, 17, 27, 25, 20, 29, 11, 17, 12, 16, 8, 1, 1, 0, 1}; + + static HUFFBITS t15HB[] = { + 7, 12, 18, 53, 47, 76,124,108, 89,123,108,119,107, 81,122, 63, + 13, 5, 16, 27, 46, 36, 61, 51, 42, 70, 52, 83, 65, 41, 59, 36, + 19, 17, 15, 24, 41, 34, 59, 48, 40, 64, 50, 78, 62, 80, 56, 33, + 29, 28, 25, 43, 39, 63, 55, 93, 76, 59, 93, 72, 54, 75, 50, 29, + 52, 22, 42, 40, 67, 57, 95, 79, 72, 57, 89, 69, 49, 66, 46, 27, + 77, 37, 35, 66, 58, 52, 91, 74, 62, 48, 79, 63, 90, 62, 40, 38, + 125, 32, 60, 56, 50, 92, 78, 65, 55, 87, 71, 51, 73, 51, 70, 30, + 109, 53, 49, 94, 88, 75, 66,122, 91, 73, 56, 42, 64, 44, 21, 25, + 90, 43, 41, 77, 73, 63, 56, 92, 77, 66, 47, 67, 48, 53, 36, 20, + 71, 34, 67, 60, 58, 49, 88, 76, 67,106, 71, 54, 38, 39, 23, 15, + 109, 53, 51, 47, 90, 82, 58, 57, 48, 72, 57, 41, 23, 27, 62, 9, + 86, 42, 40, 37, 70, 64, 52, 43, 70, 55, 42, 25, 29, 18, 11, 11, + 118, 68, 30, 55, 50, 46, 74, 65, 49, 39, 24, 16, 22, 13, 14, 7, + 91, 44, 39, 38, 34, 63, 52, 45, 31, 52, 28, 19, 14, 8, 9, 3, + 123, 60, 58, 53, 47, 43, 32, 22, 37, 24, 17, 12, 15, 10, 2, 1, + 71, 37, 34, 30, 28, 20, 17, 26, 21, 16, 10, 6, 8, 6, 2, 0}; + + static HUFFBITS t16HB[] = { + 1, 5, 14, 44, 74, 63, 110, 93, 172, 149, 138, 242, 225, 195, 376, 17, + 3, 4, 12, 20, 35, 62, 53, 47, 83, 75, 68, 119, 201, 107, 207, 9, + 15, 13, 23, 38, 67, 58, 103, 90, 161, 72, 127, 117, 110, 209, 206, 16, + 45, 21, 39, 69, 64,114, 99, 87, 158, 140, 252, 212, 199, 387, 365, 26, + 75, 36, 68, 65,115,101, 179,164, 155, 264, 246, 226, 395, 382, 362, 9, + 66, 30, 59, 56,102,185, 173,265, 142, 253, 232, 400, 388, 378, 445, 16, + 111, 54, 52,100,184,178, 160,133, 257, 244, 228, 217, 385, 366, 715, 10, + 98, 48, 91, 88,165,157, 148,261, 248, 407, 397, 372, 380, 889, 884, 8, + 85, 84, 81,159,156,143, 260,249, 427, 401, 392, 383, 727, 713, 708, 7, + 154, 76, 73,141,131,256, 245,426, 406, 394, 384, 735, 359, 710, 352, 11, + 139, 129, 67,125,247,233, 229,219, 393, 743, 737, 720, 885, 882, 439, 4, + 243, 120,118,115,227,223, 396,746, 742, 736, 721, 712, 706, 223, 436, 6, + 202, 224,222,218,216,389, 386,381, 364, 888, 443, 707, 440, 437,1728, 4, + 747, 211,210,208,370, 379,734,723, 714,1735, 883, 877, 876,3459, 865, 2, + 377, 369,102,187, 726,722,358,711, 709, 866,1734, 871,3458, 870, 434, 0, + 12, 10, 7, 11, 10, 17, 11, 9, 13, 12, 10, 7, 5, 3, 1, 3}; + + static HUFFBITS t24HB[] = { + 15, 13, 46, 80, 146, 262, 248, 434, 426, 669, 653, 649, 621, 517, 1032, 88, + 14, 12, 21, 38, 71, 130, 122, 216, 209, 198, 327, 345, 319, 297, 279, 42, + 47, 22, 41, 74, 68, 128, 120, 221, 207, 194, 182, 340, 315, 295, 541, 18, + 81, 39, 75, 70, 134, 125, 116, 220, 204, 190, 178, 325, 311, 293, 271, 16, + 147, 72, 69,135, 127, 118, 112, 210, 200, 188, 352, 323, 306, 285, 540, 14, + 263, 66,129,126, 119, 114, 214, 202, 192, 180, 341, 317, 301, 281, 262, 12, + 249,123,121,117, 113, 215, 206, 195, 185, 347, 330, 308, 291, 272, 520, 10, + 435,115,111,109, 211, 203, 196, 187, 353, 332, 313, 298, 283, 531, 381, 17, + 427,212,208,205, 201, 193, 186, 177, 169, 320, 303, 286, 268, 514, 377, 16, + 335,199,197,191, 189, 181, 174, 333, 321, 305, 289, 275, 521, 379, 371, 11, + 668,184,183,179, 175, 344, 331, 314, 304, 290, 277, 530, 383, 373, 366, 10, + 652,346,171,168, 164, 318, 309, 299, 287, 276, 263, 513, 375, 368, 362, 6, + 648,322,316,312, 307, 302, 292, 284, 269, 261, 512, 376, 370, 364, 359, 4, + 620,300,296,294, 288, 282, 273, 266, 515, 380, 374, 369, 365, 361, 357, 2, + 1033,280,278,274, 267, 264, 259, 382, 378, 372, 367, 363, 360, 358, 356, 0, + 43, 20, 19, 17, 15, 13, 11, 9, 7, 6, 4, 7, 5, 3, 1, 3}; + + static HUFFBITS t32HB[] = { + 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1}; + static HUFFBITS t33HB[] = { + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + + static unsigned char t1l[] = { + 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 3}; + + static unsigned char t2l[] = { + 1, 3, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 6}; + + static unsigned char t3l[] = { + 2, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 6}; + + static unsigned char t5l[] = { + 1, 3, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 6, 7, 8}; + + static unsigned char t6l[] = { + 3, 3, 5, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 2, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 4, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 5, 6, 7}; + + static unsigned char t7l[] = { + 1, 3, 6, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 4, 6, 7, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 5, 7, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 7, 8, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 7, 8, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 8, 9,10,10,10}; + + static unsigned char t8l[] = { + 2, 3, 6, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 2, 4, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 4, 6, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 8, 8, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 8, 9,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 9, 8, 9, 9,11,11}; + + static unsigned char t9l[] = { + 3, 3, 5, 6, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 4, 5, 6, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 4, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 5, 6, 7, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 6, 7, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 8, 8, 9, 9}; + + static unsigned char t10l[] = { + 1, 3, 6, 8, 9, 9, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 4, 6, 7, 8, 9, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 6, 7, 8, 9,10, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 7, 8, 9,10,10, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 8, 9,10,10,10,10, 10, 0, 0, 0, 0, 0, 0, 0, 0, + 9, 9,10,10,11,11,10, 11, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 8, 9,10,10,10,11, 11, 0, 0, 0, 0, 0, 0, 0, 0, + 9, 8, 9,10,10,11,11, 11}; + + static unsigned char t11l[] = { + 2, 3, 5, 7, 8, 9, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 4, 6, 8, 8, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 6, 7, 8, 9, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 6, 7, 9, 8, 10, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 8, 8, 9, 9, 10, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 8, 9,10,10, 11, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 7, 8, 9, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 8, 9,10, 10, 10, 10}; + + static unsigned char t12l[] = { + 4, 3, 5, 7, 8, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 3, 4, 5, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 4, 5, 6, 7, 8, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 5, 6, 6, 7, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 6, 7, 7, 8, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 8, 8, 8, 9, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 7, 8, 8, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, + 9, 8, 8, 9, 9, 9, 9,10}; + + static unsigned char t13l[] = { + 1, 4, 6, 7, 8, 9, 9, 10, 9, 10, 11, 11, 12, 12, 13, 13, + 3, 4, 6, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 12, 12, 12, + 6, 6, 7, 8, 9, 9, 10, 10, 9, 10, 10, 11, 11, 12, 13, 13, + 7, 7, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 13, + 8, 7, 9, 9, 10, 10, 11, 11, 10, 11, 11, 12, 12, 13, 13, 14, + 9, 8, 9, 10, 10, 10, 11, 11, 11, 11, 12, 11, 13, 13, 14, 14, + 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14, + 10, 9, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 16, 16, + 9, 8, 9, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 14, 15, 15, + 10, 9, 10, 10, 11, 11, 11, 13, 12, 13, 13, 14, 14, 14, 16, 15, + 10, 10, 10, 11, 11, 12, 12, 13, 12, 13, 14, 13, 14, 15, 16, 17, + 11, 10, 10, 11, 12, 12, 12, 12, 13, 13, 13, 14, 15, 15, 15, 16, + 11, 11, 11, 12, 12, 13, 12, 13, 14, 14, 15, 15, 15, 16, 16, 16, + 12, 11, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 16, 15, 16, 16, + 13, 12, 12, 13, 13, 13, 15, 14, 14, 17, 15, 15, 15, 17, 16, 16, + 12, 12, 13, 14, 14, 14, 15, 14, 15, 15, 16, 16, 19, 18, 19, 16}; + + static unsigned char t15l[] = { + 3, 4, 5, 7, 7, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 13, + 4, 3, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, + 5, 5, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 11, + 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, + 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, + 8, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11, 12, + 9, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, + 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 12, + 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 12, 12, 12, + 9, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, + 10, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 12, + 10, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, + 11, 10, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 13, 13, + 11, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, + 12, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 12, 13, + 12, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13}; + + static unsigned char t16l[] = { + 1, 4, 6, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 9, + 3, 4, 6, 7, 8, 9, 9, 9, 10, 10, 10, 11, 12, 11, 12, 8, + 6, 6, 7, 8, 9, 9, 10, 10, 11, 10, 11, 11, 11, 12, 12, 9, + 8, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 10, + 9, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 9, + 9, 8, 9, 9, 10, 11, 11, 12, 11, 12, 12, 13, 13, 13, 14, 10, + 10, 9, 9, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 10, + 10, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 15, 15, 10, + 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 14, 14, 14, 10, + 11, 10, 10, 11, 11, 12, 12, 13, 13, 13, 13, 14, 13, 14, 13, 11, + 11, 11, 10, 11, 12, 12, 12, 12, 13, 14, 14, 14, 15, 15, 14, 10, + 12, 11, 11, 11, 12, 12, 13, 14, 14, 14, 14, 14, 14, 13, 14, 11, + 12, 12, 12, 12, 12, 13, 13, 13, 13, 15, 14, 14, 14, 14, 16, 11, + 14, 12, 12, 12, 13, 13, 14, 14, 14, 16, 15, 15, 15, 17, 15, 11, + 13, 13, 11, 12, 14, 14, 13, 14, 14, 15, 16, 15, 17, 15, 14, 11, + 9, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8}; + + static unsigned char t24l[] = { + 4, 4, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 9, + 4, 4, 5, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 8, + 6, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 7, + 7, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 7, + 8, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 7, + 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 7, + 9, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 7, + 10, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 8, + 10, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 8, + 10, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 8, + 11, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, + 11, 10, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, + 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 8, + 11, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8, + 12, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 8, + 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 4}; + + static unsigned char t32l[] = { + 1, 4, 4, 5, 4, 6, 5, 6, 4, 5, 5, 6, 5, 6, 6, 6}; + static unsigned char t33l[] = { + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}; + + struct huffcodetab ht[HTN] = + { + /* xlen, linmax, table, hlen */ + { 0, 0,NULL,NULL}, + { 2, 0,t1HB, t1l}, + { 3, 0,t2HB, t2l}, + { 3, 0,t3HB, t3l}, + { 0, 0,NULL,NULL},/* Apparently not used */ + { 4, 0,t5HB, t5l}, + { 4, 0,t6HB, t6l}, + { 6, 0,t7HB, t7l}, + { 6, 0,t8HB, t8l}, + { 6, 0,t9HB, t9l}, + { 8, 0,t10HB, t10l}, + { 8, 0,t11HB, t11l}, + { 8, 0,t12HB, t12l}, + {16, 0,t13HB, t13l}, + { 0, 0,NULL,NULL},/* Apparently not used */ + {16, 0,t15HB, t15l}, + + { 1, 1,t16HB, t16l}, + { 2, 3,t16HB, t16l}, + { 3, 7,t16HB, t16l}, + { 4, 15,t16HB, t16l}, + { 6, 63,t16HB, t16l}, + { 8, 255,t16HB, t16l}, + {10,1023,t16HB, t16l}, + {13,8191,t16HB, t16l}, + + { 4, 15,t24HB, t24l}, + { 5, 31,t24HB, t24l}, + { 6, 63,t24HB, t24l}, + { 7, 127,t24HB, t24l}, + { 8, 255,t24HB, t24l}, + { 9, 511,t24HB, t24l}, + {11,2047,t24HB, t24l}, + {13,8191,t24HB, t24l}, + + { 0, 0,t32HB, t32l}, + { 0, 0,t33HB, t33l}, + }; + + + + + + FLOAT8 psy_data[] = + {48000.0, 61, + 0, 1, 24.5, 4.532, 0.970, 0.000, + 1, 1, 24.5, 4.532, 0.755, 0.469, + 2, 1, 24.5, 4.532, 0.738, 0.938, + 3, 1, 24.5, 0.904, 0.730, 1.406, + 4, 1, 24.5, 0.904, 0.724, 1.875, + 5, 1, 20.0, 0.090, 0.723, 2.344, + 6, 1, 20.0, 0.090, 0.723, 2.813, + 7, 1, 20.0, 0.029, 0.723, 3.281, + 8, 1, 20.0, 0.029, 0.718, 3.750, + 9, 1, 20.0, 0.009, 0.690, 4.199, + 10, 1, 20.0, 0.009, 0.660, 4.625, + 11, 1, 18.0, 0.009, 0.641, 5.047, + 12, 1, 18.0, 0.009, 0.600, 5.438, + 13, 1, 18.0, 0.009, 0.584, 5.828, + 14, 1, 12.0, 0.009, 0.532, 6.188, + 15, 1, 12.0, 0.009, 0.537, 6.522, + 16, 2, 6.0, 0.018, 0.857, 7.174, + 17, 2, 6.0, 0.018, 0.858, 7.801, + 18, 2, 3.0, 0.018, 0.853, 8.402, + 19, 2, 3.0, 0.018, 0.824, 8.966, + 20, 2, 3.0, 0.018, 0.778, 9.484, + 21, 2, 3.0, 0.018, 0.740, 9.966, + 22, 2, 0.0, 0.018, 0.709, 10.426, + 23, 2, 0.0, 0.018, 0.676, 10.866, + 24, 2, 0.0, 0.018, 0.632, 11.279, + 25, 2, 0.0, 0.018, 0.592, 11.669, + 26, 2, 0.0, 0.018, 0.553, 12.042, + 27, 2, 0.0, 0.018, 0.510, 12.386, + 28, 2, 0.0, 0.018, 0.513, 12.721, + 29, 3, 0.0, 0.027, 0.608, 13.115, + 30, 3, 0.0, 0.027, 0.673, 13.562, + 31, 3, 0.0, 0.027, 0.637, 13.984, + 32, 3, 0.0, 0.027, 0.586, 14.371, + 33, 3, 0.0, 0.027, 0.571, 14.741, + 34, 4, 0.0, 0.036, 0.616, 15.140, + 35, 4, 0.0, 0.036, 0.640, 15.563, + 36, 4, 0.0, 0.036, 0.598, 15.962, + 37, 4, 0.0, 0.036, 0.538, 16.324, + 38, 4, 0.0, 0.036, 0.512, 16.665, + 39, 5, 0.0, 0.045, 0.528, 17.020, + 40, 5, 0.0, 0.045, 0.517, 17.373, + 41, 5, 0.0, 0.045, 0.493, 17.708, + 42, 6, 0.0, 0.054, 0.499, 18.045, + 43, 7, 0.0, 0.063, 0.525, 18.398, + 44, 7, 0.0, 0.063, 0.541, 18.762, + 45, 8, 0.0, 0.072, 0.528, 19.120, + 46, 8, 0.0, 0.072, 0.510, 19.466, + 47, 8, 0.0, 0.072, 0.506, 19.807, + 48, 10, 0.0, 0.180, 0.525, 20.159, + 49, 10, 0.0, 0.180, 0.536, 20.522, + 50, 10, 0.0, 0.180, 0.518, 20.874, + 51, 13, 0.0, 0.372, 0.501, 21.214, + 52, 13, 0.0, 0.372, 0.497, 21.553, + 53, 14, 0.0, 0.400, 0.497, 21.892, + 54, 18, 0.0, 1.627, 0.495, 22.231, + 55, 18, 0.0, 1.627, 0.494, 22.569, + 56, 20, 0.0, 1.808, 0.497, 22.909, + 57, 25, 0.0, 22.607, 0.494, 23.248, + 58, 25, 0.0, 22.607, 0.487, 23.583, + 59, 35, 0.0, 31.650, 0.483, 23.915, + 60, 67, 0.0, 605.867, 0.482, 24.246, + 61, 67, 0.0, 605.867, 0.524, 24.576, + 44100.0, 62, + 0, 1, 24.5, 4.532, 0.951, 0.000, + 1, 1, 24.5, 4.532, 0.700, 0.431, + 2, 1, 24.5, 4.532, 0.681, 0.861, + 3, 1, 24.5, 0.904, 0.675, 1.292, + 4, 1, 24.5, 0.904, 0.667, 1.723, + 5, 1, 20.0, 0.090, 0.665, 2.153, + 6, 1, 20.0, 0.090, 0.664, 2.584, + 7, 1, 20.0, 0.029, 0.664, 3.015, + 8, 1, 20.0, 0.029, 0.664, 3.445, + 9, 1, 20.0, 0.029, 0.655, 3.876, + 10, 1, 20.0, 0.009, 0.616, 4.279, + 11, 1, 20.0, 0.009, 0.597, 4.670, + 12, 1, 18.0, 0.009, 0.578, 5.057, + 13, 1, 18.0, 0.009, 0.541, 5.416, + 14, 1, 18.0, 0.009, 0.575, 5.774, + 15, 2, 12.0, 0.018, 0.856, 6.422, + 16, 2, 6.0, 0.018, 0.846, 7.026, + 17, 2, 6.0, 0.018, 0.840, 7.609, + 18, 2, 3.0, 0.018, 0.822, 8.168, + 19, 2, 3.0, 0.018, 0.800, 8.710, + 20, 2, 3.0, 0.018, 0.753, 9.207, + 21, 2, 3.0, 0.018, 0.704, 9.662, + 22, 2, 0.0, 0.018, 0.674, 10.099, + 23, 2, 0.0, 0.018, 0.640, 10.515, + 24, 2, 0.0, 0.018, 0.609, 10.917, + 25, 2, 0.0, 0.018, 0.566, 11.293, + 26, 2, 0.0, 0.018, 0.535, 11.652, + 27, 2, 0.0, 0.018, 0.531, 11.997, + 28, 3, 0.0, 0.027, 0.615, 12.394, + 29, 3, 0.0, 0.027, 0.686, 12.850, + 30, 3, 0.0, 0.027, 0.650, 13.277, + 31, 3, 0.0, 0.027, 0.612, 13.681, + 32, 3, 0.0, 0.027, 0.567, 14.062, + 33, 3, 0.0, 0.027, 0.520, 14.411, + 34, 3, 0.0, 0.027, 0.513, 14.751, + 35, 4, 0.0, 0.036, 0.557, 15.119, + 36, 4, 0.0, 0.036, 0.584, 15.508, + 37, 4, 0.0, 0.036, 0.570, 15.883, + 38, 5, 0.0, 0.045, 0.579, 16.263, + 39, 5, 0.0, 0.045, 0.585, 16.654, + 40, 5, 0.0, 0.045, 0.548, 17.020, + 41, 6, 0.0, 0.054, 0.536, 17.374, + 42, 6, 0.0, 0.054, 0.550, 17.744, + 43, 7, 0.0, 0.063, 0.532, 18.104, + 44, 7, 0.0, 0.063, 0.504, 18.447, + 45, 7, 0.0, 0.063, 0.496, 18.782, + 46, 9, 0.0, 0.081, 0.517, 19.130, + 47, 9, 0.0, 0.081, 0.527, 19.487, + 48, 9, 0.0, 0.081, 0.516, 19.838, + 49, 10, 0.0, 0.180, 0.497, 20.179, + 50, 10, 0.0, 0.180, 0.489, 20.510, + 51, 11, 0.0, 0.198, 0.502, 20.852, + 52, 14, 0.0, 0.400, 0.501, 21.196, + 53, 14, 0.0, 0.400, 0.491, 21.531, + 54, 15, 0.0, 0.429, 0.497, 21.870, + 55, 20, 0.0, 1.808, 0.504, 22.214, + 56, 20, 0.0, 1.808, 0.504, 22.558, + 57, 21, 0.0, 1.898, 0.495, 22.898, + 58, 27, 0.0, 24.416, 0.486, 23.232, + 59, 27, 0.0, 24.416, 0.484, 23.564, + 60, 36, 0.0, 32.554, 0.483, 23.897, + 61, 73, 0.0, 660.124, 0.475, 24.229, + 62, 18, 0.0, 162.770, 0.515, 24.442, + 32000.0, 58, + 0, 2, 24.5, 4.532, 0.997, 0.313, + 1, 2, 24.5, 4.532, 0.893, 0.938, + 2, 2, 24.5, 1.809, 0.881, 1.563, + 3, 2, 20.0, 0.181, 0.873, 2.188, + 4, 2, 20.0, 0.181, 0.872, 2.813, + 5, 2, 20.0, 0.057, 0.871, 3.438, + 6, 2, 20.0, 0.018, 0.860, 4.045, + 7, 2, 20.0, 0.018, 0.839, 4.625, + 8, 2, 18.0, 0.018, 0.812, 5.173, + 9, 2, 18.0, 0.018, 0.784, 5.698, + 10, 2, 12.0, 0.018, 0.741, 6.185, + 11, 2, 12.0, 0.018, 0.697, 6.634, + 12, 2, 6.0, 0.018, 0.674, 7.070, + 13, 2, 6.0, 0.018, 0.651, 7.492, + 14, 2, 6.0, 0.018, 0.633, 7.905, + 15, 2, 3.0, 0.018, 0.611, 8.305, + 16, 2, 3.0, 0.018, 0.589, 8.695, + 17, 2, 3.0, 0.018, 0.575, 9.064, + 18, 3, 3.0, 0.027, 0.654, 9.484, + 19, 3, 3.0, 0.027, 0.724, 9.966, + 20, 3, 0.0, 0.027, 0.701, 10.426, + 21, 3, 0.0, 0.027, 0.673, 10.866, + 22, 3, 0.0, 0.027, 0.631, 11.279, + 23, 3, 0.0, 0.027, 0.592, 11.669, + 24, 3, 0.0, 0.027, 0.553, 12.042, + 25, 3, 0.0, 0.027, 0.510, 12.386, + 26, 3, 0.0, 0.027, 0.506, 12.721, + 27, 4, 0.0, 0.036, 0.562, 13.091, + 28, 4, 0.0, 0.036, 0.598, 13.488, + 29, 4, 0.0, 0.036, 0.589, 13.873, + 30, 5, 0.0, 0.045, 0.607, 14.268, + 31, 5, 0.0, 0.045, 0.620, 14.679, + 32, 5, 0.0, 0.045, 0.580, 15.067, + 33, 5, 0.0, 0.045, 0.532, 15.424, + 34, 5, 0.0, 0.045, 0.517, 15.771, + 35, 6, 0.0, 0.054, 0.517, 16.120, + 36, 6, 0.0, 0.054, 0.509, 16.466, + 37, 6, 0.0, 0.054, 0.506, 16.807, + 38, 8, 0.0, 0.072, 0.522, 17.158, + 39, 8, 0.0, 0.072, 0.531, 17.518, + 40, 8, 0.0, 0.072, 0.519, 17.869, + 41, 10, 0.0, 0.090, 0.512, 18.215, + 42, 10, 0.0, 0.090, 0.509, 18.563, + 43, 10, 0.0, 0.090, 0.498, 18.902, + 44, 12, 0.0, 0.109, 0.494, 19.239, + 45, 12, 0.0, 0.109, 0.501, 19.580, + 46, 13, 0.0, 0.118, 0.508, 19.925, + 47, 14, 0.0, 0.252, 0.502, 20.269, + 48, 14, 0.0, 0.252, 0.493, 20.606, + 49, 16, 0.0, 0.288, 0.497, 20.944, + 50, 20, 0.0, 0.572, 0.506, 21.288, + 51, 20, 0.0, 0.572, 0.510, 21.635, + 52, 23, 0.0, 0.658, 0.504, 21.980, + 53, 27, 0.0, 2.441, 0.496, 22.319, + 54, 27, 0.0, 2.441, 0.493, 22.656, + 55, 32, 0.0, 2.893, 0.490, 22.993, + 56, 37, 0.0, 33.458, 0.482, 23.326, + 57, 37, 0.0, 33.458, 0.458, 23.656, + 58, 12, 0.0, 10.851, 0.500, 23.937, + 24000, 59, + 0, 2, 15, 17.8250179, 0.697374165, 0.236874461, + 1, 2, 15, 17.8250179, 0.455024809, 0.71016103, + 2, 2, 15, 1.78250182, 0.431440443, 1.18193281, + 3, 2, 15, 1.78250182, 0.42391625, 1.65102732, + 4, 2, 13, 0.178250194, 0.418206781, 2.11632562, + 5, 2, 13, 0.178250194, 0.41158545, 2.57676744, + 6, 2, 13, 0.0563676581, 0.405409157, 3.03136396, + 7, 2, 13, 0.0563676581, 0.399695486, 3.47920918, + 8, 2, 13, 0.0563676581, 0.393753231, 3.91948748, + 9, 2, 12, 0.0178250186, 0.387357473, 4.35147953, + 10, 2, 12, 0.0178250186, 0.38045457, 4.77456427, + 11, 2, 10, 0.0178250186, 0.373053908, 5.18822002, + 12, 2, 10, 0.0178250186, 0.365188122, 5.59202194, + 13, 2, 10, 0.0178250186, 0.356897771, 5.98564005, + 14, 2, 9, 0.0178250186, 0.348700613, 6.36883163, + 15, 2, 9, 0.0178250186, 0.340260029, 6.74143791, + 16, 2, 6, 0.0178250186, 0.332341045, 7.10337448, + 17, 2, 6, 0.0178250186, 0.330462843, 7.45462418, + 18, 2, 6, 0.0178250186, 0.345568359, 7.79523182, + 19, 3, 3, 0.0267375279, 0.377859652, 8.20455742, + 20, 3, 3, 0.0267375279, 0.396689415, 8.67640114, + 21, 3, 3, 0.0267375279, 0.391237885, 9.12561035, + 22, 3, 3, 0.0267375279, 0.37761277, 9.55298138, + 23, 3, 3, 0.0267375279, 0.362836808, 9.95940971, + 24, 3, 0, 0.0267375279, 0.349010617, 10.3458519, + 25, 3, 0, 0.0267375279, 0.339673489, 10.7132998, + 26, 3, 0, 0.0267375279, 0.343845725, 11.0627575, + 27, 4, 0, 0.0356500372, 0.355822682, 11.447506, + 28, 4, 0, 0.0356500372, 0.358104348, 11.8627586, + 29, 4, 0, 0.0356500372, 0.34745428, 12.2520256, + 30, 4, 0, 0.0356500372, 0.334927917, 12.6173973, + 31, 4, 0, 0.0356500372, 0.331643254, 12.9608269, + 32, 5, 0, 0.0445625484, 0.333368897, 13.3219252, + 33, 5, 0, 0.0445625484, 0.332313001, 13.6976833, + 34, 5, 0, 0.0445625484, 0.3314417, 14.047802, + 35, 6, 0, 0.0534750558, 0.330947191, 14.405302, + 36, 6, 0, 0.0534750558, 0.332477689, 14.7684803, + 37, 7, 0, 0.062387567, 0.332647532, 15.1315956, + 38, 7, 0, 0.062387567, 0.330841452, 15.4940481, + 39, 8, 0, 0.0713000745, 0.327769846, 15.8516159, + 40, 8, 0, 0.0713000745, 0.324572712, 16.204628, + 41, 9, 0, 0.0802125856, 0.323825002, 16.5502281, + 42, 10, 0, 0.0891250968, 0.321414798, 16.9067478, + 43, 10, 0, 0.0891250968, 0.318189293, 17.2537231, + 44, 11, 0, 0.0980376005, 0.315934151, 17.5901108, + 45, 12, 0, 0.106950112, 0.315639287, 17.931406, + 46, 13, 0, 0.115862623, 0.316569835, 18.2750721, + 47, 14, 0, 0.124775134, 0.31656, 18.6191597, + 48, 15, 0, 0.133687645, 0.315465957, 18.9621754, + 49, 16, 0, 0.142600149, 0.313576341, 19.3029613, + 50, 17, 0, 0.151512653, 0.311635971, 19.6405869, + 51, 18, 0, 0.160425171, 0.311066717, 19.9742699, + 52, 20, 0, 0.355655879, 0.311465651, 20.3115921, + 53, 21, 0, 0.373438686, 0.311872005, 20.6507797, + 54, 23, 0, 0.409004271, 0.311015964, 20.9890823, + 55, 24, 0, 0.676411927, 0.309207708, 21.3251152, + 56, 26, 0, 0.732779562, 0.3081128, 21.6565971, + 57, 28, 0, 0.789147198, 0.310006589, 21.9881554, + 58, 31, 0, 2.76287794, 0.327113092, 22.3222847, + 59, 34, 0, 3.03025317, 0.416082352, 22.6605186, + 22050, 59, + 0, 2, 15, 17.8250179, 0.658683598, 0.217637643, + 1, 2, 15, 17.8250179, 0.432554901, 0.652563453, + 2, 2, 15, 1.78250182, 0.405113578, 1.08633137, + 3, 2, 15, 1.78250182, 0.397231787, 1.51803517, + 4, 2, 15, 1.78250182, 0.392088681, 1.94679713, + 5, 2, 13, 0.178250194, 0.386788279, 2.37177849, + 6, 2, 13, 0.178250194, 0.380574644, 2.79218864, + 7, 2, 13, 0.0563676581, 0.375309765, 3.20729256, + 8, 2, 13, 0.0563676581, 0.370087624, 3.61641645, + 9, 2, 12, 0.0178250186, 0.364568561, 4.01895428, + 10, 2, 12, 0.0178250186, 0.358959526, 4.4143672, + 11, 2, 12, 0.0178250186, 0.352938265, 4.80218887, + 12, 2, 10, 0.0178250186, 0.3465029, 5.18202305, + 13, 2, 10, 0.0178250186, 0.33968094, 5.55354261, + 14, 2, 10, 0.0178250186, 0.332571507, 5.91648674, + 15, 2, 9, 0.0178250186, 0.326015651, 6.27065945, + 16, 2, 9, 0.0178250186, 0.325442046, 6.61592293, + 17, 2, 9, 0.0178250186, 0.341315031, 6.95219517, + 18, 3, 6, 0.0267375279, 0.374984443, 7.3584404, + 19, 3, 6, 0.0267375279, 0.396138102, 7.8290925, + 20, 3, 3, 0.0267375279, 0.39271906, 8.27975655, + 21, 3, 3, 0.0267375279, 0.380755007, 8.71083069, + 22, 3, 3, 0.0267375279, 0.367386311, 9.12284088, + 23, 3, 3, 0.0267375279, 0.354351997, 9.51640987, + 24, 3, 3, 0.0267375279, 0.341508389, 9.89222908, + 25, 3, 0, 0.0267375279, 0.333577901, 10.2510386, + 26, 3, 0, 0.0267375279, 0.338108748, 10.5936022, + 27, 4, 0, 0.0356500372, 0.350744486, 10.9723492, + 28, 4, 0, 0.0356500372, 0.354519457, 11.38272, + 29, 4, 0, 0.0356500372, 0.345274031, 11.7689981, + 30, 4, 0, 0.0356500372, 0.333828837, 12.1329184, + 31, 4, 0, 0.0356500372, 0.331436664, 12.4761295, + 32, 5, 0, 0.0445625484, 0.334172577, 12.8381901, + 33, 5, 0, 0.0445625484, 0.334024847, 13.2160273, + 34, 5, 0, 0.0445625484, 0.33392629, 13.5690479, + 35, 6, 0, 0.0534750558, 0.334218502, 13.9303951, + 36, 6, 0, 0.0534750558, 0.336405039, 14.298193, + 37, 7, 0, 0.062387567, 0.337080389, 14.666563, + 38, 7, 0, 0.062387567, 0.335603535, 15.0346909, + 39, 8, 0, 0.0713000745, 0.332515866, 15.398139, + 40, 8, 0, 0.0713000745, 0.327727586, 15.7570457, + 41, 9, 0, 0.0802125856, 0.322346836, 16.1083431, + 42, 9, 0, 0.0802125856, 0.317575186, 16.4528522, + 43, 10, 0, 0.0891250968, 0.31632933, 16.7886105, + 44, 11, 0, 0.0980376005, 0.317602783, 17.132, + 45, 12, 0, 0.106950112, 0.319945186, 17.4796028, + 46, 13, 0, 0.115862623, 0.320881754, 17.8287659, + 47, 14, 0, 0.124775134, 0.320346534, 18.1774921, + 48, 15, 0, 0.133687645, 0.318628669, 18.5243168, + 49, 16, 0, 0.142600149, 0.316125751, 18.8681736, + 50, 17, 0, 0.151512653, 0.313746184, 19.2082729, + 51, 18, 0, 0.160425171, 0.312971771, 19.5440025, + 52, 20, 0, 0.178250194, 0.313278913, 19.8831882, + 53, 21, 0, 0.373438686, 0.313735574, 20.224247, + 54, 23, 0, 0.409004271, 0.31308493, 20.5646286, + 55, 24, 0, 0.426787049, 0.31156227, 20.903141, + 56, 26, 0, 0.732779562, 0.310435742, 21.2376747, + 57, 28, 0, 0.789147198, 0.31132248, 21.5730591, + 58, 30, 0, 0.845514894, 0.32730341, 21.9066811, + 59, 33, 0, 2.94112802, 0.414659739, 22.2411156, + 16000, 55, + 0, 3, 15, 26.7375278, 0.697374165, 0.236874461, + 1, 3, 15, 26.7375278, 0.455024809, 0.71016103, + 2, 3, 15, 2.67375278, 0.431440443, 1.18193281, + 3, 3, 15, 2.67375278, 0.42391625, 1.65102732, + 4, 3, 13, 0.26737529, 0.418206781, 2.11632562, + 5, 3, 13, 0.26737529, 0.41158545, 2.57676744, + 6, 3, 13, 0.0845514908, 0.405409157, 3.03136396, + 7, 3, 13, 0.0845514908, 0.399695486, 3.47920918, + 8, 3, 13, 0.0845514908, 0.393753231, 3.91948748, + 9, 3, 12, 0.0267375279, 0.387357473, 4.35147953, + 10, 3, 12, 0.0267375279, 0.38045457, 4.77456427, + 11, 3, 10, 0.0267375279, 0.373053908, 5.18822002, + 12, 3, 10, 0.0267375279, 0.365188122, 5.59202194, + 13, 3, 10, 0.0267375279, 0.356897742, 5.98564005, + 14, 3, 9, 0.0267375279, 0.34869957, 6.36883163, + 15, 3, 9, 0.0267375279, 0.340241522, 6.74143791, + 16, 3, 6, 0.0267375279, 0.332089454, 7.10337448, + 17, 3, 6, 0.0267375279, 0.328292668, 7.45462418, + 18, 3, 6, 0.0267375279, 0.336574793, 7.79523182, + 19, 4, 3, 0.0356500372, 0.354600489, 8.17827797, + 20, 4, 3, 0.0356500372, 0.364343345, 8.59994984, + 21, 4, 3, 0.0356500372, 0.359369367, 9.00363636, + 22, 4, 3, 0.0356500372, 0.347775847, 9.38988018, + 23, 4, 3, 0.0356500372, 0.335562587, 9.7592926, + 24, 4, 0, 0.0356500372, 0.326988578, 10.1125278, + 25, 4, 0, 0.0356500372, 0.327966213, 10.4502735, + 26, 5, 0, 0.0445625484, 0.334450752, 10.811614, + 27, 5, 0, 0.0445625484, 0.335228145, 11.1935263, + 28, 5, 0, 0.0445625484, 0.329595625, 11.5549288, + 29, 5, 0, 0.0445625484, 0.326683223, 11.8971443, + 30, 6, 0, 0.0534750558, 0.326986551, 12.2520256, + 31, 6, 0, 0.0534750558, 0.325072199, 12.6173973, + 32, 6, 0, 0.0534750558, 0.323560268, 12.9608269, + 33, 7, 0, 0.062387567, 0.322494298, 13.3093863, + 34, 7, 0, 0.062387567, 0.323403448, 13.6617231, + 35, 8, 0, 0.0713000745, 0.323232353, 14.0134668, + 36, 8, 0, 0.0713000745, 0.322662383, 14.3639784, + 37, 9, 0, 0.0802125856, 0.324054241, 14.7098465, + 38, 10, 0, 0.0891250968, 0.323228806, 15.0686541, + 39, 10, 0, 0.0891250968, 0.320751846, 15.4191036, + 40, 11, 0, 0.0980376005, 0.318823338, 15.7594051, + 41, 12, 0, 0.106950112, 0.318418682, 16.104557, + 42, 13, 0, 0.115862623, 0.318762124, 16.451416, + 43, 14, 0, 0.124775134, 0.317806393, 16.7975388, + 44, 15, 0, 0.133687645, 0.315653771, 17.1411018, + 45, 16, 0, 0.142600149, 0.313369036, 17.4808159, + 46, 17, 0, 0.151512653, 0.312513858, 17.8158207, + 47, 19, 0, 0.169337675, 0.312785119, 18.1543369, + 48, 20, 0, 0.178250194, 0.31343773, 18.4948578, + 49, 22, 0, 0.196075201, 0.313258767, 18.8350143, + 50, 23, 0, 0.20498772, 0.312570423, 19.1740704, + 51, 25, 0, 0.222812727, 0.312572777, 19.5104179, + 52, 27, 0, 0.240637749, 0.313047856, 19.8497677, + 53, 29, 0, 0.515701056, 0.315029174, 20.1900635, + 54, 31, 0, 0.551266611, 0.330613613, 20.5294952, + 55, 33, 0, 0.586832225, 0.41819948, 20.8664398, + 48000.0, 37, + 0, 1, 4.532, 1.000, -8.240, 0.000, + 1, 1, 0.904, 0.989, -8.240, 1.875, + 2, 1, 0.029, 0.989, -8.240, 3.750, + 3, 1, 0.009, 0.981, -8.240, 5.438, + 4, 1, 0.009, 0.985, -8.240, 6.857, + 5, 1, 0.009, 0.984, -8.240, 8.109, + 6, 1, 0.009, 0.980, -8.240, 9.237, + 7, 1, 0.009, 0.968, -8.240, 10.202, + 8, 1, 0.009, 0.954, -8.240, 11.083, + 9, 1, 0.009, 0.929, -8.240, 11.865, + 10, 1, 0.009, 0.906, -7.447, 12.554, + 11, 1, 0.009, 0.883, -7.447, 13.195, + 12, 1, 0.009, 0.844, -7.447, 13.781, + 13, 1, 0.009, 0.792, -7.447, 14.309, + 14, 1, 0.009, 0.747, -7.447, 14.803, + 15, 1, 0.009, 0.689, -7.447, 15.250, + 16, 1, 0.009, 0.644, -7.447, 15.667, + 17, 1, 0.009, 0.592, -7.447, 16.068, + 18, 1, 0.009, 0.553, -7.447, 16.409, + 19, 2, 0.018, 0.850, -7.447, 17.045, + 20, 2, 0.018, 0.811, -6.990, 17.607, + 21, 2, 0.018, 0.736, -6.990, 18.097, + 22, 2, 0.018, 0.665, -6.990, 18.528, + 23, 2, 0.018, 0.610, -6.990, 18.931, + 24, 2, 0.018, 0.544, -6.990, 19.295, + 25, 2, 0.018, 0.528, -6.990, 19.636, + 26, 3, 0.054, 0.621, -6.990, 20.038, + 27, 3, 0.054, 0.673, -6.990, 20.486, + 28, 3, 0.054, 0.635, -6.990, 20.900, + 29, 4, 0.114, 0.626, -6.990, 21.306, + 30, 4, 0.114, 0.636, -6.020, 21.722, + 31, 5, 0.452, 0.615, -6.020, 22.128, + 32, 5, 0.452, 0.579, -6.020, 22.513, + 33, 5, 0.452, 0.551, -6.020, 22.877, + 34, 7, 6.330, 0.552, -5.229, 23.241, + 35, 7, 6.330, 0.559, -5.229, 23.616, + 36, 11, 9.947, 0.528, -5.229, 23.974, + 37, 17, 153.727, 0.479, -5.229, 24.313, + 44100.0, 38, + 0, 1, 4.532, 1.000, -8.240, 0.000, + 1, 1, 0.904, 0.983, -8.240, 1.723, + 2, 1, 0.029, 0.983, -8.240, 3.445, + 3, 1, 0.009, 0.982, -8.240, 5.057, + 4, 1, 0.009, 0.985, -8.240, 6.422, + 5, 1, 0.009, 0.983, -8.240, 7.609, + 6, 1, 0.009, 0.978, -8.240, 8.710, + 7, 1, 0.009, 0.967, -8.240, 9.662, + 8, 1, 0.009, 0.948, -8.240, 10.515, + 9, 1, 0.009, 0.930, -8.240, 11.293, + 10, 1, 0.009, 0.914, -7.447, 12.009, + 11, 1, 0.009, 0.870, -7.447, 12.625, + 12, 1, 0.009, 0.845, -7.447, 13.210, + 13, 1, 0.009, 0.800, -7.447, 13.748, + 14, 1, 0.009, 0.749, -7.447, 14.241, + 15, 1, 0.009, 0.701, -7.447, 14.695, + 16, 1, 0.009, 0.653, -7.447, 15.125, + 17, 1, 0.009, 0.590, -7.447, 15.508, + 18, 1, 0.009, 0.616, -7.447, 15.891, + 19, 2, 0.018, 0.860, -7.447, 16.537, + 20, 2, 0.018, 0.823, -6.990, 17.112, + 21, 2, 0.018, 0.762, -6.990, 17.621, + 22, 2, 0.018, 0.688, -6.990, 18.073, + 23, 2, 0.018, 0.612, -6.990, 18.470, + 24, 2, 0.018, 0.594, -6.990, 18.849, + 25, 3, 0.027, 0.658, -6.990, 19.271, + 26, 3, 0.027, 0.706, -6.990, 19.741, + 27, 3, 0.054, 0.660, -6.990, 20.177, + 28, 3, 0.054, 0.606, -6.990, 20.576, + 29, 3, 0.054, 0.565, -6.990, 20.950, + 30, 4, 0.114, 0.560, -6.020, 21.316, + 31, 4, 0.114, 0.579, -6.020, 21.699, + 32, 5, 0.452, 0.567, -6.020, 22.078, + 33, 5, 0.452, 0.534, -6.020, 22.438, + 34, 5, 0.452, 0.514, -5.229, 22.782, + 35, 7, 6.330, 0.520, -5.229, 23.133, + 36, 7, 6.330, 0.518, -5.229, 23.484, + 37, 7, 6.330, 0.507, -5.229, 23.828, + 38, 19, 171.813, 0.447, -4.559, 24.173, + 32000.0, 41, + 0, 1, 4.532, 1.000, -8.240, 0.000, + 1, 1, 0.904, 0.985, -8.240, 1.250, + 2, 1, 0.090, 0.983, -8.240, 2.500, + 3, 1, 0.029, 0.983, -8.240, 3.750, + 4, 1, 0.009, 0.981, -8.240, 4.909, + 5, 1, 0.009, 0.975, -8.240, 5.958, + 6, 1, 0.009, 0.959, -8.240, 6.857, + 7, 1, 0.009, 0.944, -8.240, 7.700, + 8, 1, 0.009, 0.933, -8.240, 8.500, + 9, 1, 0.009, 0.920, -8.240, 9.237, + 10, 1, 0.009, 0.892, -7.447, 9.895, + 11, 1, 0.009, 0.863, -7.447, 10.500, + 12, 1, 0.009, 0.839, -7.447, 11.083, + 13, 1, 0.009, 0.786, -7.447, 11.604, + 14, 1, 0.009, 0.755, -7.447, 12.107, + 15, 1, 0.009, 0.698, -7.447, 12.554, + 16, 1, 0.009, 0.673, -7.447, 13.000, + 17, 1, 0.009, 0.605, -7.447, 13.391, + 18, 1, 0.009, 0.629, -7.447, 13.781, + 19, 2, 0.018, 0.883, -7.447, 14.474, + 20, 2, 0.018, 0.858, -6.990, 15.096, + 21, 2, 0.018, 0.829, -6.990, 15.667, + 22, 2, 0.018, 0.767, -6.990, 16.177, + 23, 2, 0.018, 0.705, -6.990, 16.636, + 24, 2, 0.018, 0.637, -6.990, 17.057, + 25, 2, 0.018, 0.564, -6.990, 17.429, + 26, 2, 0.018, 0.550, -6.990, 17.786, + 27, 3, 0.027, 0.603, -6.990, 18.177, + 28, 3, 0.027, 0.635, -6.990, 18.597, + 29, 3, 0.027, 0.592, -6.990, 18.994, + 30, 3, 0.027, 0.533, -6.020, 19.352, + 31, 3, 0.027, 0.518, -6.020, 19.693, + 32, 4, 0.072, 0.568, -6.020, 20.066, + 33, 4, 0.072, 0.594, -6.020, 20.462, + 34, 4, 0.072, 0.568, -5.229, 20.841, + 35, 5, 0.143, 0.536, -5.229, 21.201, + 36, 5, 0.143, 0.522, -5.229, 21.549, + 37, 6, 0.172, 0.542, -5.229, 21.911, + 38, 7, 0.633, 0.539, -4.559, 22.275, + 39, 7, 0.633, 0.519, -4.559, 22.625, + 40, 8, 0.723, 0.514, -3.980, 22.971, + 41, 10, 9.043, 0.518, -3.980, 23.321, + 24000, 44, + 0, 1, 8.91250896, 0.971850038, 0.150000006, 0, + 1, 1, 8.91250896, 0.874727964, 0.150000006, 0.946573138, + 2, 1, 0.891250908, 0.85779953, 0.150000006, 1.88476217, + 3, 1, 0.0891250968, 0.839743853, 0.150000006, 2.8056457, + 4, 1, 0.028183829, 0.82260257, 0.150000006, 3.70133615, + 5, 1, 0.00891250931, 0.80018574, 0.150000006, 4.56532001, + 6, 1, 0.00891250931, 0.771475196, 0.150000006, 5.39263105, + 7, 1, 0.00891250931, 0.737389982, 0.150000006, 6.17986727, + 8, 1, 0.00891250931, 0.701111019, 0.150000006, 6.92507982, + 9, 1, 0.00891250931, 0.65977633, 0.150000006, 7.62757969, + 10, 1, 0.00891250931, 0.615037441, 0.150000006, 8.28770351, + 11, 1, 0.00891250931, 0.568658054, 0.150000006, 8.90657234, + 12, 1, 0.00891250931, 0.522260666, 0.180000007, 9.48587132, + 13, 1, 0.00891250931, 0.478903115, 0.180000007, 10.0276566, + 14, 1, 0.00891250931, 0.43808648, 0.180000007, 10.5341988, + 15, 1, 0.00891250931, 0.412505627, 0.180000007, 11.0078659, + 16, 1, 0.00891250931, 0.39070797, 0.180000007, 11.4510288, + 17, 1, 0.00891250931, 0.371887118, 0.180000007, 11.866004, + 18, 1, 0.00891250931, 0.367617637, 0.180000007, 12.2550087, + 19, 1, 0.00891250931, 0.422220588, 0.180000007, 12.6201363, + 20, 2, 0.0178250186, 0.564990044, 0.180000007, 13.2772083, + 21, 2, 0.0178250186, 0.519700944, 0.180000007, 13.871047, + 22, 2, 0.0178250186, 0.455360681, 0.200000003, 14.4024391, + 23, 2, 0.0178250186, 0.408867925, 0.200000003, 14.8811684, + 24, 2, 0.0178250186, 0.381538749, 0.200000003, 15.3153324, + 25, 2, 0.0178250186, 0.362357527, 0.200000003, 15.7116165, + 26, 2, 0.0178250186, 0.365735918, 0.200000003, 16.0755405, + 27, 3, 0.0267375279, 0.38064, 0.200000003, 16.4882088, + 28, 3, 0.0267375279, 0.379183382, 0.200000003, 16.9410992, + 29, 3, 0.0267375279, 0.360672712, 0.200000003, 17.3513336, + 30, 3, 0.0267375279, 0.343065977, 0.200000003, 17.7264423, + 31, 3, 0.0267375279, 0.339290261, 0.200000003, 18.0722466, + 32, 4, 0.0356500372, 0.342963994, 0.200000003, 18.4426575, + 33, 4, 0.0356500372, 0.343128443, 0.200000003, 18.8344078, + 34, 4, 0.0356500372, 0.343988508, 0.25, 19.1955795, + 35, 5, 0.0445625484, 0.343928397, 0.25, 19.5697021, + 36, 5, 0.0445625484, 0.339527696, 0.25, 19.9551182, + 37, 5, 0.0889139697, 0.336541563, 0.280000001, 20.3115921, + 38, 6, 0.106696762, 0.334955156, 0.280000001, 20.6737747, + 39, 6, 0.169102982, 0.335601568, 0.300000012, 21.0404968, + 40, 7, 0.1972868, 0.334716886, 0.300000012, 21.4060211, + 41, 7, 0.1972868, 0.331676662, 0.300000012, 21.7696877, + 42, 8, 0.713000774, 0.328550965, 0.400000006, 22.1267223, + 43, 8, 0.713000774, 0.339241952, 0.400000006, 22.4769249, + 44, 9, 0.802125871, 0.425207615, 0.400000006, 22.8164864, + 22050, 44, + 0, 1, 8.91250896, 0.954045713, 0.150000006, 0, + 1, 1, 8.91250896, 0.833381653, 0.150000006, 0.869851649, + 2, 1, 0.891250908, 0.815945923, 0.150000006, 1.73325908, + 3, 1, 0.0891250968, 0.794244766, 0.150000006, 2.58322191, + 4, 1, 0.028183829, 0.776486695, 0.150000006, 3.4134295, + 5, 1, 0.00891250931, 0.755260408, 0.150000006, 4.21850443, + 6, 1, 0.00891250931, 0.731070817, 0.150000006, 4.99414825, + 7, 1, 0.00891250931, 0.701775849, 0.150000006, 5.73718691, + 8, 1, 0.00891250931, 0.667876124, 0.150000006, 6.44553185, + 9, 1, 0.00891250931, 0.630284071, 0.150000006, 7.11807632, + 10, 1, 0.00891250931, 0.590170324, 0.150000006, 7.75455618, + 11, 1, 0.00891250931, 0.548788548, 0.150000006, 8.3553915, + 12, 1, 0.00891250931, 0.507795513, 0.150000006, 8.92152882, + 13, 1, 0.00891250931, 0.469515711, 0.180000007, 9.45430183, + 14, 1, 0.00891250931, 0.432291716, 0.180000007, 9.95530319, + 15, 1, 0.00891250931, 0.411131173, 0.180000007, 10.4262848, + 16, 1, 0.00891250931, 0.390771538, 0.180000007, 10.8690758, + 17, 1, 0.00891250931, 0.373318017, 0.180000007, 11.2855215, + 18, 1, 0.00891250931, 0.36956048, 0.180000007, 11.6774378, + 19, 1, 0.00891250931, 0.42595759, 0.180000007, 12.0465794, + 20, 2, 0.0178250186, 0.576900065, 0.180000007, 12.7141209, + 21, 2, 0.0178250186, 0.533114731, 0.180000007, 13.3197365, + 22, 2, 0.0178250186, 0.469967514, 0.180000007, 13.8634901, + 23, 2, 0.0178250186, 0.417268544, 0.200000003, 14.3544445, + 24, 2, 0.0178250186, 0.389299124, 0.200000003, 14.8002586, + 25, 2, 0.0178250186, 0.362824857, 0.200000003, 15.2073727, + 26, 2, 0.0178250186, 0.346801281, 0.200000003, 15.5811834, + 27, 2, 0.0178250186, 0.349400043, 0.200000003, 15.926218, + 28, 3, 0.0267375279, 0.364026934, 0.200000003, 16.3194923, + 29, 3, 0.0267375279, 0.36560446, 0.200000003, 16.752903, + 30, 3, 0.0267375279, 0.354275256, 0.200000003, 17.1470814, + 31, 3, 0.0267375279, 0.351219416, 0.200000003, 17.5086212, + 32, 4, 0.0356500372, 0.354364097, 0.200000003, 17.8938141, + 33, 4, 0.0356500372, 0.348915905, 0.200000003, 18.2992878, + 34, 4, 0.0356500372, 0.337649345, 0.200000003, 18.6713982, + 35, 4, 0.0356500372, 0.332076877, 0.25, 19.015646, + 36, 5, 0.0445625484, 0.330793113, 0.25, 19.3734016, + 37, 5, 0.0445625484, 0.327528268, 0.25, 19.7430382, + 38, 5, 0.0889139697, 0.32551071, 0.280000001, 20.0859604, + 39, 6, 0.106696762, 0.324436843, 0.280000001, 20.4354992, + 40, 6, 0.106696762, 0.325835049, 0.280000001, 20.7905579, + 41, 7, 0.1972868, 0.326221824, 0.300000012, 21.1458054, + 42, 7, 0.1972868, 0.325960994, 0.300000012, 21.5005951, + 43, 8, 0.225470632, 0.339019388, 0.300000012, 21.8504524, + 44, 8, 0.713000774, 0.426850349, 0.400000006, 22.1951065, + 16000, 45, + 0, 1, 8.91250896, 0.834739447, 0.150000006, 0, + 1, 1, 8.91250896, 0.623757005, 0.150000006, 0.631518543, + 2, 1, 0.891250908, 0.60420388, 0.150000006, 1.2606914, + 3, 1, 0.891250908, 0.591974258, 0.150000006, 1.88476217, + 4, 1, 0.0891250968, 0.575301588, 0.150000006, 2.50111985, + 5, 1, 0.028183829, 0.561547697, 0.150000006, 3.1073606, + 6, 1, 0.028183829, 0.546665847, 0.150000006, 3.70133615, + 7, 1, 0.00891250931, 0.52986443, 0.150000006, 4.28118753, + 8, 1, 0.00891250931, 0.511183441, 0.150000006, 4.84536505, + 9, 1, 0.00891250931, 0.490902334, 0.150000006, 5.39263105, + 10, 1, 0.00891250931, 0.46938166, 0.150000006, 5.92205667, + 11, 1, 0.00891250931, 0.447003782, 0.150000006, 6.43299866, + 12, 1, 0.00891250931, 0.428170592, 0.150000006, 6.92507982, + 13, 1, 0.00891250931, 0.414536625, 0.150000006, 7.39815664, + 14, 1, 0.00891250931, 0.401033074, 0.150000006, 7.85228777, + 15, 1, 0.00891250931, 0.38779071, 0.150000006, 8.28770351, + 16, 1, 0.00891250931, 0.374230444, 0.150000006, 8.704772, + 17, 1, 0.00891250931, 0.360547513, 0.180000007, 9.10397339, + 18, 1, 0.00891250931, 0.348256677, 0.180000007, 9.48587132, + 19, 1, 0.00891250931, 0.350327015, 0.180000007, 9.85109234, + 20, 1, 0.00891250931, 0.406330824, 0.180000007, 10.200304, + 21, 2, 0.0178250186, 0.554098248, 0.180000007, 10.846529, + 22, 2, 0.0178250186, 0.528312504, 0.180000007, 11.4447651, + 23, 2, 0.0178250186, 0.476527005, 0.180000007, 11.9928398, + 24, 2, 0.0178250186, 0.428205669, 0.180000007, 12.495945, + 25, 2, 0.0178250186, 0.402271926, 0.180000007, 12.9588718, + 26, 2, 0.0178250186, 0.378024429, 0.180000007, 13.3859692, + 27, 2, 0.0178250186, 0.36254698, 0.180000007, 13.7811394, + 28, 2, 0.0178250186, 0.368058592, 0.200000003, 14.1478529, + 29, 3, 0.0267375279, 0.385963261, 0.200000003, 14.5674343, + 30, 3, 0.0267375279, 0.38640517, 0.200000003, 15.0304852, + 31, 3, 0.0267375279, 0.367834061, 0.200000003, 15.4513416, + 32, 3, 0.0267375279, 0.349686563, 0.200000003, 15.836277, + 33, 3, 0.0267375279, 0.345709383, 0.200000003, 16.1904697, + 34, 4, 0.0356500372, 0.34871915, 0.200000003, 16.5683517, + 35, 4, 0.0356500372, 0.347054332, 0.200000003, 16.9660263, + 36, 4, 0.0356500372, 0.346329987, 0.200000003, 17.3304482, + 37, 5, 0.0445625484, 0.344658494, 0.200000003, 17.7055588, + 38, 5, 0.0445625484, 0.338779271, 0.200000003, 18.0899811, + 39, 5, 0.0445625484, 0.334878683, 0.200000003, 18.4440536, + 40, 6, 0.0534750558, 0.332811534, 0.200000003, 18.8030052, + 41, 6, 0.0534750558, 0.333717585, 0.25, 19.1665268, + 42, 7, 0.062387567, 0.333986402, 0.25, 19.5299358, + 43, 7, 0.062387567, 0.334142625, 0.25, 19.8934898, + 44, 8, 0.142262354, 0.34677428, 0.280000001, 20.2535706, + 45, 8, 0.142262354, 0.436254472, 0.280000001, 20.610569, + 48000.0, 20, + 0, 3, 0, 4, 1.000, 0.056, + 1, 3, 4, 7, 0.944, 0.611, + 2, 4, 7, 11, 0.389, 0.167, + 3, 3, 11, 14, 0.833, 0.722, + 4, 3, 14, 17, 0.278, 0.639, + 5, 2, 17, 19, 0.361, 0.417, + 6, 3, 19, 22, 0.583, 0.083, + 7, 2, 22, 24, 0.917, 0.750, + 8, 3, 24, 27, 0.250, 0.417, + 9, 3, 27, 30, 0.583, 0.648, + 10, 3, 30, 33, 0.352, 0.611, + 11, 3, 33, 36, 0.389, 0.625, + 12, 4, 36, 40, 0.375, 0.144, + 13, 3, 40, 43, 0.856, 0.389, + 14, 3, 43, 46, 0.611, 0.160, + 15, 3, 46, 49, 0.840, 0.217, + 16, 3, 49, 52, 0.783, 0.184, + 17, 2, 52, 54, 0.816, 0.886, + 18, 3, 54, 57, 0.114, 0.313, + 19, 2, 57, 59, 0.687, 0.452, + 20, 1, 59, 60, 0.548, 0.908, + 44100.0, 20, + 0, 3, 0, 4, 1.000, 0.056, + 1, 3, 4, 7, 0.944, 0.611, + 2, 4, 7, 11, 0.389, 0.167, + 3, 3, 11, 14, 0.833, 0.722, + 4, 3, 14, 17, 0.278, 0.139, + 5, 1, 17, 18, 0.861, 0.917, + 6, 3, 18, 21, 0.083, 0.583, + 7, 3, 21, 24, 0.417, 0.250, + 8, 3, 24, 27, 0.750, 0.805, + 9, 3, 27, 30, 0.194, 0.574, + 10, 3, 30, 33, 0.426, 0.537, + 11, 3, 33, 36, 0.463, 0.819, + 12, 4, 36, 40, 0.180, 0.100, + 13, 3, 40, 43, 0.900, 0.468, + 14, 3, 43, 46, 0.532, 0.623, + 15, 3, 46, 49, 0.376, 0.450, + 16, 3, 49, 52, 0.550, 0.552, + 17, 3, 52, 55, 0.448, 0.403, + 18, 2, 55, 57, 0.597, 0.643, + 19, 2, 57, 59, 0.357, 0.722, + 20, 2, 59, 61, 0.278, 0.960, + 32000, 20, + 0, 1, 0, 2, 1.000, 0.528, + 1, 2, 2, 4, 0.472, 0.305, + 2, 2, 4, 6, 0.694, 0.083, + 3, 1, 6, 7, 0.917, 0.861, + 4, 2, 7, 9, 0.139, 0.639, + 5, 2, 9, 11, 0.361, 0.417, + 6, 3, 11, 14, 0.583, 0.083, + 7, 2, 14, 16, 0.917, 0.750, + 8, 3, 16, 19, 0.250, 0.870, + 9, 3, 19, 22, 0.130, 0.833, + 10, 4, 22, 26, 0.167, 0.389, + 11, 4, 26, 30, 0.611, 0.478, + 12, 4, 30, 34, 0.522, 0.033, + 13, 3, 34, 37, 0.967, 0.917, + 14, 4, 37, 41, 0.083, 0.617, + 15, 3, 41, 44, 0.383, 0.995, + 16, 4, 44, 48, 0.005, 0.274, + 17, 3, 48, 51, 0.726, 0.480, + 18, 3, 51, 54, 0.519, 0.261, + 19, 2, 54, 56, 0.739, 0.884, + 20, 2, 56, 58, 0.116, 1.000, + 24000, 20, + 0, 2, 0, 3, 1, 0.916666746, + 1, 3, 3, 6, 0.0833332539, 0.583333492, + 2, 3, 6, 9, 0.416666508, 0.25, + 3, 2, 9, 11, 0.75, 0.916666985, + 4, 3, 11, 14, 0.0833330154, 0.583333969, + 5, 3, 14, 17, 0.416666031, 0.25, + 6, 3, 17, 20, 0.75, 0.537036896, + 7, 3, 20, 23, 0.462963104, 0.5, + 8, 4, 23, 27, 0.5, 0.0555559993, + 9, 3, 27, 30, 0.944444001, 0.402778625, + 10, 3, 30, 33, 0.597221375, 0.766667187, + 11, 3, 33, 36, 0.233332828, 0.805555999, + 12, 3, 36, 39, 0.194444016, 0.769841909, + 13, 3, 39, 42, 0.23015812, 0.611111104, + 14, 3, 42, 45, 0.388888896, 0.449494779, + 15, 3, 45, 48, 0.550505221, 0.194444954, + 16, 2, 48, 50, 0.805555046, 0.913194656, + 17, 3, 50, 53, 0.0868053436, 0.580555737, + 18, 3, 53, 56, 0.419444263, 0.113426208, + 19, 2, 56, 58, 0.886573792, 0.533730626, + 20, 2, 58, 60, 0.466269344, 0.691176474, + 22050, 20, + 0, 2, 0, 3, 1, 0.916666746, + 1, 3, 3, 6, 0.0833332539, 0.583333492, + 2, 3, 6, 9, 0.416666508, 0.25, + 3, 2, 9, 11, 0.75, 0.916666985, + 4, 3, 11, 14, 0.0833330154, 0.583333969, + 5, 3, 14, 17, 0.416666031, 0.25, + 6, 3, 17, 20, 0.75, 0.203703582, + 7, 3, 20, 23, 0.796296418, 0.166666687, + 8, 3, 23, 26, 0.833333313, 0.722222686, + 9, 4, 26, 30, 0.277777344, 0.152778625, + 10, 3, 30, 33, 0.847221375, 0.566667199, + 11, 3, 33, 36, 0.433332831, 0.93518573, + 12, 4, 36, 40, 0.0648142472, 0.118056297, + 13, 3, 40, 43, 0.881943703, 0.0925937295, + 14, 2, 43, 45, 0.907406271, 0.934344172, + 15, 3, 45, 48, 0.0656557977, 0.575398028, + 16, 3, 48, 51, 0.424601972, 0.232026935, + 17, 2, 51, 53, 0.767973065, 0.758334339, + 18, 3, 53, 56, 0.241665646, 0.187501252, + 19, 2, 56, 58, 0.812498748, 0.533731699, + 20, 2, 58, 60, 0.466268271, 0.257577598, + 16000, 20, + 0, 1, 0, 2, 1, 0.944444478, + 1, 2, 2, 4, 0.0555555038, 0.722222328, + 2, 2, 4, 6, 0.277777672, 0.5, + 3, 2, 6, 8, 0.5, 0.27777797, + 4, 2, 8, 10, 0.72222203, 0.0555559993, + 5, 1, 10, 11, 0.944444001, 0.833333313, + 6, 3, 11, 14, 0.166666672, 0.203703582, + 7, 3, 14, 17, 0.796296418, 0.166666687, + 8, 3, 17, 20, 0.833333313, 0.54166698, + 9, 3, 20, 23, 0.458333015, 0.652778625, + 10, 4, 23, 27, 0.347221375, 0.166667163, + 11, 3, 27, 30, 0.833332837, 0.722222924, + 12, 4, 30, 34, 0.277777106, 0.277778625, + 13, 3, 34, 37, 0.722221375, 0.604167938, + 14, 3, 37, 40, 0.395832062, 0.627778649, + 15, 3, 40, 43, 0.37222138, 0.542736351, + 16, 3, 43, 46, 0.457263649, 0.371528625, + 17, 3, 46, 49, 0.628471375, 0.00833433867, + 18, 2, 49, 51, 0.991665661, 0.500001311, + 19, 2, 51, 53, 0.499998659, 0.886832893, + 20, 2, 53, 55, 0.113167092, 0.629034221, + 48000.0, 11, + 0, 2, 0, 2, 1.000, 0.167, + 1, 2, 3, 5, 0.833, 0.833, + 2, 3, 5, 8, 0.167, 0.500, + 3, 3, 8, 11, 0.500, 0.167, + 4, 4, 11, 15, 0.833, 0.167, + 5, 4, 15, 19, 0.833, 0.583, + 6, 3, 19, 22, 0.417, 0.917, + 7, 4, 22, 26, 0.083, 0.944, + 8, 4, 26, 30, 0.055, 0.042, + 9, 2, 30, 32, 0.958, 0.567, + 10, 3, 32, 35, 0.433, 0.167, + 11, 2, 35, 37, 0.833, 0.618, + 44100.0, 11, + 0, 2, 0, 2, 1.000, 0.167, + 1, 2, 3, 5, 0.833, 0.833, + 2, 3, 5, 8, 0.167, 0.500, + 3, 3, 8, 11, 0.500, 0.167, + 4, 4, 11, 15, 0.833, 0.167, + 5, 5, 15, 20, 0.833, 0.250, + 6, 3, 20, 23, 0.750, 0.583, + 7, 4, 23, 27, 0.417, 0.055, + 8, 3, 27, 30, 0.944, 0.375, + 9, 3, 30, 33, 0.625, 0.300, + 10, 3, 33, 36, 0.700, 0.167, + 11, 2, 36, 38, 0.833, 1.000, + 32000, 11, + 0, 2, 0, 2, 1.000, 0.167, + 1, 2, 3, 5, 0.833, 0.833, + 2, 3, 5, 8, 0.167, 0.500, + 3, 3, 8, 11, 0.500, 0.167, + 4, 4, 11, 15, 0.833, 0.167, + 5, 5, 15, 20, 0.833, 0.250, + 6, 4, 20, 24, 0.750, 0.250, + 7, 5, 24, 29, 0.750, 0.055, + 8, 4, 29, 33, 0.944, 0.375, + 9, 4, 33, 37, 0.625, 0.472, + 10, 3, 37, 40, 0.528, 0.937, + 11, 1, 40, 41, 0.062, 1.000, + 24000, 11, + 0, 3, 0, 4, 1, 0.166666746, + 1, 2, 4, 6, 0.833333254, 0.833333492, + 2, 3, 6, 9, 0.166666508, 0.5, + 3, 4, 9, 13, 0.5, 0.5, + 4, 5, 13, 18, 0.5, 0.833333969, + 5, 5, 18, 23, 0.166666031, 0.25, + 6, 4, 23, 27, 0.75, 0.25, + 7, 3, 27, 30, 0.75, 0.611111999, + 8, 4, 30, 34, 0.388888031, 0.208333969, + 9, 3, 34, 37, 0.791666031, 0.766667187, + 10, 4, 37, 41, 0.233332828, 0.45238167, + 11, 4, 41, 45, 0.54761833, 0.277778625, + 22050, 11, + 0, 3, 0, 4, 1, 0.166666746, + 1, 2, 4, 6, 0.833333254, 0.833333492, + 2, 3, 6, 9, 0.166666508, 0.5, + 3, 4, 9, 13, 0.5, 0.5, + 4, 4, 13, 17, 0.5, 0.5, + 5, 4, 17, 21, 0.5, 0.916666985, + 6, 4, 21, 25, 0.0833330154, 0.25, + 7, 4, 25, 29, 0.75, 0.611111999, + 8, 4, 29, 33, 0.388888031, 0.458333969, + 9, 4, 33, 37, 0.541666031, 0.633334339, + 10, 4, 37, 41, 0.366665661, 0.583334565, + 11, 4, 41, 45, 0.416665405, 0.437500954, + 16000, 11, + 0, 0, 0, 4, 1, 0.166666746, + 1, 0, 4, 6, 0.833333254, 0.833333492, + 2, 0, 6, 9, 0.166666508, 0.5, + 3, 0, 9, 13, 0.5, 0.5, + 4, 0, 13, 18, 0.5, 0.833333969, + 5, 0, 18, 23, 0.166666031, 0.75, + 6, 0, 23, 27, 0.25, 0.75, + 7, 0, 27, 31, 0.25, 0.611111999, + 8, 0, 31, 35, 0.388888031, 0.458333969, + 9, 0, 35, 39, 0.541666031, 0.166667163, + 10, 0, 39, 42, 0.833332837, 0.805555999, + 11, 0, 42, 46, 0.194444016, 0.4375}; + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tables.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tables.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/tables.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,43 ---- + /* + ** Copyright (C) 1999 Albert L. Faber + ** + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + #ifndef TABLES_H_INCLUDED + #define TABLES_H_INCLUDED + #include "encoder.h" + extern FLOAT8 psy_data[]; + + #define HUFFBITS unsigned long int + #define HTN 34 + + struct huffcodetab { + unsigned int xlen; /*max. x-index+ */ + unsigned int linmax; /*max number to be stored in linbits */ + HUFFBITS *table; /*pointer to array[xlen][ylen] */ + unsigned char *hlen; /*pointer to array[xlen][ylen] */ + }; + + extern struct huffcodetab ht[HTN];/* global memory block */ + /* array of all huffcodtable headers */ + /* 0..31 Huffman code table 0..31 */ + /* 32,33 count1-tables */ + + + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/takehiro.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/takehiro.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/takehiro.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,765 ---- + /* + * MP3 huffman table selecting and bit counting + * + * Copyright (c) 1999 Takehiro TOMINAGA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + + #include "util.h" + #include "l3side.h" + #include "tables.h" + #include "quantize-pvt.h" + + + + + struct + { + unsigned region0_count; + unsigned region1_count; + } subdv_table[ 23 ] = + { + {0, 0}, /* 0 bands */ + {0, 0}, /* 1 bands */ + {0, 0}, /* 2 bands */ + {0, 0}, /* 3 bands */ + {0, 0}, /* 4 bands */ + {0, 1}, /* 5 bands */ + {1, 1}, /* 6 bands */ + {1, 1}, /* 7 bands */ + {1, 2}, /* 8 bands */ + {2, 2}, /* 9 bands */ + {2, 3}, /* 10 bands */ + {2, 3}, /* 11 bands */ + {3, 4}, /* 12 bands */ + {3, 4}, /* 13 bands */ + {3, 4}, /* 14 bands */ + {4, 5}, /* 15 bands */ + {4, 5}, /* 16 bands */ + {4, 6}, /* 17 bands */ + {5, 6}, /* 18 bands */ + {5, 6}, /* 19 bands */ + {5, 7}, /* 20 bands */ + {6, 7}, /* 21 bands */ + {6, 7}, /* 22 bands */ + }; + + + /*************************************************************************/ + /* ix_max */ + /*************************************************************************/ + + static int ix_max(int *ix, int *end) + { + int max = 0; + + while (ix < end) { + int x = *ix++; + if (max < x) + max = x; + + x = *ix++; + if (max < x) + max = x; + } + return max; + } + + + /*************************************************************************/ + /* count_bit */ + /*************************************************************************/ + + /* + Function: Count the number of bits necessary to code the subregion. + */ + + static int cb_esc_buf[288]; + static int cb_esc_sign; + static int *cb_esc_end; + static const int huf_tbl_noESC[15] = { + 1, 2, 5, 7, 7,10,10,13,13,13,13,13,13,13,13 + }; + + static int + count_bit_ESC(int *ix, int *end, int t1, int t2, int *s) + { + /* ESC-table is used */ + int linbits1 = ht[t1].xlen; + int linbits2 = ht[t2].xlen; + int sum = 0; + int sum1 = 0; + int sum2 = 0; + + while (ix < end) { + int x = *ix++; + int y = *ix++; + + if (x != 0) { + sum++; + if (x > 14) { + x = 15; + sum1 += linbits1; + sum2 += linbits2; + } + x *= 16; + } + + if (y != 0) { + sum++; + if (y > 14) { + y = 15; + sum1 += linbits1; + sum2 += linbits2; + } + x += y; + } + + sum1 += ht[16].hlen[x]; + sum2 += ht[24].hlen[x]; + } + + if (sum1 > sum2) { + sum1 = sum2; + t1 = t2; + } + + *s += sum + sum1; + return t1; + } + + static int + count_bit_noESC(int *ix, int *end, unsigned int table) + { + /* No ESC-words */ + int sum = 0, sign = 0; + unsigned char *hlen = ht[table].hlen; + int *p = cb_esc_buf; + + do { + int x = *ix++; + int y = *ix++; + if (x != 0) { + sign++; + x *= 16; + } + + if (y != 0) { + sign++; + x += y; + } + + *p++ = x; + sum += hlen[x]; + } while (ix < end); + + cb_esc_sign = sign; + cb_esc_end = p; + return sum + sign; + } + + + + static int + count_bit_noESC2(unsigned int table) + { + /* No ESC-words */ + int sum = cb_esc_sign; + int *p = cb_esc_buf; + + do { + sum += ht[table].hlen[*p++]; + } while (p < cb_esc_end); + + return sum; + } + + + + static int + count_bit_short_ESC(int *ix, int *end, int t1, int t2, int *s) + { + /* ESC-table is used */ + int linbits1 = ht[t1].xlen; + int linbits2 = ht[t2].xlen; + int sum = 0; + int sum1 = 0; + int sum2 = 0; + + do { + int i; + for (i = 0; i < 3; i++) { + int y = *(ix + 3); + int x = *ix++; + + if (x != 0) { + sum++; + if (x > 14) { + x = 15; + sum1 += linbits1; + sum2 += linbits2; + } + x *= 16; + } + + if (y != 0) { + sum++; + if (y > 14) { + y = 15; + sum1 += linbits1; + sum2 += linbits2; + } + x += y; + } + + sum1 += ht[16].hlen[x]; + sum2 += ht[24].hlen[x]; + } + ix += 3; + } while (ix < end); + + if (sum1 > sum2) { + sum1 = sum2; + t1 = t2; + } + + *s += sum + sum1; + return t1; + } + + + + static int + count_bit_short_noESC(int *ix, int *end, unsigned int table) + { + /* No ESC-words */ + int sum = 0, sign = 0; + unsigned char *hlen = ht[table].hlen; + int *p = cb_esc_buf; + + do { + int i; + for (i = 0; i < 3; i++) { + int y = *(ix + 3); + int x = *ix++; + if (x != 0) { + sign++; + x *= 16; + } + + if (y != 0) { + sign++; + x += y; + } + + *p++ = x; + sum += hlen[x]; + } + ix += 3; + } while (ix < end); + + cb_esc_sign = sign; + cb_esc_end = p; + return sum + sign; + } + + + + /*************************************************************************/ + /* new_choose table */ + /*************************************************************************/ + + /* + Choose the Huffman table that will encode ix[begin..end] with + the fewest bits. + + Note: This code contains knowledge about the sizes and characteristics + of the Huffman tables as defined in the IS (Table B.7), and will not work + with any arbitrary tables. + */ + + static int choose_table(int *ix, int *end, int *s) + { + int max; + int choice0, sum0; + int choice1, sum1; + + max = ix_max(ix, end); + + if (max > IXMAX_VAL) { + *s = 100000; + return -1; + } + + if (max <= 15) { + if (max == 0) { + return 0; + } + /* try tables with no linbits */ + choice0 = huf_tbl_noESC[max - 1]; + sum0 = count_bit_noESC(ix, end, choice0); + choice1 = choice0; + + switch (choice0) { + case 7: + case 10: + choice1++; + sum1 = count_bit_noESC2(choice1); + if (sum0 > sum1) { + sum0 = sum1; + choice0 = choice1; + } + /*fall*/ + case 2: + case 5: + choice1++; + sum1 = count_bit_noESC2(choice1); + if (sum0 > sum1) { + sum0 = sum1; + choice0 = choice1; + } + break; + + case 13: + choice1 += 2; + sum1 = count_bit_noESC2(choice1); + if (sum0 > sum1) { + sum0 = sum1; + choice0 = choice1; + } + break; + + default: + break; + } + *s += sum0; + } else { + /* try tables with linbits */ + max -= 15; + + for (choice1 = 24; choice1 < 32; choice1++) { + if ((int)ht[choice1].linmax >= max) { + break; + } + } + + for (choice0 = choice1 - 8; choice0 < 24; choice0++) { + if ((int)ht[choice0].linmax >= max) { + break; + } + } + + choice0 = count_bit_ESC(ix, end, choice0, choice1, s); + } + + return choice0; + } + + static int choose_table_short(int *ix, int *end, int * s) + { + int max; + int choice0, sum0; + int choice1, sum1; + + max = ix_max(ix, end); + + if (max > IXMAX_VAL) { + *s = 100000; + return -1; + } + + if (max <= 15) { + if (max == 0) { + return 0; + } + /* try tables with no linbits */ + choice0 = huf_tbl_noESC[max - 1]; + sum0 = count_bit_short_noESC(ix, end, choice0); + choice1 = choice0; + + switch (choice0) { + case 7: + case 10: + choice1++; + sum1 = count_bit_noESC2(choice1); + if (sum0 > sum1) { + sum0 = sum1; + choice0 = choice1; + } + /*fall*/ + case 2: + case 5: + choice1++; + sum1 = count_bit_noESC2(choice1); + if (sum0 > sum1) { + sum0 = sum1; + choice0 = choice1; + } + break; + + case 13: + choice1 += 2; + sum1 = count_bit_noESC2(choice1); + if (sum0 > sum1) { + sum0 = sum1; + choice0 = choice1; + } + break; + + default: + break; + } + *s += sum0; + } else { + /* try tables with linbits */ + max -= 15; + for (choice1 = 24; choice1 < 32; choice1++) { + if ((int)ht[choice1].linmax >= max) { + break; + } + } + + for (choice0 = choice1 - 8; choice0 < 24; choice0++) { + if ((int)ht[choice0].linmax >= max) { + break; + } + } + choice0 = count_bit_short_ESC(ix, end, choice0, choice1, s); + } + + return choice0; + } + + + + static int count_bits_long(int ix[576], gr_info *gi) + { + int i, a1, a2; + int bits = 0; + + i=576; + for (; i > 1; i -= 2) + if (ix[i - 1] | ix[i - 2]) + break; + + /* Determines the number of bits to encode the quadruples. */ + gi->count1 = i; + a1 = 0; + for (; i > 3; i -= 4) { + int p, v; + if ((unsigned int)(ix[i-1] | ix[i-2] | ix[i-3] | ix[i-4]) > 1) + break; + + v = ix[i-1]; + p = v; + bits += v; + + v = ix[i-2]; + if (v != 0) { + p += 2; + bits++; + } + + v = ix[i-3]; + if (v != 0) { + p += 4; + bits++; + } + + v = ix[i-4]; + if (v != 0) { + p += 8; + bits++; + } + + a1 += ht[32].hlen[p]; + } + a2 = gi->count1 - i; + if (a1 < a2) { + bits += a1; + gi->count1table_select = 0; + } else { + bits += a2; + gi->count1table_select = 1; + } + + gi->count1bits = bits; + gi->big_values = i; + if (i == 0) + return bits; + + if (gi->block_type == NORM_TYPE) { + int index; + int scfb_anz = 0; + + while (scalefac_band.l[++scfb_anz] < i) + ; + index = subdv_table[scfb_anz].region0_count; + while (scalefac_band.l[index + 1] > i) + index--; + gi->region0_count = index; + + index = subdv_table[scfb_anz].region1_count; + while (scalefac_band.l[index + gi->region0_count + 2] > i) + index--; + gi->region1_count = index; + + a1 = scalefac_band.l[gi->region0_count + 1]; + a2 = scalefac_band.l[index + gi->region0_count + 2]; + gi->table_select[2] = choose_table(ix + a2, ix + i, &bits); + + } else { + gi->region0_count = 7; + /*gi->region1_count = SBPSY_l - 7 - 1;*/ + gi->region1_count = SBMAX_l -1 - 7 - 1; + a1 = scalefac_band.l[7 + 1]; + a2 = i; + if (a1 > a2) { + a1 = a2; + } + } + + /* Count the number of bits necessary to code the bigvalues region. */ + gi->table_select[0] = choose_table(ix, ix + a1, &bits); + gi->table_select[1] = choose_table(ix + a1, ix + a2, &bits); + return bits; + } + + + + + int count_bits(lame_global_flags *gfp,int *ix, FLOAT8 *xr, gr_info *cod_info) + { + int bits=0,i; + /* since quantize_xrpow uses table lookup, we need to check this first: */ + FLOAT8 w = (IXMAX_VAL) / IPOW20(cod_info->global_gain); + for ( i = 0; i < 576; i++ ) { + if (xr[i] > w) + return 100000; + } + if (gfp->quantization) + quantize_xrpow(xr, ix, cod_info); + else + quantize_xrpow_ISO(xr, ix, cod_info); + + + + if (cod_info->block_type==SHORT_TYPE) { + cod_info->table_select[0] = choose_table_short(ix, ix + 36, &bits); + cod_info->table_select[1] = choose_table_short(ix + 36, ix + 576, &bits); + cod_info->big_values = 288; + }else{ + bits=count_bits_long(ix, cod_info); + cod_info->count1 = (cod_info->count1 - cod_info->big_values) / 4; + cod_info->big_values /= 2; + } + return bits; + + } + + void best_huffman_divide(int gr, int ch, gr_info *gi, int *ix) + { + int *bits, r0, r1, a1, a2, bigv; + int r1_bits; + int r3_bits[7 + 15 + 2 + 1]; + int r3_tbl[7 + 15 + 2 + 1]; + gr_info cod_info; + + memcpy(&cod_info, gi, sizeof(gr_info)); + bigv = cod_info.big_values * 2; + bits = (int *) &cod_info.part2_3_length; + + for (r0 = 2; r0 < SBMAX_l + 1; r0++) { + a2 = scalefac_band.l[r0]; + if (a2 > bigv) + break; + + r3_bits[r0] = cod_info.count1bits + cod_info.part2_length; + r3_tbl[r0] = choose_table(ix + a2, ix + bigv, &r3_bits[r0]); + } + for (; r0 <= 7 + 15 + 2; r0++) { + r3_bits[r0] = 100000; + } + + for (r0 = 0; r0 < 16; r0++) { + a1 = scalefac_band.l[r0 + 1]; + if (a1 > bigv) + break; + cod_info.region0_count = r0; + r1_bits = 0; + cod_info.table_select[0] = choose_table(ix, ix + a1, &r1_bits); + if ((int)gi->part2_3_length < r1_bits) + break; + + for (r1 = 0; r1 < 8; r1++) { + *bits = r1_bits + r3_bits[r0 + r1 + 2]; + if ((int)gi->part2_3_length < *bits) + continue; + + a2 = scalefac_band.l[r0 + r1 + 2]; + + cod_info.table_select[1] = choose_table(ix + a1, ix + a2, bits); + if ((int)gi->part2_3_length < *bits) + continue; + + cod_info.region1_count = r1; + cod_info.table_select[2] = r3_tbl[r0 + r1 + 2]; + memcpy(gi, &cod_info, sizeof(gr_info)); + } + } + } + + static void + scfsi_calc(int ch, + III_side_info_t *l3_side, + III_scalefac_t scalefac[2][2]) + { + int i, s1, s2, c1, c2; + int sfb; + gr_info *gi = &l3_side->gr[1].ch[ch].tt; + + static const int scfsi_band[5] = { 0, 6, 11, 16, 21 }; + + static const int slen1_n[16] = { 0, 1, 1, 1, 8, 2, 2, 2, 4, 4, 4, 8, 8, 8,16,16 }; + static const int slen2_n[16] = { 0, 2, 4, 8, 1, 2, 4, 8, 2, 4, 8, 2, 4, 8, 4, 8 }; + + static const int slen1_tab[16] = { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 }; + static const int slen2_tab[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 }; + + for (i = 0; i < 4; i++) + l3_side->scfsi[ch][i] = 0; + + for (i = 0; i < (int)(sizeof(scfsi_band) / sizeof(int)) - 1; i++) { + for (sfb = scfsi_band[i]; sfb < scfsi_band[i + 1]; sfb++) { + if (scalefac[0][ch].l[sfb] != scalefac[1][ch].l[sfb]) + break; + } + if (sfb == scfsi_band[i + 1]) { + for (sfb = scfsi_band[i]; sfb < scfsi_band[i + 1]; sfb++) { + scalefac[1][ch].l[sfb] = -1; + } + l3_side->scfsi[ch][i] = 1; + } + } + + s1 = c1 = 0; + for (sfb = 0; sfb < 11; sfb++) { + if (scalefac[1][ch].l[sfb] < 0) + continue; + c1++; + if (s1 < scalefac[1][ch].l[sfb]) + s1 = scalefac[1][ch].l[sfb]; + } + + s2 = c2 = 0; + for (; sfb < SBPSY_l; sfb++) { + if (scalefac[1][ch].l[sfb] < 0) + continue; + c2++; + if (s2 < scalefac[1][ch].l[sfb]) + s2 = scalefac[1][ch].l[sfb]; + } + for (i = 0; i < 16; i++) { + if (s1 < slen1_n[i] && s2 < slen2_n[i]) { + int c = slen1_tab[i] * c1 + slen2_tab[i] * c2; + if ((int)gi->part2_length > c) { + gi->part2_length = c; + gi->scalefac_compress = i; + } + } + } + } + + void best_scalefac_store(lame_global_flags *gfp,int gr, int ch, + int l3_enc[2][2][576], + III_side_info_t *l3_side, + III_scalefac_t scalefac[2][2]) + { + /* use scalefac_scale if we can */ + gr_info *gi = &l3_side->gr[gr].ch[ch].tt; + + /* remove scalefacs from bands with ix=0. This idea comes + * from the AAC ISO docs. added mt 3/00 */ + int sfb,i,l,start,end; + /* check if l3_enc=0 */ + for ( sfb = 0; sfb < gi->sfb_lmax; sfb++ ) { + if (scalefac[gr][ch].l[sfb]>0) { + start = scalefac_band.l[ sfb ]; + end = scalefac_band.l[ sfb+1 ]; + for ( l = start; l < end; l++ ) if (l3_enc[gr][ch][l]!=0) break; + if (l==end) scalefac[gr][ch].l[sfb]=0; + } + } + for ( i = 0; i < 3; i++ ) { + for ( sfb = gi->sfb_smax; sfb < SBPSY_s; sfb++ ) { + if (scalefac[gr][ch].s[sfb][i]>0) { + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb+1 ]; + for ( l = start; l < end; l++ ) + if (l3_enc[gr][ch][3*l+i]!=0) break; + if (l==end) scalefac[gr][ch].s[sfb][i]=0; + } + } + } + + + gi->part2_3_length -= gi->part2_length; + if (!gi->scalefac_scale && !gi->preflag) { + u_int sfb; + int b, s = 0; + for (sfb = 0; sfb < gi->sfb_lmax; sfb++) { + s |= scalefac[gr][ch].l[sfb]; + } + + for (sfb = gi->sfb_smax; sfb < SBPSY_s; sfb++) { + for (b = 0; b < 3; b++) { + s |= scalefac[gr][ch].s[sfb][b]; + } + } + + if (!(s & 1) && s != 0) { + for (sfb = 0; sfb < gi->sfb_lmax; sfb++) { + scalefac[gr][ch].l[sfb] /= 2; + } + for (sfb = gi->sfb_smax; sfb < SBPSY_s; sfb++) { + for (b = 0; b < 3; b++) { + scalefac[gr][ch].s[sfb][b] /= 2; + } + } + + gi->scalefac_scale = 1; + gi->part2_length = 99999999; + if (gfp->mode_gr == 2) { + scale_bitcount(&scalefac[gr][ch], gi); + } else { + scale_bitcount_lsf(&scalefac[gr][ch], gi); + } + } + } + + if (gfp->mode_gr == 2 && gr == 1 + && l3_side->gr[0].ch[ch].tt.block_type != SHORT_TYPE + && l3_side->gr[1].ch[ch].tt.block_type != SHORT_TYPE + && l3_side->gr[0].ch[ch].tt.scalefac_scale + == l3_side->gr[1].ch[ch].tt.scalefac_scale + && l3_side->gr[0].ch[ch].tt.preflag + == l3_side->gr[1].ch[ch].tt.preflag) { + scfsi_calc(ch, l3_side, scalefac); + } + gi->part2_3_length += gi->part2_length; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/timestatus.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/timestatus.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/timestatus.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,146 ---- + #include "timestatus.h" + #include "util.h" + #include <time.h> + + #if defined(CLOCKS_PER_SEC) + /* ANSI/ISO systems */ + # define TS_CLOCKS_PER_SEC CLOCKS_PER_SEC + #elif defined(CLK_TCK) + /* Non-standard systems */ + # define TS_CLOCKS_PER_SEC CLK_TCK + #elif defined(HZ) + /* Older BSD systems */ + # define TS_CLOCKS_PER_SEC HZ + #else + # error no suitable value for TS_CLOCKS_PER_SEC + #endif + + /*********************************************************/ + /* ts_real_time: real time elapsed in seconds */ + /*********************************************************/ + FLOAT ts_real_time(long frame) { + + static time_t initial_time; + time_t current_time; + + time(¤t_time); + + if (frame==0) { + initial_time = current_time; + } + + return (FLOAT) difftime(current_time, initial_time); + } + + /*********************************************************/ + /* ts_process_time: process time elapsed in seconds */ + /*********************************************************/ + FLOAT ts_process_time(long frame) { + static clock_t initial_time; + clock_t current_time; + + #if ( defined(_MSC_VER) || defined(__BORLANDC__) ) + + { static HANDLE hProcess; + FILETIME Ignored1, Ignored2, KernelTime, UserTime; + + if ( frame==0 ) { + hProcess = GetCurrentProcess(); + } + + /* GetProcessTimes() always fails under Win9x */ + if (GetProcessTimes(hProcess, &Ignored1, &Ignored2, &KernelTime, &UserTime)) { + LARGE_INTEGER Kernel = { KernelTime.dwLowDateTime, KernelTime.dwHighDateTime }; + LARGE_INTEGER User = { UserTime.dwLowDateTime, UserTime.dwHighDateTime }; + + current_time = (clock_t)((FLOAT)(Kernel.QuadPart + User.QuadPart) * TS_CLOCKS_PER_SEC / 10000000); + } else { + current_time = clock(); + } + } + #else + current_time = clock(); + #endif + + if (frame==0) { + initial_time = current_time; + } + + return (FLOAT)(current_time - initial_time) / TS_CLOCKS_PER_SEC; + } + + #undef TS_CLOCKS_PER_SEC + + typedef struct ts_times { + FLOAT so_far; + FLOAT estimated; + FLOAT speed; + FLOAT eta; + } ts_times; + + /*********************************************************/ + /* ts_calc_times: calculate time info (eta, speed, etc.) */ + /*********************************************************/ + void ts_calc_times(ts_times *time, int samp_rate, long frame, long frames,int framesize) + { + if (frame > 0) { + time->estimated = time->so_far * frames / frame; + if (samp_rate * time->estimated > 0) { + time->speed = frames * framesize / (samp_rate * time->estimated); + } else { + time->speed = 0; + } + time->eta = time->estimated - time->so_far; + } else { + time->estimated = 0; + time->speed = 0; + time->eta = 0; + } + } + + /*********************************************************/ + /* timestatus: display encoding process time information */ + /*********************************************************/ + void timestatus(int samp_rate,long frameNum,long totalframes,int framesize) + { + ts_times real_time, process_time; + int percent; + + real_time.so_far = ts_real_time(frameNum); + process_time.so_far = ts_process_time(frameNum); + + if (frameNum == 0) { + fprintf(stderr, " Frame | CPU/estimated | time/estimated | play/CPU | ETA\n"); + return; + } + + ts_calc_times(&real_time, samp_rate, frameNum, totalframes, framesize); + ts_calc_times(&process_time, samp_rate, frameNum, totalframes, framesize); + + if (totalframes > 1) { + percent = (int)(100.0 * frameNum / (totalframes - 1)); + } else { + percent = 100; + } + + # define TS_TIME_DECOMPOSE(time) \ + (int)((long)(time+.5) / 3600), \ + (int)((long)((time+.5) / 60) % 60), \ + (int)((long)(time+.5) % 60) + + fprintf(stderr, + "\r%6ld/%6ld(%3d%%)|%2d:%02d:%02d/%2d:%02d:%02d|%2d:%02d:%02d/%2d:%02d:%02d|%10.4f|%2d:%02d:%02d ", + frameNum, + totalframes - 1, + percent, + TS_TIME_DECOMPOSE(process_time.so_far), + TS_TIME_DECOMPOSE(process_time.estimated), + TS_TIME_DECOMPOSE(real_time.so_far), + TS_TIME_DECOMPOSE(real_time.estimated), + process_time.speed, + TS_TIME_DECOMPOSE(real_time.eta) + ); + + fflush(stderr); + } + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/timestatus.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/timestatus.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/timestatus.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,8 ---- + #ifndef TIMESTATUS_H_INCLUDED + #define TIMESTATUS_H_INCLUDED + + + void timestatus(int samp_rate,long frameNum,long totalframes, int framesize); + + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/util.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/util.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/util.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,342 ---- + #include "util.h" + #include <assert.h> + + /*********************************************************************** + * + * Global Variable Definitions + * + ***********************************************************************/ + + + /* 1: MPEG-1, 0: MPEG-2 LSF, 1995-07-11 shn */ + FLOAT8 s_freq_table[2][4] = {{22.05, 24, 16, 0}, {44.1, 48, 32, 0}}; + + /* 1: MPEG-1, 0: MPEG-2 LSF, 1995-07-11 shn */ + int bitrate_table[2][15] = { + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160}, + {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320}}; + + + enum byte_order NativeByteOrder = order_unknown; + + /*********************************************************************** + * + * Global Function Definitions + * + ***********************************************************************/ + + + /*********************************************************************** + * compute bitsperframe and mean_bits for a layer III frame + **********************************************************************/ + void getframebits(lame_global_flags *gfp,int *bitsPerFrame, int *mean_bits) { + int whole_SpF; + FLOAT8 bit_rate,samp; + int bitsPerSlot; + int sideinfo_len; + + samp = gfp->out_samplerate/1000.0; + bit_rate = bitrate_table[gfp->version][gfp->bitrate_index]; + bitsPerSlot = 8; + + /* determine the mean bitrate for main data */ + sideinfo_len = 32; + if ( gfp->version == 1 ) + { /* MPEG 1 */ + if ( gfp->stereo == 1 ) + sideinfo_len += 136; + else + sideinfo_len += 256; + } + else + { /* MPEG 2 */ + if ( gfp->stereo == 1 ) + sideinfo_len += 72; + else + sideinfo_len += 136; + } + + if (gfp->error_protection) sideinfo_len += 16; + + /* -f fast-math option causes some strange rounding here, be carefull: */ + whole_SpF = floor( (gfp->framesize /samp)*(bit_rate / (FLOAT8)bitsPerSlot) + 1e-9); + *bitsPerFrame = 8 * whole_SpF + (gfp->padding * 8); + *mean_bits = (*bitsPerFrame - sideinfo_len) / gfp->mode_gr; + } + + + + + void display_bitrates(FILE *out_fh) + { + int index,version; + + version = 1; + fprintf(out_fh,"\n"); + fprintf(out_fh,"MPEG1 samplerates(kHz): 32 44.1 48 \n"); + + fprintf(out_fh,"bitrates(kbs): "); + for (index=1;index<15;index++) { + fprintf(out_fh,"%i ",bitrate_table[version][index]); + } + fprintf(out_fh,"\n"); + + + version = 0; + fprintf(out_fh,"\n"); + fprintf(out_fh,"MPEG2 samplerates(kHz): 16 22.05 24 \n"); + fprintf(out_fh,"bitrates(kbs): "); + for (index=1;index<15;index++) { + fprintf(out_fh,"%i ",bitrate_table[version][index]); + } + fprintf(out_fh,"\n"); + } + + + int BitrateIndex( + int bRate, /* legal rates from 32 to 448 */ + int version, /* MPEG-1 or MPEG-2 LSF */ + int samplerate) /* convert bitrate in kbps to index */ + { + int index = 0; + int found = 0; + + while(!found && index<15) { + if(bitrate_table[version][index] == bRate) + found = 1; + else + ++index; + } + if(found) + return(index); + else { + fprintf(stderr,"Bitrate %dkbs not legal for %iHz output sampling.\n", + bRate, samplerate); + return(-1); /* Error! */ + } + } + + int SmpFrqIndex( /* convert samp frq in Hz to index */ + long sRate, /* legal rates 16000, 22050, 24000, 32000, 44100, 48000 */ + int *version) + { + /* Assign default value */ + *version=0; + + if (sRate == 44100L) { + *version = 1; return(0); + } + else if (sRate == 48000L) { + *version = 1; return(1); + } + else if (sRate == 32000L) { + *version = 1; return(2); + } + else if (sRate == 24000L) { + *version = 0; return(1); + } + else if (sRate == 22050L) { + *version = 0; return(0); + } + else if (sRate == 16000L) { + *version = 0; return(2); + } + else { + fprintf(stderr, "SmpFrqIndex: %ldHz is not a legal sample rate\n", sRate); + return(-1); /* Error! */ + } + } + + /******************************************************************************* + * + * Allocate number of bytes of memory equal to "block". + * + *******************************************************************************/ + /* exit(0) changed to exit(1) on memory allocation + * error -- 1999/06 Alvaro Martinez Echevarria */ + + void *mem_alloc(unsigned long block, char *item) + { + + void *ptr; + + /* what kind of shit does ISO put out? */ + ptr = (void *) malloc((size_t) block /* <<1 */ ); /* allocate twice as much memory as needed. fixes dodgy + memory problem on most systems */ + + + if (ptr != NULL) { + memset(ptr, 0, (size_t) block); + } else { + fprintf(stderr,"Unable to allocate %s\n", item); + exit(1); + } + return(ptr); + } + + + + /***************************************************************************** + * + * Routines to determine byte order and swap bytes + * + *****************************************************************************/ + + enum byte_order DetermineByteOrder(void) + { + char s[ sizeof(long) + 1 ]; + union + { + long longval; + char charval[ sizeof(long) ]; + } probe; + probe.longval = 0x41424344L; /* ABCD in ASCII */ + strncpy( s, probe.charval, sizeof(long) ); + s[ sizeof(long) ] = '\0'; + /* fprintf( stderr, "byte order is %s\n", s ); */ + if ( strcmp(s, "ABCD") == 0 ) + return order_bigEndian; + else + if ( strcmp(s, "DCBA") == 0 ) + return order_littleEndian; + else + return order_unknown; + } + + void SwapBytesInWords( short *loc, int words ) + { + int i; + short thisval; + char *dst, *src; + src = (char *) &thisval; + for ( i = 0; i < words; i++ ) + { + thisval = *loc; + dst = (char *) loc++; + dst[0] = src[1]; + dst[1] = src[0]; + } + } + + + + + + + /***************************************************************************** + * + * bit_stream.c package + * Author: Jean-Georges Fritsch, C-Cube Microsystems + * + *****************************************************************************/ + + /******************************************************************** + This package provides functions to write (exclusive or read) + information from (exclusive or to) the bit stream. + + If the bit stream is opened in read mode only the get functions are + available. If the bit stream is opened in write mode only the put + functions are available. + ********************************************************************/ + + /*alloc_buffer(); open and initialize the buffer; */ + /*desalloc_buffer(); empty and close the buffer */ + /*back_track_buffer(); goes back N bits in the buffer */ + /*unsigned int get1bit(); read 1 bit from the bit stream */ + /*unsigned long look_ahead(); grep the next N bits in the bit stream without*/ + /* changing the buffer pointer */ + /*putbits(); write N bits from the bit stream */ + /*int seek_sync(); return 1 if a sync word was found in the bit stream */ + /* otherwise returns 0 */ + + + + void empty_buffer(Bit_stream_struc *bs) + { + int minimum=1+bs->buf_byte_idx; /* end of the buffer to empty */ + if (bs->buf_size-minimum <= 0) return; + bs->buf_byte_idx = bs->buf_size -1; + bs->buf_bit_idx = 8; + + bs->buf[bs->buf_byte_idx] = 0; /* what does this do? */ + + } + int copy_buffer(char *buffer,int size,Bit_stream_struc *bs) + { + int i,j=0; + if (size!=0 && (bs->buf_size-1 - bs->buf_byte_idx) > size ) return -1; + for (i=bs->buf_size-1 ; i > bs->buf_byte_idx ; (i-- )) + buffer[j++]=bs->buf[i]; + assert(j == (bs->buf_size-1 - bs->buf_byte_idx)); + empty_buffer(bs); /* empty buffer, (changes bs->buf_size) */ + return j; + } + + + + + + void init_bit_stream_w(Bit_stream_struc* bs) + { + alloc_buffer(bs, BUFFER_SIZE); + bs->buf_byte_idx = BUFFER_SIZE-1; + bs->buf_bit_idx=8; + bs->totbit=0; + } + + + /*open and initialize the buffer; */ + void alloc_buffer( + Bit_stream_struc *bs, /* bit stream structure */ + int size) + { + bs->buf = (unsigned char *) + mem_alloc((unsigned long) (size * sizeof(unsigned char)), "buffer"); + bs->buf_size = size; + } + + /*empty and close the buffer */ + void desalloc_buffer(Bit_stream_struc *bs) /* bit stream structure */ + { + free(bs->buf); + } + + int putmask[9]={0x0, 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff}; + + + /*write N bits into the bit stream */ + void putbits( + Bit_stream_struc *bs, /* bit stream structure */ + unsigned int val, /* val to write into the buffer */ + int N) /* number of bits of val */ + { + register int j = N; + register int k, tmp; + + if (N > MAX_LENGTH) + fprintf(stderr,"Cannot read or write more than %d bits at a time.\n", MAX_LENGTH); + + bs->totbit += N; + while (j > 0) { + k = Min(j, bs->buf_bit_idx); + tmp = val >> (j-k); + bs->buf[bs->buf_byte_idx] |= (tmp&putmask[k]) << (bs->buf_bit_idx-k); + bs->buf_bit_idx -= k; + if (!bs->buf_bit_idx) { + bs->buf_bit_idx = 8; + bs->buf_byte_idx--; + assert(bs->buf_byte_idx >= 0); + bs->buf[bs->buf_byte_idx] = 0; + } + j -= k; + } + } + + + + /***************************************************************************** + * + * End of bit_stream.c package + * + *****************************************************************************/ + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/util.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/util.h:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/util.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,158 ---- + #ifndef UTIL_DOT_H + #define UTIL_DOT_H + /*********************************************************************** + * + * Global Include Files + * + ***********************************************************************/ + #include "machine.h" + #include "encoder.h" + #include "lame.h" + + /*********************************************************************** + * + * Global Definitions + * + ***********************************************************************/ + + /* General Definitions */ + #ifndef FALSE + #define FALSE 0 + #endif + + #ifndef TRUE + #define TRUE 1 + #endif + + #define MAX_U_32_NUM 0xFFFFFFFF + + #ifndef PI + # ifdef M_PI + # define PI M_PI + # else + # define PI 3.14159265358979323846 + # endif + #endif + + + #ifdef M_LN2 + # define LOG2 M_LN2 + #else + # define LOG2 0.69314718055994530942 + #endif + + #ifdef M_LN10 + # define LOG10 M_LN10 + #else + # define LOG10 2.30258509299404568402 + #endif + + + #ifdef M_SQRT2 + # define SQRT2 M_SQRT2 + #else + # define SQRT2 1.41421356237309504880 + #endif + + + #define BITS_IN_A_BYTE 8 + #define HAN_SIZE 512 + #define CRC16_POLYNOMIAL 0x8005 + + /* MPEG Header Definitions - Mode Values */ + + #define MPG_MD_STEREO 0 + #define MPG_MD_JOINT_STEREO 1 + #define MPG_MD_DUAL_CHANNEL 2 + #define MPG_MD_MONO 3 + + /* Mode Extention */ + + #define MPG_MD_LR_LR 0 + #define MPG_MD_LR_I 1 + #define MPG_MD_MS_LR 2 + #define MPG_MD_MS_I 3 + + + /* "bit_stream.h" Definitions */ + + #define MINIMUM 4 /* Minimum size of the buffer in bytes */ + #define MAX_LENGTH 32 /* Maximum length of word written or + read from bit stream */ + #define BUFFER_SIZE LAME_MAXMP3BUFFER + + #define Min(A, B) ((A) < (B) ? (A) : (B)) + #define Max(A, B) ((A) > (B) ? (A) : (B)) + + /*********************************************************************** + * + * Global Type Definitions + * + ***********************************************************************/ + + /* Structure for Reading Layer II Allocation Tables from File */ + + typedef struct { + unsigned int steps; + unsigned int bits; + unsigned int group; + unsigned int quant; + } sb_alloc, *alloc_ptr; + + typedef sb_alloc al_table[SBLIMIT][16]; + + /* Header Information Structure */ + + + + enum byte_order { order_unknown, order_bigEndian, order_littleEndian }; + extern enum byte_order NativeByteOrder; + + /* "bit_stream.h" Type Definitions */ + + typedef struct bit_stream_struc { + unsigned char* pbtOutBuf; /* for .DLL code */ + int nOutBufPos; /* for .DLL code */ + FILE *pt; /* pointer to bit stream device */ + unsigned char *buf; /* bit stream buffer */ + int buf_size; /* size of buffer (in number of bytes) */ + unsigned long totbit; /* bit counter of bit stream */ + int buf_byte_idx; /* pointer to top byte in buffer */ + int buf_bit_idx; /* pointer to top bit of top byte in buffer */ + + /* format of file in rd mode (BINARY/ASCII) */ + } Bit_stream_struc; + + #include "l3side.h" + + /*********************************************************************** + * + * Global Variable External Declarations + * + ***********************************************************************/ + + extern int bitrate_table[2][15]; + + /*********************************************************************** + * + * Global Function Prototype Declarations + * + ***********************************************************************/ + + extern void display_bitrates(FILE *out_fh); + extern int BitrateIndex(int, int,int); + extern int SmpFrqIndex(long, int*); + extern void *mem_alloc(unsigned long, char*); + extern int copy_buffer(char *buffer,int buffer_size,Bit_stream_struc *bs); + extern void init_bit_stream_w(Bit_stream_struc*); + extern void alloc_buffer(Bit_stream_struc*, int); + extern void desalloc_buffer(Bit_stream_struc*); + extern void putbits(Bit_stream_struc*, unsigned int, int); + + extern enum byte_order DetermineByteOrder(void); + extern void SwapBytesInWords( short *loc, int words ); + + extern void + getframebits(lame_global_flags *gfp,int *bitsPerFrame, int *mean_bits); + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/vbrquantize.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/vbrquantize.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/vbrquantize.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,342 ---- + /* + * MP3 quantization + * + * Copyright (c) 1999 Mark Taylor + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + */ + #include <assert.h> + #include "util.h" + #include "l3side.h" + #include "quantize.h" + #include "l3bitstream.h" + #include "reservoir.h" + #include "quantize-pvt.h" + #ifdef HAVEGTK + #include "gtkanal.h" + #endif + + + + #define DEBUGXX + FLOAT8 calc_sfb_ave_noise(FLOAT8 *xr, FLOAT8 *xr34, int stride, int bw, FLOAT8 sfpow) + { + int j; + FLOAT8 xfsf=0; + FLOAT8 sfpow34 = pow(sfpow,3.0/4.0); + + for ( j=0; j < stride*bw ; j += stride) { + int ix; + FLOAT8 temp,temp2; + + /* ix=(int)( xr34[j]/sfpow34 + 0.4054);*/ + ix=floor( xr34[j]/sfpow34); + if (ix > IXMAX_VAL) return -1.0; + + temp = fabs(xr[j])- pow43[ix]*sfpow; + if (ix < IXMAX_VAL) { + temp2 = fabs(xr[j])- pow43[ix+1]*sfpow; + if (fabs(temp2)<fabs(temp)) temp=temp2; + } + #ifdef MAXQUANTERROR + temp *= temp; + xfsf = bw*Max(xfsf,temp); + #else + xfsf += temp * temp; + #endif + } + return xfsf/bw; + } + + + + FLOAT8 find_scalefac(FLOAT8 *xr,FLOAT8 *xr34,int stride,int sfb, + FLOAT8 l3_xmin,int bw) + { + FLOAT8 xfsf,sfpow,sf,sf_ok,delsf; + int sf4,sf_ok4,delsf4; + int i; + + /* search will range from sf: -52.25 -> 11.25 */ + /* search will range from sf4: -209 -> 45 */ + sf = -20.5; + sf4 = -82; + delsf = 32; + delsf4 = 128; + + sf_ok =10000; + sf_ok4=10000; + for (i=0; i<7; i++) { + delsf /= 2; + delsf4 /= 2; + sfpow = pow(2.0,sf); + /* sfpow = pow(2.0,sf4/4.0); */ + xfsf = calc_sfb_ave_noise(xr,xr34,stride,bw,sfpow); + + if (xfsf < 0) { + /* scalefactors too small */ + sf += delsf; + sf4 += delsf4; + }else{ + if (sf_ok==10000) sf_ok=sf; + if (sf_ok4==10000) sf_ok4=sf4; + if (xfsf > l3_xmin) { + /* distortion. try a smaller scalefactor */ + sf -= delsf; + sf4 -= delsf4; + }else{ + sf_ok=sf; + sf_ok4 = sf4; + sf += delsf; + sf4 += delsf4; + } + } + } + /* sf_ok accurate to within +/- 2*final_value_of_delsf */ + assert(sf_ok!=10000); + + /* NOTE: noise is not a monotone function of the sf, even though + * the number of bits used is! do a brute force search in the + * neighborhood of sf_ok: + * + * sf = sf_ok + 1.75 works 1% of the time + * sf = sf_ok + 1.50 works 1% of the time + * sf = sf_ok + 1.25 works 2% of the time + * sf = sf_ok + 1.00 works 3% of the time + * sf = sf_ok + 0.75 works 9% of the time + * sf = sf_ok + 0.50 0 % (because it was tried above) + * sf = sf_ok + 0.25 works 39% of the time + * sf = sf_ok + 0.00 works the rest of the time + */ + + sf = sf_ok + 0.75; + sf4 = sf_ok4 + 3; + + while (sf>(sf_ok+.01)) { + /* sf = sf_ok + 2*delsf was tried above, skip it: */ + if (fabs(sf-(sf_ok+2*delsf)) < .01) sf -=.25; + if (sf4 == sf_ok4+2*delsf4) sf4 -=1; + + sfpow = pow(2.0,sf); + /* sfpow = pow(2.0,sf4/4.0) */ + xfsf = calc_sfb_ave_noise(xr,xr34,stride,bw,sfpow); + if (xfsf > 0) { + if (xfsf <= l3_xmin) return sf; + } + sf -= .25; + sf4 -= 1; + } + return sf_ok; + } + + + + /* + sfb=0..5 scalefac < 16 + sfb>5 scalefac < 8 + + ifqstep = ( cod_info->scalefac_scale == 0 ) ? .5 : 1.0; + ol_sf = (cod_info->global_gain-210.0)/4.0; + ol_sf -= 2*cod_info->subblock_gain[i]; + ol_sf -= ifqstep*scalefac[gr][ch].s[sfb][i]; + */ + FLOAT8 compute_scalefacs_short(FLOAT8 vbrsf[SBPSY_s][3],gr_info *cod_info,int scalefac[SBPSY_s][3]) + { + FLOAT8 maxrange,maxover; + FLOAT8 sf[SBPSY_s][3]; + int sfb,i; + int ifqstep_inv = ( cod_info->scalefac_scale == 0 ) ? 2 : 1; + + /* make a working copy of the desired scalefacs */ + memcpy(sf,vbrsf,SBPSY_s*3*sizeof(FLOAT8)); + + /* see if we should use subblock gain */ + + + maxover=0; + for ( sfb = 0; sfb < SBPSY_s; sfb++ ) { + for (i=0; i<3; ++i) { + /* ifqstep*scalefac + 2*subblock_gain >= -sf[sfb] */ + scalefac[sfb][i]=floor( -sf[sfb][i]*ifqstep_inv +.75 + .0001) ; + + if (sfb < 6) maxrange = 15.0/ifqstep_inv; + else maxrange = 7.0/ifqstep_inv; + + if (maxrange + sf[sfb][i] > maxover) maxover = maxrange+sf[sfb][i]; + } + } + return maxover; + } + + + + + /* + sfb=0..10 scalefac < 16 + sfb>10 scalefac < 8 + + ifqstep = ( cod_info->scalefac_scale == 0 ) ? .5 : 1.0; + ol_sf = (cod_info->global_gain-210.0)/4.0; + ol_sf -= ifqstep*scalefac[gr][ch].l[sfb]; + if (cod_info->preflag && sfb>=11) + ol_sf -= ifqstep*pretab[sfb]; + */ + FLOAT8 compute_scalefacs_long(FLOAT8 vbrsf[SBPSY_l],gr_info *cod_info,int scalefac[SBPSY_l]) + { + int sfb; + FLOAT8 sf[SBPSY_l]; + FLOAT8 maxrange,maxover; + int ifqstep_inv = ( cod_info->scalefac_scale == 0 ) ? 2 : 1; + + /* make a working copy of the desired scalefacs */ + memcpy(sf,vbrsf,SBPSY_l*sizeof(FLOAT8)); + + cod_info->preflag=0; + for ( sfb = 11; sfb < SBPSY_l; sfb++ ) { + if (sf[sfb] + pretab[sfb]/ifqstep_inv > 0) break; + } + if (sfb==SBPSY_l) { + cod_info->preflag=1; + for ( sfb = 11; sfb < SBPSY_l; sfb++ ) + sf[sfb] += pretab[sfb]/ifqstep_inv; + } + + maxover=0; + for ( sfb = 0; sfb < SBPSY_l; sfb++ ) { + /* ifqstep*scalefac >= -sf[sfb] */ + scalefac[sfb]=floor( -sf[sfb]*ifqstep_inv +.75 + .0001) ; + + if (sfb < 11) maxrange = 15.0/ifqstep_inv; + else maxrange = 7.0/ifqstep_inv; + + if (maxrange + sf[sfb] > maxover) maxover = maxrange+sf[sfb]; + } + return maxover; + } + + + + + + /************************************************************************ + * + * VBR_iteration_loop() + * + * + ************************************************************************/ + void + VBR_iteration_loop_new (lame_global_flags *gfp, + FLOAT8 pe[2][2], FLOAT8 ms_ener_ratio[2], + FLOAT8 xr[2][2][576], III_psy_ratio ratio[2][2], + III_side_info_t * l3_side, int l3_enc[2][2][576], + III_scalefac_t scalefac[2][2]) + { + III_psy_xmin l3_xmin[2][2]; + FLOAT8 masking_lower_db; + FLOAT8 ifqstep; + int start,end,bw,sfb, i,ch, gr, over; + III_psy_xmin vbrsf; + FLOAT8 vbrmax; + + + iteration_init(gfp,l3_side,l3_enc); + + /* Adjust allowed masking based on quality setting */ + /* db_lower varies from -10 to +8 db */ + masking_lower_db = -10 + 2*gfp->VBR_q; + /* adjust by -6(min)..0(max) depending on bitrate */ + masking_lower = pow(10.0,masking_lower_db/10); + masking_lower = 1; + + + for (gr = 0; gr < gfp->mode_gr; gr++) { + if (convert_mdct) + ms_convert(xr[gr],xr[gr]); + for (ch = 0; ch < gfp->stereo; ch++) { + FLOAT8 xr34[576]; + gr_info *cod_info = &l3_side->gr[gr].ch[ch].tt; + int shortblock; + over = 0; + shortblock = (cod_info->block_type == SHORT_TYPE); + + for(i=0;i<576;i++) { + FLOAT8 temp=fabs(xr[gr][ch][i]); + xr34[i]=sqrt(sqrt(temp)*temp); + } + + calc_xmin( gfp,xr[gr][ch], &ratio[gr][ch], cod_info, &l3_xmin[gr][ch]); + + vbrmax=0; + if (shortblock) { + for ( sfb = 0; sfb < SBPSY_s; sfb++ ) { + for ( i = 0; i < 3; i++ ) { + start = scalefac_band.s[ sfb ]; + end = scalefac_band.s[ sfb+1 ]; + bw = end - start; + vbrsf.s[sfb][i] = find_scalefac(&xr[gr][ch][3*start+i],&xr34[3*start+i],3,sfb, + masking_lower*l3_xmin[gr][ch].s[sfb][i],bw); + if (vbrsf.s[sfb][i]>vbrmax) vbrmax=vbrsf.s[sfb][i]; + } + } + }else{ + for ( sfb = 0; sfb < SBPSY_l; sfb++ ) { + start = scalefac_band.l[ sfb ]; + end = scalefac_band.l[ sfb+1 ]; + bw = end - start; + vbrsf.l[sfb] = find_scalefac(&xr[gr][ch][start],&xr34[start],1,sfb, + masking_lower*l3_xmin[gr][ch].l[sfb],bw); + if (vbrsf.l[sfb]>vbrmax) vbrmax = vbrsf.l[sfb]; + } + + } /* compute scalefactors */ + + /* sf = (cod_info->global_gain-210.0)/4.0; */ + cod_info->global_gain = floor(4*vbrmax +210 + .5); + + + if (shortblock) { + for ( sfb = 0; sfb < SBPSY_s; sfb++ ) { + for ( i = 0; i < 3; i++ ) { + vbrsf.s[sfb][i] -= vbrmax; + } + } + cod_info->scalefac_scale = 0; + if (compute_scalefacs_short(vbrsf.s,cod_info,scalefac[gr][ch].s) > 0) { + cod_info->scalefac_scale = 1; + if (compute_scalefacs_short(vbrsf.s,cod_info,scalefac[gr][ch].s) >0) { + /* what do we do now? */ + exit(32); + } + } + }else{ + for ( sfb = 0; sfb < SBPSY_l; sfb++ ) + vbrsf.l[sfb] -= vbrmax; + + /* can we get away with scalefac_scale=0? */ + cod_info->scalefac_scale = 0; + if (compute_scalefacs_long(vbrsf.l,cod_info,scalefac[gr][ch].l) > 0) { + cod_info->scalefac_scale = 1; + if (compute_scalefacs_long(vbrsf.l,cod_info,scalefac[gr][ch].l) >0) { + /* what do we do now? */ + exit(32); + } + } + } + } /* ch */ + } /* gr */ + } + + + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/version.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/version.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/version.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,69 ---- + /* + * Version numbering for LAME. + * + * Copyright (c) 1999 A.L. Faber + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + + #include "version.h" + #include "lame.h" + #include <stdio.h> + + static char lpszVersion[80]; + + void lame_print_version(FILE *ofile) { + fprintf(ofile,"LAME version %s (www.sulaco.org/mp3) \n",get_lame_version()); + fprintf(ofile,"GPSYCHO: GPL psycho-acoustic and noise shaping model version %s. \n",get_psy_version()); + #ifdef LIBSNDFILE + fprintf(ofile,"Input handled by libsndfile (www.zip.com.au/~erikd/libsndfile)\n"); + #endif + } + + + char* get_lame_version(void) + { + if (LAME_ALPHAVERSION>0) + sprintf(lpszVersion,"%d.%02d (alpha %d)",LAME_MAJOR_VERSION,LAME_MINOR_VERSION,LAME_ALPHAVERSION); + else if (LAME_BETAVERSION>0) + sprintf(lpszVersion,"%d.%02d (beta %d)",LAME_MAJOR_VERSION,LAME_MINOR_VERSION,LAME_BETAVERSION); + else + sprintf(lpszVersion,"%d.%02d",LAME_MAJOR_VERSION,LAME_MINOR_VERSION); + return lpszVersion; + } + + char* get_psy_version(void) + { + if (PSY_ALPHAVERSION>0) + sprintf(lpszVersion,"%d.%02d (alpha %d)",PSY_MAJOR_VERSION,PSY_MINOR_VERSION,PSY_ALPHAVERSION); + else if (PSY_BETAVERSION>0) + sprintf(lpszVersion,"%d.%02d (beta %d)",PSY_MAJOR_VERSION,PSY_MINOR_VERSION,PSY_BETAVERSION); + else + sprintf(lpszVersion,"%d.%02d",PSY_MAJOR_VERSION,PSY_MINOR_VERSION); + return lpszVersion; + } + + char* get_mp3x_version(void) + { + if (MP3X_ALPHAVERSION>0) + sprintf(lpszVersion,"%d:%02d (alpha %d)",MP3X_MAJOR_VERSION,MP3X_MINOR_VERSION,MP3X_ALPHAVERSION); + else if (MP3X_BETAVERSION>0) + sprintf(lpszVersion,"%d:%02d (beta %d)",MP3X_MAJOR_VERSION,MP3X_MINOR_VERSION,MP3X_BETAVERSION); + else + sprintf(lpszVersion,"%d:%02d",MP3X_MAJOR_VERSION,MP3X_MINOR_VERSION); + return lpszVersion; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/version.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/version.h:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-lame/version.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,46 ---- + /* + * Version numbering for LAME. + * + * Copyright (c) 1999 A.L. Faber + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + #ifndef LAME_H_INCLUDED + #define LAME_H_INCLUDED + + #define LAME_MAJOR_VERSION 3 /* Major version number */ + #define LAME_MINOR_VERSION 70 /* Minor version number */ + #define LAME_ALPHAVERSION 0 /* Set number if this is an alpha version, otherwise zero */ + #define LAME_BETAVERSION 0 /* Set number if this is a beta version, otherwise zero */ + + #define PSY_MAJOR_VERSION 0 /* Major version number */ + #define PSY_MINOR_VERSION 77 /* Minor version number */ + #define PSY_ALPHAVERSION 0 /* Set number if this is an alpha version, otherwise zero */ + #define PSY_BETAVERSION 0 /* Set number if this is a beta version, otherwise zero */ + + #define MP3X_MAJOR_VERSION 0 /* Major version number */ + #define MP3X_MINOR_VERSION 82 /* Minor version number */ + #define MP3X_ALPHAVERSION 0 /* Set number if this is an alpha version, otherwise zero */ + #define MP3X_BETAVERSION 0 /* Set number if this is a beta version, otherwise zero */ + + #include "machine.h" + void lame_print_version(FILE *); + char* get_lame_version(void); /* returns lame version number string */ + char* get_psy_version(void); /* returns psy model version number string */ + char* get_mp3x_version(void); /* returns mp3x version number string */ + + #endif From sabre at nondot.org Tue Jan 9 17:45:04 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 17:45:04 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/LICENSE Makefile README cderror.h cdjpeg.c cdjpeg.h djpeg.c input_large.jpg input_large.ppm input_small.jpg input_small.ppm jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c jchuff.h jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jconfig.h jcparam.c jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jdct.h jddctmgr.c jdhuff.c jdhuff.h jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c jerror.h jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c jinclude.h jmemmgr.c jmemnobs.c jmemsys.h jmorecfg.h jpegint.h jpeglib.h jquant1.c jquant2.c jutils.c jversion.h output_large_decode.ppm rdcolmap.c wrbmp.c wrgif.c wrppm.c wrrle.c wrtarga.c Message-ID: <200701092345.l09Nj4hw029315@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg: LICENSE added (r1.1) Makefile added (r1.1) README added (r1.1) cderror.h added (r1.1) cdjpeg.c added (r1.1) cdjpeg.h added (r1.1) djpeg.c added (r1.1) input_large.jpg added (r1.1) input_large.ppm added (r1.1) input_small.jpg added (r1.1) input_small.ppm added (r1.1) jcapimin.c added (r1.1) jcapistd.c added (r1.1) jccoefct.c added (r1.1) jccolor.c added (r1.1) jcdctmgr.c added (r1.1) jchuff.c added (r1.1) jchuff.h added (r1.1) jcinit.c added (r1.1) jcmainct.c added (r1.1) jcmarker.c added (r1.1) jcmaster.c added (r1.1) jcomapi.c added (r1.1) jconfig.h added (r1.1) jcparam.c added (r1.1) jcphuff.c added (r1.1) jcprepct.c added (r1.1) jcsample.c added (r1.1) jctrans.c added (r1.1) jdapimin.c added (r1.1) jdapistd.c added (r1.1) jdatadst.c added (r1.1) jdatasrc.c added (r1.1) jdcoefct.c added (r1.1) jdcolor.c added (r1.1) jdct.h added (r1.1) jddctmgr.c added (r1.1) jdhuff.c added (r1.1) jdhuff.h added (r1.1) jdinput.c added (r1.1) jdmainct.c added (r1.1) jdmarker.c added (r1.1) jdmaster.c added (r1.1) jdmerge.c added (r1.1) jdphuff.c added (r1.1) jdpostct.c added (r1.1) jdsample.c added (r1.1) jdtrans.c added (r1.1) jerror.c added (r1.1) jerror.h added (r1.1) jfdctflt.c added (r1.1) jfdctfst.c added (r1.1) jfdctint.c added (r1.1) jidctflt.c added (r1.1) jidctfst.c added (r1.1) jidctint.c added (r1.1) jidctred.c added (r1.1) jinclude.h added (r1.1) jmemmgr.c added (r1.1) jmemnobs.c added (r1.1) jmemsys.h added (r1.1) jmorecfg.h added (r1.1) jpegint.h added (r1.1) jpeglib.h added (r1.1) jquant1.c added (r1.1) jquant2.c added (r1.1) jutils.c added (r1.1) jversion.h added (r1.1) output_large_decode.ppm added (r1.1) rdcolmap.c added (r1.1) wrbmp.c added (r1.1) wrgif.c added (r1.1) wrppm.c added (r1.1) wrrle.c added (r1.1) wrtarga.c added (r1.1) --- Log message: Readd mibench --- Diffs of the changes: (+26189 -0) LICENSE | 84 +++ Makefile | 6 README | 1 cderror.h | 132 ++++ cdjpeg.c | 179 ++++++ cdjpeg.h | 179 ++++++ djpeg.c | 604 ++++++++++++++++++++++ input_large.jpg | 0 input_large.ppm | 0 input_small.jpg | 0 input_small.ppm | 0 jcapimin.c | 236 ++++++++ jcapistd.c | 161 +++++ jccoefct.c | 448 ++++++++++++++++ jccolor.c | 459 ++++++++++++++++ jcdctmgr.c | 387 ++++++++++++++ jchuff.c | 846 ++++++++++++++++++++++++++++++ jchuff.h | 34 + jcinit.c | 72 ++ jcmainct.c | 293 ++++++++++ jcmarker.c | 641 +++++++++++++++++++++++ jcmaster.c | 578 +++++++++++++++++++++ jcomapi.c | 94 +++ jconfig.h | 45 + jcparam.c | 574 +++++++++++++++++++++ jcphuff.c | 829 ++++++++++++++++++++++++++++++ jcprepct.c | 354 ++++++++++++ jcsample.c | 519 +++++++++++++++++++ jctrans.c | 371 +++++++++++++ jdapimin.c | 406 ++++++++++++++ jdapistd.c | 275 ++++++++++ jdatadst.c | 151 +++++ jdatasrc.c | 212 +++++++ jdcoefct.c | 735 ++++++++++++++++++++++++++ jdcolor.c | 367 +++++++++++++ jdct.h | 176 ++++++ jddctmgr.c | 269 +++++++++ jdhuff.c | 574 +++++++++++++++++++++ jdhuff.h | 202 +++++++ jdinput.c | 381 +++++++++++++ jdmainct.c | 512 ++++++++++++++++++ jdmarker.c | 1055 ++++++++++++++++++++++++++++++++++++++ jdmaster.c | 555 ++++++++++++++++++++ jdmerge.c | 400 ++++++++++++++ jdphuff.c | 642 +++++++++++++++++++++++ jdpostct.c | 290 ++++++++++ jdsample.c | 478 +++++++++++++++++ jdtrans.c | 122 ++++ jerror.c | 228 ++++++++ jerror.h | 277 ++++++++++ jfdctflt.c | 168 ++++++ jfdctfst.c | 224 ++++++++ jfdctint.c | 283 ++++++++++ jidctflt.c | 241 ++++++++ jidctfst.c | 367 +++++++++++++ jidctint.c | 388 ++++++++++++++ jidctred.c | 397 ++++++++++++++ jinclude.h | 91 +++ jmemmgr.c | 1115 ++++++++++++++++++++++++++++++++++++++++ jmemnobs.c | 109 +++ jmemsys.h | 183 ++++++ jmorecfg.h | 362 +++++++++++++ jpegint.h | 388 ++++++++++++++ jpeglib.h | 1055 ++++++++++++++++++++++++++++++++++++++ jquant1.c | 856 +++++++++++++++++++++++++++++++ jquant2.c | 1310 ++++++++++++++++++++++++++++++++++++++++++++++++ jutils.c | 179 ++++++ jversion.h | 14 output_large_decode.ppm | 0 rdcolmap.c | 253 +++++++++ wrbmp.c | 442 ++++++++++++++++ wrgif.c | 505 ++++++++++++++++++ wrppm.c | 268 +++++++++ wrrle.c | 305 +++++++++++ wrtarga.c | 253 +++++++++ 75 files changed, 26189 insertions(+) Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/LICENSE diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/LICENSE:1.1 *** /dev/null Tue Jan 9 17:44:45 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/LICENSE Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,84 ---- + LEGAL ISSUES + ============ + + In plain English: + + 1. We don't promise that this software works. (But if you find any bugs, + please let us know!) + 2. You can use this software for whatever you want. You don't have to pay us. + 3. You may not pretend that you wrote this software. If you use it in a + program, you must acknowledge somewhere in your documentation that + you've used the IJG code. + + In legalese: + + The authors make NO WARRANTY or representation, either express or implied, + with respect to this software, its quality, accuracy, merchantability, or + fitness for a particular purpose. This software is provided "AS IS", and you, + its user, assume the entire risk as to its quality and accuracy. + + This software is copyright (C) 1991-1996, Thomas G. Lane. + All Rights Reserved except as specified below. + + Permission is hereby granted to use, copy, modify, and distribute this + software (or portions thereof) for any purpose, without fee, subject to these + conditions: + (1) If any part of the source code for this software is distributed, then this + README file must be included, with this copyright and no-warranty notice + unaltered; and any additions, deletions, or changes to the original files + must be clearly indicated in accompanying documentation. + (2) If only executable code is distributed, then the accompanying + documentation must state that "this software is based in part on the work of + the Independent JPEG Group". + (3) Permission for use of this software is granted only if the user accepts + full responsibility for any undesirable consequences; the authors accept + NO LIABILITY for damages of any kind. + + These conditions apply to any software derived from or based on the IJG code, + not just to the unmodified library. If you use our work, you ought to + acknowledge us. + + Permission is NOT granted for the use of any IJG author's name or company name + in advertising or publicity relating to this software or products derived from + it. This software may be referred to only as "the Independent JPEG Group's + software". + + We specifically permit and encourage the use of this software as the basis of + commercial products, provided that all warranty or liability claims are + assumed by the product vendor. + + + ansi2knr.c is included in this distribution by permission of L. Peter Deutsch, + sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA. + ansi2knr.c is NOT covered by the above copyright and conditions, but instead + by the usual distribution terms of the Free Software Foundation; principally, + that you must include source code if you redistribute it. (See the file + ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part + of any program generated from the IJG code, this does not limit you more than + the foregoing paragraphs do. + + The configuration script "configure" was produced with GNU Autoconf. It + is copyright by the Free Software Foundation but is freely distributable. + + It appears that the arithmetic coding option of the JPEG spec is covered by + patents owned by IBM, AT&T, and Mitsubishi. Hence arithmetic coding cannot + legally be used without obtaining one or more licenses. For this reason, + support for arithmetic coding has been removed from the free JPEG software. + (Since arithmetic coding provides only a marginal gain over the unpatented + Huffman mode, it is unlikely that very many implementations will support it.) + So far as we are aware, there are no patent restrictions on the remaining + code. + + WARNING: Unisys has begun to enforce their patent on LZW compression against + GIF encoders and decoders. You will need a license from Unisys to use the + included rdgif.c or wrgif.c files in a commercial or shareware application. + At this time, Unisys is not enforcing their patent against freeware, so + distribution of this package remains legal. However, we intend to remove + GIF support from the IJG package as soon as a suitable replacement format + becomes reasonably popular. + + We are required to state that + "The Graphics Interchange Format(c) is the Copyright property of + CompuServe Incorporated. GIF(sm) is a Service Mark property of + CompuServe Incorporated." + Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/Makefile Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,6 ---- + LEVEL = ../../../.. + + PROG = consumer-jpeg + LDFLAGS = -lm + RUN_OPTIONS = -dct int -ppm -outfile output_large_decode.ppm input_large.jpg + include $(LEVEL)/MultiSource/Makefile.multisrc Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/README diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/README:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/README Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1 ---- + Have to run make in jpeg-6a directory. Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cderror.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cderror.h:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cderror.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,132 ---- + /* + * cderror.h + * + * Copyright (C) 1994, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the error and message codes for the cjpeg/djpeg + * applications. These strings are not needed as part of the JPEG library + * proper. + * Edit this file to add new codes, or to translate the message strings to + * some other language. + */ + + /* + * To define the enum list of message codes, include this file without + * defining macro JMESSAGE. To create a message string table, include it + * again with a suitable JMESSAGE definition (see jerror.c for an example). + */ + #ifndef JMESSAGE + #ifndef CDERROR_H + #define CDERROR_H + /* First time through, define the enum list */ + #define JMAKE_ENUM_LIST + #else + /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ + #define JMESSAGE(code,string) + #endif /* CDERROR_H */ + #endif /* JMESSAGE */ + + #ifdef JMAKE_ENUM_LIST + + typedef enum { + + #define JMESSAGE(code,string) code , + + #endif /* JMAKE_ENUM_LIST */ + + JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */ + + #ifdef BMP_SUPPORTED + JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format") + JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported") + JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length") + JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1") + JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB") + JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported") + JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM") + JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image") + JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image") + JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image") + JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image") + #endif /* BMP_SUPPORTED */ + + #ifdef GIF_SUPPORTED + JMESSAGE(JERR_GIF_BUG, "GIF output got confused") + JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d") + JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB") + JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file") + JMESSAGE(JERR_GIF_NOT, "Not a GIF file") + JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image") + JMESSAGE(JTRC_GIF_BADVERSION, + "Warning: unexpected GIF version number '%c%c%c'") + JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x") + JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input") + JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file") + JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring") + JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image") + JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits") + #endif /* GIF_SUPPORTED */ + + #ifdef PPM_SUPPORTED + JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB") + JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file") + JMESSAGE(JERR_PPM_NOT, "Not a PPM file") + JMESSAGE(JTRC_PGM, "%ux%u PGM image") + JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image") + JMESSAGE(JTRC_PPM, "%ux%u PPM image") + JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image") + #endif /* PPM_SUPPORTED */ + + #ifdef RLE_SUPPORTED + JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library") + JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB") + JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE") + JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file") + JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header") + JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header") + JMESSAGE(JERR_RLE_NOT, "Not an RLE file") + JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE") + JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup") + JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file") + JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d") + JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file") + JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d") + JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d") + #endif /* RLE_SUPPORTED */ + + #ifdef TARGA_SUPPORTED + JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format") + JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file") + JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB") + JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image") + JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image") + JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image") + #else + JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled") + #endif /* TARGA_SUPPORTED */ + + JMESSAGE(JERR_BAD_CMAP_FILE, + "Color map file is invalid or of unsupported format") + JMESSAGE(JERR_TOO_MANY_COLORS, + "Output file format cannot handle %d colormap entries") + JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed") + #ifdef TARGA_SUPPORTED + JMESSAGE(JERR_UNKNOWN_FORMAT, + "Unrecognized input file format --- perhaps you need -targa") + #else + JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format") + #endif + JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format") + + #ifdef JMAKE_ENUM_LIST + + JMSG_LASTADDONCODE + } ADDON_MESSAGE_CODE; + + #undef JMAKE_ENUM_LIST + #endif /* JMAKE_ENUM_LIST */ + + /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ + #undef JMESSAGE Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cdjpeg.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cdjpeg.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cdjpeg.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,179 ---- + /* + * cdjpeg.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains common support routines used by the IJG application + * programs (cjpeg, djpeg, jpegtran). + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + #include <ctype.h> /* to declare isupper(), tolower() */ + #ifdef NEED_SIGNAL_CATCHER + #include <signal.h> /* to declare signal() */ + #endif + #ifdef USE_SETMODE + #include <fcntl.h> /* to declare setmode()'s parameter macros */ + /* If you have setmode() but not <io.h>, just delete this line: */ + #include <io.h> /* to declare setmode() */ + #endif + + + /* + * Signal catcher to ensure that temporary files are removed before aborting. + * NB: for Amiga Manx C this is actually a global routine named _abort(); + * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus... + */ + + #ifdef NEED_SIGNAL_CATCHER + + static j_common_ptr sig_cinfo; + + void /* must be global for Manx C */ + signal_catcher (int signum) + { + if (sig_cinfo != NULL) { + if (sig_cinfo->err != NULL) /* turn off trace output */ + sig_cinfo->err->trace_level = 0; + jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */ + } + exit(EXIT_FAILURE); + } + + + GLOBAL(void) + enable_signal_catcher (j_common_ptr cinfo) + { + sig_cinfo = cinfo; + signal(SIGINT, signal_catcher); + #ifdef SIGTERM /* not all systems have SIGTERM */ + signal(SIGTERM, signal_catcher); + #endif + } + + #endif + + + /* + * Optional progress monitor: display a percent-done figure on stderr. + */ + + #ifdef PROGRESS_REPORT + + METHODDEF(void) + progress_monitor (j_common_ptr cinfo) + { + cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress; + int total_passes = prog->pub.total_passes + prog->total_extra_passes; + int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit); + + if (percent_done != prog->percent_done) { + prog->percent_done = percent_done; + if (total_passes > 1) { + fprintf(stderr, "\rPass %d/%d: %3d%% ", + prog->pub.completed_passes + prog->completed_extra_passes + 1, + total_passes, percent_done); + } else { + fprintf(stderr, "\r %3d%% ", percent_done); + } + fflush(stderr); + } + } + + + GLOBAL(void) + start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress) + { + /* Enable progress display, unless trace output is on */ + if (cinfo->err->trace_level == 0) { + progress->pub.progress_monitor = progress_monitor; + progress->completed_extra_passes = 0; + progress->total_extra_passes = 0; + progress->percent_done = -1; + cinfo->progress = &progress->pub; + } + } + + + GLOBAL(void) + end_progress_monitor (j_common_ptr cinfo) + { + /* Clear away progress display */ + if (cinfo->err->trace_level == 0) { + fprintf(stderr, "\r \r"); + fflush(stderr); + } + } + + #endif + + + /* + * Case-insensitive matching of possibly-abbreviated keyword switches. + * keyword is the constant keyword (must be lower case already), + * minchars is length of minimum legal abbreviation. + */ + + GLOBAL(boolean) + keymatch (char * arg, const char * keyword, int minchars) + { + register int ca, ck; + register int nmatched = 0; + + while ((ca = *arg++) != '\0') { + if ((ck = *keyword++) == '\0') + return FALSE; /* arg longer than keyword, no good */ + if (isupper(ca)) /* force arg to lcase (assume ck is already) */ + ca = tolower(ca); + if (ca != ck) + return FALSE; /* no good */ + nmatched++; /* count matched characters */ + } + /* reached end of argument; fail if it's too short for unique abbrev */ + if (nmatched < minchars) + return FALSE; + return TRUE; /* A-OK */ + } + + + /* + * Routines to establish binary I/O mode for stdin and stdout. + * Non-Unix systems often require some hacking to get out of text mode. + */ + + GLOBAL(FILE *) + read_stdin (void) + { + FILE * input_file = stdin; + + #ifdef USE_SETMODE /* need to hack file mode? */ + setmode(fileno(stdin), O_BINARY); + #endif + #ifdef USE_FDOPEN /* need to re-open in binary mode? */ + if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) { + fprintf(stderr, "Cannot reopen stdin\n"); + exit(EXIT_FAILURE); + } + #endif + return input_file; + } + + + GLOBAL(FILE *) + write_stdout (void) + { + FILE * output_file = stdout; + + #ifdef USE_SETMODE /* need to hack file mode? */ + setmode(fileno(stdout), O_BINARY); + #endif + #ifdef USE_FDOPEN /* need to re-open in binary mode? */ + if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { + fprintf(stderr, "Cannot reopen stdout\n"); + exit(EXIT_FAILURE); + } + #endif + return output_file; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cdjpeg.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cdjpeg.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/cdjpeg.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,179 ---- + /* + * cdjpeg.h + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains common declarations for the sample applications + * cjpeg and djpeg. It is NOT used by the core JPEG library. + */ + + #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */ + #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */ + #include "jinclude.h" + #include "jpeglib.h" + #include "jerror.h" /* get library error codes too */ + #include "cderror.h" /* get application-specific error codes */ + + + /* + * Object interface for cjpeg's source file decoding modules + */ + + typedef struct cjpeg_source_struct * cjpeg_source_ptr; + + struct cjpeg_source_struct { + JMETHOD(void, start_input, (j_compress_ptr cinfo, + cjpeg_source_ptr sinfo)); + JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, + cjpeg_source_ptr sinfo)); + JMETHOD(void, finish_input, (j_compress_ptr cinfo, + cjpeg_source_ptr sinfo)); + + FILE *input_file; + + JSAMPARRAY buffer; + JDIMENSION buffer_height; + }; + + + /* + * Object interface for djpeg's output file encoding modules + */ + + typedef struct djpeg_dest_struct * djpeg_dest_ptr; + + struct djpeg_dest_struct { + /* start_output is called after jpeg_start_decompress finishes. + * The color map will be ready at this time, if one is needed. + */ + JMETHOD(void, start_output, (j_decompress_ptr cinfo, + djpeg_dest_ptr dinfo)); + /* Emit the specified number of pixel rows from the buffer. */ + JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo, + djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied)); + /* Finish up at the end of the image. */ + JMETHOD(void, finish_output, (j_decompress_ptr cinfo, + djpeg_dest_ptr dinfo)); + + /* Target file spec; filled in by djpeg.c after object is created. */ + FILE * output_file; + + /* Output pixel-row buffer. Created by module init or start_output. + * Width is cinfo->output_width * cinfo->output_components; + * height is buffer_height. + */ + JSAMPARRAY buffer; + JDIMENSION buffer_height; + }; + + + /* + * cjpeg/djpeg may need to perform extra passes to convert to or from + * the source/destination file format. The JPEG library does not know + * about these passes, but we'd like them to be counted by the progress + * monitor. We use an expanded progress monitor object to hold the + * additional pass count. + */ + + struct cdjpeg_progress_mgr { + struct jpeg_progress_mgr pub; /* fields known to JPEG library */ + int completed_extra_passes; /* extra passes completed */ + int total_extra_passes; /* total extra */ + /* last printed percentage stored here to avoid multiple printouts */ + int percent_done; + }; + + typedef struct cdjpeg_progress_mgr * cd_progress_ptr; + + + /* Short forms of external names for systems with brain-damaged linkers. */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jinit_read_bmp jIRdBMP + #define jinit_write_bmp jIWrBMP + #define jinit_read_gif jIRdGIF + #define jinit_write_gif jIWrGIF + #define jinit_read_ppm jIRdPPM + #define jinit_write_ppm jIWrPPM + #define jinit_read_rle jIRdRLE + #define jinit_write_rle jIWrRLE + #define jinit_read_targa jIRdTarga + #define jinit_write_targa jIWrTarga + #define read_quant_tables RdQTables + #define read_scan_script RdScnScript + #define set_quant_slots SetQSlots + #define set_sample_factors SetSFacts + #define read_color_map RdCMap + #define enable_signal_catcher EnSigCatcher + #define start_progress_monitor StProgMon + #define end_progress_monitor EnProgMon + #define read_stdin RdStdin + #define write_stdout WrStdout + #endif /* NEED_SHORT_EXTERNAL_NAMES */ + + /* Module selection routines for I/O modules. */ + + EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo)); + EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo, + boolean is_os2)); + EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo)); + EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo)); + EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo)); + EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo)); + EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo)); + EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo)); + EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo)); + EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo)); + + /* cjpeg support routines (in rdswitch.c) */ + + EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename, + int scale_factor, boolean force_baseline)); + EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename)); + EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg)); + EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg)); + + /* djpeg support routines (in rdcolmap.c) */ + + EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile)); + + /* common support routines (in cdjpeg.c) */ + + EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo)); + EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo, + cd_progress_ptr progress)); + EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo)); + EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars)); + EXTERN(FILE *) read_stdin JPP((void)); + EXTERN(FILE *) write_stdout JPP((void)); + + /* miscellaneous useful macros */ + + #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ + #define READ_BINARY "r" + #define WRITE_BINARY "w" + #else + #define READ_BINARY "rb" + #define WRITE_BINARY "wb" + #endif + + #ifndef EXIT_FAILURE /* define exit() codes if not provided */ + #define EXIT_FAILURE 1 + #endif + #ifndef EXIT_SUCCESS + #ifdef VMS + #define EXIT_SUCCESS 1 /* VMS is very nonstandard */ + #else + #define EXIT_SUCCESS 0 + #endif + #endif + #ifndef EXIT_WARNING + #ifdef VMS + #define EXIT_WARNING 1 /* VMS is very nonstandard */ + #else + #define EXIT_WARNING 2 + #endif + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/djpeg.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/djpeg.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/djpeg.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,604 ---- + /* + * djpeg.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a command-line user interface for the JPEG decompressor. + * It should work on any system with Unix- or MS-DOS-style command lines. + * + * Two different command line styles are permitted, depending on the + * compile-time switch TWO_FILE_COMMANDLINE: + * djpeg [options] inputfile outputfile + * djpeg [options] [inputfile] + * In the second style, output is always to standard output, which you'd + * normally redirect to a file or pipe to some other program. Input is + * either from a named file or from standard input (typically redirected). + * The second style is convenient on Unix but is unhelpful on systems that + * don't support pipes. Also, you MUST use the first style if your system + * doesn't do binary I/O to stdin/stdout. + * To simplify script writing, the "-outfile" switch is provided. The syntax + * djpeg [options] -outfile outputfile inputfile + * works regardless of which command line style is used. + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + #include "jversion.h" /* for version message */ + + #include <ctype.h> /* to declare isprint() */ + + #ifdef USE_CCOMMAND /* command-line reader for Macintosh */ + #ifdef __MWERKS__ + #include <SIOUX.h> /* Metrowerks needs this */ + #include <console.h> /* ... and this */ + #endif + #ifdef THINK_C + #include <console.h> /* Think declares it here */ + #endif + #endif + + + /* Create the add-on message string table. */ + + #define JMESSAGE(code,string) string , + + static const char * const cdjpeg_message_table[] = { + #include "cderror.h" + NULL + }; + + + /* + * This list defines the known output image formats + * (not all of which need be supported by a given version). + * You can change the default output format by defining DEFAULT_FMT; + * indeed, you had better do so if you undefine PPM_SUPPORTED. + */ + + typedef enum { + FMT_BMP, /* BMP format (Windows flavor) */ + FMT_GIF, /* GIF format */ + FMT_OS2, /* BMP format (OS/2 flavor) */ + FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ + FMT_RLE, /* RLE format */ + FMT_TARGA, /* Targa format */ + FMT_TIFF /* TIFF format */ + } IMAGE_FORMATS; + + #ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ + #define DEFAULT_FMT FMT_PPM + #endif + + static IMAGE_FORMATS requested_fmt; + + + /* + * Argument-parsing code. + * The switch parser is designed to be useful with DOS-style command line + * syntax, ie, intermixed switches and file names, where only the switches + * to the left of a given file name affect processing of that file. + * The main program in this file doesn't actually use this capability... + */ + + + static const char * progname; /* program name for error messages */ + static char * outfilename; /* for -outfile switch */ + + + LOCAL(void) + usage (void) + /* complain about bad command line */ + { + fprintf(stderr, "usage: %s [switches] ", progname); + #ifdef TWO_FILE_COMMANDLINE + fprintf(stderr, "inputfile outputfile\n"); + #else + fprintf(stderr, "[inputfile]\n"); + #endif + + fprintf(stderr, "Switches (names may be abbreviated):\n"); + fprintf(stderr, " -colors N Reduce image to no more than N colors\n"); + fprintf(stderr, " -fast Fast, low-quality processing\n"); + fprintf(stderr, " -grayscale Force grayscale output\n"); + #ifdef IDCT_SCALING_SUPPORTED + fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); + #endif + #ifdef BMP_SUPPORTED + fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", + (DEFAULT_FMT == FMT_BMP ? " (default)" : "")); + #endif + #ifdef GIF_SUPPORTED + fprintf(stderr, " -gif Select GIF output format%s\n", + (DEFAULT_FMT == FMT_GIF ? " (default)" : "")); + #endif + #ifdef BMP_SUPPORTED + fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", + (DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); + #endif + #ifdef PPM_SUPPORTED + fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", + (DEFAULT_FMT == FMT_PPM ? " (default)" : "")); + #endif + #ifdef RLE_SUPPORTED + fprintf(stderr, " -rle Select Utah RLE output format%s\n", + (DEFAULT_FMT == FMT_RLE ? " (default)" : "")); + #endif + #ifdef TARGA_SUPPORTED + fprintf(stderr, " -targa Select Targa output format%s\n", + (DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); + #endif + fprintf(stderr, "Switches for advanced users:\n"); + #ifdef DCT_ISLOW_SUPPORTED + fprintf(stderr, " -dct int Use integer DCT method%s\n", + (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); + #endif + #ifdef DCT_IFAST_SUPPORTED + fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", + (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); + #endif + #ifdef DCT_FLOAT_SUPPORTED + fprintf(stderr, " -dct float Use floating-point DCT method%s\n", + (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); + #endif + fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); + fprintf(stderr, " -dither none Don't use dithering in quantization\n"); + fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n"); + #ifdef QUANT_2PASS_SUPPORTED + fprintf(stderr, " -map FILE Map to colors used in named image file\n"); + #endif + fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n"); + #ifdef QUANT_1PASS_SUPPORTED + fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n"); + #endif + fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); + fprintf(stderr, " -outfile name Specify name for output file\n"); + fprintf(stderr, " -verbose or -debug Emit debug output\n"); + exit(EXIT_FAILURE); + } + + + LOCAL(int) + parse_switches (j_decompress_ptr cinfo, int argc, char **argv, + int last_file_arg_seen, boolean for_real) + /* Parse optional switches. + * Returns argv[] index of first file-name argument (== argc if none). + * Any file names with indexes <= last_file_arg_seen are ignored; + * they have presumably been processed in a previous iteration. + * (Pass 0 for last_file_arg_seen on the first or only iteration.) + * for_real is FALSE on the first (dummy) pass; we may skip any expensive + * processing. + */ + { + int argn; + char * arg; + + /* Set up default JPEG parameters. */ + requested_fmt = DEFAULT_FMT; /* set default output file format */ + outfilename = NULL; + cinfo->err->trace_level = 0; + + /* Scan command line options, adjust parameters */ + + for (argn = 1; argn < argc; argn++) { + arg = argv[argn]; + if (*arg != '-') { + /* Not a switch, must be a file name argument */ + if (argn <= last_file_arg_seen) { + outfilename = NULL; /* -outfile applies to just one input file */ + continue; /* ignore this name if previously processed */ + } + break; /* else done parsing switches */ + } + arg++; /* advance past switch marker character */ + + if (keymatch(arg, "bmp", 1)) { + /* BMP output format. */ + requested_fmt = FMT_BMP; + + } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || + keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { + /* Do color quantization. */ + int val; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%d", &val) != 1) + usage(); + cinfo->desired_number_of_colors = val; + cinfo->quantize_colors = TRUE; + + } else if (keymatch(arg, "dct", 2)) { + /* Select IDCT algorithm. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "int", 1)) { + cinfo->dct_method = JDCT_ISLOW; + } else if (keymatch(argv[argn], "fast", 2)) { + cinfo->dct_method = JDCT_IFAST; + } else if (keymatch(argv[argn], "float", 2)) { + cinfo->dct_method = JDCT_FLOAT; + } else + usage(); + + } else if (keymatch(arg, "dither", 2)) { + /* Select dithering algorithm. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (keymatch(argv[argn], "fs", 2)) { + cinfo->dither_mode = JDITHER_FS; + } else if (keymatch(argv[argn], "none", 2)) { + cinfo->dither_mode = JDITHER_NONE; + } else if (keymatch(argv[argn], "ordered", 2)) { + cinfo->dither_mode = JDITHER_ORDERED; + } else + usage(); + + } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { + /* Enable debug printouts. */ + /* On first -d, print version identification */ + static boolean printed_version = FALSE; + + if (! printed_version) { + fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n", + JVERSION, JCOPYRIGHT); + printed_version = TRUE; + } + cinfo->err->trace_level++; + + } else if (keymatch(arg, "fast", 1)) { + /* Select recommended processing options for quick-and-dirty output. */ + cinfo->two_pass_quantize = FALSE; + cinfo->dither_mode = JDITHER_ORDERED; + if (! cinfo->quantize_colors) /* don't override an earlier -colors */ + cinfo->desired_number_of_colors = 216; + cinfo->dct_method = JDCT_FASTEST; + cinfo->do_fancy_upsampling = FALSE; + + } else if (keymatch(arg, "gif", 1)) { + /* GIF output format. */ + requested_fmt = FMT_GIF; + + } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { + /* Force monochrome output. */ + cinfo->out_color_space = JCS_GRAYSCALE; + + } else if (keymatch(arg, "map", 3)) { + /* Quantize to a color map taken from an input file. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (for_real) { /* too expensive to do twice! */ + #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ + FILE * mapfile; + + if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); + exit(EXIT_FAILURE); + } + read_color_map(cinfo, mapfile); + fclose(mapfile); + cinfo->quantize_colors = TRUE; + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } + + } else if (keymatch(arg, "maxmemory", 3)) { + /* Maximum memory in Kb (or Mb with 'm'). */ + long lval; + char ch = 'x'; + + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) + usage(); + if (ch == 'm' || ch == 'M') + lval *= 1000L; + cinfo->mem->max_memory_to_use = lval * 1000L; + + } else if (keymatch(arg, "nosmooth", 3)) { + /* Suppress fancy upsampling */ + cinfo->do_fancy_upsampling = FALSE; + + } else if (keymatch(arg, "onepass", 3)) { + /* Use fast one-pass quantization. */ + cinfo->two_pass_quantize = FALSE; + + } else if (keymatch(arg, "os2", 3)) { + /* BMP output format (OS/2 flavor). */ + requested_fmt = FMT_OS2; + + } else if (keymatch(arg, "outfile", 4)) { + /* Set output file name. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + outfilename = argv[argn]; /* save it away for later use */ + + } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) { + /* PPM/PGM output format. */ + requested_fmt = FMT_PPM; + + } else if (keymatch(arg, "rle", 1)) { + /* RLE output format. */ + requested_fmt = FMT_RLE; + + } else if (keymatch(arg, "scale", 1)) { + /* Scale the output image by a fraction M/N. */ + if (++argn >= argc) /* advance to next argument */ + usage(); + if (sscanf(argv[argn], "%d/%d", + &cinfo->scale_num, &cinfo->scale_denom) != 2) + usage(); + + } else if (keymatch(arg, "targa", 1)) { + /* Targa output format. */ + requested_fmt = FMT_TARGA; + + } else { + usage(); /* bogus switch */ + } + } + + return argn; /* return index of next arg (file name) */ + } + + + /* + * Marker processor for COM markers. + * This replaces the library's built-in processor, which just skips the marker. + * We want to print out the marker as text, if possible. + * Note this code relies on a non-suspending data source. + */ + + LOCAL(unsigned int) + jpeg_getc (j_decompress_ptr cinfo) + /* Read next byte */ + { + struct jpeg_source_mgr * datasrc = cinfo->src; + + if (datasrc->bytes_in_buffer == 0) { + if (! (*datasrc->fill_input_buffer) (cinfo)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } + datasrc->bytes_in_buffer--; + return GETJOCTET(*datasrc->next_input_byte++); + } + + + METHODDEF(boolean) + COM_handler (j_decompress_ptr cinfo) + { + boolean traceit = (cinfo->err->trace_level >= 1); + INT32 length; + unsigned int ch; + unsigned int lastch = 0; + + length = jpeg_getc(cinfo) << 8; + length += jpeg_getc(cinfo); + length -= 2; /* discount the length word itself */ + + if (traceit) + fprintf(stderr, "Comment, length %ld:\n", (long) length); + + while (--length >= 0) { + ch = jpeg_getc(cinfo); + if (traceit) { + /* Emit the character in a readable form. + * Nonprintables are converted to \nnn form, + * while \ is converted to \\. + * Newlines in CR, CR/LF, or LF form will be printed as one newline. + */ + if (ch == '\r') { + fprintf(stderr, "\n"); + } else if (ch == '\n') { + if (lastch != '\r') + fprintf(stderr, "\n"); + } else if (ch == '\\') { + fprintf(stderr, "\\\\"); + } else if (isprint(ch)) { + putc(ch, stderr); + } else { + fprintf(stderr, "\\%03o", ch); + } + lastch = ch; + } + } + + if (traceit) + fprintf(stderr, "\n"); + + return TRUE; + } + + + /* + * The main program. + */ + + int + main (int argc, char **argv) + { + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + #ifdef PROGRESS_REPORT + struct cdjpeg_progress_mgr progress; + #endif + int file_index; + djpeg_dest_ptr dest_mgr = NULL; + FILE * input_file; + FILE * output_file; + JDIMENSION num_scanlines; + + /* On Mac, fetch a command line. */ + #ifdef USE_CCOMMAND + argc = ccommand(&argv); + #endif + + progname = argv[0]; + if (progname == NULL || progname[0] == 0) + progname = "djpeg"; /* in case C library doesn't provide it */ + + /* Initialize the JPEG decompression object with default error handling. */ + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + /* Add some application-specific error messages (from cderror.h) */ + jerr.addon_message_table = cdjpeg_message_table; + jerr.first_addon_message = JMSG_FIRSTADDONCODE; + jerr.last_addon_message = JMSG_LASTADDONCODE; + /* Insert custom COM marker processor. */ + jpeg_set_marker_processor(&cinfo, JPEG_COM, COM_handler); + + /* Now safe to enable signal catcher. */ + #ifdef NEED_SIGNAL_CATCHER + enable_signal_catcher((j_common_ptr) &cinfo); + #endif + + /* Scan command line to find file names. */ + /* It is convenient to use just one switch-parsing routine, but the switch + * values read here are ignored; we will rescan the switches after opening + * the input file. + * (Exception: tracing level set here controls verbosity for COM markers + * found during jpeg_read_header...) + */ + + file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); + + #ifdef TWO_FILE_COMMANDLINE + /* Must have either -outfile switch or explicit output file name */ + if (outfilename == NULL) { + if (file_index != argc-2) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + outfilename = argv[file_index+1]; + } else { + if (file_index != argc-1) { + fprintf(stderr, "%s: must name one input and one output file\n", + progname); + usage(); + } + } + #else + /* Unix style: expect zero or one file name */ + if (file_index < argc-1) { + fprintf(stderr, "%s: only one input file\n", progname); + usage(); + } + #endif /* TWO_FILE_COMMANDLINE */ + + /* Open the input file. */ + if (file_index < argc) { + if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); + exit(EXIT_FAILURE); + } + } else { + /* default input file is stdin */ + input_file = read_stdin(); + } + + /* Open the output file. */ + if (outfilename != NULL) { + if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { + fprintf(stderr, "%s: can't open %s\n", progname, outfilename); + exit(EXIT_FAILURE); + } + } else { + /* default output file is stdout */ + output_file = write_stdout(); + } + + #ifdef PROGRESS_REPORT + start_progress_monitor((j_common_ptr) &cinfo, &progress); + #endif + + /* Specify data source for decompression */ + jpeg_stdio_src(&cinfo, input_file); + + /* Read file header, set default decompression parameters */ + (void) jpeg_read_header(&cinfo, TRUE); + + /* Adjust default decompression parameters by re-parsing the options */ + file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); + + /* Initialize the output module now to let it override any crucial + * option settings (for instance, GIF wants to force color quantization). + */ + switch (requested_fmt) { + #ifdef BMP_SUPPORTED + case FMT_BMP: + dest_mgr = jinit_write_bmp(&cinfo, FALSE); + break; + case FMT_OS2: + dest_mgr = jinit_write_bmp(&cinfo, TRUE); + break; + #endif + #ifdef GIF_SUPPORTED + case FMT_GIF: + dest_mgr = jinit_write_gif(&cinfo); + break; + #endif + #ifdef PPM_SUPPORTED + case FMT_PPM: + dest_mgr = jinit_write_ppm(&cinfo); + break; + #endif + #ifdef RLE_SUPPORTED + case FMT_RLE: + dest_mgr = jinit_write_rle(&cinfo); + break; + #endif + #ifdef TARGA_SUPPORTED + case FMT_TARGA: + dest_mgr = jinit_write_targa(&cinfo); + break; + #endif + default: + ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); + break; + } + dest_mgr->output_file = output_file; + + /* Start decompressor */ + (void) jpeg_start_decompress(&cinfo); + + /* Write output file header */ + (*dest_mgr->start_output) (&cinfo, dest_mgr); + + /* Process data */ + while (cinfo.output_scanline < cinfo.output_height) { + num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, + dest_mgr->buffer_height); + (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); + } + + #ifdef PROGRESS_REPORT + /* Hack: count final pass as done in case finish_output does an extra pass. + * The library won't have updated completed_passes. + */ + progress.pub.completed_passes = progress.pub.total_passes; + #endif + + /* Finish decompression and release memory. + * I must do it in this order because output module has allocated memory + * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory. + */ + (*dest_mgr->finish_output) (&cinfo, dest_mgr); + (void) jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + /* Close files, if we opened them */ + if (input_file != stdin) + fclose(input_file); + if (output_file != stdout) + fclose(output_file); + + #ifdef PROGRESS_REPORT + end_progress_monitor((j_common_ptr) &cinfo); + #endif + + /* All done. */ + exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); + return 0; /* suppress no-return-value warnings */ + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/input_large.jpg Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/input_large.ppm Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/input_small.jpg Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/input_small.ppm Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcapimin.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcapimin.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcapimin.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,236 ---- + /* + * jcapimin.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the compression half + * of the JPEG library. These are the "minimum" API routines that may be + * needed in either the normal full-compression case or the transcoding-only + * case. + * + * Most of the routines intended to be called directly by an application + * are in this file or in jcapistd.c. But also see jcparam.c for + * parameter-setup helper routines, jcomapi.c for routines shared by + * compression and decompression, and jctrans.c for the transcoding case. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * Initialization of a JPEG compression object. + * The error manager must already be set up (in case memory manager fails). + */ + + GLOBAL(void) + jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) + { + int i; + + /* Guard against version mismatches between library and caller. */ + cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ + if (version != JPEG_LIB_VERSION) + ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); + if (structsize != SIZEOF(struct jpeg_compress_struct)) + ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, + (int) SIZEOF(struct jpeg_compress_struct), (int) structsize); + + /* For debugging purposes, zero the whole master structure. + * But error manager pointer is already there, so save and restore it. + */ + { + struct jpeg_error_mgr * err = cinfo->err; + MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct)); + cinfo->err = err; + } + cinfo->is_decompressor = FALSE; + + /* Initialize a memory manager instance for this object */ + jinit_memory_mgr((j_common_ptr) cinfo); + + /* Zero out pointers to permanent structures. */ + cinfo->progress = NULL; + cinfo->dest = NULL; + + cinfo->comp_info = NULL; + + for (i = 0; i < NUM_QUANT_TBLS; i++) + cinfo->quant_tbl_ptrs[i] = NULL; + + for (i = 0; i < NUM_HUFF_TBLS; i++) { + cinfo->dc_huff_tbl_ptrs[i] = NULL; + cinfo->ac_huff_tbl_ptrs[i] = NULL; + } + + cinfo->input_gamma = 1.0; /* in case application forgets */ + + /* OK, I'm ready */ + cinfo->global_state = CSTATE_START; + } + + + /* + * Destruction of a JPEG compression object + */ + + GLOBAL(void) + jpeg_destroy_compress (j_compress_ptr cinfo) + { + jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ + } + + + /* + * Abort processing of a JPEG compression operation, + * but don't destroy the object itself. + */ + + GLOBAL(void) + jpeg_abort_compress (j_compress_ptr cinfo) + { + jpeg_abort((j_common_ptr) cinfo); /* use common routine */ + } + + + /* + * Forcibly suppress or un-suppress all quantization and Huffman tables. + * Marks all currently defined tables as already written (if suppress) + * or not written (if !suppress). This will control whether they get emitted + * by a subsequent jpeg_start_compress call. + * + * This routine is exported for use by applications that want to produce + * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but + * since it is called by jpeg_start_compress, we put it here --- otherwise + * jcparam.o would be linked whether the application used it or not. + */ + + GLOBAL(void) + jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress) + { + int i; + JQUANT_TBL * qtbl; + JHUFF_TBL * htbl; + + for (i = 0; i < NUM_QUANT_TBLS; i++) { + if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL) + qtbl->sent_table = suppress; + } + + for (i = 0; i < NUM_HUFF_TBLS; i++) { + if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL) + htbl->sent_table = suppress; + if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL) + htbl->sent_table = suppress; + } + } + + + /* + * Finish JPEG compression. + * + * If a multipass operating mode was selected, this may do a great deal of + * work including most of the actual output. + */ + + GLOBAL(void) + jpeg_finish_compress (j_compress_ptr cinfo) + { + JDIMENSION iMCU_row; + + if (cinfo->global_state == CSTATE_SCANNING || + cinfo->global_state == CSTATE_RAW_OK) { + /* Terminate first pass */ + if (cinfo->next_scanline < cinfo->image_height) + ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); + (*cinfo->master->finish_pass) (cinfo); + } else if (cinfo->global_state != CSTATE_WRCOEFS) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Perform any remaining passes */ + while (! cinfo->master->is_last_pass) { + (*cinfo->master->prepare_for_pass) (cinfo); + for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) iMCU_row; + cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + /* We bypass the main controller and invoke coef controller directly; + * all work is being done from the coefficient buffer. + */ + if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } + (*cinfo->master->finish_pass) (cinfo); + } + /* Write EOI, do final cleanup */ + (*cinfo->marker->write_file_trailer) (cinfo); + (*cinfo->dest->term_destination) (cinfo); + /* We can use jpeg_abort to release memory and reset global_state */ + jpeg_abort((j_common_ptr) cinfo); + } + + + /* + * Write a special marker. + * This is only recommended for writing COM or APPn markers. + * Must be called after jpeg_start_compress() and before + * first call to jpeg_write_scanlines() or jpeg_write_raw_data(). + */ + + GLOBAL(void) + jpeg_write_marker (j_compress_ptr cinfo, int marker, + const JOCTET *dataptr, unsigned int datalen) + { + if (cinfo->next_scanline != 0 || + (cinfo->global_state != CSTATE_SCANNING && + cinfo->global_state != CSTATE_RAW_OK && + cinfo->global_state != CSTATE_WRCOEFS)) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + (*cinfo->marker->write_any_marker) (cinfo, marker, dataptr, datalen); + } + + + /* + * Alternate compression function: just write an abbreviated table file. + * Before calling this, all parameters and a data destination must be set up. + * + * To produce a pair of files containing abbreviated tables and abbreviated + * image data, one would proceed as follows: + * + * initialize JPEG object + * set JPEG parameters + * set destination to table file + * jpeg_write_tables(cinfo); + * set destination to image file + * jpeg_start_compress(cinfo, FALSE); + * write data... + * jpeg_finish_compress(cinfo); + * + * jpeg_write_tables has the side effect of marking all tables written + * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress + * will not re-emit the tables unless it is passed write_all_tables=TRUE. + */ + + GLOBAL(void) + jpeg_write_tables (j_compress_ptr cinfo) + { + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* (Re)initialize error mgr and destination modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->dest->init_destination) (cinfo); + /* Initialize the marker writer ... bit of a crock to do it here. */ + jinit_marker_writer(cinfo); + /* Write them tables! */ + (*cinfo->marker->write_tables_only) (cinfo); + /* And clean up. */ + (*cinfo->dest->term_destination) (cinfo); + /* We can use jpeg_abort to release memory. */ + jpeg_abort((j_common_ptr) cinfo); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcapistd.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcapistd.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcapistd.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,161 ---- + /* + * jcapistd.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the compression half + * of the JPEG library. These are the "standard" API routines that are + * used in the normal full-compression case. They are not used by a + * transcoding-only application. Note that if an application links in + * jpeg_start_compress, it will end up linking in the entire compressor. + * We thus must separate this file from jcapimin.c to avoid linking the + * whole compression library into a transcoder. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * Compression initialization. + * Before calling this, all parameters and a data destination must be set up. + * + * We require a write_all_tables parameter as a failsafe check when writing + * multiple datastreams from the same compression object. Since prior runs + * will have left all the tables marked sent_table=TRUE, a subsequent run + * would emit an abbreviated stream (no tables) by default. This may be what + * is wanted, but for safety's sake it should not be the default behavior: + * programmers should have to make a deliberate choice to emit abbreviated + * images. Therefore the documentation and examples should encourage people + * to pass write_all_tables=TRUE; then it will take active thought to do the + * wrong thing. + */ + + GLOBAL(void) + jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) + { + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + if (write_all_tables) + jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ + + /* (Re)initialize error mgr and destination modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->dest->init_destination) (cinfo); + /* Perform master selection of active modules */ + jinit_compress_master(cinfo); + /* Set up for the first pass */ + (*cinfo->master->prepare_for_pass) (cinfo); + /* Ready for application to drive first pass through jpeg_write_scanlines + * or jpeg_write_raw_data. + */ + cinfo->next_scanline = 0; + cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING); + } + + + /* + * Write some scanlines of data to the JPEG compressor. + * + * The return value will be the number of lines actually written. + * This should be less than the supplied num_lines only in case that + * the data destination module has requested suspension of the compressor, + * or if more than image_height scanlines are passed in. + * + * Note: we warn about excess calls to jpeg_write_scanlines() since + * this likely signals an application programmer error. However, + * excess scanlines passed in the last valid call are *silently* ignored, + * so that the application need not adjust num_lines for end-of-image + * when using a multiple-scanline buffer. + */ + + GLOBAL(JDIMENSION) + jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, + JDIMENSION num_lines) + { + JDIMENSION row_ctr, rows_left; + + if (cinfo->global_state != CSTATE_SCANNING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->next_scanline >= cinfo->image_height) + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->next_scanline; + cinfo->progress->pass_limit = (long) cinfo->image_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Give master control module another chance if this is first call to + * jpeg_write_scanlines. This lets output of the frame/scan headers be + * delayed so that application can write COM, etc, markers between + * jpeg_start_compress and jpeg_write_scanlines. + */ + if (cinfo->master->call_pass_startup) + (*cinfo->master->pass_startup) (cinfo); + + /* Ignore any extra scanlines at bottom of image. */ + rows_left = cinfo->image_height - cinfo->next_scanline; + if (num_lines > rows_left) + num_lines = rows_left; + + row_ctr = 0; + (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines); + cinfo->next_scanline += row_ctr; + return row_ctr; + } + + + /* + * Alternate entry point to write raw data. + * Processes exactly one iMCU row per call, unless suspended. + */ + + GLOBAL(JDIMENSION) + jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, + JDIMENSION num_lines) + { + JDIMENSION lines_per_iMCU_row; + + if (cinfo->global_state != CSTATE_RAW_OK) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->next_scanline >= cinfo->image_height) { + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + return 0; + } + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->next_scanline; + cinfo->progress->pass_limit = (long) cinfo->image_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Give master control module another chance if this is first call to + * jpeg_write_raw_data. This lets output of the frame/scan headers be + * delayed so that application can write COM, etc, markers between + * jpeg_start_compress and jpeg_write_raw_data. + */ + if (cinfo->master->call_pass_startup) + (*cinfo->master->pass_startup) (cinfo); + + /* Verify that at least one iMCU row has been passed. */ + lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE; + if (num_lines < lines_per_iMCU_row) + ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* Directly compress the row. */ + if (! (*cinfo->coef->compress_data) (cinfo, data)) { + /* If compressor did not consume the whole row, suspend processing. */ + return 0; + } + + /* OK, we processed one iMCU row. */ + cinfo->next_scanline += lines_per_iMCU_row; + return lines_per_iMCU_row; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jccoefct.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jccoefct.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jccoefct.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,448 ---- + /* + * jccoefct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the coefficient buffer controller for compression. + * This controller is the top level of the JPEG compressor proper. + * The coefficient buffer lies between forward-DCT and entropy encoding steps. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* We use a full-image coefficient buffer when doing Huffman optimization, + * and also for writing multiple-scan JPEG files. In all cases, the DCT + * step is run during the first pass, and subsequent passes need only read + * the buffered coefficients. + */ + #ifdef ENTROPY_OPT_SUPPORTED + #define FULL_COEF_BUFFER_SUPPORTED + #else + #ifdef C_MULTISCAN_FILES_SUPPORTED + #define FULL_COEF_BUFFER_SUPPORTED + #endif + #endif + + + /* Private buffer controller object */ + + typedef struct { + struct jpeg_c_coef_controller pub; /* public fields */ + + JDIMENSION iMCU_row_num; /* iMCU row # within image */ + JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ + int MCU_vert_offset; /* counts MCU rows within iMCU row */ + int MCU_rows_per_iMCU_row; /* number of such rows needed */ + + /* For single-pass compression, it's sufficient to buffer just one MCU + * (although this may prove a bit slow in practice). We allocate a + * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each + * MCU constructed and sent. (On 80x86, the workspace is FAR even though + * it's not really very big; this is to keep the module interfaces unchanged + * when a large coefficient buffer is necessary.) + * In multi-pass modes, this array points to the current MCU's blocks + * within the virtual arrays. + */ + JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; + + /* In multi-pass modes, we need a virtual block array for each component. */ + jvirt_barray_ptr whole_image[MAX_COMPONENTS]; + } my_coef_controller; + + typedef my_coef_controller * my_coef_ptr; + + + /* Forward declarations */ + METHODDEF(boolean) compress_data + JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); + #ifdef FULL_COEF_BUFFER_SUPPORTED + METHODDEF(boolean) compress_first_pass + JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); + METHODDEF(boolean) compress_output + JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf)); + #endif + + + LOCAL(void) + start_iMCU_row (j_compress_ptr cinfo) + /* Reset within-iMCU-row counters for a new row */ + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* In an interleaved scan, an MCU row is the same as an iMCU row. + * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. + * But at the bottom of the image, process only what's left. + */ + if (cinfo->comps_in_scan > 1) { + coef->MCU_rows_per_iMCU_row = 1; + } else { + if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; + else + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; + } + + coef->mcu_ctr = 0; + coef->MCU_vert_offset = 0; + } + + + /* + * Initialize for a processing pass. + */ + + METHODDEF(void) + start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + coef->iMCU_row_num = 0; + start_iMCU_row(cinfo); + + switch (pass_mode) { + case JBUF_PASS_THRU: + if (coef->whole_image[0] != NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + coef->pub.compress_data = compress_data; + break; + #ifdef FULL_COEF_BUFFER_SUPPORTED + case JBUF_SAVE_AND_PASS: + if (coef->whole_image[0] == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + coef->pub.compress_data = compress_first_pass; + break; + case JBUF_CRANK_DEST: + if (coef->whole_image[0] == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + coef->pub.compress_data = compress_output; + break; + #endif + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } + } + + + /* + * Process some data in the single-pass case. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the image. + * Returns TRUE if the iMCU row is completed, FALSE if suspended. + * + * NB: input_buf contains a plane for each component in image. + * For single pass, this is the same as the components in the scan. + */ + + METHODDEF(boolean) + compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + int blkn, bi, ci, yindex, yoffset, blockcnt; + JDIMENSION ypos, xpos; + jpeg_component_info *compptr; + + /* Loop to write as much as one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col; + MCU_col_num++) { + /* Determine where data comes from in input_buf and do the DCT thing. + * Each call on forward_DCT processes a horizontal row of DCT blocks + * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks + * sequentially. Dummy blocks at the right or bottom edge are filled in + * specially. The data in them does not matter for image reconstruction, + * so we fill them with values that will encode to the smallest amount of + * data, viz: all zeroes in the AC entries, DC entries equal to previous + * block's DC value. (Thanks to Thomas Kinsman for this idea.) + */ + blkn = 0; + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width + : compptr->last_col_width; + xpos = MCU_col_num * compptr->MCU_sample_width; + ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */ + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + if (coef->iMCU_row_num < last_iMCU_row || + yoffset+yindex < compptr->last_row_height) { + (*cinfo->fdct->forward_DCT) (cinfo, compptr, + input_buf[ci], coef->MCU_buffer[blkn], + ypos, xpos, (JDIMENSION) blockcnt); + if (blockcnt < compptr->MCU_width) { + /* Create some dummy blocks at the right edge of the image. */ + jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt], + (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK)); + for (bi = blockcnt; bi < compptr->MCU_width; bi++) { + coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0]; + } + } + } else { + /* Create a row of dummy blocks at the bottom of the image. */ + jzero_far((void FAR *) coef->MCU_buffer[blkn], + compptr->MCU_width * SIZEOF(JBLOCK)); + for (bi = 0; bi < compptr->MCU_width; bi++) { + coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0]; + } + } + blkn += compptr->MCU_width; + ypos += DCTSIZE; + } + } + /* Try to write the MCU. In event of a suspension failure, we will + * re-DCT the MCU on restart (a bit inefficient, could be fixed...) + */ + if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->mcu_ctr = MCU_col_num; + return FALSE; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->mcu_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + coef->iMCU_row_num++; + start_iMCU_row(cinfo); + return TRUE; + } + + + #ifdef FULL_COEF_BUFFER_SUPPORTED + + /* + * Process some data in the first pass of a multi-pass case. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the image. + * This amount of data is read from the source buffer, DCT'd and quantized, + * and saved into the virtual arrays. We also generate suitable dummy blocks + * as needed at the right and lower edges. (The dummy blocks are constructed + * in the virtual arrays, which have been padded appropriately.) This makes + * it possible for subsequent passes not to worry about real vs. dummy blocks. + * + * We must also emit the data to the entropy encoder. This is conveniently + * done by calling compress_output() after we've loaded the current strip + * of the virtual arrays. + * + * NB: input_buf contains a plane for each component in image. All + * components are DCT'd and loaded into the virtual arrays in this pass. + * However, it may be that only a subset of the components are emitted to + * the entropy encoder during this first pass; be careful about looking + * at the scan-dependent variables (MCU dimensions, etc). + */ + + METHODDEF(boolean) + compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + JDIMENSION blocks_across, MCUs_across, MCUindex; + int bi, ci, h_samp_factor, block_row, block_rows, ndummy; + JCOEF lastDC; + jpeg_component_info *compptr; + JBLOCKARRAY buffer; + JBLOCKROW thisblockrow, lastblockrow; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Align the virtual buffer for this component. */ + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + coef->iMCU_row_num * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, TRUE); + /* Count non-dummy DCT block rows in this iMCU row. */ + if (coef->iMCU_row_num < last_iMCU_row) + block_rows = compptr->v_samp_factor; + else { + /* NB: can't use last_row_height here, since may not be set! */ + block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (block_rows == 0) block_rows = compptr->v_samp_factor; + } + blocks_across = compptr->width_in_blocks; + h_samp_factor = compptr->h_samp_factor; + /* Count number of dummy blocks to be added at the right margin. */ + ndummy = (int) (blocks_across % h_samp_factor); + if (ndummy > 0) + ndummy = h_samp_factor - ndummy; + /* Perform DCT for all non-dummy blocks in this iMCU row. Each call + * on forward_DCT processes a complete horizontal row of DCT blocks. + */ + for (block_row = 0; block_row < block_rows; block_row++) { + thisblockrow = buffer[block_row]; + (*cinfo->fdct->forward_DCT) (cinfo, compptr, + input_buf[ci], thisblockrow, + (JDIMENSION) (block_row * DCTSIZE), + (JDIMENSION) 0, blocks_across); + if (ndummy > 0) { + /* Create dummy blocks at the right edge of the image. */ + thisblockrow += blocks_across; /* => first dummy block */ + jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); + lastDC = thisblockrow[-1][0]; + for (bi = 0; bi < ndummy; bi++) { + thisblockrow[bi][0] = lastDC; + } + } + } + /* If at end of image, create dummy block rows as needed. + * The tricky part here is that within each MCU, we want the DC values + * of the dummy blocks to match the last real block's DC value. + * This squeezes a few more bytes out of the resulting file... + */ + if (coef->iMCU_row_num == last_iMCU_row) { + blocks_across += ndummy; /* include lower right corner */ + MCUs_across = blocks_across / h_samp_factor; + for (block_row = block_rows; block_row < compptr->v_samp_factor; + block_row++) { + thisblockrow = buffer[block_row]; + lastblockrow = buffer[block_row-1]; + jzero_far((void FAR *) thisblockrow, + (size_t) (blocks_across * SIZEOF(JBLOCK))); + for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { + lastDC = lastblockrow[h_samp_factor-1][0]; + for (bi = 0; bi < h_samp_factor; bi++) { + thisblockrow[bi][0] = lastDC; + } + thisblockrow += h_samp_factor; /* advance to next MCU in row */ + lastblockrow += h_samp_factor; + } + } + } + } + /* NB: compress_output will increment iMCU_row_num if successful. + * A suspension return will result in redoing all the work above next time. + */ + + /* Emit data to the entropy encoder, sharing code with subsequent passes */ + return compress_output(cinfo, input_buf); + } + + + /* + * Process some data in subsequent passes of a multi-pass case. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the scan. + * The data is obtained from the virtual arrays and fed to the entropy coder. + * Returns TRUE if the iMCU row is completed, FALSE if suspended. + * + * NB: input_buf is ignored; it is likely to be a NULL pointer. + */ + + METHODDEF(boolean) + compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + int blkn, ci, xindex, yindex, yoffset; + JDIMENSION start_col; + JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; + JBLOCKROW buffer_ptr; + jpeg_component_info *compptr; + + /* Align the virtual buffers for the components used in this scan. + * NB: during first pass, this is safe only because the buffers will + * already be aligned properly, so jmemmgr.c won't need to do any I/O. + */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + buffer[ci] = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], + coef->iMCU_row_num * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } + + /* Loop to process one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; + MCU_col_num++) { + /* Construct list of pointers to DCT blocks belonging to this MCU */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + start_col = MCU_col_num * compptr->MCU_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + buffer_ptr = buffer[ci][yindex+yoffset] + start_col; + for (xindex = 0; xindex < compptr->MCU_width; xindex++) { + coef->MCU_buffer[blkn++] = buffer_ptr++; + } + } + } + /* Try to write the MCU. */ + if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->mcu_ctr = MCU_col_num; + return FALSE; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->mcu_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + coef->iMCU_row_num++; + start_iMCU_row(cinfo); + return TRUE; + } + + #endif /* FULL_COEF_BUFFER_SUPPORTED */ + + + /* + * Initialize coefficient buffer controller. + */ + + GLOBAL(void) + jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer) + { + my_coef_ptr coef; + + coef = (my_coef_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_coef_controller)); + cinfo->coef = (struct jpeg_c_coef_controller *) coef; + coef->pub.start_pass = start_pass_coef; + + /* Create the coefficient buffer. */ + if (need_full_buffer) { + #ifdef FULL_COEF_BUFFER_SUPPORTED + /* Allocate a full-image virtual array for each component, */ + /* padded to a multiple of samp_factor DCT blocks in each direction. */ + int ci; + jpeg_component_info *compptr; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + (JDIMENSION) jround_up((long) compptr->width_in_blocks, + (long) compptr->h_samp_factor), + (JDIMENSION) jround_up((long) compptr->height_in_blocks, + (long) compptr->v_samp_factor), + (JDIMENSION) compptr->v_samp_factor); + } + #else + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + #endif + } else { + /* We only need a single-MCU buffer. */ + JBLOCKROW buffer; + int i; + + buffer = (JBLOCKROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { + coef->MCU_buffer[i] = buffer + i; + } + coef->whole_image[0] = NULL; /* flag for no virtual arrays */ + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jccolor.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jccolor.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jccolor.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,459 ---- + /* + * jccolor.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains input colorspace conversion routines. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Private subobject */ + + typedef struct { + struct jpeg_color_converter pub; /* public fields */ + + /* Private state for RGB->YCC conversion */ + INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */ + } my_color_converter; + + typedef my_color_converter * my_cconvert_ptr; + + + /**************** RGB -> YCbCr conversion: most common case **************/ + + /* + * YCbCr is defined per CCIR 601-1, except that Cb and Cr are + * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. + * The conversion equations to be implemented are therefore + * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE + * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE + * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) + * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, + * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and + * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0) + * were not represented exactly. Now we sacrifice exact representation of + * maximum red and maximum blue in order to get exact grayscales. + * + * To avoid floating-point arithmetic, we represent the fractional constants + * as integers scaled up by 2^16 (about 4 digits precision); we have to divide + * the products by 2^16, with appropriate rounding, to get the correct answer. + * + * For even more speed, we avoid doing any multiplications in the inner loop + * by precalculating the constants times R,G,B for all possible values. + * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); + * for 12-bit samples it is still acceptable. It's not very reasonable for + * 16-bit samples, but if you want lossless storage you shouldn't be changing + * colorspace anyway. + * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included + * in the tables to save adding them separately in the inner loop. + */ + + #define SCALEBITS 16 /* speediest right-shift on some machines */ + #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS) + #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) + #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) + + /* We allocate one big table and divide it up into eight parts, instead of + * doing eight alloc_small requests. This lets us use a single table base + * address, which can be held in a register in the inner loops on many + * machines (more than can hold all eight addresses, anyway). + */ + + #define R_Y_OFF 0 /* offset to R => Y section */ + #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ + #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ + #define R_CB_OFF (3*(MAXJSAMPLE+1)) + #define G_CB_OFF (4*(MAXJSAMPLE+1)) + #define B_CB_OFF (5*(MAXJSAMPLE+1)) + #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ + #define G_CR_OFF (6*(MAXJSAMPLE+1)) + #define B_CR_OFF (7*(MAXJSAMPLE+1)) + #define TABLE_SIZE (8*(MAXJSAMPLE+1)) + + + /* + * Initialize for RGB->YCC colorspace conversion. + */ + + METHODDEF(void) + rgb_ycc_start (j_compress_ptr cinfo) + { + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + INT32 * rgb_ycc_tab; + INT32 i; + + /* Allocate and fill in the conversion tables. */ + cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (TABLE_SIZE * SIZEOF(INT32))); + + for (i = 0; i <= MAXJSAMPLE; i++) { + rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; + rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; + rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; + rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; + rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; + /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. + * This ensures that the maximum output will round to MAXJSAMPLE + * not MAXJSAMPLE+1, and thus that we don't have to range-limit. + */ + rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; + /* B=>Cb and R=>Cr tables are the same + rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; + */ + rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; + rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; + } + } + + + /* + * Convert some rows of samples to the JPEG colorspace. + * + * Note that we change from the application's interleaved-pixel format + * to our internal noninterleaved, one-plane-per-component format. + * The input buffer is therefore three times as wide as the output buffer. + * + * A starting row offset is provided only for the output buffer. The caller + * can easily adjust the passed input_buf value to accommodate any row + * offset required on that side. + */ + + METHODDEF(void) + rgb_ycc_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) + { + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int r, g, b; + register INT32 * ctab = cconvert->rgb_ycc_tab; + register JSAMPROW inptr; + register JSAMPROW outptr0, outptr1, outptr2; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr0 = output_buf[0][output_row]; + outptr1 = output_buf[1][output_row]; + outptr2 = output_buf[2][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + r = GETJSAMPLE(inptr[RGB_RED]); + g = GETJSAMPLE(inptr[RGB_GREEN]); + b = GETJSAMPLE(inptr[RGB_BLUE]); + inptr += RGB_PIXELSIZE; + /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations + * must be too; we do not need an explicit range-limiting operation. + * Hence the value being shifted is never negative, and we don't + * need the general RIGHT_SHIFT macro. + */ + /* Y */ + outptr0[col] = (JSAMPLE) + ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) + >> SCALEBITS); + /* Cb */ + outptr1[col] = (JSAMPLE) + ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) + >> SCALEBITS); + /* Cr */ + outptr2[col] = (JSAMPLE) + ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) + >> SCALEBITS); + } + } + } + + + /**************** Cases other than RGB -> YCbCr **************/ + + + /* + * Convert some rows of samples to the JPEG colorspace. + * This version handles RGB->grayscale conversion, which is the same + * as the RGB->Y portion of RGB->YCbCr. + * We assume rgb_ycc_start has been called (we only use the Y tables). + */ + + METHODDEF(void) + rgb_gray_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) + { + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int r, g, b; + register INT32 * ctab = cconvert->rgb_ycc_tab; + register JSAMPROW inptr; + register JSAMPROW outptr; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr = output_buf[0][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + r = GETJSAMPLE(inptr[RGB_RED]); + g = GETJSAMPLE(inptr[RGB_GREEN]); + b = GETJSAMPLE(inptr[RGB_BLUE]); + inptr += RGB_PIXELSIZE; + /* Y */ + outptr[col] = (JSAMPLE) + ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) + >> SCALEBITS); + } + } + } + + + /* + * Convert some rows of samples to the JPEG colorspace. + * This version handles Adobe-style CMYK->YCCK conversion, + * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same + * conversion as above, while passing K (black) unchanged. + * We assume rgb_ycc_start has been called. + */ + + METHODDEF(void) + cmyk_ycck_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) + { + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int r, g, b; + register INT32 * ctab = cconvert->rgb_ycc_tab; + register JSAMPROW inptr; + register JSAMPROW outptr0, outptr1, outptr2, outptr3; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr0 = output_buf[0][output_row]; + outptr1 = output_buf[1][output_row]; + outptr2 = output_buf[2][output_row]; + outptr3 = output_buf[3][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + r = MAXJSAMPLE - GETJSAMPLE(inptr[0]); + g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); + b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); + /* K passes through as-is */ + outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ + inptr += 4; + /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations + * must be too; we do not need an explicit range-limiting operation. + * Hence the value being shifted is never negative, and we don't + * need the general RIGHT_SHIFT macro. + */ + /* Y */ + outptr0[col] = (JSAMPLE) + ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) + >> SCALEBITS); + /* Cb */ + outptr1[col] = (JSAMPLE) + ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) + >> SCALEBITS); + /* Cr */ + outptr2[col] = (JSAMPLE) + ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) + >> SCALEBITS); + } + } + } + + + /* + * Convert some rows of samples to the JPEG colorspace. + * This version handles grayscale output with no conversion. + * The source can be either plain grayscale or YCbCr (since Y == gray). + */ + + METHODDEF(void) + grayscale_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) + { + register JSAMPROW inptr; + register JSAMPROW outptr; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->image_width; + int instride = cinfo->input_components; + + while (--num_rows >= 0) { + inptr = *input_buf++; + outptr = output_buf[0][output_row]; + output_row++; + for (col = 0; col < num_cols; col++) { + outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ + inptr += instride; + } + } + } + + + /* + * Convert some rows of samples to the JPEG colorspace. + * This version handles multi-component colorspaces without conversion. + * We assume input_components == num_components. + */ + + METHODDEF(void) + null_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) + { + register JSAMPROW inptr; + register JSAMPROW outptr; + register JDIMENSION col; + register int ci; + int nc = cinfo->num_components; + JDIMENSION num_cols = cinfo->image_width; + + while (--num_rows >= 0) { + /* It seems fastest to make a separate pass for each component. */ + for (ci = 0; ci < nc; ci++) { + inptr = *input_buf; + outptr = output_buf[ci][output_row]; + for (col = 0; col < num_cols; col++) { + outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ + inptr += nc; + } + } + input_buf++; + output_row++; + } + } + + + /* + * Empty method for start_pass. + */ + + METHODDEF(void) + null_method (j_compress_ptr cinfo) + { + /* no work needed */ + } + + + /* + * Module initialization routine for input colorspace conversion. + */ + + GLOBAL(void) + jinit_color_converter (j_compress_ptr cinfo) + { + my_cconvert_ptr cconvert; + + cconvert = (my_cconvert_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_color_converter)); + cinfo->cconvert = (struct jpeg_color_converter *) cconvert; + /* set start_pass to null method until we find out differently */ + cconvert->pub.start_pass = null_method; + + /* Make sure input_components agrees with in_color_space */ + switch (cinfo->in_color_space) { + case JCS_GRAYSCALE: + if (cinfo->input_components != 1) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + + case JCS_RGB: + #if RGB_PIXELSIZE != 3 + if (cinfo->input_components != RGB_PIXELSIZE) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + #endif /* else share code with YCbCr */ + + case JCS_YCbCr: + if (cinfo->input_components != 3) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + + case JCS_CMYK: + case JCS_YCCK: + if (cinfo->input_components != 4) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + + default: /* JCS_UNKNOWN can be anything */ + if (cinfo->input_components < 1) + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + break; + } + + /* Check num_components, set conversion method based on requested space */ + switch (cinfo->jpeg_color_space) { + case JCS_GRAYSCALE: + if (cinfo->num_components != 1) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_GRAYSCALE) + cconvert->pub.color_convert = grayscale_convert; + else if (cinfo->in_color_space == JCS_RGB) { + cconvert->pub.start_pass = rgb_ycc_start; + cconvert->pub.color_convert = rgb_gray_convert; + } else if (cinfo->in_color_space == JCS_YCbCr) + cconvert->pub.color_convert = grayscale_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_RGB: + if (cinfo->num_components != 3) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3) + cconvert->pub.color_convert = null_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_YCbCr: + if (cinfo->num_components != 3) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_RGB) { + cconvert->pub.start_pass = rgb_ycc_start; + cconvert->pub.color_convert = rgb_ycc_convert; + } else if (cinfo->in_color_space == JCS_YCbCr) + cconvert->pub.color_convert = null_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_CMYK: + if (cinfo->num_components != 4) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_CMYK) + cconvert->pub.color_convert = null_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_YCCK: + if (cinfo->num_components != 4) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + if (cinfo->in_color_space == JCS_CMYK) { + cconvert->pub.start_pass = rgb_ycc_start; + cconvert->pub.color_convert = cmyk_ycck_convert; + } else if (cinfo->in_color_space == JCS_YCCK) + cconvert->pub.color_convert = null_convert; + else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + default: /* allow null conversion of JCS_UNKNOWN */ + if (cinfo->jpeg_color_space != cinfo->in_color_space || + cinfo->num_components != cinfo->input_components) + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + cconvert->pub.color_convert = null_convert; + break; + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcdctmgr.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcdctmgr.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcdctmgr.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,387 ---- + /* + * jcdctmgr.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the forward-DCT management logic. + * This code selects a particular DCT implementation to be used, + * and it performs related housekeeping chores including coefficient + * quantization. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + + /* Private subobject for this module */ + + typedef struct { + struct jpeg_forward_dct pub; /* public fields */ + + /* Pointer to the DCT routine actually in use */ + forward_DCT_method_ptr do_dct; + + /* The actual post-DCT divisors --- not identical to the quant table + * entries, because of scaling (especially for an unnormalized DCT). + * Each table is given in normal array order. + */ + DCTELEM * divisors[NUM_QUANT_TBLS]; + + #ifdef DCT_FLOAT_SUPPORTED + /* Same as above for the floating-point case. */ + float_DCT_method_ptr do_float_dct; + FAST_FLOAT * float_divisors[NUM_QUANT_TBLS]; + #endif + } my_fdct_controller; + + typedef my_fdct_controller * my_fdct_ptr; + + + /* + * Initialize for a processing pass. + * Verify that all referenced Q-tables are present, and set up + * the divisor table for each one. + * In the current implementation, DCT of all components is done during + * the first pass, even if only some components will be output in the + * first scan. Hence all components should be examined here. + */ + + METHODDEF(void) + start_pass_fdctmgr (j_compress_ptr cinfo) + { + my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; + int ci, qtblno, i; + jpeg_component_info *compptr; + JQUANT_TBL * qtbl; + DCTELEM * dtbl; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + qtblno = compptr->quant_tbl_no; + /* Make sure specified quantization table is present */ + if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || + cinfo->quant_tbl_ptrs[qtblno] == NULL) + ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); + qtbl = cinfo->quant_tbl_ptrs[qtblno]; + /* Compute divisors for this quant table */ + /* We may do this more than once for same table, but it's not a big deal */ + switch (cinfo->dct_method) { + #ifdef DCT_ISLOW_SUPPORTED + case JDCT_ISLOW: + /* For LL&M IDCT method, divisors are equal to raw quantization + * coefficients multiplied by 8 (to counteract scaling). + */ + if (fdct->divisors[qtblno] == NULL) { + fdct->divisors[qtblno] = (DCTELEM *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + DCTSIZE2 * SIZEOF(DCTELEM)); + } + dtbl = fdct->divisors[qtblno]; + for (i = 0; i < DCTSIZE2; i++) { + dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3; + } + break; + #endif + #ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + { + /* For AA&N IDCT method, divisors are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + * We apply a further scale factor of 8. + */ + #define CONST_BITS 14 + static const INT16 aanscales[DCTSIZE2] = { + /* precomputed values scaled up by 14 bits */ + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, + 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, + 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, + 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, + 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 + }; + SHIFT_TEMPS + + if (fdct->divisors[qtblno] == NULL) { + fdct->divisors[qtblno] = (DCTELEM *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + DCTSIZE2 * SIZEOF(DCTELEM)); + } + dtbl = fdct->divisors[qtblno]; + for (i = 0; i < DCTSIZE2; i++) { + dtbl[i] = (DCTELEM) + DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], + (INT32) aanscales[i]), + CONST_BITS-3); + } + } + break; + #endif + #ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + { + /* For float AA&N IDCT method, divisors are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + * We apply a further scale factor of 8. + * What's actually stored is 1/divisor so that the inner loop can + * use a multiplication rather than a division. + */ + FAST_FLOAT * fdtbl; + int row, col; + static const double aanscalefactor[DCTSIZE] = { + 1.0, 1.387039845, 1.306562965, 1.175875602, + 1.0, 0.785694958, 0.541196100, 0.275899379 + }; + + if (fdct->float_divisors[qtblno] == NULL) { + fdct->float_divisors[qtblno] = (FAST_FLOAT *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + DCTSIZE2 * SIZEOF(FAST_FLOAT)); + } + fdtbl = fdct->float_divisors[qtblno]; + i = 0; + for (row = 0; row < DCTSIZE; row++) { + for (col = 0; col < DCTSIZE; col++) { + fdtbl[i] = (FAST_FLOAT) + (1.0 / (((double) qtbl->quantval[i] * + aanscalefactor[row] * aanscalefactor[col] * 8.0))); + i++; + } + } + } + break; + #endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + } + } + + + /* + * Perform forward DCT on one or more blocks of a component. + * + * The input samples are taken from the sample_data[] array starting at + * position start_row/start_col, and moving to the right for any additional + * blocks. The quantized coefficients are returned in coef_blocks[]. + */ + + METHODDEF(void) + forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY sample_data, JBLOCKROW coef_blocks, + JDIMENSION start_row, JDIMENSION start_col, + JDIMENSION num_blocks) + /* This version is used for integer DCT implementations. */ + { + /* This routine is heavily used, so it's worth coding it tightly. */ + my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; + forward_DCT_method_ptr do_dct = fdct->do_dct; + DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no]; + DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */ + JDIMENSION bi; + + sample_data += start_row; /* fold in the vertical offset once */ + + for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { + /* Load data into workspace, applying unsigned->signed conversion */ + { register DCTELEM *workspaceptr; + register JSAMPROW elemptr; + register int elemr; + + workspaceptr = workspace; + for (elemr = 0; elemr < DCTSIZE; elemr++) { + elemptr = sample_data[elemr] + start_col; + #if DCTSIZE == 8 /* unroll the inner loop */ + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + #else + { register int elemc; + for (elemc = DCTSIZE; elemc > 0; elemc--) { + *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; + } + } + #endif + } + } + + /* Perform the DCT */ + (*do_dct) (workspace); + + /* Quantize/descale the coefficients, and store into coef_blocks[] */ + { register DCTELEM temp, qval; + register int i; + register JCOEFPTR output_ptr = coef_blocks[bi]; + + for (i = 0; i < DCTSIZE2; i++) { + qval = divisors[i]; + temp = workspace[i]; + /* Divide the coefficient value by qval, ensuring proper rounding. + * Since C does not specify the direction of rounding for negative + * quotients, we have to force the dividend positive for portability. + * + * In most files, at least half of the output values will be zero + * (at default quantization settings, more like three-quarters...) + * so we should ensure that this case is fast. On many machines, + * a comparison is enough cheaper than a divide to make a special test + * a win. Since both inputs will be nonnegative, we need only test + * for a < b to discover whether a/b is 0. + * If your machine's division is fast enough, define FAST_DIVIDE. + */ + #ifdef FAST_DIVIDE + #define DIVIDE_BY(a,b) a /= b + #else + #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0 + #endif + if (temp < 0) { + temp = -temp; + temp += qval>>1; /* for rounding */ + DIVIDE_BY(temp, qval); + temp = -temp; + } else { + temp += qval>>1; /* for rounding */ + DIVIDE_BY(temp, qval); + } + output_ptr[i] = (JCOEF) temp; + } + } + } + } + + + #ifdef DCT_FLOAT_SUPPORTED + + METHODDEF(void) + forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY sample_data, JBLOCKROW coef_blocks, + JDIMENSION start_row, JDIMENSION start_col, + JDIMENSION num_blocks) + /* This version is used for floating-point DCT implementations. */ + { + /* This routine is heavily used, so it's worth coding it tightly. */ + my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; + float_DCT_method_ptr do_dct = fdct->do_float_dct; + FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no]; + FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */ + JDIMENSION bi; + + sample_data += start_row; /* fold in the vertical offset once */ + + for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { + /* Load data into workspace, applying unsigned->signed conversion */ + { register FAST_FLOAT *workspaceptr; + register JSAMPROW elemptr; + register int elemr; + + workspaceptr = workspace; + for (elemr = 0; elemr < DCTSIZE; elemr++) { + elemptr = sample_data[elemr] + start_col; + #if DCTSIZE == 8 /* unroll the inner loop */ + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + #else + { register int elemc; + for (elemc = DCTSIZE; elemc > 0; elemc--) { + *workspaceptr++ = (FAST_FLOAT) + (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); + } + } + #endif + } + } + + /* Perform the DCT */ + (*do_dct) (workspace); + + /* Quantize/descale the coefficients, and store into coef_blocks[] */ + { register FAST_FLOAT temp; + register int i; + register JCOEFPTR output_ptr = coef_blocks[bi]; + + for (i = 0; i < DCTSIZE2; i++) { + /* Apply the quantization and scaling factor */ + temp = workspace[i] * divisors[i]; + /* Round to nearest integer. + * Since C does not specify the direction of rounding for negative + * quotients, we have to force the dividend positive for portability. + * The maximum coefficient size is +-16K (for 12-bit data), so this + * code should work for either 16-bit or 32-bit ints. + */ + output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384); + } + } + } + } + + #endif /* DCT_FLOAT_SUPPORTED */ + + + /* + * Initialize FDCT manager. + */ + + GLOBAL(void) + jinit_forward_dct (j_compress_ptr cinfo) + { + my_fdct_ptr fdct; + int i; + + fdct = (my_fdct_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_fdct_controller)); + cinfo->fdct = (struct jpeg_forward_dct *) fdct; + fdct->pub.start_pass = start_pass_fdctmgr; + + switch (cinfo->dct_method) { + #ifdef DCT_ISLOW_SUPPORTED + case JDCT_ISLOW: + fdct->pub.forward_DCT = forward_DCT; + fdct->do_dct = jpeg_fdct_islow; + break; + #endif + #ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + fdct->pub.forward_DCT = forward_DCT; + fdct->do_dct = jpeg_fdct_ifast; + break; + #endif + #ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + fdct->pub.forward_DCT = forward_DCT_float; + fdct->do_float_dct = jpeg_fdct_float; + break; + #endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + + /* Mark divisor tables unallocated */ + for (i = 0; i < NUM_QUANT_TBLS; i++) { + fdct->divisors[i] = NULL; + #ifdef DCT_FLOAT_SUPPORTED + fdct->float_divisors[i] = NULL; + #endif + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jchuff.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jchuff.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jchuff.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,846 ---- + /* + * jchuff.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy encoding routines. + * + * Much of the complexity here has to do with supporting output suspension. + * If the data destination module demands suspension, we want to be able to + * back up to the start of the current MCU. To do this, we copy state + * variables into local working storage, and update them back to the + * permanent JPEG objects only upon successful completion of an MCU. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jchuff.h" /* Declarations shared with jcphuff.c */ + + + /* Expanded entropy encoder object for Huffman encoding. + * + * The savable_state subrecord contains fields that change within an MCU, + * but must not be updated permanently until we complete the MCU. + */ + + typedef struct { + INT32 put_buffer; /* current bit-accumulation buffer */ + int put_bits; /* # of bits now in it */ + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ + } savable_state; + + /* This macro is to work around compilers with missing or broken + * structure assignment. You'll need to fix this code if you have + * such a compiler and you change MAX_COMPS_IN_SCAN. + */ + + #ifndef NO_STRUCT_ASSIGN + #define ASSIGN_STATE(dest,src) ((dest) = (src)) + #else + #if MAX_COMPS_IN_SCAN == 4 + #define ASSIGN_STATE(dest,src) \ + ((dest).put_buffer = (src).put_buffer, \ + (dest).put_bits = (src).put_bits, \ + (dest).last_dc_val[0] = (src).last_dc_val[0], \ + (dest).last_dc_val[1] = (src).last_dc_val[1], \ + (dest).last_dc_val[2] = (src).last_dc_val[2], \ + (dest).last_dc_val[3] = (src).last_dc_val[3]) + #endif + #endif + + + typedef struct { + struct jpeg_entropy_encoder pub; /* public fields */ + + savable_state saved; /* Bit buffer & DC state at start of MCU */ + + /* These fields are NOT loaded into local working state. */ + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + int next_restart_num; /* next restart number to write (0-7) */ + + /* Pointers to derived tables (these workspaces have image lifespan) */ + c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; + c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]; + + #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */ + long * dc_count_ptrs[NUM_HUFF_TBLS]; + long * ac_count_ptrs[NUM_HUFF_TBLS]; + #endif + } huff_entropy_encoder; + + typedef huff_entropy_encoder * huff_entropy_ptr; + + /* Working state while writing an MCU. + * This struct contains all the fields that are needed by subroutines. + */ + + typedef struct { + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + savable_state cur; /* Current bit buffer & DC state */ + j_compress_ptr cinfo; /* dump_buffer needs access to this */ + } working_state; + + + /* Forward declarations */ + METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo)); + #ifdef ENTROPY_OPT_SUPPORTED + METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo)); + #endif + + + /* + * Initialize for a Huffman-compressed scan. + * If gather_statistics is TRUE, we do not output anything during the scan, + * just count the Huffman symbols used and generate Huffman code tables. + */ + + METHODDEF(void) + start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci, dctbl, actbl; + jpeg_component_info * compptr; + + if (gather_statistics) { + #ifdef ENTROPY_OPT_SUPPORTED + entropy->pub.encode_mcu = encode_mcu_gather; + entropy->pub.finish_pass = finish_pass_gather; + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else { + entropy->pub.encode_mcu = encode_mcu_huff; + entropy->pub.finish_pass = finish_pass_huff; + } + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + dctbl = compptr->dc_tbl_no; + actbl = compptr->ac_tbl_no; + /* Make sure requested tables are present */ + /* (In gather mode, tables need not be allocated yet) */ + if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS || + (cinfo->dc_huff_tbl_ptrs[dctbl] == NULL && !gather_statistics)) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); + if (actbl < 0 || actbl >= NUM_HUFF_TBLS || + (cinfo->ac_huff_tbl_ptrs[actbl] == NULL && !gather_statistics)) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); + if (gather_statistics) { + #ifdef ENTROPY_OPT_SUPPORTED + /* Allocate and zero the statistics tables */ + /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ + if (entropy->dc_count_ptrs[dctbl] == NULL) + entropy->dc_count_ptrs[dctbl] = (long *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 257 * SIZEOF(long)); + MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long)); + if (entropy->ac_count_ptrs[actbl] == NULL) + entropy->ac_count_ptrs[actbl] = (long *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 257 * SIZEOF(long)); + MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long)); + #endif + } else { + /* Compute derived values for Huffman tables */ + /* We may do this more than once for a table, but it's not expensive */ + jpeg_make_c_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl], + & entropy->dc_derived_tbls[dctbl]); + jpeg_make_c_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl], + & entropy->ac_derived_tbls[actbl]); + } + /* Initialize DC predictions to 0 */ + entropy->saved.last_dc_val[ci] = 0; + } + + /* Initialize bit buffer to empty */ + entropy->saved.put_buffer = 0; + entropy->saved.put_bits = 0; + + /* Initialize restart stuff */ + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num = 0; + } + + + /* + * Compute the derived values for a Huffman table. + * Note this is also used by jcphuff.c. + */ + + GLOBAL(void) + jpeg_make_c_derived_tbl (j_compress_ptr cinfo, JHUFF_TBL * htbl, + c_derived_tbl ** pdtbl) + { + c_derived_tbl *dtbl; + int p, i, l, lastp, si; + char huffsize[257]; + unsigned int huffcode[257]; + unsigned int code; + + /* Allocate a workspace if we haven't already done so. */ + if (*pdtbl == NULL) + *pdtbl = (c_derived_tbl *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(c_derived_tbl)); + dtbl = *pdtbl; + + /* Figure C.1: make table of Huffman code length for each symbol */ + /* Note that this is in code-length order. */ + + p = 0; + for (l = 1; l <= 16; l++) { + for (i = 1; i <= (int) htbl->bits[l]; i++) + huffsize[p++] = (char) l; + } + huffsize[p] = 0; + lastp = p; + + /* Figure C.2: generate the codes themselves */ + /* Note that this is in code-length order. */ + + code = 0; + si = huffsize[0]; + p = 0; + while (huffsize[p]) { + while (((int) huffsize[p]) == si) { + huffcode[p++] = code; + code++; + } + code <<= 1; + si++; + } + + /* Figure C.3: generate encoding tables */ + /* These are code and size indexed by symbol value */ + + /* Set any codeless symbols to have code length 0; + * this allows emit_bits to detect any attempt to emit such symbols. + */ + MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi)); + + for (p = 0; p < lastp; p++) { + dtbl->ehufco[htbl->huffval[p]] = huffcode[p]; + dtbl->ehufsi[htbl->huffval[p]] = huffsize[p]; + } + } + + + /* Outputting bytes to the file */ + + /* Emit a byte, taking 'action' if must suspend. */ + #define emit_byte(state,val,action) \ + { *(state)->next_output_byte++ = (JOCTET) (val); \ + if (--(state)->free_in_buffer == 0) \ + if (! dump_buffer(state)) \ + { action; } } + + + LOCAL(boolean) + dump_buffer (working_state * state) + /* Empty the output buffer; return TRUE if successful, FALSE if must suspend */ + { + struct jpeg_destination_mgr * dest = state->cinfo->dest; + + if (! (*dest->empty_output_buffer) (state->cinfo)) + return FALSE; + /* After a successful buffer dump, must reset buffer pointers */ + state->next_output_byte = dest->next_output_byte; + state->free_in_buffer = dest->free_in_buffer; + return TRUE; + } + + + /* Outputting bits to the file */ + + /* Only the right 24 bits of put_buffer are used; the valid bits are + * left-justified in this part. At most 16 bits can be passed to emit_bits + * in one call, and we never retain more than 7 bits in put_buffer + * between calls, so 24 bits are sufficient. + */ + + INLINE + LOCAL(boolean) + emit_bits (working_state * state, unsigned int code, int size) + /* Emit some bits; return TRUE if successful, FALSE if must suspend */ + { + /* This routine is heavily used, so it's worth coding tightly. */ + register INT32 put_buffer = (INT32) code; + register int put_bits = state->cur.put_bits; + + /* if size is 0, caller used an invalid Huffman table entry */ + if (size == 0) + ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE); + + put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */ + + put_bits += size; /* new number of bits in buffer */ + + put_buffer <<= 24 - put_bits; /* align incoming bits */ + + put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */ + + while (put_bits >= 8) { + int c = (int) ((put_buffer >> 16) & 0xFF); + + emit_byte(state, c, return FALSE); + if (c == 0xFF) { /* need to stuff a zero byte? */ + emit_byte(state, 0, return FALSE); + } + put_buffer <<= 8; + put_bits -= 8; + } + + state->cur.put_buffer = put_buffer; /* update state variables */ + state->cur.put_bits = put_bits; + + return TRUE; + } + + + LOCAL(boolean) + flush_bits (working_state * state) + { + if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */ + return FALSE; + state->cur.put_buffer = 0; /* and reset bit-buffer to empty */ + state->cur.put_bits = 0; + return TRUE; + } + + + /* Encode a single block's worth of coefficients */ + + LOCAL(boolean) + encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, + c_derived_tbl *dctbl, c_derived_tbl *actbl) + { + register int temp, temp2; + register int nbits; + register int k, r, i; + + /* Encode the DC coefficient difference per section F.1.2.1 */ + + temp = temp2 = block[0] - last_dc_val; + + if (temp < 0) { + temp = -temp; /* temp is abs value of input */ + /* For a negative input, want temp2 = bitwise complement of abs(input) */ + /* This code assumes we are on a two's complement machine */ + temp2--; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 0; + while (temp) { + nbits++; + temp >>= 1; + } + + /* Emit the Huffman-coded symbol for the number of bits */ + if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits])) + return FALSE; + + /* Emit that number of bits of the value, if positive, */ + /* or the complement of its magnitude, if negative. */ + if (nbits) /* emit_bits rejects calls with size 0 */ + if (! emit_bits(state, (unsigned int) temp2, nbits)) + return FALSE; + + /* Encode the AC coefficients per section F.1.2.2 */ + + r = 0; /* r = run length of zeros */ + + for (k = 1; k < DCTSIZE2; k++) { + if ((temp = block[jpeg_natural_order[k]]) == 0) { + r++; + } else { + /* if run length > 15, must emit special run-length-16 codes (0xF0) */ + while (r > 15) { + if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0])) + return FALSE; + r -= 16; + } + + temp2 = temp; + if (temp < 0) { + temp = -temp; /* temp is abs value of input */ + /* This code assumes we are on a two's complement machine */ + temp2--; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 1; /* there must be at least one 1 bit */ + while ((temp >>= 1)) + nbits++; + + /* Emit Huffman symbol for run length / number of bits */ + i = (r << 4) + nbits; + if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i])) + return FALSE; + + /* Emit that number of bits of the value, if positive, */ + /* or the complement of its magnitude, if negative. */ + if (! emit_bits(state, (unsigned int) temp2, nbits)) + return FALSE; + + r = 0; + } + } + + /* If the last coef(s) were zero, emit an end-of-block code */ + if (r > 0) + if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0])) + return FALSE; + + return TRUE; + } + + + /* + * Emit a restart marker & resynchronize predictions. + */ + + LOCAL(boolean) + emit_restart (working_state * state, int restart_num) + { + int ci; + + if (! flush_bits(state)) + return FALSE; + + emit_byte(state, 0xFF, return FALSE); + emit_byte(state, JPEG_RST0 + restart_num, return FALSE); + + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < state->cinfo->comps_in_scan; ci++) + state->cur.last_dc_val[ci] = 0; + + /* The restart counter is not updated until we successfully write the MCU. */ + + return TRUE; + } + + + /* + * Encode and output one MCU's worth of Huffman-compressed coefficients. + */ + + METHODDEF(boolean) + encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + working_state state; + int blkn, ci; + jpeg_component_info * compptr; + + /* Load up working state */ + state.next_output_byte = cinfo->dest->next_output_byte; + state.free_in_buffer = cinfo->dest->free_in_buffer; + ASSIGN_STATE(state.cur, entropy->saved); + state.cinfo = cinfo; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! emit_restart(&state, entropy->next_restart_num)) + return FALSE; + } + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + if (! encode_one_block(&state, + MCU_data[blkn][0], state.cur.last_dc_val[ci], + entropy->dc_derived_tbls[compptr->dc_tbl_no], + entropy->ac_derived_tbls[compptr->ac_tbl_no])) + return FALSE; + /* Update last_dc_val */ + state.cur.last_dc_val[ci] = MCU_data[blkn][0][0]; + } + + /* Completed MCU, so update state */ + cinfo->dest->next_output_byte = state.next_output_byte; + cinfo->dest->free_in_buffer = state.free_in_buffer; + ASSIGN_STATE(entropy->saved, state.cur); + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; + } + + + /* + * Finish up at the end of a Huffman-compressed scan. + */ + + METHODDEF(void) + finish_pass_huff (j_compress_ptr cinfo) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + working_state state; + + /* Load up working state ... flush_bits needs it */ + state.next_output_byte = cinfo->dest->next_output_byte; + state.free_in_buffer = cinfo->dest->free_in_buffer; + ASSIGN_STATE(state.cur, entropy->saved); + state.cinfo = cinfo; + + /* Flush out the last data */ + if (! flush_bits(&state)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + + /* Update state */ + cinfo->dest->next_output_byte = state.next_output_byte; + cinfo->dest->free_in_buffer = state.free_in_buffer; + ASSIGN_STATE(entropy->saved, state.cur); + } + + + /* + * Huffman coding optimization. + * + * This actually is optimization, in the sense that we find the best possible + * Huffman table(s) for the given data. We first scan the supplied data and + * count the number of uses of each symbol that is to be Huffman-coded. + * (This process must agree with the code above.) Then we build an + * optimal Huffman coding tree for the observed counts. + * + * The JPEG standard requires Huffman codes to be no more than 16 bits long. + * If some symbols have a very small but nonzero probability, the Huffman tree + * must be adjusted to meet the code length restriction. We currently use + * the adjustment method suggested in the JPEG spec. This method is *not* + * optimal; it may not choose the best possible limited-length code. But + * since the symbols involved are infrequently used, it's not clear that + * going to extra trouble is worthwhile. + */ + + #ifdef ENTROPY_OPT_SUPPORTED + + + /* Process a single block's worth of coefficients */ + + LOCAL(void) + htest_one_block (JCOEFPTR block, int last_dc_val, + long dc_counts[], long ac_counts[]) + { + register int temp; + register int nbits; + register int k, r; + + /* Encode the DC coefficient difference per section F.1.2.1 */ + + temp = block[0] - last_dc_val; + if (temp < 0) + temp = -temp; + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 0; + while (temp) { + nbits++; + temp >>= 1; + } + + /* Count the Huffman symbol for the number of bits */ + dc_counts[nbits]++; + + /* Encode the AC coefficients per section F.1.2.2 */ + + r = 0; /* r = run length of zeros */ + + for (k = 1; k < DCTSIZE2; k++) { + if ((temp = block[jpeg_natural_order[k]]) == 0) { + r++; + } else { + /* if run length > 15, must emit special run-length-16 codes (0xF0) */ + while (r > 15) { + ac_counts[0xF0]++; + r -= 16; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + if (temp < 0) + temp = -temp; + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 1; /* there must be at least one 1 bit */ + while ((temp >>= 1)) + nbits++; + + /* Count Huffman symbol for run length / number of bits */ + ac_counts[(r << 4) + nbits]++; + + r = 0; + } + } + + /* If the last coef(s) were zero, emit an end-of-block code */ + if (r > 0) + ac_counts[0]++; + } + + + /* + * Trial-encode one MCU's worth of Huffman-compressed coefficients. + * No data is actually output, so no suspension return is possible. + */ + + METHODDEF(boolean) + encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int blkn, ci; + jpeg_component_info * compptr; + + /* Take care of restart intervals if needed */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) + entropy->saved.last_dc_val[ci] = 0; + /* Update restart state */ + entropy->restarts_to_go = cinfo->restart_interval; + } + entropy->restarts_to_go--; + } + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + htest_one_block(MCU_data[blkn][0], entropy->saved.last_dc_val[ci], + entropy->dc_count_ptrs[compptr->dc_tbl_no], + entropy->ac_count_ptrs[compptr->ac_tbl_no]); + entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0]; + } + + return TRUE; + } + + + /* + * Generate the optimal coding for the given counts, fill htbl. + * Note this is also used by jcphuff.c. + */ + + GLOBAL(void) + jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]) + { + #define MAX_CLEN 32 /* assumed maximum initial code length */ + UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */ + int codesize[257]; /* codesize[k] = code length of symbol k */ + int others[257]; /* next symbol in current branch of tree */ + int c1, c2; + int p, i, j; + long v; + + /* This algorithm is explained in section K.2 of the JPEG standard */ + + MEMZERO(bits, SIZEOF(bits)); + MEMZERO(codesize, SIZEOF(codesize)); + for (i = 0; i < 257; i++) + others[i] = -1; /* init links to empty */ + + freq[256] = 1; /* make sure there is a nonzero count */ + /* Including the pseudo-symbol 256 in the Huffman procedure guarantees + * that no real symbol is given code-value of all ones, because 256 + * will be placed in the largest codeword category. + */ + + /* Huffman's basic algorithm to assign optimal code lengths to symbols */ + + for (;;) { + /* Find the smallest nonzero frequency, set c1 = its symbol */ + /* In case of ties, take the larger symbol number */ + c1 = -1; + v = 1000000000L; + for (i = 0; i <= 256; i++) { + if (freq[i] && freq[i] <= v) { + v = freq[i]; + c1 = i; + } + } + + /* Find the next smallest nonzero frequency, set c2 = its symbol */ + /* In case of ties, take the larger symbol number */ + c2 = -1; + v = 1000000000L; + for (i = 0; i <= 256; i++) { + if (freq[i] && freq[i] <= v && i != c1) { + v = freq[i]; + c2 = i; + } + } + + /* Done if we've merged everything into one frequency */ + if (c2 < 0) + break; + + /* Else merge the two counts/trees */ + freq[c1] += freq[c2]; + freq[c2] = 0; + + /* Increment the codesize of everything in c1's tree branch */ + codesize[c1]++; + while (others[c1] >= 0) { + c1 = others[c1]; + codesize[c1]++; + } + + others[c1] = c2; /* chain c2 onto c1's tree branch */ + + /* Increment the codesize of everything in c2's tree branch */ + codesize[c2]++; + while (others[c2] >= 0) { + c2 = others[c2]; + codesize[c2]++; + } + } + + /* Now count the number of symbols of each code length */ + for (i = 0; i <= 256; i++) { + if (codesize[i]) { + /* The JPEG standard seems to think that this can't happen, */ + /* but I'm paranoid... */ + if (codesize[i] > MAX_CLEN) + ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW); + + bits[codesize[i]]++; + } + } + + /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure + * Huffman procedure assigned any such lengths, we must adjust the coding. + * Here is what the JPEG spec says about how this next bit works: + * Since symbols are paired for the longest Huffman code, the symbols are + * removed from this length category two at a time. The prefix for the pair + * (which is one bit shorter) is allocated to one of the pair; then, + * skipping the BITS entry for that prefix length, a code word from the next + * shortest nonzero BITS entry is converted into a prefix for two code words + * one bit longer. + */ + + for (i = MAX_CLEN; i > 16; i--) { + while (bits[i] > 0) { + j = i - 2; /* find length of new prefix to be used */ + while (bits[j] == 0) + j--; + + bits[i] -= 2; /* remove two symbols */ + bits[i-1]++; /* one goes in this length */ + bits[j+1] += 2; /* two new symbols in this length */ + bits[j]--; /* symbol of this length is now a prefix */ + } + } + + /* Remove the count for the pseudo-symbol 256 from the largest codelength */ + while (bits[i] == 0) /* find largest codelength still in use */ + i--; + bits[i]--; + + /* Return final symbol counts (only for lengths 0..16) */ + MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits)); + + /* Return a list of the symbols sorted by code length */ + /* It's not real clear to me why we don't need to consider the codelength + * changes made above, but the JPEG spec seems to think this works. + */ + p = 0; + for (i = 1; i <= MAX_CLEN; i++) { + for (j = 0; j <= 255; j++) { + if (codesize[j] == i) { + htbl->huffval[p] = (UINT8) j; + p++; + } + } + } + + /* Set sent_table FALSE so updated table will be written to JPEG file. */ + htbl->sent_table = FALSE; + } + + + /* + * Finish up a statistics-gathering pass and create the new Huffman tables. + */ + + METHODDEF(void) + finish_pass_gather (j_compress_ptr cinfo) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci, dctbl, actbl; + jpeg_component_info * compptr; + JHUFF_TBL **htblptr; + boolean did_dc[NUM_HUFF_TBLS]; + boolean did_ac[NUM_HUFF_TBLS]; + + /* It's important not to apply jpeg_gen_optimal_table more than once + * per table, because it clobbers the input frequency counts! + */ + MEMZERO(did_dc, SIZEOF(did_dc)); + MEMZERO(did_ac, SIZEOF(did_ac)); + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + dctbl = compptr->dc_tbl_no; + actbl = compptr->ac_tbl_no; + if (! did_dc[dctbl]) { + htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl]; + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]); + did_dc[dctbl] = TRUE; + } + if (! did_ac[actbl]) { + htblptr = & cinfo->ac_huff_tbl_ptrs[actbl]; + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]); + did_ac[actbl] = TRUE; + } + } + } + + + #endif /* ENTROPY_OPT_SUPPORTED */ + + + /* + * Module initialization routine for Huffman entropy encoding. + */ + + GLOBAL(void) + jinit_huff_encoder (j_compress_ptr cinfo) + { + huff_entropy_ptr entropy; + int i; + + entropy = (huff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(huff_entropy_encoder)); + cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; + entropy->pub.start_pass = start_pass_huff; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; + #ifdef ENTROPY_OPT_SUPPORTED + entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL; + #endif + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jchuff.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jchuff.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jchuff.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,34 ---- + /* + * jchuff.h + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains declarations for Huffman entropy encoding routines + * that are shared between the sequential encoder (jchuff.c) and the + * progressive encoder (jcphuff.c). No other modules need to see these. + */ + + /* Derived data constructed for each Huffman table */ + + typedef struct { + unsigned int ehufco[256]; /* code for each symbol */ + char ehufsi[256]; /* length of code for each symbol */ + /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */ + } c_derived_tbl; + + /* Short forms of external names for systems with brain-damaged linkers. */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jpeg_make_c_derived_tbl jMkCDerived + #define jpeg_gen_optimal_table jGenOptTbl + #endif /* NEED_SHORT_EXTERNAL_NAMES */ + + /* Expand a Huffman table definition into the derived format */ + EXTERN(void) jpeg_make_c_derived_tbl + JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, c_derived_tbl ** pdtbl)); + + /* Generate an optimal table definition given the specified counts */ + EXTERN(void) jpeg_gen_optimal_table + JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])); Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcinit.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcinit.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcinit.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,72 ---- + /* + * jcinit.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains initialization logic for the JPEG compressor. + * This routine is in charge of selecting the modules to be executed and + * making an initialization call to each one. + * + * Logically, this code belongs in jcmaster.c. It's split out because + * linking this routine implies linking the entire compression library. + * For a transcoding-only application, we want to be able to use jcmaster.c + * without linking in the whole library. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * Master selection of compression modules. + * This is done once at the start of processing an image. We determine + * which modules will be used and give them appropriate initialization calls. + */ + + GLOBAL(void) + jinit_compress_master (j_compress_ptr cinfo) + { + /* Initialize master control (includes parameter checking/processing) */ + jinit_c_master_control(cinfo, FALSE /* full compression */); + + /* Preprocessing */ + if (! cinfo->raw_data_in) { + jinit_color_converter(cinfo); + jinit_downsampler(cinfo); + jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); + } + /* Forward DCT */ + jinit_forward_dct(cinfo); + /* Entropy encoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); + } else { + if (cinfo->progressive_mode) { + #ifdef C_PROGRESSIVE_SUPPORTED + jinit_phuff_encoder(cinfo); + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else + jinit_huff_encoder(cinfo); + } + + /* Need a full-image coefficient buffer in any multi-pass mode. */ + jinit_c_coef_controller(cinfo, + (cinfo->num_scans > 1 || cinfo->optimize_coding)); + jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); + + jinit_marker_writer(cinfo); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Write the datastream header (SOI) immediately. + * Frame and scan headers are postponed till later. + * This lets application insert special markers after the SOI. + */ + (*cinfo->marker->write_file_header) (cinfo); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmainct.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmainct.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmainct.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,293 ---- + /* + * jcmainct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the main buffer controller for compression. + * The main buffer lies between the pre-processor and the JPEG + * compressor proper; it holds downsampled data in the JPEG colorspace. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Note: currently, there is no operating mode in which a full-image buffer + * is needed at this step. If there were, that mode could not be used with + * "raw data" input, since this module is bypassed in that case. However, + * we've left the code here for possible use in special applications. + */ + #undef FULL_MAIN_BUFFER_SUPPORTED + + + /* Private buffer controller object */ + + typedef struct { + struct jpeg_c_main_controller pub; /* public fields */ + + JDIMENSION cur_iMCU_row; /* number of current iMCU row */ + JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */ + boolean suspended; /* remember if we suspended output */ + J_BUF_MODE pass_mode; /* current operating mode */ + + /* If using just a strip buffer, this points to the entire set of buffers + * (we allocate one for each component). In the full-image case, this + * points to the currently accessible strips of the virtual arrays. + */ + JSAMPARRAY buffer[MAX_COMPONENTS]; + + #ifdef FULL_MAIN_BUFFER_SUPPORTED + /* If using full-image storage, this array holds pointers to virtual-array + * control blocks for each component. Unused if not full-image storage. + */ + jvirt_sarray_ptr whole_image[MAX_COMPONENTS]; + #endif + } my_main_controller; + + typedef my_main_controller * my_main_ptr; + + + /* Forward declarations */ + METHODDEF(void) process_data_simple_main + JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, + JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); + #ifdef FULL_MAIN_BUFFER_SUPPORTED + METHODDEF(void) process_data_buffer_main + JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, + JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); + #endif + + + /* + * Initialize for a processing pass. + */ + + METHODDEF(void) + start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode) + { + my_main_ptr main = (my_main_ptr) cinfo->main; + + /* Do nothing in raw-data mode. */ + if (cinfo->raw_data_in) + return; + + main->cur_iMCU_row = 0; /* initialize counters */ + main->rowgroup_ctr = 0; + main->suspended = FALSE; + main->pass_mode = pass_mode; /* save mode for use by process_data */ + + switch (pass_mode) { + case JBUF_PASS_THRU: + #ifdef FULL_MAIN_BUFFER_SUPPORTED + if (main->whole_image[0] != NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + #endif + main->pub.process_data = process_data_simple_main; + break; + #ifdef FULL_MAIN_BUFFER_SUPPORTED + case JBUF_SAVE_SOURCE: + case JBUF_CRANK_DEST: + case JBUF_SAVE_AND_PASS: + if (main->whole_image[0] == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + main->pub.process_data = process_data_buffer_main; + break; + #endif + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } + } + + + /* + * Process some data. + * This routine handles the simple pass-through mode, + * where we have only a strip buffer. + */ + + METHODDEF(void) + process_data_simple_main (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail) + { + my_main_ptr main = (my_main_ptr) cinfo->main; + + while (main->cur_iMCU_row < cinfo->total_iMCU_rows) { + /* Read input data if we haven't filled the main buffer yet */ + if (main->rowgroup_ctr < DCTSIZE) + (*cinfo->prep->pre_process_data) (cinfo, + input_buf, in_row_ctr, in_rows_avail, + main->buffer, &main->rowgroup_ctr, + (JDIMENSION) DCTSIZE); + + /* If we don't have a full iMCU row buffered, return to application for + * more data. Note that preprocessor will always pad to fill the iMCU row + * at the bottom of the image. + */ + if (main->rowgroup_ctr != DCTSIZE) + return; + + /* Send the completed row to the compressor */ + if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) { + /* If compressor did not consume the whole row, then we must need to + * suspend processing and return to the application. In this situation + * we pretend we didn't yet consume the last input row; otherwise, if + * it happened to be the last row of the image, the application would + * think we were done. + */ + if (! main->suspended) { + (*in_row_ctr)--; + main->suspended = TRUE; + } + return; + } + /* We did finish the row. Undo our little suspension hack if a previous + * call suspended; then mark the main buffer empty. + */ + if (main->suspended) { + (*in_row_ctr)++; + main->suspended = FALSE; + } + main->rowgroup_ctr = 0; + main->cur_iMCU_row++; + } + } + + + #ifdef FULL_MAIN_BUFFER_SUPPORTED + + /* + * Process some data. + * This routine handles all of the modes that use a full-size buffer. + */ + + METHODDEF(void) + process_data_buffer_main (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail) + { + my_main_ptr main = (my_main_ptr) cinfo->main; + int ci; + jpeg_component_info *compptr; + boolean writing = (main->pass_mode != JBUF_CRANK_DEST); + + while (main->cur_iMCU_row < cinfo->total_iMCU_rows) { + /* Realign the virtual buffers if at the start of an iMCU row. */ + if (main->rowgroup_ctr == 0) { + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + main->buffer[ci] = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, main->whole_image[ci], + main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE), + (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing); + } + /* In a read pass, pretend we just read some source data. */ + if (! writing) { + *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE; + main->rowgroup_ctr = DCTSIZE; + } + } + + /* If a write pass, read input data until the current iMCU row is full. */ + /* Note: preprocessor will pad if necessary to fill the last iMCU row. */ + if (writing) { + (*cinfo->prep->pre_process_data) (cinfo, + input_buf, in_row_ctr, in_rows_avail, + main->buffer, &main->rowgroup_ctr, + (JDIMENSION) DCTSIZE); + /* Return to application if we need more data to fill the iMCU row. */ + if (main->rowgroup_ctr < DCTSIZE) + return; + } + + /* Emit data, unless this is a sink-only pass. */ + if (main->pass_mode != JBUF_SAVE_SOURCE) { + if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) { + /* If compressor did not consume the whole row, then we must need to + * suspend processing and return to the application. In this situation + * we pretend we didn't yet consume the last input row; otherwise, if + * it happened to be the last row of the image, the application would + * think we were done. + */ + if (! main->suspended) { + (*in_row_ctr)--; + main->suspended = TRUE; + } + return; + } + /* We did finish the row. Undo our little suspension hack if a previous + * call suspended; then mark the main buffer empty. + */ + if (main->suspended) { + (*in_row_ctr)++; + main->suspended = FALSE; + } + } + + /* If get here, we are done with this iMCU row. Mark buffer empty. */ + main->rowgroup_ctr = 0; + main->cur_iMCU_row++; + } + } + + #endif /* FULL_MAIN_BUFFER_SUPPORTED */ + + + /* + * Initialize main buffer controller. + */ + + GLOBAL(void) + jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer) + { + my_main_ptr main; + int ci; + jpeg_component_info *compptr; + + main = (my_main_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_main_controller)); + cinfo->main = (struct jpeg_c_main_controller *) main; + main->pub.start_pass = start_pass_main; + + /* We don't need to create a buffer in raw-data mode. */ + if (cinfo->raw_data_in) + return; + + /* Create the buffer. It holds downsampled data, so each component + * may be of a different size. + */ + if (need_full_buffer) { + #ifdef FULL_MAIN_BUFFER_SUPPORTED + /* Allocate a full-image virtual array for each component */ + /* Note we pad the bottom to a multiple of the iMCU height */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + main->whole_image[ci] = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + compptr->width_in_blocks * DCTSIZE, + (JDIMENSION) jround_up((long) compptr->height_in_blocks, + (long) compptr->v_samp_factor) * DCTSIZE, + (JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); + } + #else + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + #endif + } else { + #ifdef FULL_MAIN_BUFFER_SUPPORTED + main->whole_image[0] = NULL; /* flag for no virtual arrays */ + #endif + /* Allocate a strip buffer for each component */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + main->buffer[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + compptr->width_in_blocks * DCTSIZE, + (JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); + } + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmarker.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmarker.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmarker.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,641 ---- + /* + * jcmarker.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write JPEG datastream markers. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + typedef enum { /* JPEG marker codes */ + M_SOF0 = 0xc0, + M_SOF1 = 0xc1, + M_SOF2 = 0xc2, + M_SOF3 = 0xc3, + + M_SOF5 = 0xc5, + M_SOF6 = 0xc6, + M_SOF7 = 0xc7, + + M_JPG = 0xc8, + M_SOF9 = 0xc9, + M_SOF10 = 0xca, + M_SOF11 = 0xcb, + + M_SOF13 = 0xcd, + M_SOF14 = 0xce, + M_SOF15 = 0xcf, + + M_DHT = 0xc4, + + M_DAC = 0xcc, + + M_RST0 = 0xd0, + M_RST1 = 0xd1, + M_RST2 = 0xd2, + M_RST3 = 0xd3, + M_RST4 = 0xd4, + M_RST5 = 0xd5, + M_RST6 = 0xd6, + M_RST7 = 0xd7, + + M_SOI = 0xd8, + M_EOI = 0xd9, + M_SOS = 0xda, + M_DQT = 0xdb, + M_DNL = 0xdc, + M_DRI = 0xdd, + M_DHP = 0xde, + M_EXP = 0xdf, + + M_APP0 = 0xe0, + M_APP1 = 0xe1, + M_APP2 = 0xe2, + M_APP3 = 0xe3, + M_APP4 = 0xe4, + M_APP5 = 0xe5, + M_APP6 = 0xe6, + M_APP7 = 0xe7, + M_APP8 = 0xe8, + M_APP9 = 0xe9, + M_APP10 = 0xea, + M_APP11 = 0xeb, + M_APP12 = 0xec, + M_APP13 = 0xed, + M_APP14 = 0xee, + M_APP15 = 0xef, + + M_JPG0 = 0xf0, + M_JPG13 = 0xfd, + M_COM = 0xfe, + + M_TEM = 0x01, + + M_ERROR = 0x100 + } JPEG_MARKER; + + + /* + * Basic output routines. + * + * Note that we do not support suspension while writing a marker. + * Therefore, an application using suspension must ensure that there is + * enough buffer space for the initial markers (typ. 600-700 bytes) before + * calling jpeg_start_compress, and enough space to write the trailing EOI + * (a few bytes) before calling jpeg_finish_compress. Multipass compression + * modes are not supported at all with suspension, so those two are the only + * points where markers will be written. + */ + + LOCAL(void) + emit_byte (j_compress_ptr cinfo, int val) + /* Emit a byte */ + { + struct jpeg_destination_mgr * dest = cinfo->dest; + + *(dest->next_output_byte)++ = (JOCTET) val; + if (--dest->free_in_buffer == 0) { + if (! (*dest->empty_output_buffer) (cinfo)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } + } + + + LOCAL(void) + emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark) + /* Emit a marker code */ + { + emit_byte(cinfo, 0xFF); + emit_byte(cinfo, (int) mark); + } + + + LOCAL(void) + emit_2bytes (j_compress_ptr cinfo, int value) + /* Emit a 2-byte integer; these are always MSB first in JPEG files */ + { + emit_byte(cinfo, (value >> 8) & 0xFF); + emit_byte(cinfo, value & 0xFF); + } + + + /* + * Routines to write specific marker types. + */ + + LOCAL(int) + emit_dqt (j_compress_ptr cinfo, int index) + /* Emit a DQT marker */ + /* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */ + { + JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index]; + int prec; + int i; + + if (qtbl == NULL) + ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index); + + prec = 0; + for (i = 0; i < DCTSIZE2; i++) { + if (qtbl->quantval[i] > 255) + prec = 1; + } + + if (! qtbl->sent_table) { + emit_marker(cinfo, M_DQT); + + emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2); + + emit_byte(cinfo, index + (prec<<4)); + + for (i = 0; i < DCTSIZE2; i++) { + /* The table entries must be emitted in zigzag order. */ + unsigned int qval = qtbl->quantval[jpeg_natural_order[i]]; + if (prec) + emit_byte(cinfo, qval >> 8); + emit_byte(cinfo, qval & 0xFF); + } + + qtbl->sent_table = TRUE; + } + + return prec; + } + + + LOCAL(void) + emit_dht (j_compress_ptr cinfo, int index, boolean is_ac) + /* Emit a DHT marker */ + { + JHUFF_TBL * htbl; + int length, i; + + if (is_ac) { + htbl = cinfo->ac_huff_tbl_ptrs[index]; + index += 0x10; /* output index has AC bit set */ + } else { + htbl = cinfo->dc_huff_tbl_ptrs[index]; + } + + if (htbl == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index); + + if (! htbl->sent_table) { + emit_marker(cinfo, M_DHT); + + length = 0; + for (i = 1; i <= 16; i++) + length += htbl->bits[i]; + + emit_2bytes(cinfo, length + 2 + 1 + 16); + emit_byte(cinfo, index); + + for (i = 1; i <= 16; i++) + emit_byte(cinfo, htbl->bits[i]); + + for (i = 0; i < length; i++) + emit_byte(cinfo, htbl->huffval[i]); + + htbl->sent_table = TRUE; + } + } + + + LOCAL(void) + emit_dac (j_compress_ptr cinfo) + /* Emit a DAC marker */ + /* Since the useful info is so small, we want to emit all the tables in */ + /* one DAC marker. Therefore this routine does its own scan of the table. */ + { + #ifdef C_ARITH_CODING_SUPPORTED + char dc_in_use[NUM_ARITH_TBLS]; + char ac_in_use[NUM_ARITH_TBLS]; + int length, i; + jpeg_component_info *compptr; + + for (i = 0; i < NUM_ARITH_TBLS; i++) + dc_in_use[i] = ac_in_use[i] = 0; + + for (i = 0; i < cinfo->comps_in_scan; i++) { + compptr = cinfo->cur_comp_info[i]; + dc_in_use[compptr->dc_tbl_no] = 1; + ac_in_use[compptr->ac_tbl_no] = 1; + } + + length = 0; + for (i = 0; i < NUM_ARITH_TBLS; i++) + length += dc_in_use[i] + ac_in_use[i]; + + emit_marker(cinfo, M_DAC); + + emit_2bytes(cinfo, length*2 + 2); + + for (i = 0; i < NUM_ARITH_TBLS; i++) { + if (dc_in_use[i]) { + emit_byte(cinfo, i); + emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4)); + } + if (ac_in_use[i]) { + emit_byte(cinfo, i + 0x10); + emit_byte(cinfo, cinfo->arith_ac_K[i]); + } + } + #endif /* C_ARITH_CODING_SUPPORTED */ + } + + + LOCAL(void) + emit_dri (j_compress_ptr cinfo) + /* Emit a DRI marker */ + { + emit_marker(cinfo, M_DRI); + + emit_2bytes(cinfo, 4); /* fixed length */ + + emit_2bytes(cinfo, (int) cinfo->restart_interval); + } + + + LOCAL(void) + emit_sof (j_compress_ptr cinfo, JPEG_MARKER code) + /* Emit a SOF marker */ + { + int ci; + jpeg_component_info *compptr; + + emit_marker(cinfo, code); + + emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */ + + /* Make sure image isn't bigger than SOF field can handle */ + if ((long) cinfo->image_height > 65535L || + (long) cinfo->image_width > 65535L) + ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535); + + emit_byte(cinfo, cinfo->data_precision); + emit_2bytes(cinfo, (int) cinfo->image_height); + emit_2bytes(cinfo, (int) cinfo->image_width); + + emit_byte(cinfo, cinfo->num_components); + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + emit_byte(cinfo, compptr->component_id); + emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor); + emit_byte(cinfo, compptr->quant_tbl_no); + } + } + + + LOCAL(void) + emit_sos (j_compress_ptr cinfo) + /* Emit a SOS marker */ + { + int i, td, ta; + jpeg_component_info *compptr; + + emit_marker(cinfo, M_SOS); + + emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */ + + emit_byte(cinfo, cinfo->comps_in_scan); + + for (i = 0; i < cinfo->comps_in_scan; i++) { + compptr = cinfo->cur_comp_info[i]; + emit_byte(cinfo, compptr->component_id); + td = compptr->dc_tbl_no; + ta = compptr->ac_tbl_no; + if (cinfo->progressive_mode) { + /* Progressive mode: only DC or only AC tables are used in one scan; + * furthermore, Huffman coding of DC refinement uses no table at all. + * We emit 0 for unused field(s); this is recommended by the P&M text + * but does not seem to be specified in the standard. + */ + if (cinfo->Ss == 0) { + ta = 0; /* DC scan */ + if (cinfo->Ah != 0 && !cinfo->arith_code) + td = 0; /* no DC table either */ + } else { + td = 0; /* AC scan */ + } + } + emit_byte(cinfo, (td << 4) + ta); + } + + emit_byte(cinfo, cinfo->Ss); + emit_byte(cinfo, cinfo->Se); + emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al); + } + + + LOCAL(void) + emit_jfif_app0 (j_compress_ptr cinfo) + /* Emit a JFIF-compliant APP0 marker */ + { + /* + * Length of APP0 block (2 bytes) + * Block ID (4 bytes - ASCII "JFIF") + * Zero byte (1 byte to terminate the ID string) + * Version Major, Minor (2 bytes - 0x01, 0x01) + * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm) + * Xdpu (2 bytes - dots per unit horizontal) + * Ydpu (2 bytes - dots per unit vertical) + * Thumbnail X size (1 byte) + * Thumbnail Y size (1 byte) + */ + + emit_marker(cinfo, M_APP0); + + emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */ + + emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */ + emit_byte(cinfo, 0x46); + emit_byte(cinfo, 0x49); + emit_byte(cinfo, 0x46); + emit_byte(cinfo, 0); + /* We currently emit version code 1.01 since we use no 1.02 features. + * This may avoid complaints from some older decoders. + */ + emit_byte(cinfo, 1); /* Major version */ + emit_byte(cinfo, 1); /* Minor version */ + emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */ + emit_2bytes(cinfo, (int) cinfo->X_density); + emit_2bytes(cinfo, (int) cinfo->Y_density); + emit_byte(cinfo, 0); /* No thumbnail image */ + emit_byte(cinfo, 0); + } + + + LOCAL(void) + emit_adobe_app14 (j_compress_ptr cinfo) + /* Emit an Adobe APP14 marker */ + { + /* + * Length of APP14 block (2 bytes) + * Block ID (5 bytes - ASCII "Adobe") + * Version Number (2 bytes - currently 100) + * Flags0 (2 bytes - currently 0) + * Flags1 (2 bytes - currently 0) + * Color transform (1 byte) + * + * Although Adobe TN 5116 mentions Version = 101, all the Adobe files + * now in circulation seem to use Version = 100, so that's what we write. + * + * We write the color transform byte as 1 if the JPEG color space is + * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with + * whether the encoder performed a transformation, which is pretty useless. + */ + + emit_marker(cinfo, M_APP14); + + emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */ + + emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */ + emit_byte(cinfo, 0x64); + emit_byte(cinfo, 0x6F); + emit_byte(cinfo, 0x62); + emit_byte(cinfo, 0x65); + emit_2bytes(cinfo, 100); /* Version */ + emit_2bytes(cinfo, 0); /* Flags0 */ + emit_2bytes(cinfo, 0); /* Flags1 */ + switch (cinfo->jpeg_color_space) { + case JCS_YCbCr: + emit_byte(cinfo, 1); /* Color transform = 1 */ + break; + case JCS_YCCK: + emit_byte(cinfo, 2); /* Color transform = 2 */ + break; + default: + emit_byte(cinfo, 0); /* Color transform = 0 */ + break; + } + } + + + /* + * This routine is exported for possible use by applications. + * The intended use is to emit COM or APPn markers after calling + * jpeg_start_compress() and before the first jpeg_write_scanlines() call + * (hence, after write_file_header but before write_frame_header). + * Other uses are not guaranteed to produce desirable results. + */ + + METHODDEF(void) + write_any_marker (j_compress_ptr cinfo, int marker, + const JOCTET *dataptr, unsigned int datalen) + /* Emit an arbitrary marker with parameters */ + { + if (datalen <= (unsigned int) 65533) { /* safety check */ + emit_marker(cinfo, (JPEG_MARKER) marker); + + emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */ + + while (datalen--) { + emit_byte(cinfo, *dataptr); + dataptr++; + } + } + } + + + /* + * Write datastream header. + * This consists of an SOI and optional APPn markers. + * We recommend use of the JFIF marker, but not the Adobe marker, + * when using YCbCr or grayscale data. The JFIF marker should NOT + * be used for any other JPEG colorspace. The Adobe marker is helpful + * to distinguish RGB, CMYK, and YCCK colorspaces. + * Note that an application can write additional header markers after + * jpeg_start_compress returns. + */ + + METHODDEF(void) + write_file_header (j_compress_ptr cinfo) + { + emit_marker(cinfo, M_SOI); /* first the SOI */ + + if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */ + emit_jfif_app0(cinfo); + if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */ + emit_adobe_app14(cinfo); + } + + + /* + * Write frame header. + * This consists of DQT and SOFn markers. + * Note that we do not emit the SOF until we have emitted the DQT(s). + * This avoids compatibility problems with incorrect implementations that + * try to error-check the quant table numbers as soon as they see the SOF. + */ + + METHODDEF(void) + write_frame_header (j_compress_ptr cinfo) + { + int ci, prec; + boolean is_baseline; + jpeg_component_info *compptr; + + /* Emit DQT for each quantization table. + * Note that emit_dqt() suppresses any duplicate tables. + */ + prec = 0; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + prec += emit_dqt(cinfo, compptr->quant_tbl_no); + } + /* now prec is nonzero iff there are any 16-bit quant tables. */ + + /* Check for a non-baseline specification. + * Note we assume that Huffman table numbers won't be changed later. + */ + if (cinfo->arith_code || cinfo->progressive_mode || + cinfo->data_precision != 8) { + is_baseline = FALSE; + } else { + is_baseline = TRUE; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1) + is_baseline = FALSE; + } + if (prec && is_baseline) { + is_baseline = FALSE; + /* If it's baseline except for quantizer size, warn the user */ + TRACEMS(cinfo, 0, JTRC_16BIT_TABLES); + } + } + + /* Emit the proper SOF marker */ + if (cinfo->arith_code) { + emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */ + } else { + if (cinfo->progressive_mode) + emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */ + else if (is_baseline) + emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */ + else + emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */ + } + } + + + /* + * Write scan header. + * This consists of DHT or DAC markers, optional DRI, and SOS. + * Compressed data will be written following the SOS. + */ + + METHODDEF(void) + write_scan_header (j_compress_ptr cinfo) + { + int i; + jpeg_component_info *compptr; + + if (cinfo->arith_code) { + /* Emit arith conditioning info. We may have some duplication + * if the file has multiple scans, but it's so small it's hardly + * worth worrying about. + */ + emit_dac(cinfo); + } else { + /* Emit Huffman tables. + * Note that emit_dht() suppresses any duplicate tables. + */ + for (i = 0; i < cinfo->comps_in_scan; i++) { + compptr = cinfo->cur_comp_info[i]; + if (cinfo->progressive_mode) { + /* Progressive mode: only DC or only AC tables are used in one scan */ + if (cinfo->Ss == 0) { + if (cinfo->Ah == 0) /* DC needs no table for refinement scan */ + emit_dht(cinfo, compptr->dc_tbl_no, FALSE); + } else { + emit_dht(cinfo, compptr->ac_tbl_no, TRUE); + } + } else { + /* Sequential mode: need both DC and AC tables */ + emit_dht(cinfo, compptr->dc_tbl_no, FALSE); + emit_dht(cinfo, compptr->ac_tbl_no, TRUE); + } + } + } + + /* Emit DRI if required --- note that DRI value could change for each scan. + * If it doesn't, a tiny amount of space is wasted in multiple-scan files. + * We assume DRI will never be nonzero for one scan and zero for a later one. + */ + if (cinfo->restart_interval) + emit_dri(cinfo); + + emit_sos(cinfo); + } + + + /* + * Write datastream trailer. + */ + + METHODDEF(void) + write_file_trailer (j_compress_ptr cinfo) + { + emit_marker(cinfo, M_EOI); + } + + + /* + * Write an abbreviated table-specification datastream. + * This consists of SOI, DQT and DHT tables, and EOI. + * Any table that is defined and not marked sent_table = TRUE will be + * emitted. Note that all tables will be marked sent_table = TRUE at exit. + */ + + METHODDEF(void) + write_tables_only (j_compress_ptr cinfo) + { + int i; + + emit_marker(cinfo, M_SOI); + + for (i = 0; i < NUM_QUANT_TBLS; i++) { + if (cinfo->quant_tbl_ptrs[i] != NULL) + (void) emit_dqt(cinfo, i); + } + + if (! cinfo->arith_code) { + for (i = 0; i < NUM_HUFF_TBLS; i++) { + if (cinfo->dc_huff_tbl_ptrs[i] != NULL) + emit_dht(cinfo, i, FALSE); + if (cinfo->ac_huff_tbl_ptrs[i] != NULL) + emit_dht(cinfo, i, TRUE); + } + } + + emit_marker(cinfo, M_EOI); + } + + + /* + * Initialize the marker writer module. + */ + + GLOBAL(void) + jinit_marker_writer (j_compress_ptr cinfo) + { + /* Create the subobject */ + cinfo->marker = (struct jpeg_marker_writer *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(struct jpeg_marker_writer)); + /* Initialize method pointers */ + cinfo->marker->write_any_marker = write_any_marker; + cinfo->marker->write_file_header = write_file_header; + cinfo->marker->write_frame_header = write_frame_header; + cinfo->marker->write_scan_header = write_scan_header; + cinfo->marker->write_file_trailer = write_file_trailer; + cinfo->marker->write_tables_only = write_tables_only; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmaster.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmaster.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcmaster.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,578 ---- + /* + * jcmaster.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains master control logic for the JPEG compressor. + * These routines are concerned with parameter validation, initial setup, + * and inter-pass control (determining the number of passes and the work + * to be done in each pass). + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Private state */ + + typedef enum { + main_pass, /* input data, also do first output step */ + huff_opt_pass, /* Huffman code optimization pass */ + output_pass /* data output pass */ + } c_pass_type; + + typedef struct { + struct jpeg_comp_master pub; /* public fields */ + + c_pass_type pass_type; /* the type of the current pass */ + + int pass_number; /* # of passes completed */ + int total_passes; /* total # of passes needed */ + + int scan_number; /* current index in scan_info[] */ + } my_comp_master; + + typedef my_comp_master * my_master_ptr; + + + /* + * Support routines that do various essential calculations. + */ + + LOCAL(void) + initial_setup (j_compress_ptr cinfo) + /* Do computations that are needed before master selection phase */ + { + int ci; + jpeg_component_info *compptr; + long samplesperrow; + JDIMENSION jd_samplesperrow; + + /* Sanity check on image dimensions */ + if (cinfo->image_height <= 0 || cinfo->image_width <= 0 + || cinfo->num_components <= 0 || cinfo->input_components <= 0) + ERREXIT(cinfo, JERR_EMPTY_IMAGE); + + /* Make sure image isn't bigger than I can handle */ + if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || + (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) + ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); + + /* Width of an input scanline must be representable as JDIMENSION. */ + samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components; + jd_samplesperrow = (JDIMENSION) samplesperrow; + if ((long) jd_samplesperrow != samplesperrow) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + + /* For now, precision must match compiled-in value... */ + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + + /* Check that number of components won't exceed internal array sizes */ + if (cinfo->num_components > MAX_COMPONENTS) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPONENTS); + + /* Compute maximum sampling factors; check factor validity */ + cinfo->max_h_samp_factor = 1; + cinfo->max_v_samp_factor = 1; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || + compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) + ERREXIT(cinfo, JERR_BAD_SAMPLING); + cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, + compptr->h_samp_factor); + cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, + compptr->v_samp_factor); + } + + /* Compute dimensions of components */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Fill in the correct component_index value; don't rely on application */ + compptr->component_index = ci; + /* For compression, we never do DCT scaling. */ + compptr->DCT_scaled_size = DCTSIZE; + /* Size in DCT blocks */ + compptr->width_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, + (long) (cinfo->max_h_samp_factor * DCTSIZE)); + compptr->height_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, + (long) (cinfo->max_v_samp_factor * DCTSIZE)); + /* Size in samples */ + compptr->downsampled_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, + (long) cinfo->max_h_samp_factor); + compptr->downsampled_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, + (long) cinfo->max_v_samp_factor); + /* Mark component needed (this flag isn't actually used for compression) */ + compptr->component_needed = TRUE; + } + + /* Compute number of fully interleaved MCU rows (number of times that + * main controller will call coefficient controller). + */ + cinfo->total_iMCU_rows = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); + } + + + #ifdef C_MULTISCAN_FILES_SUPPORTED + + LOCAL(void) + validate_script (j_compress_ptr cinfo) + /* Verify that the scan script in cinfo->scan_info[] is valid; also + * determine whether it uses progressive JPEG, and set cinfo->progressive_mode. + */ + { + const jpeg_scan_info * scanptr; + int scanno, ncomps, ci, coefi, thisi; + int Ss, Se, Ah, Al; + boolean component_sent[MAX_COMPONENTS]; + #ifdef C_PROGRESSIVE_SUPPORTED + int * last_bitpos_ptr; + int last_bitpos[MAX_COMPONENTS][DCTSIZE2]; + /* -1 until that coefficient has been seen; then last Al for it */ + #endif + + if (cinfo->num_scans <= 0) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0); + + /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1; + * for progressive JPEG, no scan can have this. + */ + scanptr = cinfo->scan_info; + if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) { + #ifdef C_PROGRESSIVE_SUPPORTED + cinfo->progressive_mode = TRUE; + last_bitpos_ptr = & last_bitpos[0][0]; + for (ci = 0; ci < cinfo->num_components; ci++) + for (coefi = 0; coefi < DCTSIZE2; coefi++) + *last_bitpos_ptr++ = -1; + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else { + cinfo->progressive_mode = FALSE; + for (ci = 0; ci < cinfo->num_components; ci++) + component_sent[ci] = FALSE; + } + + for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) { + /* Validate component indexes */ + ncomps = scanptr->comps_in_scan; + if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN); + for (ci = 0; ci < ncomps; ci++) { + thisi = scanptr->component_index[ci]; + if (thisi < 0 || thisi >= cinfo->num_components) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); + /* Components must appear in SOF order within each scan */ + if (ci > 0 && thisi <= scanptr->component_index[ci-1]) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); + } + /* Validate progression parameters */ + Ss = scanptr->Ss; + Se = scanptr->Se; + Ah = scanptr->Ah; + Al = scanptr->Al; + if (cinfo->progressive_mode) { + #ifdef C_PROGRESSIVE_SUPPORTED + if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || + Ah < 0 || Ah > 13 || Al < 0 || Al > 13) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + if (Ss == 0) { + if (Se != 0) /* DC and AC together not OK */ + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } else { + if (ncomps != 1) /* AC scans must be for only one component */ + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } + for (ci = 0; ci < ncomps; ci++) { + last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0]; + if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */ + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + for (coefi = Ss; coefi <= Se; coefi++) { + if (last_bitpos_ptr[coefi] < 0) { + /* first scan of this coefficient */ + if (Ah != 0) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } else { + /* not first scan */ + if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + } + last_bitpos_ptr[coefi] = Al; + } + } + #endif + } else { + /* For sequential JPEG, all progression parameters must be these: */ + if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0) + ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); + /* Make sure components are not sent twice */ + for (ci = 0; ci < ncomps; ci++) { + thisi = scanptr->component_index[ci]; + if (component_sent[thisi]) + ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); + component_sent[thisi] = TRUE; + } + } + } + + /* Now verify that everything got sent. */ + if (cinfo->progressive_mode) { + #ifdef C_PROGRESSIVE_SUPPORTED + /* For progressive mode, we only check that at least some DC data + * got sent for each component; the spec does not require that all bits + * of all coefficients be transmitted. Would it be wiser to enforce + * transmission of all coefficient bits?? + */ + for (ci = 0; ci < cinfo->num_components; ci++) { + if (last_bitpos[ci][0] < 0) + ERREXIT(cinfo, JERR_MISSING_DATA); + } + #endif + } else { + for (ci = 0; ci < cinfo->num_components; ci++) { + if (! component_sent[ci]) + ERREXIT(cinfo, JERR_MISSING_DATA); + } + } + } + + #endif /* C_MULTISCAN_FILES_SUPPORTED */ + + + LOCAL(void) + select_scan_parameters (j_compress_ptr cinfo) + /* Set up the scan parameters for the current scan */ + { + int ci; + + #ifdef C_MULTISCAN_FILES_SUPPORTED + if (cinfo->scan_info != NULL) { + /* Prepare for current scan --- the script is already validated */ + my_master_ptr master = (my_master_ptr) cinfo->master; + const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number; + + cinfo->comps_in_scan = scanptr->comps_in_scan; + for (ci = 0; ci < scanptr->comps_in_scan; ci++) { + cinfo->cur_comp_info[ci] = + &cinfo->comp_info[scanptr->component_index[ci]]; + } + cinfo->Ss = scanptr->Ss; + cinfo->Se = scanptr->Se; + cinfo->Ah = scanptr->Ah; + cinfo->Al = scanptr->Al; + } + else + #endif + { + /* Prepare for single sequential-JPEG scan containing all components */ + if (cinfo->num_components > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPS_IN_SCAN); + cinfo->comps_in_scan = cinfo->num_components; + for (ci = 0; ci < cinfo->num_components; ci++) { + cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; + } + cinfo->Ss = 0; + cinfo->Se = DCTSIZE2-1; + cinfo->Ah = 0; + cinfo->Al = 0; + } + } + + + LOCAL(void) + per_scan_setup (j_compress_ptr cinfo) + /* Do computations that are needed before processing a JPEG scan */ + /* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */ + { + int ci, mcublks, tmp; + jpeg_component_info *compptr; + + if (cinfo->comps_in_scan == 1) { + + /* Noninterleaved (single-component) scan */ + compptr = cinfo->cur_comp_info[0]; + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = compptr->width_in_blocks; + cinfo->MCU_rows_in_scan = compptr->height_in_blocks; + + /* For noninterleaved scan, always one block per MCU */ + compptr->MCU_width = 1; + compptr->MCU_height = 1; + compptr->MCU_blocks = 1; + compptr->MCU_sample_width = DCTSIZE; + compptr->last_col_width = 1; + /* For noninterleaved scans, it is convenient to define last_row_height + * as the number of block rows present in the last iMCU row. + */ + tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (tmp == 0) tmp = compptr->v_samp_factor; + compptr->last_row_height = tmp; + + /* Prepare array describing MCU composition */ + cinfo->blocks_in_MCU = 1; + cinfo->MCU_membership[0] = 0; + + } else { + + /* Interleaved (multi-component) scan */ + if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, + MAX_COMPS_IN_SCAN); + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width, + (long) (cinfo->max_h_samp_factor*DCTSIZE)); + cinfo->MCU_rows_in_scan = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); + + cinfo->blocks_in_MCU = 0; + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Sampling factors give # of blocks of component in each MCU */ + compptr->MCU_width = compptr->h_samp_factor; + compptr->MCU_height = compptr->v_samp_factor; + compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; + compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE; + /* Figure number of non-dummy blocks in last MCU column & row */ + tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); + if (tmp == 0) tmp = compptr->MCU_width; + compptr->last_col_width = tmp; + tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); + if (tmp == 0) tmp = compptr->MCU_height; + compptr->last_row_height = tmp; + /* Prepare array describing MCU composition */ + mcublks = compptr->MCU_blocks; + if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) + ERREXIT(cinfo, JERR_BAD_MCU_SIZE); + while (mcublks-- > 0) { + cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; + } + } + + } + + /* Convert restart specified in rows to actual MCU count. */ + /* Note that count must fit in 16 bits, so we provide limiting. */ + if (cinfo->restart_in_rows > 0) { + long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row; + cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L); + } + } + + + /* + * Per-pass setup. + * This is called at the beginning of each pass. We determine which modules + * will be active during this pass and give them appropriate start_pass calls. + * We also set is_last_pass to indicate whether any more passes will be + * required. + */ + + METHODDEF(void) + prepare_for_pass (j_compress_ptr cinfo) + { + my_master_ptr master = (my_master_ptr) cinfo->master; + + switch (master->pass_type) { + case main_pass: + /* Initial pass: will collect input data, and do either Huffman + * optimization or data output for the first scan. + */ + select_scan_parameters(cinfo); + per_scan_setup(cinfo); + if (! cinfo->raw_data_in) { + (*cinfo->cconvert->start_pass) (cinfo); + (*cinfo->downsample->start_pass) (cinfo); + (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU); + } + (*cinfo->fdct->start_pass) (cinfo); + (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding); + (*cinfo->coef->start_pass) (cinfo, + (master->total_passes > 1 ? + JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); + (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); + if (cinfo->optimize_coding) { + /* No immediate data output; postpone writing frame/scan headers */ + master->pub.call_pass_startup = FALSE; + } else { + /* Will write frame/scan headers at first jpeg_write_scanlines call */ + master->pub.call_pass_startup = TRUE; + } + break; + #ifdef ENTROPY_OPT_SUPPORTED + case huff_opt_pass: + /* Do Huffman optimization for a scan after the first one. */ + select_scan_parameters(cinfo); + per_scan_setup(cinfo); + if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) { + (*cinfo->entropy->start_pass) (cinfo, TRUE); + (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); + master->pub.call_pass_startup = FALSE; + break; + } + /* Special case: Huffman DC refinement scans need no Huffman table + * and therefore we can skip the optimization pass for them. + */ + master->pass_type = output_pass; + master->pass_number++; + /*FALLTHROUGH*/ + #endif + case output_pass: + /* Do a data-output pass. */ + /* We need not repeat per-scan setup if prior optimization pass did it. */ + if (! cinfo->optimize_coding) { + select_scan_parameters(cinfo); + per_scan_setup(cinfo); + } + (*cinfo->entropy->start_pass) (cinfo, FALSE); + (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); + /* We emit frame/scan headers now */ + if (master->scan_number == 0) + (*cinfo->marker->write_frame_header) (cinfo); + (*cinfo->marker->write_scan_header) (cinfo); + master->pub.call_pass_startup = FALSE; + break; + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + } + + master->pub.is_last_pass = (master->pass_number == master->total_passes-1); + + /* Set up progress monitor's pass info if present */ + if (cinfo->progress != NULL) { + cinfo->progress->completed_passes = master->pass_number; + cinfo->progress->total_passes = master->total_passes; + } + } + + + /* + * Special start-of-pass hook. + * This is called by jpeg_write_scanlines if call_pass_startup is TRUE. + * In single-pass processing, we need this hook because we don't want to + * write frame/scan headers during jpeg_start_compress; we want to let the + * application write COM markers etc. between jpeg_start_compress and the + * jpeg_write_scanlines loop. + * In multi-pass processing, this routine is not used. + */ + + METHODDEF(void) + pass_startup (j_compress_ptr cinfo) + { + cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */ + + (*cinfo->marker->write_frame_header) (cinfo); + (*cinfo->marker->write_scan_header) (cinfo); + } + + + /* + * Finish up at end of pass. + */ + + METHODDEF(void) + finish_pass_master (j_compress_ptr cinfo) + { + my_master_ptr master = (my_master_ptr) cinfo->master; + + /* The entropy coder always needs an end-of-pass call, + * either to analyze statistics or to flush its output buffer. + */ + (*cinfo->entropy->finish_pass) (cinfo); + + /* Update state for next pass */ + switch (master->pass_type) { + case main_pass: + /* next pass is either output of scan 0 (after optimization) + * or output of scan 1 (if no optimization). + */ + master->pass_type = output_pass; + if (! cinfo->optimize_coding) + master->scan_number++; + break; + case huff_opt_pass: + /* next pass is always output of current scan */ + master->pass_type = output_pass; + break; + case output_pass: + /* next pass is either optimization or output of next scan */ + if (cinfo->optimize_coding) + master->pass_type = huff_opt_pass; + master->scan_number++; + break; + } + + master->pass_number++; + } + + + /* + * Initialize master compression control. + */ + + GLOBAL(void) + jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) + { + my_master_ptr master; + + master = (my_master_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_comp_master)); + cinfo->master = (struct jpeg_comp_master *) master; + master->pub.prepare_for_pass = prepare_for_pass; + master->pub.pass_startup = pass_startup; + master->pub.finish_pass = finish_pass_master; + master->pub.is_last_pass = FALSE; + + /* Validate parameters, determine derived values */ + initial_setup(cinfo); + + if (cinfo->scan_info != NULL) { + #ifdef C_MULTISCAN_FILES_SUPPORTED + validate_script(cinfo); + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else { + cinfo->progressive_mode = FALSE; + cinfo->num_scans = 1; + } + + if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */ + cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */ + + /* Initialize my private state */ + if (transcode_only) { + /* no main pass in transcoding */ + if (cinfo->optimize_coding) + master->pass_type = huff_opt_pass; + else + master->pass_type = output_pass; + } else { + /* for normal compression, first pass is always this type: */ + master->pass_type = main_pass; + } + master->scan_number = 0; + master->pass_number = 0; + if (cinfo->optimize_coding) + master->total_passes = cinfo->num_scans * 2; + else + master->total_passes = cinfo->num_scans; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcomapi.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcomapi.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcomapi.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,94 ---- + /* + * jcomapi.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface routines that are used for both + * compression and decompression. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * Abort processing of a JPEG compression or decompression operation, + * but don't destroy the object itself. + * + * For this, we merely clean up all the nonpermanent memory pools. + * Note that temp files (virtual arrays) are not allowed to belong to + * the permanent pool, so we will be able to close all temp files here. + * Closing a data source or destination, if necessary, is the application's + * responsibility. + */ + + GLOBAL(void) + jpeg_abort (j_common_ptr cinfo) + { + int pool; + + /* Releasing pools in reverse order might help avoid fragmentation + * with some (brain-damaged) malloc libraries. + */ + for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { + (*cinfo->mem->free_pool) (cinfo, pool); + } + + /* Reset overall state for possible reuse of object */ + cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START); + } + + + /* + * Destruction of a JPEG object. + * + * Everything gets deallocated except the master jpeg_compress_struct itself + * and the error manager struct. Both of these are supplied by the application + * and must be freed, if necessary, by the application. (Often they are on + * the stack and so don't need to be freed anyway.) + * Closing a data source or destination, if necessary, is the application's + * responsibility. + */ + + GLOBAL(void) + jpeg_destroy (j_common_ptr cinfo) + { + /* We need only tell the memory manager to release everything. */ + /* NB: mem pointer is NULL if memory mgr failed to initialize. */ + if (cinfo->mem != NULL) + (*cinfo->mem->self_destruct) (cinfo); + cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ + cinfo->global_state = 0; /* mark it destroyed */ + } + + + /* + * Convenience routines for allocating quantization and Huffman tables. + * (Would jutils.c be a more reasonable place to put these?) + */ + + GLOBAL(JQUANT_TBL *) + jpeg_alloc_quant_table (j_common_ptr cinfo) + { + JQUANT_TBL *tbl; + + tbl = (JQUANT_TBL *) + (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); + tbl->sent_table = FALSE; /* make sure this is false in any new table */ + return tbl; + } + + + GLOBAL(JHUFF_TBL *) + jpeg_alloc_huff_table (j_common_ptr cinfo) + { + JHUFF_TBL *tbl; + + tbl = (JHUFF_TBL *) + (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); + tbl->sent_table = FALSE; /* make sure this is false in any new table */ + return tbl; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jconfig.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jconfig.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jconfig.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,45 ---- + /* jconfig.h. Generated automatically by configure. */ + /* jconfig.cfg --- source file edited by configure script */ + /* see jconfig.doc for explanations */ + + #define HAVE_PROTOTYPES + #define HAVE_UNSIGNED_CHAR + #define HAVE_UNSIGNED_SHORT + #undef void + #undef const + #undef CHAR_IS_UNSIGNED + #define HAVE_STDDEF_H + #define HAVE_STDLIB_H + #undef NEED_BSD_STRINGS + #undef NEED_SYS_TYPES_H + #undef NEED_FAR_POINTERS + #undef NEED_SHORT_EXTERNAL_NAMES + /* Define this if you get warnings about undefined structures. */ + #undef INCOMPLETE_TYPES_BROKEN + + #ifdef JPEG_INTERNALS + + #undef RIGHT_SHIFT_IS_UNSIGNED + #define INLINE inline + /* These are for configuring the JPEG memory manager. */ + #undef DEFAULT_MAX_MEM + #undef NO_MKTEMP + + #endif /* JPEG_INTERNALS */ + + #ifdef JPEG_CJPEG_DJPEG + + #define BMP_SUPPORTED /* BMP image file format */ + #define GIF_SUPPORTED /* GIF image file format */ + #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ + #undef RLE_SUPPORTED /* Utah RLE image file format */ + #define TARGA_SUPPORTED /* Targa image file format */ + + #undef TWO_FILE_COMMANDLINE + #undef NEED_SIGNAL_CATCHER + #undef DONT_USE_B_MODE + + /* Define this if you want percent-done progress reports from cjpeg/djpeg. */ + #undef PROGRESS_REPORT + + #endif /* JPEG_CJPEG_DJPEG */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcparam.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcparam.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcparam.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,574 ---- + /* + * jcparam.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains optional default-setting code for the JPEG compressor. + * Applications do not have to use this file, but those that don't use it + * must know a lot more about the innards of the JPEG code. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * Quantization table setup routines + */ + + GLOBAL(void) + jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, + const unsigned int *basic_table, + int scale_factor, boolean force_baseline) + /* Define a quantization table equal to the basic_table times + * a scale factor (given as a percentage). + * If force_baseline is TRUE, the computed quantization table entries + * are limited to 1..255 for JPEG baseline compatibility. + */ + { + JQUANT_TBL ** qtblptr = & cinfo->quant_tbl_ptrs[which_tbl]; + int i; + long temp; + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + if (*qtblptr == NULL) + *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo); + + for (i = 0; i < DCTSIZE2; i++) { + temp = ((long) basic_table[i] * scale_factor + 50L) / 100L; + /* limit the values to the valid range */ + if (temp <= 0L) temp = 1L; + if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */ + if (force_baseline && temp > 255L) + temp = 255L; /* limit to baseline range if requested */ + (*qtblptr)->quantval[i] = (UINT16) temp; + } + + /* Initialize sent_table FALSE so table will be written to JPEG file. */ + (*qtblptr)->sent_table = FALSE; + } + + + GLOBAL(void) + jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, + boolean force_baseline) + /* Set or change the 'quality' (quantization) setting, using default tables + * and a straight percentage-scaling quality scale. In most cases it's better + * to use jpeg_set_quality (below); this entry point is provided for + * applications that insist on a linear percentage scaling. + */ + { + /* These are the sample quantization tables given in JPEG spec section K.1. + * The spec says that the values given produce "good" quality, and + * when divided by 2, "very good" quality. + */ + static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { + 16, 11, 10, 16, 24, 40, 51, 61, + 12, 12, 14, 19, 26, 58, 60, 55, + 14, 13, 16, 24, 40, 57, 69, 56, + 14, 17, 22, 29, 51, 87, 80, 62, + 18, 22, 37, 56, 68, 109, 103, 77, + 24, 35, 55, 64, 81, 104, 113, 92, + 49, 64, 78, 87, 103, 121, 120, 101, + 72, 92, 95, 98, 112, 100, 103, 99 + }; + static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { + 17, 18, 24, 47, 99, 99, 99, 99, + 18, 21, 26, 66, 99, 99, 99, 99, + 24, 26, 56, 99, 99, 99, 99, 99, + 47, 66, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99 + }; + + /* Set up two quantization tables using the specified scaling */ + jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, + scale_factor, force_baseline); + jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, + scale_factor, force_baseline); + } + + + GLOBAL(int) + jpeg_quality_scaling (int quality) + /* Convert a user-specified quality rating to a percentage scaling factor + * for an underlying quantization table, using our recommended scaling curve. + * The input 'quality' factor should be 0 (terrible) to 100 (very good). + */ + { + /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */ + if (quality <= 0) quality = 1; + if (quality > 100) quality = 100; + + /* The basic table is used as-is (scaling 100) for a quality of 50. + * Qualities 50..100 are converted to scaling percentage 200 - 2*Q; + * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table + * to make all the table entries 1 (hence, minimum quantization loss). + * Qualities 1..50 are converted to scaling percentage 5000/Q. + */ + if (quality < 50) + quality = 5000 / quality; + else + quality = 200 - quality*2; + + return quality; + } + + + GLOBAL(void) + jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) + /* Set or change the 'quality' (quantization) setting, using default tables. + * This is the standard quality-adjusting entry point for typical user + * interfaces; only those who want detailed control over quantization tables + * would use the preceding three routines directly. + */ + { + /* Convert user 0-100 rating to percentage scaling */ + quality = jpeg_quality_scaling(quality); + + /* Set up standard quality tables */ + jpeg_set_linear_quality(cinfo, quality, force_baseline); + } + + + /* + * Huffman table setup routines + */ + + LOCAL(void) + add_huff_table (j_compress_ptr cinfo, + JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) + /* Define a Huffman table */ + { + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + + MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); + MEMCOPY((*htblptr)->huffval, val, SIZEOF((*htblptr)->huffval)); + + /* Initialize sent_table FALSE so table will be written to JPEG file. */ + (*htblptr)->sent_table = FALSE; + } + + + LOCAL(void) + std_huff_tables (j_compress_ptr cinfo) + /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ + /* IMPORTANT: these are only valid for 8-bit data precision! */ + { + static const UINT8 bits_dc_luminance[17] = + { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; + static const UINT8 val_dc_luminance[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + + static const UINT8 bits_dc_chrominance[17] = + { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; + static const UINT8 val_dc_chrominance[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + + static const UINT8 bits_ac_luminance[17] = + { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; + static const UINT8 val_ac_luminance[] = + { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, + 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, + 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, + 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, + 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, + 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, + 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, + 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa }; + + static const UINT8 bits_ac_chrominance[17] = + { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; + static const UINT8 val_ac_chrominance[] = + { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, + 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, + 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, + 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, + 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, + 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, + 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, + 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, + 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, + 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa }; + + add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0], + bits_dc_luminance, val_dc_luminance); + add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0], + bits_ac_luminance, val_ac_luminance); + add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1], + bits_dc_chrominance, val_dc_chrominance); + add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1], + bits_ac_chrominance, val_ac_chrominance); + } + + + /* + * Default parameter setup for compression. + * + * Applications that don't choose to use this routine must do their + * own setup of all these parameters. Alternately, you can call this + * to establish defaults and then alter parameters selectively. This + * is the recommended approach since, if we add any new parameters, + * your code will still work (they'll be set to reasonable defaults). + */ + + GLOBAL(void) + jpeg_set_defaults (j_compress_ptr cinfo) + { + int i; + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* Allocate comp_info array large enough for maximum component count. + * Array is made permanent in case application wants to compress + * multiple images at same param settings. + */ + if (cinfo->comp_info == NULL) + cinfo->comp_info = (jpeg_component_info *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + MAX_COMPONENTS * SIZEOF(jpeg_component_info)); + + /* Initialize everything not dependent on the color space */ + + cinfo->data_precision = BITS_IN_JSAMPLE; + /* Set up two quantization tables using default quality of 75 */ + jpeg_set_quality(cinfo, 75, TRUE); + /* Set up two Huffman tables */ + std_huff_tables(cinfo); + + /* Initialize default arithmetic coding conditioning */ + for (i = 0; i < NUM_ARITH_TBLS; i++) { + cinfo->arith_dc_L[i] = 0; + cinfo->arith_dc_U[i] = 1; + cinfo->arith_ac_K[i] = 5; + } + + /* Default is no multiple-scan output */ + cinfo->scan_info = NULL; + cinfo->num_scans = 0; + + /* Expect normal source image, not raw downsampled data */ + cinfo->raw_data_in = FALSE; + + /* Use Huffman coding, not arithmetic coding, by default */ + cinfo->arith_code = FALSE; + + /* By default, don't do extra passes to optimize entropy coding */ + cinfo->optimize_coding = FALSE; + /* The standard Huffman tables are only valid for 8-bit data precision. + * If the precision is higher, force optimization on so that usable + * tables will be computed. This test can be removed if default tables + * are supplied that are valid for the desired precision. + */ + if (cinfo->data_precision > 8) + cinfo->optimize_coding = TRUE; + + /* By default, use the simpler non-cosited sampling alignment */ + cinfo->CCIR601_sampling = FALSE; + + /* No input smoothing */ + cinfo->smoothing_factor = 0; + + /* DCT algorithm preference */ + cinfo->dct_method = JDCT_DEFAULT; + + /* No restart markers */ + cinfo->restart_interval = 0; + cinfo->restart_in_rows = 0; + + /* Fill in default JFIF marker parameters. Note that whether the marker + * will actually be written is determined by jpeg_set_colorspace. + */ + cinfo->density_unit = 0; /* Pixel size is unknown by default */ + cinfo->X_density = 1; /* Pixel aspect ratio is square by default */ + cinfo->Y_density = 1; + + /* Choose JPEG colorspace based on input space, set defaults accordingly */ + + jpeg_default_colorspace(cinfo); + } + + + /* + * Select an appropriate JPEG colorspace for in_color_space. + */ + + GLOBAL(void) + jpeg_default_colorspace (j_compress_ptr cinfo) + { + switch (cinfo->in_color_space) { + case JCS_GRAYSCALE: + jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); + break; + case JCS_RGB: + jpeg_set_colorspace(cinfo, JCS_YCbCr); + break; + case JCS_YCbCr: + jpeg_set_colorspace(cinfo, JCS_YCbCr); + break; + case JCS_CMYK: + jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */ + break; + case JCS_YCCK: + jpeg_set_colorspace(cinfo, JCS_YCCK); + break; + case JCS_UNKNOWN: + jpeg_set_colorspace(cinfo, JCS_UNKNOWN); + break; + default: + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); + } + } + + + /* + * Set the JPEG colorspace, and choose colorspace-dependent default values. + */ + + GLOBAL(void) + jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) + { + jpeg_component_info * compptr; + int ci; + + #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \ + (compptr = &cinfo->comp_info[index], \ + compptr->component_id = (id), \ + compptr->h_samp_factor = (hsamp), \ + compptr->v_samp_factor = (vsamp), \ + compptr->quant_tbl_no = (quant), \ + compptr->dc_tbl_no = (dctbl), \ + compptr->ac_tbl_no = (actbl) ) + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* For all colorspaces, we use Q and Huff tables 0 for luminance components, + * tables 1 for chrominance components. + */ + + cinfo->jpeg_color_space = colorspace; + + cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */ + cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */ + + switch (colorspace) { + case JCS_GRAYSCALE: + cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ + cinfo->num_components = 1; + /* JFIF specifies component ID 1 */ + SET_COMP(0, 1, 1,1, 0, 0,0); + break; + case JCS_RGB: + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ + cinfo->num_components = 3; + SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0); + SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); + SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0); + break; + case JCS_YCbCr: + cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ + cinfo->num_components = 3; + /* JFIF specifies component IDs 1,2,3 */ + /* We default to 2x2 subsamples of chrominance */ + SET_COMP(0, 1, 2,2, 0, 0,0); + SET_COMP(1, 2, 1,1, 1, 1,1); + SET_COMP(2, 3, 1,1, 1, 1,1); + break; + case JCS_CMYK: + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */ + cinfo->num_components = 4; + SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0); + SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0); + SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0); + SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0); + break; + case JCS_YCCK: + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */ + cinfo->num_components = 4; + SET_COMP(0, 1, 2,2, 0, 0,0); + SET_COMP(1, 2, 1,1, 1, 1,1); + SET_COMP(2, 3, 1,1, 1, 1,1); + SET_COMP(3, 4, 2,2, 0, 0,0); + break; + case JCS_UNKNOWN: + cinfo->num_components = cinfo->input_components; + if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPONENTS); + for (ci = 0; ci < cinfo->num_components; ci++) { + SET_COMP(ci, ci, 1,1, 0, 0,0); + } + break; + default: + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + } + } + + + #ifdef C_PROGRESSIVE_SUPPORTED + + LOCAL(jpeg_scan_info *) + fill_a_scan (jpeg_scan_info * scanptr, int ci, + int Ss, int Se, int Ah, int Al) + /* Support routine: generate one scan for specified component */ + { + scanptr->comps_in_scan = 1; + scanptr->component_index[0] = ci; + scanptr->Ss = Ss; + scanptr->Se = Se; + scanptr->Ah = Ah; + scanptr->Al = Al; + scanptr++; + return scanptr; + } + + LOCAL(jpeg_scan_info *) + fill_scans (jpeg_scan_info * scanptr, int ncomps, + int Ss, int Se, int Ah, int Al) + /* Support routine: generate one scan for each component */ + { + int ci; + + for (ci = 0; ci < ncomps; ci++) { + scanptr->comps_in_scan = 1; + scanptr->component_index[0] = ci; + scanptr->Ss = Ss; + scanptr->Se = Se; + scanptr->Ah = Ah; + scanptr->Al = Al; + scanptr++; + } + return scanptr; + } + + LOCAL(jpeg_scan_info *) + fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al) + /* Support routine: generate interleaved DC scan if possible, else N scans */ + { + int ci; + + if (ncomps <= MAX_COMPS_IN_SCAN) { + /* Single interleaved DC scan */ + scanptr->comps_in_scan = ncomps; + for (ci = 0; ci < ncomps; ci++) + scanptr->component_index[ci] = ci; + scanptr->Ss = scanptr->Se = 0; + scanptr->Ah = Ah; + scanptr->Al = Al; + scanptr++; + } else { + /* Noninterleaved DC scan for each component */ + scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al); + } + return scanptr; + } + + + /* + * Create a recommended progressive-JPEG script. + * cinfo->num_components and cinfo->jpeg_color_space must be correct. + */ + + GLOBAL(void) + jpeg_simple_progression (j_compress_ptr cinfo) + { + int ncomps = cinfo->num_components; + int nscans; + jpeg_scan_info * scanptr; + + /* Safety check to ensure start_compress not called yet. */ + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + /* Figure space needed for script. Calculation must match code below! */ + if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { + /* Custom script for YCbCr color images. */ + nscans = 10; + } else { + /* All-purpose script for other color spaces. */ + if (ncomps > MAX_COMPS_IN_SCAN) + nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */ + else + nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */ + } + + /* Allocate space for script. */ + /* We use permanent pool just in case application re-uses script. */ + scanptr = (jpeg_scan_info *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + nscans * SIZEOF(jpeg_scan_info)); + cinfo->scan_info = scanptr; + cinfo->num_scans = nscans; + + if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { + /* Custom script for YCbCr color images. */ + /* Initial DC scan */ + scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); + /* Initial AC scan: get some luma data out in a hurry */ + scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2); + /* Chroma data is too small to be worth expending many scans on */ + scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1); + scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1); + /* Complete spectral selection for luma AC */ + scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2); + /* Refine next bit of luma AC */ + scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1); + /* Finish DC successive approximation */ + scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); + /* Finish AC successive approximation */ + scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0); + scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0); + /* Luma bottom bit comes last since it's usually largest scan */ + scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0); + } else { + /* All-purpose script for other color spaces. */ + /* Successive approximation first pass */ + scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); + scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2); + scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2); + /* Successive approximation second pass */ + scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1); + /* Successive approximation final pass */ + scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); + scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0); + } + } + + #endif /* C_PROGRESSIVE_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcphuff.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcphuff.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcphuff.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,829 ---- + /* + * jcphuff.c + * + * Copyright (C) 1995-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy encoding routines for progressive JPEG. + * + * We do not support output suspension in this module, since the library + * currently does not allow multiple-scan files to be written with output + * suspension. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jchuff.h" /* Declarations shared with jchuff.c */ + + #ifdef C_PROGRESSIVE_SUPPORTED + + /* Expanded entropy encoder object for progressive Huffman encoding. */ + + typedef struct { + struct jpeg_entropy_encoder pub; /* public fields */ + + /* Mode flag: TRUE for optimization, FALSE for actual data output */ + boolean gather_statistics; + + /* Bit-level coding status. + * next_output_byte/free_in_buffer are local copies of cinfo->dest fields. + */ + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + INT32 put_buffer; /* current bit-accumulation buffer */ + int put_bits; /* # of bits now in it */ + j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */ + + /* Coding status for DC components */ + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ + + /* Coding status for AC components */ + int ac_tbl_no; /* the table number of the single component */ + unsigned int EOBRUN; /* run length of EOBs */ + unsigned int BE; /* # of buffered correction bits before MCU */ + char * bit_buffer; /* buffer for correction bits (1 per char) */ + /* packing correction bits tightly would save some space but cost time... */ + + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + int next_restart_num; /* next restart number to write (0-7) */ + + /* Pointers to derived tables (these workspaces have image lifespan). + * Since any one scan codes only DC or only AC, we only need one set + * of tables, not one for DC and one for AC. + */ + c_derived_tbl * derived_tbls[NUM_HUFF_TBLS]; + + /* Statistics tables for optimization; again, one set is enough */ + long * count_ptrs[NUM_HUFF_TBLS]; + } phuff_entropy_encoder; + + typedef phuff_entropy_encoder * phuff_entropy_ptr; + + /* MAX_CORR_BITS is the number of bits the AC refinement correction-bit + * buffer can hold. Larger sizes may slightly improve compression, but + * 1000 is already well into the realm of overkill. + * The minimum safe size is 64 bits. + */ + + #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */ + + /* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32. + * We assume that int right shift is unsigned if INT32 right shift is, + * which should be safe. + */ + + #ifdef RIGHT_SHIFT_IS_UNSIGNED + #define ISHIFT_TEMPS int ishift_temp; + #define IRIGHT_SHIFT(x,shft) \ + ((ishift_temp = (x)) < 0 ? \ + (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \ + (ishift_temp >> (shft))) + #else + #define ISHIFT_TEMPS + #define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) + #endif + + /* Forward declarations */ + METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo)); + METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo)); + + + /* + * Initialize for a Huffman-compressed scan using progressive JPEG. + */ + + METHODDEF(void) + start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + boolean is_DC_band; + int ci, tbl; + jpeg_component_info * compptr; + + entropy->cinfo = cinfo; + entropy->gather_statistics = gather_statistics; + + is_DC_band = (cinfo->Ss == 0); + + /* We assume jcmaster.c already validated the scan parameters. */ + + /* Select execution routines */ + if (cinfo->Ah == 0) { + if (is_DC_band) + entropy->pub.encode_mcu = encode_mcu_DC_first; + else + entropy->pub.encode_mcu = encode_mcu_AC_first; + } else { + if (is_DC_band) + entropy->pub.encode_mcu = encode_mcu_DC_refine; + else { + entropy->pub.encode_mcu = encode_mcu_AC_refine; + /* AC refinement needs a correction bit buffer */ + if (entropy->bit_buffer == NULL) + entropy->bit_buffer = (char *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + MAX_CORR_BITS * SIZEOF(char)); + } + } + if (gather_statistics) + entropy->pub.finish_pass = finish_pass_gather_phuff; + else + entropy->pub.finish_pass = finish_pass_phuff; + + /* Only DC coefficients may be interleaved, so cinfo->comps_in_scan = 1 + * for AC coefficients. + */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Initialize DC predictions to 0 */ + entropy->last_dc_val[ci] = 0; + /* Make sure requested tables are present */ + /* (In gather mode, tables need not be allocated yet) */ + if (is_DC_band) { + if (cinfo->Ah != 0) /* DC refinement needs no table */ + continue; + tbl = compptr->dc_tbl_no; + if (tbl < 0 || tbl >= NUM_HUFF_TBLS || + (cinfo->dc_huff_tbl_ptrs[tbl] == NULL && !gather_statistics)) + ERREXIT1(cinfo,JERR_NO_HUFF_TABLE, tbl); + } else { + entropy->ac_tbl_no = tbl = compptr->ac_tbl_no; + if (tbl < 0 || tbl >= NUM_HUFF_TBLS || + (cinfo->ac_huff_tbl_ptrs[tbl] == NULL && !gather_statistics)) + ERREXIT1(cinfo,JERR_NO_HUFF_TABLE, tbl); + } + if (gather_statistics) { + /* Allocate and zero the statistics tables */ + /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ + if (entropy->count_ptrs[tbl] == NULL) + entropy->count_ptrs[tbl] = (long *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 257 * SIZEOF(long)); + MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long)); + } else { + /* Compute derived values for Huffman tables */ + /* We may do this more than once for a table, but it's not expensive */ + if (is_DC_band) + jpeg_make_c_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[tbl], + & entropy->derived_tbls[tbl]); + else + jpeg_make_c_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[tbl], + & entropy->derived_tbls[tbl]); + } + } + + /* Initialize AC stuff */ + entropy->EOBRUN = 0; + entropy->BE = 0; + + /* Initialize bit buffer to empty */ + entropy->put_buffer = 0; + entropy->put_bits = 0; + + /* Initialize restart stuff */ + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num = 0; + } + + + /* Outputting bytes to the file. + * NB: these must be called only when actually outputting, + * that is, entropy->gather_statistics == FALSE. + */ + + /* Emit a byte */ + #define emit_byte(entropy,val) \ + { *(entropy)->next_output_byte++ = (JOCTET) (val); \ + if (--(entropy)->free_in_buffer == 0) \ + dump_buffer(entropy); } + + + LOCAL(void) + dump_buffer (phuff_entropy_ptr entropy) + /* Empty the output buffer; we do not support suspension in this module. */ + { + struct jpeg_destination_mgr * dest = entropy->cinfo->dest; + + if (! (*dest->empty_output_buffer) (entropy->cinfo)) + ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND); + /* After a successful buffer dump, must reset buffer pointers */ + entropy->next_output_byte = dest->next_output_byte; + entropy->free_in_buffer = dest->free_in_buffer; + } + + + /* Outputting bits to the file */ + + /* Only the right 24 bits of put_buffer are used; the valid bits are + * left-justified in this part. At most 16 bits can be passed to emit_bits + * in one call, and we never retain more than 7 bits in put_buffer + * between calls, so 24 bits are sufficient. + */ + + INLINE + LOCAL(void) + emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size) + /* Emit some bits, unless we are in gather mode */ + { + /* This routine is heavily used, so it's worth coding tightly. */ + register INT32 put_buffer = (INT32) code; + register int put_bits = entropy->put_bits; + + /* if size is 0, caller used an invalid Huffman table entry */ + if (size == 0) + ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); + + if (entropy->gather_statistics) + return; /* do nothing if we're only getting stats */ + + put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */ + + put_bits += size; /* new number of bits in buffer */ + + put_buffer <<= 24 - put_bits; /* align incoming bits */ + + put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */ + + while (put_bits >= 8) { + int c = (int) ((put_buffer >> 16) & 0xFF); + + emit_byte(entropy, c); + if (c == 0xFF) { /* need to stuff a zero byte? */ + emit_byte(entropy, 0); + } + put_buffer <<= 8; + put_bits -= 8; + } + + entropy->put_buffer = put_buffer; /* update variables */ + entropy->put_bits = put_bits; + } + + + LOCAL(void) + flush_bits (phuff_entropy_ptr entropy) + { + emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */ + entropy->put_buffer = 0; /* and reset bit-buffer to empty */ + entropy->put_bits = 0; + } + + + /* + * Emit (or just count) a Huffman symbol. + */ + + INLINE + LOCAL(void) + emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol) + { + if (entropy->gather_statistics) + entropy->count_ptrs[tbl_no][symbol]++; + else { + c_derived_tbl * tbl = entropy->derived_tbls[tbl_no]; + emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]); + } + } + + + /* + * Emit bits from a correction bit buffer. + */ + + LOCAL(void) + emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart, + unsigned int nbits) + { + if (entropy->gather_statistics) + return; /* no real work */ + + while (nbits > 0) { + emit_bits(entropy, (unsigned int) (*bufstart), 1); + bufstart++; + nbits--; + } + } + + + /* + * Emit any pending EOBRUN symbol. + */ + + LOCAL(void) + emit_eobrun (phuff_entropy_ptr entropy) + { + register int temp, nbits; + + if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */ + temp = entropy->EOBRUN; + nbits = 0; + while ((temp >>= 1)) + nbits++; + + emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4); + if (nbits) + emit_bits(entropy, entropy->EOBRUN, nbits); + + entropy->EOBRUN = 0; + + /* Emit any buffered correction bits */ + emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE); + entropy->BE = 0; + } + } + + + /* + * Emit a restart marker & resynchronize predictions. + */ + + LOCAL(void) + emit_restart (phuff_entropy_ptr entropy, int restart_num) + { + int ci; + + emit_eobrun(entropy); + + if (! entropy->gather_statistics) { + flush_bits(entropy); + emit_byte(entropy, 0xFF); + emit_byte(entropy, JPEG_RST0 + restart_num); + } + + if (entropy->cinfo->Ss == 0) { + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++) + entropy->last_dc_val[ci] = 0; + } else { + /* Re-initialize all AC-related fields to 0 */ + entropy->EOBRUN = 0; + entropy->BE = 0; + } + } + + + /* + * MCU encoding for DC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + + METHODDEF(boolean) + encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp, temp2; + register int nbits; + int blkn, ci; + int Al = cinfo->Al; + JBLOCKROW block; + jpeg_component_info * compptr; + ISHIFT_TEMPS + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + + /* Compute the DC value after the required point transform by Al. + * This is simply an arithmetic right shift. + */ + temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al); + + /* DC differences are figured on the point-transformed values. */ + temp = temp2 - entropy->last_dc_val[ci]; + entropy->last_dc_val[ci] = temp2; + + /* Encode the DC coefficient difference per section G.1.2.1 */ + temp2 = temp; + if (temp < 0) { + temp = -temp; /* temp is abs value of input */ + /* For a negative input, want temp2 = bitwise complement of abs(input) */ + /* This code assumes we are on a two's complement machine */ + temp2--; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 0; + while (temp) { + nbits++; + temp >>= 1; + } + + /* Count/emit the Huffman-coded symbol for the number of bits */ + emit_symbol(entropy, compptr->dc_tbl_no, nbits); + + /* Emit that number of bits of the value, if positive, */ + /* or the complement of its magnitude, if negative. */ + if (nbits) /* emit_bits rejects calls with size 0 */ + emit_bits(entropy, (unsigned int) temp2, nbits); + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; + } + + + /* + * MCU encoding for AC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + + METHODDEF(boolean) + encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp, temp2; + register int nbits; + register int r, k; + int Se = cinfo->Se; + int Al = cinfo->Al; + JBLOCKROW block; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data block */ + block = MCU_data[0]; + + /* Encode the AC coefficients per section G.1.2.2, fig. G.3 */ + + r = 0; /* r = run length of zeros */ + + for (k = cinfo->Ss; k <= Se; k++) { + if ((temp = (*block)[jpeg_natural_order[k]]) == 0) { + r++; + continue; + } + /* We must apply the point transform by Al. For AC coefficients this + * is an integer division with rounding towards 0. To do this portably + * in C, we shift after obtaining the absolute value; so the code is + * interwoven with finding the abs value (temp) and output bits (temp2). + */ + if (temp < 0) { + temp = -temp; /* temp is abs value of input */ + temp >>= Al; /* apply the point transform */ + /* For a negative coef, want temp2 = bitwise complement of abs(coef) */ + temp2 = ~temp; + } else { + temp >>= Al; /* apply the point transform */ + temp2 = temp; + } + /* Watch out for case that nonzero coef is zero after point transform */ + if (temp == 0) { + r++; + continue; + } + + /* Emit any pending EOBRUN */ + if (entropy->EOBRUN > 0) + emit_eobrun(entropy); + /* if run length > 15, must emit special run-length-16 codes (0xF0) */ + while (r > 15) { + emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); + r -= 16; + } + + /* Find the number of bits needed for the magnitude of the coefficient */ + nbits = 1; /* there must be at least one 1 bit */ + while ((temp >>= 1)) + nbits++; + + /* Count/emit Huffman symbol for run length / number of bits */ + emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits); + + /* Emit that number of bits of the value, if positive, */ + /* or the complement of its magnitude, if negative. */ + emit_bits(entropy, (unsigned int) temp2, nbits); + + r = 0; /* reset zero run length */ + } + + if (r > 0) { /* If there are trailing zeroes, */ + entropy->EOBRUN++; /* count an EOB */ + if (entropy->EOBRUN == 0x7FFF) + emit_eobrun(entropy); /* force it out to avoid overflow */ + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; + } + + + /* + * MCU encoding for DC successive approximation refinement scan. + * Note: we assume such scans can be multi-component, although the spec + * is not very clear on the point. + */ + + METHODDEF(boolean) + encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp; + int blkn; + int Al = cinfo->Al; + JBLOCKROW block; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data blocks */ + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + + /* We simply emit the Al'th bit of the DC coefficient value. */ + temp = (*block)[0]; + emit_bits(entropy, (unsigned int) (temp >> Al), 1); + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; + } + + + /* + * MCU encoding for AC successive approximation refinement scan. + */ + + METHODDEF(boolean) + encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + register int temp; + register int r, k; + int EOB; + char *BR_buffer; + unsigned int BR; + int Se = cinfo->Se; + int Al = cinfo->Al; + JBLOCKROW block; + int absvalues[DCTSIZE2]; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Emit restart marker if needed */ + if (cinfo->restart_interval) + if (entropy->restarts_to_go == 0) + emit_restart(entropy, entropy->next_restart_num); + + /* Encode the MCU data block */ + block = MCU_data[0]; + + /* It is convenient to make a pre-pass to determine the transformed + * coefficients' absolute values and the EOB position. + */ + EOB = 0; + for (k = cinfo->Ss; k <= Se; k++) { + temp = (*block)[jpeg_natural_order[k]]; + /* We must apply the point transform by Al. For AC coefficients this + * is an integer division with rounding towards 0. To do this portably + * in C, we shift after obtaining the absolute value. + */ + if (temp < 0) + temp = -temp; /* temp is abs value of input */ + temp >>= Al; /* apply the point transform */ + absvalues[k] = temp; /* save abs value for main pass */ + if (temp == 1) + EOB = k; /* EOB = index of last newly-nonzero coef */ + } + + /* Encode the AC coefficients per section G.1.2.3, fig. G.7 */ + + r = 0; /* r = run length of zeros */ + BR = 0; /* BR = count of buffered bits added now */ + BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */ + + for (k = cinfo->Ss; k <= Se; k++) { + if ((temp = absvalues[k]) == 0) { + r++; + continue; + } + + /* Emit any required ZRLs, but not if they can be folded into EOB */ + while (r > 15 && k <= EOB) { + /* emit any pending EOBRUN and the BE correction bits */ + emit_eobrun(entropy); + /* Emit ZRL */ + emit_symbol(entropy, entropy->ac_tbl_no, 0xF0); + r -= 16; + /* Emit buffered correction bits that must be associated with ZRL */ + emit_buffered_bits(entropy, BR_buffer, BR); + BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ + BR = 0; + } + + /* If the coef was previously nonzero, it only needs a correction bit. + * NOTE: a straight translation of the spec's figure G.7 would suggest + * that we also need to test r > 15. But if r > 15, we can only get here + * if k > EOB, which implies that this coefficient is not 1. + */ + if (temp > 1) { + /* The correction bit is the next bit of the absolute value. */ + BR_buffer[BR++] = (char) (temp & 1); + continue; + } + + /* Emit any pending EOBRUN and the BE correction bits */ + emit_eobrun(entropy); + + /* Count/emit Huffman symbol for run length / number of bits */ + emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1); + + /* Emit output bit for newly-nonzero coef */ + temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1; + emit_bits(entropy, (unsigned int) temp, 1); + + /* Emit buffered correction bits that must be associated with this code */ + emit_buffered_bits(entropy, BR_buffer, BR); + BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ + BR = 0; + r = 0; /* reset zero run length */ + } + + if (r > 0 || BR > 0) { /* If there are trailing zeroes, */ + entropy->EOBRUN++; /* count an EOB */ + entropy->BE += BR; /* concat my correction bits to older ones */ + /* We force out the EOB if we risk either: + * 1. overflow of the EOB counter; + * 2. overflow of the correction bit buffer during the next MCU. + */ + if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1)) + emit_eobrun(entropy); + } + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + + /* Update restart-interval state too */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) { + entropy->restarts_to_go = cinfo->restart_interval; + entropy->next_restart_num++; + entropy->next_restart_num &= 7; + } + entropy->restarts_to_go--; + } + + return TRUE; + } + + + /* + * Finish up at the end of a Huffman-compressed progressive scan. + */ + + METHODDEF(void) + finish_pass_phuff (j_compress_ptr cinfo) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + + entropy->next_output_byte = cinfo->dest->next_output_byte; + entropy->free_in_buffer = cinfo->dest->free_in_buffer; + + /* Flush out any buffered data */ + emit_eobrun(entropy); + flush_bits(entropy); + + cinfo->dest->next_output_byte = entropy->next_output_byte; + cinfo->dest->free_in_buffer = entropy->free_in_buffer; + } + + + /* + * Finish up a statistics-gathering pass and create the new Huffman tables. + */ + + METHODDEF(void) + finish_pass_gather_phuff (j_compress_ptr cinfo) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + boolean is_DC_band; + int ci, tbl; + jpeg_component_info * compptr; + JHUFF_TBL **htblptr; + boolean did[NUM_HUFF_TBLS]; + + /* Flush out buffered data (all we care about is counting the EOB symbol) */ + emit_eobrun(entropy); + + is_DC_band = (cinfo->Ss == 0); + + /* It's important not to apply jpeg_gen_optimal_table more than once + * per table, because it clobbers the input frequency counts! + */ + MEMZERO(did, SIZEOF(did)); + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + if (is_DC_band) { + if (cinfo->Ah != 0) /* DC refinement needs no table */ + continue; + tbl = compptr->dc_tbl_no; + } else { + tbl = compptr->ac_tbl_no; + } + if (! did[tbl]) { + if (is_DC_band) + htblptr = & cinfo->dc_huff_tbl_ptrs[tbl]; + else + htblptr = & cinfo->ac_huff_tbl_ptrs[tbl]; + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]); + did[tbl] = TRUE; + } + } + } + + + /* + * Module initialization routine for progressive Huffman entropy encoding. + */ + + GLOBAL(void) + jinit_phuff_encoder (j_compress_ptr cinfo) + { + phuff_entropy_ptr entropy; + int i; + + entropy = (phuff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(phuff_entropy_encoder)); + cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; + entropy->pub.start_pass = start_pass_phuff; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->derived_tbls[i] = NULL; + entropy->count_ptrs[i] = NULL; + } + entropy->bit_buffer = NULL; /* needed only in AC refinement scan */ + } + + #endif /* C_PROGRESSIVE_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcprepct.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcprepct.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcprepct.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,354 ---- + /* + * jcprepct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the compression preprocessing controller. + * This controller manages the color conversion, downsampling, + * and edge expansion steps. + * + * Most of the complexity here is associated with buffering input rows + * as required by the downsampler. See the comments at the head of + * jcsample.c for the downsampler's needs. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* At present, jcsample.c can request context rows only for smoothing. + * In the future, we might also need context rows for CCIR601 sampling + * or other more-complex downsampling procedures. The code to support + * context rows should be compiled only if needed. + */ + #ifdef INPUT_SMOOTHING_SUPPORTED + #define CONTEXT_ROWS_SUPPORTED + #endif + + + /* + * For the simple (no-context-row) case, we just need to buffer one + * row group's worth of pixels for the downsampling step. At the bottom of + * the image, we pad to a full row group by replicating the last pixel row. + * The downsampler's last output row is then replicated if needed to pad + * out to a full iMCU row. + * + * When providing context rows, we must buffer three row groups' worth of + * pixels. Three row groups are physically allocated, but the row pointer + * arrays are made five row groups high, with the extra pointers above and + * below "wrapping around" to point to the last and first real row groups. + * This allows the downsampler to access the proper context rows. + * At the top and bottom of the image, we create dummy context rows by + * copying the first or last real pixel row. This copying could be avoided + * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the + * trouble on the compression side. + */ + + + /* Private buffer controller object */ + + typedef struct { + struct jpeg_c_prep_controller pub; /* public fields */ + + /* Downsampling input buffer. This buffer holds color-converted data + * until we have enough to do a downsample step. + */ + JSAMPARRAY color_buf[MAX_COMPONENTS]; + + JDIMENSION rows_to_go; /* counts rows remaining in source image */ + int next_buf_row; /* index of next row to store in color_buf */ + + #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */ + int this_row_group; /* starting row index of group to process */ + int next_buf_stop; /* downsample when we reach this index */ + #endif + } my_prep_controller; + + typedef my_prep_controller * my_prep_ptr; + + + /* + * Initialize for a processing pass. + */ + + METHODDEF(void) + start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode) + { + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + + if (pass_mode != JBUF_PASS_THRU) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + /* Initialize total-height counter for detecting bottom of image */ + prep->rows_to_go = cinfo->image_height; + /* Mark the conversion buffer empty */ + prep->next_buf_row = 0; + #ifdef CONTEXT_ROWS_SUPPORTED + /* Preset additional state variables for context mode. + * These aren't used in non-context mode, so we needn't test which mode. + */ + prep->this_row_group = 0; + /* Set next_buf_stop to stop after two row groups have been read in. */ + prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; + #endif + } + + + /* + * Expand an image vertically from height input_rows to height output_rows, + * by duplicating the bottom row. + */ + + LOCAL(void) + expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, + int input_rows, int output_rows) + { + register int row; + + for (row = input_rows; row < output_rows; row++) { + jcopy_sample_rows(image_data, input_rows-1, image_data, row, + 1, num_cols); + } + } + + + /* + * Process some data in the simple no-context case. + * + * Preprocessor output data is counted in "row groups". A row group + * is defined to be v_samp_factor sample rows of each component. + * Downsampling will produce this much data from each max_v_samp_factor + * input rows. + */ + + METHODDEF(void) + pre_process_data (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail, + JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, + JDIMENSION out_row_groups_avail) + { + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + int numrows, ci; + JDIMENSION inrows; + jpeg_component_info * compptr; + + while (*in_row_ctr < in_rows_avail && + *out_row_group_ctr < out_row_groups_avail) { + /* Do color conversion to fill the conversion buffer. */ + inrows = in_rows_avail - *in_row_ctr; + numrows = cinfo->max_v_samp_factor - prep->next_buf_row; + numrows = (int) MIN((JDIMENSION) numrows, inrows); + (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, + prep->color_buf, + (JDIMENSION) prep->next_buf_row, + numrows); + *in_row_ctr += numrows; + prep->next_buf_row += numrows; + prep->rows_to_go -= numrows; + /* If at bottom of image, pad to fill the conversion buffer. */ + if (prep->rows_to_go == 0 && + prep->next_buf_row < cinfo->max_v_samp_factor) { + for (ci = 0; ci < cinfo->num_components; ci++) { + expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, + prep->next_buf_row, cinfo->max_v_samp_factor); + } + prep->next_buf_row = cinfo->max_v_samp_factor; + } + /* If we've filled the conversion buffer, empty it. */ + if (prep->next_buf_row == cinfo->max_v_samp_factor) { + (*cinfo->downsample->downsample) (cinfo, + prep->color_buf, (JDIMENSION) 0, + output_buf, *out_row_group_ctr); + prep->next_buf_row = 0; + (*out_row_group_ctr)++; + } + /* If at bottom of image, pad the output to a full iMCU height. + * Note we assume the caller is providing a one-iMCU-height output buffer! + */ + if (prep->rows_to_go == 0 && + *out_row_group_ctr < out_row_groups_avail) { + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + expand_bottom_edge(output_buf[ci], + compptr->width_in_blocks * DCTSIZE, + (int) (*out_row_group_ctr * compptr->v_samp_factor), + (int) (out_row_groups_avail * compptr->v_samp_factor)); + } + *out_row_group_ctr = out_row_groups_avail; + break; /* can exit outer loop without test */ + } + } + } + + + #ifdef CONTEXT_ROWS_SUPPORTED + + /* + * Process some data in the context case. + */ + + METHODDEF(void) + pre_process_context (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail, + JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, + JDIMENSION out_row_groups_avail) + { + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + int numrows, ci; + int buf_height = cinfo->max_v_samp_factor * 3; + JDIMENSION inrows; + + while (*out_row_group_ctr < out_row_groups_avail) { + if (*in_row_ctr < in_rows_avail) { + /* Do color conversion to fill the conversion buffer. */ + inrows = in_rows_avail - *in_row_ctr; + numrows = prep->next_buf_stop - prep->next_buf_row; + numrows = (int) MIN((JDIMENSION) numrows, inrows); + (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, + prep->color_buf, + (JDIMENSION) prep->next_buf_row, + numrows); + /* Pad at top of image, if first time through */ + if (prep->rows_to_go == cinfo->image_height) { + for (ci = 0; ci < cinfo->num_components; ci++) { + int row; + for (row = 1; row <= cinfo->max_v_samp_factor; row++) { + jcopy_sample_rows(prep->color_buf[ci], 0, + prep->color_buf[ci], -row, + 1, cinfo->image_width); + } + } + } + *in_row_ctr += numrows; + prep->next_buf_row += numrows; + prep->rows_to_go -= numrows; + } else { + /* Return for more data, unless we are at the bottom of the image. */ + if (prep->rows_to_go != 0) + break; + /* When at bottom of image, pad to fill the conversion buffer. */ + if (prep->next_buf_row < prep->next_buf_stop) { + for (ci = 0; ci < cinfo->num_components; ci++) { + expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, + prep->next_buf_row, prep->next_buf_stop); + } + prep->next_buf_row = prep->next_buf_stop; + } + } + /* If we've gotten enough data, downsample a row group. */ + if (prep->next_buf_row == prep->next_buf_stop) { + (*cinfo->downsample->downsample) (cinfo, + prep->color_buf, + (JDIMENSION) prep->this_row_group, + output_buf, *out_row_group_ctr); + (*out_row_group_ctr)++; + /* Advance pointers with wraparound as necessary. */ + prep->this_row_group += cinfo->max_v_samp_factor; + if (prep->this_row_group >= buf_height) + prep->this_row_group = 0; + if (prep->next_buf_row >= buf_height) + prep->next_buf_row = 0; + prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; + } + } + } + + + /* + * Create the wrapped-around downsampling input buffer needed for context mode. + */ + + LOCAL(void) + create_context_buffer (j_compress_ptr cinfo) + { + my_prep_ptr prep = (my_prep_ptr) cinfo->prep; + int rgroup_height = cinfo->max_v_samp_factor; + int ci, i; + jpeg_component_info * compptr; + JSAMPARRAY true_buffer, fake_buffer; + + /* Grab enough space for fake row pointers for all the components; + * we need five row groups' worth of pointers for each component. + */ + fake_buffer = (JSAMPARRAY) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (cinfo->num_components * 5 * rgroup_height) * + SIZEOF(JSAMPROW)); + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Allocate the actual buffer space (3 row groups) for this component. + * We make the buffer wide enough to allow the downsampler to edge-expand + * horizontally within the buffer, if it so chooses. + */ + true_buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * + cinfo->max_h_samp_factor) / compptr->h_samp_factor), + (JDIMENSION) (3 * rgroup_height)); + /* Copy true buffer row pointers into the middle of the fake row array */ + MEMCOPY(fake_buffer + rgroup_height, true_buffer, + 3 * rgroup_height * SIZEOF(JSAMPROW)); + /* Fill in the above and below wraparound pointers */ + for (i = 0; i < rgroup_height; i++) { + fake_buffer[i] = true_buffer[2 * rgroup_height + i]; + fake_buffer[4 * rgroup_height + i] = true_buffer[i]; + } + prep->color_buf[ci] = fake_buffer + rgroup_height; + fake_buffer += 5 * rgroup_height; /* point to space for next component */ + } + } + + #endif /* CONTEXT_ROWS_SUPPORTED */ + + + /* + * Initialize preprocessing controller. + */ + + GLOBAL(void) + jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) + { + my_prep_ptr prep; + int ci; + jpeg_component_info * compptr; + + if (need_full_buffer) /* safety check */ + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + prep = (my_prep_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_prep_controller)); + cinfo->prep = (struct jpeg_c_prep_controller *) prep; + prep->pub.start_pass = start_pass_prep; + + /* Allocate the color conversion buffer. + * We make the buffer wide enough to allow the downsampler to edge-expand + * horizontally within the buffer, if it so chooses. + */ + if (cinfo->downsample->need_context_rows) { + /* Set up to provide context rows */ + #ifdef CONTEXT_ROWS_SUPPORTED + prep->pub.pre_process_data = pre_process_context; + create_context_buffer(cinfo); + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else { + /* No context, just make it tall enough for one row group */ + prep->pub.pre_process_data = pre_process_data; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * + cinfo->max_h_samp_factor) / compptr->h_samp_factor), + (JDIMENSION) cinfo->max_v_samp_factor); + } + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcsample.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcsample.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jcsample.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,519 ---- + /* + * jcsample.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains downsampling routines. + * + * Downsampling input data is counted in "row groups". A row group + * is defined to be max_v_samp_factor pixel rows of each component, + * from which the downsampler produces v_samp_factor sample rows. + * A single row group is processed in each call to the downsampler module. + * + * The downsampler is responsible for edge-expansion of its output data + * to fill an integral number of DCT blocks horizontally. The source buffer + * may be modified if it is helpful for this purpose (the source buffer is + * allocated wide enough to correspond to the desired output width). + * The caller (the prep controller) is responsible for vertical padding. + * + * The downsampler may request "context rows" by setting need_context_rows + * during startup. In this case, the input arrays will contain at least + * one row group's worth of pixels above and below the passed-in data; + * the caller will create dummy rows at image top and bottom by replicating + * the first or last real pixel row. + * + * An excellent reference for image resampling is + * Digital Image Warping, George Wolberg, 1990. + * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. + * + * The downsampling algorithm used here is a simple average of the source + * pixels covered by the output pixel. The hi-falutin sampling literature + * refers to this as a "box filter". In general the characteristics of a box + * filter are not very good, but for the specific cases we normally use (1:1 + * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not + * nearly so bad. If you intend to use other sampling ratios, you'd be well + * advised to improve this code. + * + * A simple input-smoothing capability is provided. This is mainly intended + * for cleaning up color-dithered GIF input files (if you find it inadequate, + * we suggest using an external filtering program such as pnmconvol). When + * enabled, each input pixel P is replaced by a weighted sum of itself and its + * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF, + * where SF = (smoothing_factor / 1024). + * Currently, smoothing is only supported for 2h2v sampling factors. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Pointer to routine to downsample a single component */ + typedef JMETHOD(void, downsample1_ptr, + (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data)); + + /* Private subobject */ + + typedef struct { + struct jpeg_downsampler pub; /* public fields */ + + /* Downsampling method pointers, one per component */ + downsample1_ptr methods[MAX_COMPONENTS]; + } my_downsampler; + + typedef my_downsampler * my_downsample_ptr; + + + /* + * Initialize for a downsampling pass. + */ + + METHODDEF(void) + start_pass_downsample (j_compress_ptr cinfo) + { + /* no work for now */ + } + + + /* + * Expand a component horizontally from width input_cols to width output_cols, + * by duplicating the rightmost samples. + */ + + LOCAL(void) + expand_right_edge (JSAMPARRAY image_data, int num_rows, + JDIMENSION input_cols, JDIMENSION output_cols) + { + register JSAMPROW ptr; + register JSAMPLE pixval; + register int count; + int row; + int numcols = (int) (output_cols - input_cols); + + if (numcols > 0) { + for (row = 0; row < num_rows; row++) { + ptr = image_data[row] + input_cols; + pixval = ptr[-1]; /* don't need GETJSAMPLE() here */ + for (count = numcols; count > 0; count--) + *ptr++ = pixval; + } + } + } + + + /* + * Do downsampling for a whole row group (all components). + * + * In this version we simply downsample each component independently. + */ + + METHODDEF(void) + sep_downsample (j_compress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_index, + JSAMPIMAGE output_buf, JDIMENSION out_row_group_index) + { + my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample; + int ci; + jpeg_component_info * compptr; + JSAMPARRAY in_ptr, out_ptr; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + in_ptr = input_buf[ci] + in_row_index; + out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); + (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); + } + } + + + /* + * Downsample pixel values of a single component. + * One row group is processed per call. + * This version handles arbitrary integral sampling ratios, without smoothing. + * Note that this version is not actually used for customary sampling ratios. + */ + + METHODDEF(void) + int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) + { + int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; + JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + JSAMPROW inptr, outptr; + INT32 outvalue; + + h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; + v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; + numpix = h_expand * v_expand; + numpix2 = numpix/2; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data, cinfo->max_v_samp_factor, + cinfo->image_width, output_cols * h_expand); + + inrow = 0; + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + for (outcol = 0, outcol_h = 0; outcol < output_cols; + outcol++, outcol_h += h_expand) { + outvalue = 0; + for (v = 0; v < v_expand; v++) { + inptr = input_data[inrow+v] + outcol_h; + for (h = 0; h < h_expand; h++) { + outvalue += (INT32) GETJSAMPLE(*inptr++); + } + } + *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix); + } + inrow += v_expand; + } + } + + + /* + * Downsample pixel values of a single component. + * This version handles the special case of a full-size component, + * without smoothing. + */ + + METHODDEF(void) + fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) + { + /* Copy the data */ + jcopy_sample_rows(input_data, 0, output_data, 0, + cinfo->max_v_samp_factor, cinfo->image_width); + /* Edge-expand */ + expand_right_edge(output_data, cinfo->max_v_samp_factor, + cinfo->image_width, compptr->width_in_blocks * DCTSIZE); + } + + + /* + * Downsample pixel values of a single component. + * This version handles the common case of 2:1 horizontal and 1:1 vertical, + * without smoothing. + * + * A note about the "bias" calculations: when rounding fractional values to + * integer, we do not want to always round 0.5 up to the next integer. + * If we did that, we'd introduce a noticeable bias towards larger values. + * Instead, this code is arranged so that 0.5 will be rounded up or down at + * alternate pixel locations (a simple ordered dither pattern). + */ + + METHODDEF(void) + h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) + { + int outrow; + JDIMENSION outcol; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr, outptr; + register int bias; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data, cinfo->max_v_samp_factor, + cinfo->image_width, output_cols * 2); + + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr = input_data[outrow]; + bias = 0; /* bias = 0,1,0,1,... for successive samples */ + for (outcol = 0; outcol < output_cols; outcol++) { + *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) + + bias) >> 1); + bias ^= 1; /* 0=>1, 1=>0 */ + inptr += 2; + } + } + } + + + /* + * Downsample pixel values of a single component. + * This version handles the standard case of 2:1 horizontal and 2:1 vertical, + * without smoothing. + */ + + METHODDEF(void) + h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) + { + int inrow, outrow; + JDIMENSION outcol; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr0, inptr1, outptr; + register int bias; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data, cinfo->max_v_samp_factor, + cinfo->image_width, output_cols * 2); + + inrow = 0; + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr0 = input_data[inrow]; + inptr1 = input_data[inrow+1]; + bias = 1; /* bias = 1,2,1,2,... for successive samples */ + for (outcol = 0; outcol < output_cols; outcol++) { + *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) + + bias) >> 2); + bias ^= 3; /* 1=>2, 2=>1 */ + inptr0 += 2; inptr1 += 2; + } + inrow += 2; + } + } + + + #ifdef INPUT_SMOOTHING_SUPPORTED + + /* + * Downsample pixel values of a single component. + * This version handles the standard case of 2:1 horizontal and 2:1 vertical, + * with smoothing. One row of context is required. + */ + + METHODDEF(void) + h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) + { + int inrow, outrow; + JDIMENSION colctr; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr; + INT32 membersum, neighsum, memberscale, neighscale; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, + cinfo->image_width, output_cols * 2); + + /* We don't bother to form the individual "smoothed" input pixel values; + * we can directly compute the output which is the average of the four + * smoothed values. Each of the four member pixels contributes a fraction + * (1-8*SF) to its own smoothed image and a fraction SF to each of the three + * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final + * output. The four corner-adjacent neighbor pixels contribute a fraction + * SF to just one smoothed pixel, or SF/4 to the final output; while the + * eight edge-adjacent neighbors contribute SF to each of two smoothed + * pixels, or SF/2 overall. In order to use integer arithmetic, these + * factors are scaled by 2^16 = 65536. + * Also recall that SF = smoothing_factor / 1024. + */ + + memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */ + neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */ + + inrow = 0; + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr0 = input_data[inrow]; + inptr1 = input_data[inrow+1]; + above_ptr = input_data[inrow-1]; + below_ptr = input_data[inrow+2]; + + /* Special case for first column: pretend column -1 is same as column 0 */ + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + + GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]); + neighsum += neighsum; + neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]); + membersum = membersum * memberscale + neighsum * neighscale; + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; + + for (colctr = output_cols - 2; colctr > 0; colctr--) { + /* sum of pixels directly mapped to this output element */ + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); + /* sum of edge-neighbor pixels */ + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) + + GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]); + /* The edge-neighbors count twice as much as corner-neighbors */ + neighsum += neighsum; + /* Add in the corner-neighbors */ + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) + + GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]); + /* form final output scaled up by 2^16 */ + membersum = membersum * memberscale + neighsum * neighscale; + /* round, descale and output it */ + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; + } + + /* Special case for last column */ + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) + + GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]); + neighsum += neighsum; + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) + + GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]); + membersum = membersum * memberscale + neighsum * neighscale; + *outptr = (JSAMPLE) ((membersum + 32768) >> 16); + + inrow += 2; + } + } + + + /* + * Downsample pixel values of a single component. + * This version handles the special case of a full-size component, + * with smoothing. One row of context is required. + */ + + METHODDEF(void) + fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) + { + int outrow; + JDIMENSION colctr; + JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; + register JSAMPROW inptr, above_ptr, below_ptr, outptr; + INT32 membersum, neighsum, memberscale, neighscale; + int colsum, lastcolsum, nextcolsum; + + /* Expand input data enough to let all the output samples be generated + * by the standard loop. Special-casing padded output would be more + * efficient. + */ + expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, + cinfo->image_width, output_cols); + + /* Each of the eight neighbor pixels contributes a fraction SF to the + * smoothed pixel, while the main pixel contributes (1-8*SF). In order + * to use integer arithmetic, these factors are multiplied by 2^16 = 65536. + * Also recall that SF = smoothing_factor / 1024. + */ + + memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */ + neighscale = cinfo->smoothing_factor * 64; /* scaled SF */ + + for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { + outptr = output_data[outrow]; + inptr = input_data[outrow]; + above_ptr = input_data[outrow-1]; + below_ptr = input_data[outrow+1]; + + /* Special case for first column */ + colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) + + GETJSAMPLE(*inptr); + membersum = GETJSAMPLE(*inptr++); + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + + GETJSAMPLE(*inptr); + neighsum = colsum + (colsum - membersum) + nextcolsum; + membersum = membersum * memberscale + neighsum * neighscale; + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + lastcolsum = colsum; colsum = nextcolsum; + + for (colctr = output_cols - 2; colctr > 0; colctr--) { + membersum = GETJSAMPLE(*inptr++); + above_ptr++; below_ptr++; + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + + GETJSAMPLE(*inptr); + neighsum = lastcolsum + (colsum - membersum) + nextcolsum; + membersum = membersum * memberscale + neighsum * neighscale; + *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); + lastcolsum = colsum; colsum = nextcolsum; + } + + /* Special case for last column */ + membersum = GETJSAMPLE(*inptr); + neighsum = lastcolsum + (colsum - membersum) + colsum; + membersum = membersum * memberscale + neighsum * neighscale; + *outptr = (JSAMPLE) ((membersum + 32768) >> 16); + + } + } + + #endif /* INPUT_SMOOTHING_SUPPORTED */ + + + /* + * Module initialization routine for downsampling. + * Note that we must select a routine for each component. + */ + + GLOBAL(void) + jinit_downsampler (j_compress_ptr cinfo) + { + my_downsample_ptr downsample; + int ci; + jpeg_component_info * compptr; + boolean smoothok = TRUE; + + downsample = (my_downsample_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_downsampler)); + cinfo->downsample = (struct jpeg_downsampler *) downsample; + downsample->pub.start_pass = start_pass_downsample; + downsample->pub.downsample = sep_downsample; + downsample->pub.need_context_rows = FALSE; + + if (cinfo->CCIR601_sampling) + ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); + + /* Verify we can handle the sampling factors, and set up method pointers */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->h_samp_factor == cinfo->max_h_samp_factor && + compptr->v_samp_factor == cinfo->max_v_samp_factor) { + #ifdef INPUT_SMOOTHING_SUPPORTED + if (cinfo->smoothing_factor) { + downsample->methods[ci] = fullsize_smooth_downsample; + downsample->pub.need_context_rows = TRUE; + } else + #endif + downsample->methods[ci] = fullsize_downsample; + } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && + compptr->v_samp_factor == cinfo->max_v_samp_factor) { + smoothok = FALSE; + downsample->methods[ci] = h2v1_downsample; + } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && + compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { + #ifdef INPUT_SMOOTHING_SUPPORTED + if (cinfo->smoothing_factor) { + downsample->methods[ci] = h2v2_smooth_downsample; + downsample->pub.need_context_rows = TRUE; + } else + #endif + downsample->methods[ci] = h2v2_downsample; + } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && + (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { + smoothok = FALSE; + downsample->methods[ci] = int_downsample; + } else + ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); + } + + #ifdef INPUT_SMOOTHING_SUPPORTED + if (cinfo->smoothing_factor && !smoothok) + TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); + #endif + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jctrans.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jctrans.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jctrans.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,371 ---- + /* + * jctrans.c + * + * Copyright (C) 1995-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains library routines for transcoding compression, + * that is, writing raw DCT coefficient arrays to an output JPEG file. + * The routines in jcapimin.c will also be needed by a transcoder. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Forward declarations */ + LOCAL(void) transencode_master_selection + JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); + LOCAL(void) transencode_coef_controller + JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); + + + /* + * Compression initialization for writing raw-coefficient data. + * Before calling this, all parameters and a data destination must be set up. + * Call jpeg_finish_compress() to actually write the data. + * + * The number of passed virtual arrays must match cinfo->num_components. + * Note that the virtual arrays need not be filled or even realized at + * the time write_coefficients is called; indeed, if the virtual arrays + * were requested from this compression object's memory manager, they + * typically will be realized during this routine and filled afterwards. + */ + + GLOBAL(void) + jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays) + { + if (cinfo->global_state != CSTATE_START) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Mark all tables to be written */ + jpeg_suppress_tables(cinfo, FALSE); + /* (Re)initialize error mgr and destination modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->dest->init_destination) (cinfo); + /* Perform master selection of active modules */ + transencode_master_selection(cinfo, coef_arrays); + /* Wait for jpeg_finish_compress() call */ + cinfo->next_scanline = 0; /* so jpeg_write_marker works */ + cinfo->global_state = CSTATE_WRCOEFS; + } + + + /* + * Initialize the compression object with default parameters, + * then copy from the source object all parameters needed for lossless + * transcoding. Parameters that can be varied without loss (such as + * scan script and Huffman optimization) are left in their default states. + */ + + GLOBAL(void) + jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, + j_compress_ptr dstinfo) + { + JQUANT_TBL ** qtblptr; + jpeg_component_info *incomp, *outcomp; + JQUANT_TBL *c_quant, *slot_quant; + int tblno, ci, coefi; + + /* Safety check to ensure start_compress not called yet. */ + if (dstinfo->global_state != CSTATE_START) + ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state); + /* Copy fundamental image dimensions */ + dstinfo->image_width = srcinfo->image_width; + dstinfo->image_height = srcinfo->image_height; + dstinfo->input_components = srcinfo->num_components; + dstinfo->in_color_space = srcinfo->jpeg_color_space; + /* Initialize all parameters to default values */ + jpeg_set_defaults(dstinfo); + /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. + * Fix it to get the right header markers for the image colorspace. + */ + jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space); + dstinfo->data_precision = srcinfo->data_precision; + dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling; + /* Copy the source's quantization tables. */ + for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { + if (srcinfo->quant_tbl_ptrs[tblno] != NULL) { + qtblptr = & dstinfo->quant_tbl_ptrs[tblno]; + if (*qtblptr == NULL) + *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo); + MEMCOPY((*qtblptr)->quantval, + srcinfo->quant_tbl_ptrs[tblno]->quantval, + SIZEOF((*qtblptr)->quantval)); + (*qtblptr)->sent_table = FALSE; + } + } + /* Copy the source's per-component info. + * Note we assume jpeg_set_defaults has allocated the dest comp_info array. + */ + dstinfo->num_components = srcinfo->num_components; + if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS) + ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components, + MAX_COMPONENTS); + for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info; + ci < dstinfo->num_components; ci++, incomp++, outcomp++) { + outcomp->component_id = incomp->component_id; + outcomp->h_samp_factor = incomp->h_samp_factor; + outcomp->v_samp_factor = incomp->v_samp_factor; + outcomp->quant_tbl_no = incomp->quant_tbl_no; + /* Make sure saved quantization table for component matches the qtable + * slot. If not, the input file re-used this qtable slot. + * IJG encoder currently cannot duplicate this. + */ + tblno = outcomp->quant_tbl_no; + if (tblno < 0 || tblno >= NUM_QUANT_TBLS || + srcinfo->quant_tbl_ptrs[tblno] == NULL) + ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno); + slot_quant = srcinfo->quant_tbl_ptrs[tblno]; + c_quant = incomp->quant_table; + if (c_quant != NULL) { + for (coefi = 0; coefi < DCTSIZE2; coefi++) { + if (c_quant->quantval[coefi] != slot_quant->quantval[coefi]) + ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); + } + } + /* Note: we do not copy the source's Huffman table assignments; + * instead we rely on jpeg_set_colorspace to have made a suitable choice. + */ + } + } + + + /* + * Master selection of compression modules for transcoding. + * This substitutes for jcinit.c's initialization of the full compressor. + */ + + LOCAL(void) + transencode_master_selection (j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays) + { + /* Although we don't actually use input_components for transcoding, + * jcmaster.c's initial_setup will complain if input_components is 0. + */ + cinfo->input_components = 1; + /* Initialize master control (includes parameter checking/processing) */ + jinit_c_master_control(cinfo, TRUE /* transcode only */); + + /* Entropy encoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); + } else { + if (cinfo->progressive_mode) { + #ifdef C_PROGRESSIVE_SUPPORTED + jinit_phuff_encoder(cinfo); + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else + jinit_huff_encoder(cinfo); + } + + /* We need a special coefficient buffer controller. */ + transencode_coef_controller(cinfo, coef_arrays); + + jinit_marker_writer(cinfo); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Write the datastream header (SOI) immediately. + * Frame and scan headers are postponed till later. + * This lets application insert special markers after the SOI. + */ + (*cinfo->marker->write_file_header) (cinfo); + } + + + /* + * The rest of this file is a special implementation of the coefficient + * buffer controller. This is similar to jccoefct.c, but it handles only + * output from presupplied virtual arrays. Furthermore, we generate any + * dummy padding blocks on-the-fly rather than expecting them to be present + * in the arrays. + */ + + /* Private buffer controller object */ + + typedef struct { + struct jpeg_c_coef_controller pub; /* public fields */ + + JDIMENSION iMCU_row_num; /* iMCU row # within image */ + JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ + int MCU_vert_offset; /* counts MCU rows within iMCU row */ + int MCU_rows_per_iMCU_row; /* number of such rows needed */ + + /* Virtual block array for each component. */ + jvirt_barray_ptr * whole_image; + + /* Workspace for constructing dummy blocks at right/bottom edges. */ + JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU]; + } my_coef_controller; + + typedef my_coef_controller * my_coef_ptr; + + + LOCAL(void) + start_iMCU_row (j_compress_ptr cinfo) + /* Reset within-iMCU-row counters for a new row */ + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* In an interleaved scan, an MCU row is the same as an iMCU row. + * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. + * But at the bottom of the image, process only what's left. + */ + if (cinfo->comps_in_scan > 1) { + coef->MCU_rows_per_iMCU_row = 1; + } else { + if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; + else + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; + } + + coef->mcu_ctr = 0; + coef->MCU_vert_offset = 0; + } + + + /* + * Initialize for a processing pass. + */ + + METHODDEF(void) + start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + if (pass_mode != JBUF_CRANK_DEST) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + coef->iMCU_row_num = 0; + start_iMCU_row(cinfo); + } + + + /* + * Process some data. + * We process the equivalent of one fully interleaved MCU row ("iMCU" row) + * per call, ie, v_samp_factor block rows for each component in the scan. + * The data is obtained from the virtual arrays and fed to the entropy coder. + * Returns TRUE if the iMCU row is completed, FALSE if suspended. + * + * NB: input_buf is ignored; it is likely to be a NULL pointer. + */ + + METHODDEF(boolean) + compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + int blkn, ci, xindex, yindex, yoffset, blockcnt; + JDIMENSION start_col; + JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; + JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; + JBLOCKROW buffer_ptr; + jpeg_component_info *compptr; + + /* Align the virtual buffers for the components used in this scan. */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + buffer[ci] = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], + coef->iMCU_row_num * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + } + + /* Loop to process one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; + MCU_col_num++) { + /* Construct list of pointers to DCT blocks belonging to this MCU */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + start_col = MCU_col_num * compptr->MCU_width; + blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width + : compptr->last_col_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + if (coef->iMCU_row_num < last_iMCU_row || + yindex+yoffset < compptr->last_row_height) { + /* Fill in pointers to real blocks in this row */ + buffer_ptr = buffer[ci][yindex+yoffset] + start_col; + for (xindex = 0; xindex < blockcnt; xindex++) + MCU_buffer[blkn++] = buffer_ptr++; + } else { + /* At bottom of image, need a whole row of dummy blocks */ + xindex = 0; + } + /* Fill in any dummy blocks needed in this row. + * Dummy blocks are filled in the same way as in jccoefct.c: + * all zeroes in the AC entries, DC entries equal to previous + * block's DC value. The init routine has already zeroed the + * AC entries, so we need only set the DC entries correctly. + */ + for (; xindex < compptr->MCU_width; xindex++) { + MCU_buffer[blkn] = coef->dummy_buffer[blkn]; + MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0]; + blkn++; + } + } + } + /* Try to write the MCU. */ + if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->mcu_ctr = MCU_col_num; + return FALSE; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->mcu_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + coef->iMCU_row_num++; + start_iMCU_row(cinfo); + return TRUE; + } + + + /* + * Initialize coefficient buffer controller. + * + * Each passed coefficient array must be the right size for that + * coefficient: width_in_blocks wide and height_in_blocks high, + * with unitheight at least v_samp_factor. + */ + + LOCAL(void) + transencode_coef_controller (j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays) + { + my_coef_ptr coef; + JBLOCKROW buffer; + int i; + + coef = (my_coef_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_coef_controller)); + cinfo->coef = (struct jpeg_c_coef_controller *) coef; + coef->pub.start_pass = start_pass_coef; + coef->pub.compress_data = compress_output; + + /* Save pointer to virtual arrays */ + coef->whole_image = coef_arrays; + + /* Allocate and pre-zero space for dummy DCT blocks. */ + buffer = (JBLOCKROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { + coef->dummy_buffer[i] = buffer + i; + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdapimin.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdapimin.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdapimin.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,406 ---- + /* + * jdapimin.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the decompression half + * of the JPEG library. These are the "minimum" API routines that may be + * needed in either the normal full-decompression case or the + * transcoding-only case. + * + * Most of the routines intended to be called directly by an application + * are in this file or in jdapistd.c. But also see jcomapi.c for routines + * shared by compression and decompression, and jdtrans.c for the transcoding + * case. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * Initialization of a JPEG decompression object. + * The error manager must already be set up (in case memory manager fails). + */ + + GLOBAL(void) + jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) + { + int i; + + /* Guard against version mismatches between library and caller. */ + cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ + if (version != JPEG_LIB_VERSION) + ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); + if (structsize != SIZEOF(struct jpeg_decompress_struct)) + ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, + (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize); + + /* For debugging purposes, zero the whole master structure. + * But error manager pointer is already there, so save and restore it. + */ + { + struct jpeg_error_mgr * err = cinfo->err; + MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct)); + cinfo->err = err; + } + cinfo->is_decompressor = TRUE; + + /* Initialize a memory manager instance for this object */ + jinit_memory_mgr((j_common_ptr) cinfo); + + /* Zero out pointers to permanent structures. */ + cinfo->progress = NULL; + cinfo->src = NULL; + + for (i = 0; i < NUM_QUANT_TBLS; i++) + cinfo->quant_tbl_ptrs[i] = NULL; + + for (i = 0; i < NUM_HUFF_TBLS; i++) { + cinfo->dc_huff_tbl_ptrs[i] = NULL; + cinfo->ac_huff_tbl_ptrs[i] = NULL; + } + + /* Initialize marker processor so application can override methods + * for COM, APPn markers before calling jpeg_read_header. + */ + jinit_marker_reader(cinfo); + + /* And initialize the overall input controller. */ + jinit_input_controller(cinfo); + + /* OK, I'm ready */ + cinfo->global_state = DSTATE_START; + } + + + /* + * Destruction of a JPEG decompression object + */ + + GLOBAL(void) + jpeg_destroy_decompress (j_decompress_ptr cinfo) + { + jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ + } + + + /* + * Abort processing of a JPEG decompression operation, + * but don't destroy the object itself. + */ + + GLOBAL(void) + jpeg_abort_decompress (j_decompress_ptr cinfo) + { + jpeg_abort((j_common_ptr) cinfo); /* use common routine */ + } + + + /* + * Install a special processing method for COM or APPn markers. + */ + + GLOBAL(void) + jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code, + jpeg_marker_parser_method routine) + { + if (marker_code == JPEG_COM) + cinfo->marker->process_COM = routine; + else if (marker_code >= JPEG_APP0 && marker_code <= JPEG_APP0+15) + cinfo->marker->process_APPn[marker_code-JPEG_APP0] = routine; + else + ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code); + } + + + /* + * Set default decompression parameters. + */ + + LOCAL(void) + default_decompress_parms (j_decompress_ptr cinfo) + { + /* Guess the input colorspace, and set output colorspace accordingly. */ + /* (Wish JPEG committee had provided a real way to specify this...) */ + /* Note application may override our guesses. */ + switch (cinfo->num_components) { + case 1: + cinfo->jpeg_color_space = JCS_GRAYSCALE; + cinfo->out_color_space = JCS_GRAYSCALE; + break; + + case 3: + if (cinfo->saw_JFIF_marker) { + cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ + } else if (cinfo->saw_Adobe_marker) { + switch (cinfo->Adobe_transform) { + case 0: + cinfo->jpeg_color_space = JCS_RGB; + break; + case 1: + cinfo->jpeg_color_space = JCS_YCbCr; + break; + default: + WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); + cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ + break; + } + } else { + /* Saw no special markers, try to guess from the component IDs */ + int cid0 = cinfo->comp_info[0].component_id; + int cid1 = cinfo->comp_info[1].component_id; + int cid2 = cinfo->comp_info[2].component_id; + + if (cid0 == 1 && cid1 == 2 && cid2 == 3) + cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ + else if (cid0 == 82 && cid1 == 71 && cid2 == 66) + cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ + else { + TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); + cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ + } + } + /* Always guess RGB is proper output colorspace. */ + cinfo->out_color_space = JCS_RGB; + break; + + case 4: + if (cinfo->saw_Adobe_marker) { + switch (cinfo->Adobe_transform) { + case 0: + cinfo->jpeg_color_space = JCS_CMYK; + break; + case 2: + cinfo->jpeg_color_space = JCS_YCCK; + break; + default: + WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); + cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ + break; + } + } else { + /* No special markers, assume straight CMYK. */ + cinfo->jpeg_color_space = JCS_CMYK; + } + cinfo->out_color_space = JCS_CMYK; + break; + + default: + cinfo->jpeg_color_space = JCS_UNKNOWN; + cinfo->out_color_space = JCS_UNKNOWN; + break; + } + + /* Set defaults for other decompression parameters. */ + cinfo->scale_num = 1; /* 1:1 scaling */ + cinfo->scale_denom = 1; + cinfo->output_gamma = 1.0; + cinfo->buffered_image = FALSE; + cinfo->raw_data_out = FALSE; + cinfo->dct_method = JDCT_DEFAULT; + cinfo->do_fancy_upsampling = TRUE; + cinfo->do_block_smoothing = TRUE; + cinfo->quantize_colors = FALSE; + /* We set these in case application only sets quantize_colors. */ + cinfo->dither_mode = JDITHER_FS; + #ifdef QUANT_2PASS_SUPPORTED + cinfo->two_pass_quantize = TRUE; + #else + cinfo->two_pass_quantize = FALSE; + #endif + cinfo->desired_number_of_colors = 256; + cinfo->colormap = NULL; + /* Initialize for no mode change in buffered-image mode. */ + cinfo->enable_1pass_quant = FALSE; + cinfo->enable_external_quant = FALSE; + cinfo->enable_2pass_quant = FALSE; + } + + + /* + * Decompression startup: read start of JPEG datastream to see what's there. + * Need only initialize JPEG object and supply a data source before calling. + * + * This routine will read as far as the first SOS marker (ie, actual start of + * compressed data), and will save all tables and parameters in the JPEG + * object. It will also initialize the decompression parameters to default + * values, and finally return JPEG_HEADER_OK. On return, the application may + * adjust the decompression parameters and then call jpeg_start_decompress. + * (Or, if the application only wanted to determine the image parameters, + * the data need not be decompressed. In that case, call jpeg_abort or + * jpeg_destroy to release any temporary space.) + * If an abbreviated (tables only) datastream is presented, the routine will + * return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then + * re-use the JPEG object to read the abbreviated image datastream(s). + * It is unnecessary (but OK) to call jpeg_abort in this case. + * The JPEG_SUSPENDED return code only occurs if the data source module + * requests suspension of the decompressor. In this case the application + * should load more source data and then re-call jpeg_read_header to resume + * processing. + * If a non-suspending data source is used and require_image is TRUE, then the + * return code need not be inspected since only JPEG_HEADER_OK is possible. + * + * This routine is now just a front end to jpeg_consume_input, with some + * extra error checking. + */ + + GLOBAL(int) + jpeg_read_header (j_decompress_ptr cinfo, boolean require_image) + { + int retcode; + + if (cinfo->global_state != DSTATE_START && + cinfo->global_state != DSTATE_INHEADER) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + retcode = jpeg_consume_input(cinfo); + + switch (retcode) { + case JPEG_REACHED_SOS: + retcode = JPEG_HEADER_OK; + break; + case JPEG_REACHED_EOI: + if (require_image) /* Complain if application wanted an image */ + ERREXIT(cinfo, JERR_NO_IMAGE); + /* Reset to start state; it would be safer to require the application to + * call jpeg_abort, but we can't change it now for compatibility reasons. + * A side effect is to free any temporary memory (there shouldn't be any). + */ + jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */ + retcode = JPEG_HEADER_TABLES_ONLY; + break; + case JPEG_SUSPENDED: + /* no work */ + break; + } + + return retcode; + } + + + /* + * Consume data in advance of what the decompressor requires. + * This can be called at any time once the decompressor object has + * been created and a data source has been set up. + * + * This routine is essentially a state machine that handles a couple + * of critical state-transition actions, namely initial setup and + * transition from header scanning to ready-for-start_decompress. + * All the actual input is done via the input controller's consume_input + * method. + */ + + GLOBAL(int) + jpeg_consume_input (j_decompress_ptr cinfo) + { + int retcode = JPEG_SUSPENDED; + + /* NB: every possible DSTATE value should be listed in this switch */ + switch (cinfo->global_state) { + case DSTATE_START: + /* Start-of-datastream actions: reset appropriate modules */ + (*cinfo->inputctl->reset_input_controller) (cinfo); + /* Initialize application's data source module */ + (*cinfo->src->init_source) (cinfo); + cinfo->global_state = DSTATE_INHEADER; + /*FALLTHROUGH*/ + case DSTATE_INHEADER: + retcode = (*cinfo->inputctl->consume_input) (cinfo); + if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */ + /* Set up default parameters based on header data */ + default_decompress_parms(cinfo); + /* Set global state: ready for start_decompress */ + cinfo->global_state = DSTATE_READY; + } + break; + case DSTATE_READY: + /* Can't advance past first SOS until start_decompress is called */ + retcode = JPEG_REACHED_SOS; + break; + case DSTATE_PRELOAD: + case DSTATE_PRESCAN: + case DSTATE_SCANNING: + case DSTATE_RAW_OK: + case DSTATE_BUFIMAGE: + case DSTATE_BUFPOST: + case DSTATE_STOPPING: + retcode = (*cinfo->inputctl->consume_input) (cinfo); + break; + default: + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + } + return retcode; + } + + + /* + * Have we finished reading the input file? + */ + + GLOBAL(boolean) + jpeg_input_complete (j_decompress_ptr cinfo) + { + /* Check for valid jpeg object */ + if (cinfo->global_state < DSTATE_START || + cinfo->global_state > DSTATE_STOPPING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + return cinfo->inputctl->eoi_reached; + } + + + /* + * Is there more than one scan? + */ + + GLOBAL(boolean) + jpeg_has_multiple_scans (j_decompress_ptr cinfo) + { + /* Only valid after jpeg_read_header completes */ + if (cinfo->global_state < DSTATE_READY || + cinfo->global_state > DSTATE_STOPPING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + return cinfo->inputctl->has_multiple_scans; + } + + + /* + * Finish JPEG decompression. + * + * This will normally just verify the file trailer and release temp storage. + * + * Returns FALSE if suspended. The return value need be inspected only if + * a suspending data source is used. + */ + + GLOBAL(boolean) + jpeg_finish_decompress (j_decompress_ptr cinfo) + { + if ((cinfo->global_state == DSTATE_SCANNING || + cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) { + /* Terminate final pass of non-buffered mode */ + if (cinfo->output_scanline < cinfo->output_height) + ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); + (*cinfo->master->finish_output_pass) (cinfo); + cinfo->global_state = DSTATE_STOPPING; + } else if (cinfo->global_state == DSTATE_BUFIMAGE) { + /* Finishing after a buffered-image operation */ + cinfo->global_state = DSTATE_STOPPING; + } else if (cinfo->global_state != DSTATE_STOPPING) { + /* STOPPING = repeat call after a suspension, anything else is error */ + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + } + /* Read until EOI */ + while (! cinfo->inputctl->eoi_reached) { + if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) + return FALSE; /* Suspend, come back later */ + } + /* Do final cleanup */ + (*cinfo->src->term_source) (cinfo); + /* We can use jpeg_abort to release memory and reset global_state */ + jpeg_abort((j_common_ptr) cinfo); + return TRUE; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdapistd.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdapistd.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdapistd.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,275 ---- + /* + * jdapistd.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains application interface code for the decompression half + * of the JPEG library. These are the "standard" API routines that are + * used in the normal full-decompression case. They are not used by a + * transcoding-only application. Note that if an application links in + * jpeg_start_decompress, it will end up linking in the entire decompressor. + * We thus must separate this file from jdapimin.c to avoid linking the + * whole decompression library into a transcoder. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Forward declarations */ + LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo)); + + + /* + * Decompression initialization. + * jpeg_read_header must be completed before calling this. + * + * If a multipass operating mode was selected, this will do all but the + * last pass, and thus may take a great deal of time. + * + * Returns FALSE if suspended. The return value need be inspected only if + * a suspending data source is used. + */ + + GLOBAL(boolean) + jpeg_start_decompress (j_decompress_ptr cinfo) + { + if (cinfo->global_state == DSTATE_READY) { + /* First call: initialize master control, select active modules */ + jinit_master_decompress(cinfo); + if (cinfo->buffered_image) { + /* No more work here; expecting jpeg_start_output next */ + cinfo->global_state = DSTATE_BUFIMAGE; + return TRUE; + } + cinfo->global_state = DSTATE_PRELOAD; + } + if (cinfo->global_state == DSTATE_PRELOAD) { + /* If file has multiple scans, absorb them all into the coef buffer */ + if (cinfo->inputctl->has_multiple_scans) { + #ifdef D_MULTISCAN_FILES_SUPPORTED + for (;;) { + int retcode; + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + /* Absorb some more input */ + retcode = (*cinfo->inputctl->consume_input) (cinfo); + if (retcode == JPEG_SUSPENDED) + return FALSE; + if (retcode == JPEG_REACHED_EOI) + break; + /* Advance progress counter if appropriate */ + if (cinfo->progress != NULL && + (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { + if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { + /* jdmaster underestimated number of scans; ratchet up one scan */ + cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; + } + } + } + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif /* D_MULTISCAN_FILES_SUPPORTED */ + } + cinfo->output_scan_number = cinfo->input_scan_number; + } else if (cinfo->global_state != DSTATE_PRESCAN) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Perform any dummy output passes, and set up for the final pass */ + return output_pass_setup(cinfo); + } + + + /* + * Set up for an output pass, and perform any dummy pass(es) needed. + * Common subroutine for jpeg_start_decompress and jpeg_start_output. + * Entry: global_state = DSTATE_PRESCAN only if previously suspended. + * Exit: If done, returns TRUE and sets global_state for proper output mode. + * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN. + */ + + LOCAL(boolean) + output_pass_setup (j_decompress_ptr cinfo) + { + if (cinfo->global_state != DSTATE_PRESCAN) { + /* First call: do pass setup */ + (*cinfo->master->prepare_for_output_pass) (cinfo); + cinfo->output_scanline = 0; + cinfo->global_state = DSTATE_PRESCAN; + } + /* Loop over any required dummy passes */ + while (cinfo->master->is_dummy_pass) { + #ifdef QUANT_2PASS_SUPPORTED + /* Crank through the dummy pass */ + while (cinfo->output_scanline < cinfo->output_height) { + JDIMENSION last_scanline; + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->output_scanline; + cinfo->progress->pass_limit = (long) cinfo->output_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + /* Process some data */ + last_scanline = cinfo->output_scanline; + (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL, + &cinfo->output_scanline, (JDIMENSION) 0); + if (cinfo->output_scanline == last_scanline) + return FALSE; /* No progress made, must suspend */ + } + /* Finish up dummy pass, and set up for another one */ + (*cinfo->master->finish_output_pass) (cinfo); + (*cinfo->master->prepare_for_output_pass) (cinfo); + cinfo->output_scanline = 0; + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif /* QUANT_2PASS_SUPPORTED */ + } + /* Ready for application to drive output pass through + * jpeg_read_scanlines or jpeg_read_raw_data. + */ + cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING; + return TRUE; + } + + + /* + * Read some scanlines of data from the JPEG decompressor. + * + * The return value will be the number of lines actually read. + * This may be less than the number requested in several cases, + * including bottom of image, data source suspension, and operating + * modes that emit multiple scanlines at a time. + * + * Note: we warn about excess calls to jpeg_read_scanlines() since + * this likely signals an application programmer error. However, + * an oversize buffer (max_lines > scanlines remaining) is not an error. + */ + + GLOBAL(JDIMENSION) + jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, + JDIMENSION max_lines) + { + JDIMENSION row_ctr; + + if (cinfo->global_state != DSTATE_SCANNING) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->output_scanline >= cinfo->output_height) { + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + return 0; + } + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->output_scanline; + cinfo->progress->pass_limit = (long) cinfo->output_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Process some data */ + row_ctr = 0; + (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines); + cinfo->output_scanline += row_ctr; + return row_ctr; + } + + + /* + * Alternate entry point to read raw data. + * Processes exactly one iMCU row per call, unless suspended. + */ + + GLOBAL(JDIMENSION) + jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, + JDIMENSION max_lines) + { + JDIMENSION lines_per_iMCU_row; + + if (cinfo->global_state != DSTATE_RAW_OK) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + if (cinfo->output_scanline >= cinfo->output_height) { + WARNMS(cinfo, JWRN_TOO_MUCH_DATA); + return 0; + } + + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) { + cinfo->progress->pass_counter = (long) cinfo->output_scanline; + cinfo->progress->pass_limit = (long) cinfo->output_height; + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + } + + /* Verify that at least one iMCU row can be returned. */ + lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size; + if (max_lines < lines_per_iMCU_row) + ERREXIT(cinfo, JERR_BUFFER_SIZE); + + /* Decompress directly into user's buffer. */ + if (! (*cinfo->coef->decompress_data) (cinfo, data)) + return 0; /* suspension forced, can do nothing more */ + + /* OK, we processed one iMCU row. */ + cinfo->output_scanline += lines_per_iMCU_row; + return lines_per_iMCU_row; + } + + + /* Additional entry points for buffered-image mode. */ + + #ifdef D_MULTISCAN_FILES_SUPPORTED + + /* + * Initialize for an output pass in buffered-image mode. + */ + + GLOBAL(boolean) + jpeg_start_output (j_decompress_ptr cinfo, int scan_number) + { + if (cinfo->global_state != DSTATE_BUFIMAGE && + cinfo->global_state != DSTATE_PRESCAN) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Limit scan number to valid range */ + if (scan_number <= 0) + scan_number = 1; + if (cinfo->inputctl->eoi_reached && + scan_number > cinfo->input_scan_number) + scan_number = cinfo->input_scan_number; + cinfo->output_scan_number = scan_number; + /* Perform any dummy output passes, and set up for the real pass */ + return output_pass_setup(cinfo); + } + + + /* + * Finish up after an output pass in buffered-image mode. + * + * Returns FALSE if suspended. The return value need be inspected only if + * a suspending data source is used. + */ + + GLOBAL(boolean) + jpeg_finish_output (j_decompress_ptr cinfo) + { + if ((cinfo->global_state == DSTATE_SCANNING || + cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) { + /* Terminate this pass. */ + /* We do not require the whole pass to have been completed. */ + (*cinfo->master->finish_output_pass) (cinfo); + cinfo->global_state = DSTATE_BUFPOST; + } else if (cinfo->global_state != DSTATE_BUFPOST) { + /* BUFPOST = repeat call after a suspension, anything else is error */ + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + } + /* Read markers looking for SOS or EOI */ + while (cinfo->input_scan_number <= cinfo->output_scan_number && + ! cinfo->inputctl->eoi_reached) { + if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) + return FALSE; /* Suspend, come back later */ + } + cinfo->global_state = DSTATE_BUFIMAGE; + return TRUE; + } + + #endif /* D_MULTISCAN_FILES_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdatadst.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdatadst.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdatadst.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,151 ---- + /* + * jdatadst.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains compression data destination routines for the case of + * emitting JPEG data to a file (or any stdio stream). While these routines + * are sufficient for most applications, some will want to use a different + * destination manager. + * IMPORTANT: we assume that fwrite() will correctly transcribe an array of + * JOCTETs into 8-bit-wide elements on external storage. If char is wider + * than 8 bits on your machine, you may need to do some tweaking. + */ + + /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ + #include "jinclude.h" + #include "jpeglib.h" + #include "jerror.h" + + + /* Expanded data destination object for stdio output */ + + typedef struct { + struct jpeg_destination_mgr pub; /* public fields */ + + FILE * outfile; /* target stream */ + JOCTET * buffer; /* start of buffer */ + } my_destination_mgr; + + typedef my_destination_mgr * my_dest_ptr; + + #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ + + + /* + * Initialize destination --- called by jpeg_start_compress + * before any data is actually written. + */ + + METHODDEF(void) + init_destination (j_compress_ptr cinfo) + { + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + + /* Allocate the output buffer --- it will be released when done with image */ + dest->buffer = (JOCTET *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + } + + + /* + * Empty the output buffer --- called whenever buffer fills up. + * + * In typical applications, this should write the entire output buffer + * (ignoring the current state of next_output_byte & free_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been dumped. + * + * In applications that need to be able to suspend compression due to output + * overrun, a FALSE return indicates that the buffer cannot be emptied now. + * In this situation, the compressor will return to its caller (possibly with + * an indication that it has not accepted all the supplied scanlines). The + * application should resume compression after it has made more room in the + * output buffer. Note that there are substantial restrictions on the use of + * suspension --- see the documentation. + * + * When suspending, the compressor will back up to a convenient restart point + * (typically the start of the current MCU). next_output_byte & free_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point will be regenerated after resumption, so do not + * write it out when emptying the buffer externally. + */ + + METHODDEF(boolean) + empty_output_buffer (j_compress_ptr cinfo) + { + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + + if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != + (size_t) OUTPUT_BUF_SIZE) + ERREXIT(cinfo, JERR_FILE_WRITE); + + dest->pub.next_output_byte = dest->buffer; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + + return TRUE; + } + + + /* + * Terminate destination --- called by jpeg_finish_compress + * after all data has been written. Usually needs to flush buffer. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ + + METHODDEF(void) + term_destination (j_compress_ptr cinfo) + { + my_dest_ptr dest = (my_dest_ptr) cinfo->dest; + size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; + + /* Write any data remaining in the buffer */ + if (datacount > 0) { + if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + fflush(dest->outfile); + /* Make sure we wrote the output file OK */ + if (ferror(dest->outfile)) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + + + /* + * Prepare for output to a stdio stream. + * The caller must have already opened the stream, and is responsible + * for closing it after finishing compression. + */ + + GLOBAL(void) + jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile) + { + my_dest_ptr dest; + + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same file without re-executing jpeg_stdio_dest. + * This makes it dangerous to use this manager and a different destination + * manager serially with the same JPEG object, because their private object + * sizes may be different. Caveat programmer. + */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_destination_mgr)); + } + + dest = (my_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_destination; + dest->pub.empty_output_buffer = empty_output_buffer; + dest->pub.term_destination = term_destination; + dest->outfile = outfile; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdatasrc.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdatasrc.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdatasrc.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,212 ---- + /* + * jdatasrc.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains decompression data source routines for the case of + * reading JPEG data from a file (or any stdio stream). While these routines + * are sufficient for most applications, some will want to use a different + * source manager. + * IMPORTANT: we assume that fread() will correctly transcribe an array of + * JOCTETs from 8-bit-wide elements on external storage. If char is wider + * than 8 bits on your machine, you may need to do some tweaking. + */ + + /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ + #include "jinclude.h" + #include "jpeglib.h" + #include "jerror.h" + + + /* Expanded data source object for stdio input */ + + typedef struct { + struct jpeg_source_mgr pub; /* public fields */ + + FILE * infile; /* source stream */ + JOCTET * buffer; /* start of buffer */ + boolean start_of_file; /* have we gotten any data yet? */ + } my_source_mgr; + + typedef my_source_mgr * my_src_ptr; + + #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */ + + + /* + * Initialize source --- called by jpeg_read_header + * before any data is actually read. + */ + + METHODDEF(void) + init_source (j_decompress_ptr cinfo) + { + my_src_ptr src = (my_src_ptr) cinfo->src; + + /* We reset the empty-input-file flag for each image, + * but we don't clear the input buffer. + * This is correct behavior for reading a series of images from one source. + */ + src->start_of_file = TRUE; + } + + + /* + * Fill the input buffer --- called whenever buffer is emptied. + * + * In typical applications, this should read fresh data into the buffer + * (ignoring the current state of next_input_byte & bytes_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been reloaded. It is not necessary to + * fill the buffer entirely, only to obtain at least one more byte. + * + * There is no such thing as an EOF return. If the end of the file has been + * reached, the routine has a choice of ERREXIT() or inserting fake data into + * the buffer. In most cases, generating a warning message and inserting a + * fake EOI marker is the best course of action --- this will allow the + * decompressor to output however much of the image is there. However, + * the resulting error message is misleading if the real problem is an empty + * input file, so we handle that case specially. + * + * In applications that need to be able to suspend compression due to input + * not being available yet, a FALSE return indicates that no more data can be + * obtained right now, but more may be forthcoming later. In this situation, + * the decompressor will return to its caller (with an indication of the + * number of scanlines it has read, if any). The application should resume + * decompression after it has loaded more data into the input buffer. Note + * that there are substantial restrictions on the use of suspension --- see + * the documentation. + * + * When suspending, the decompressor will back up to a convenient restart point + * (typically the start of the current MCU). next_input_byte & bytes_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point must be rescanned after resumption, so move it to + * the front of the buffer rather than discarding it. + */ + + METHODDEF(boolean) + fill_input_buffer (j_decompress_ptr cinfo) + { + my_src_ptr src = (my_src_ptr) cinfo->src; + size_t nbytes; + + nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); + + if (nbytes <= 0) { + if (src->start_of_file) /* Treat empty input file as fatal error */ + ERREXIT(cinfo, JERR_INPUT_EMPTY); + WARNMS(cinfo, JWRN_JPEG_EOF); + /* Insert a fake EOI marker */ + src->buffer[0] = (JOCTET) 0xFF; + src->buffer[1] = (JOCTET) JPEG_EOI; + nbytes = 2; + } + + src->pub.next_input_byte = src->buffer; + src->pub.bytes_in_buffer = nbytes; + src->start_of_file = FALSE; + + return TRUE; + } + + + /* + * Skip data --- used to skip over a potentially large amount of + * uninteresting data (such as an APPn marker). + * + * Writers of suspendable-input applications must note that skip_input_data + * is not granted the right to give a suspension return. If the skip extends + * beyond the data currently in the buffer, the buffer can be marked empty so + * that the next read will cause a fill_input_buffer call that can suspend. + * Arranging for additional bytes to be discarded before reloading the input + * buffer is the application writer's problem. + */ + + METHODDEF(void) + skip_input_data (j_decompress_ptr cinfo, long num_bytes) + { + my_src_ptr src = (my_src_ptr) cinfo->src; + + /* Just a dumb implementation for now. Could use fseek() except + * it doesn't work on pipes. Not clear that being smart is worth + * any trouble anyway --- large skips are infrequent. + */ + if (num_bytes > 0) { + while (num_bytes > (long) src->pub.bytes_in_buffer) { + num_bytes -= (long) src->pub.bytes_in_buffer; + (void) fill_input_buffer(cinfo); + /* note we assume that fill_input_buffer will never return FALSE, + * so suspension need not be handled. + */ + } + src->pub.next_input_byte += (size_t) num_bytes; + src->pub.bytes_in_buffer -= (size_t) num_bytes; + } + } + + + /* + * An additional method that can be provided by data source modules is the + * resync_to_restart method for error recovery in the presence of RST markers. + * For the moment, this source module just uses the default resync method + * provided by the JPEG library. That method assumes that no backtracking + * is possible. + */ + + + /* + * Terminate source --- called by jpeg_finish_decompress + * after all data has been read. Often a no-op. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ + + METHODDEF(void) + term_source (j_decompress_ptr cinfo) + { + /* no work necessary here */ + } + + + /* + * Prepare for input from a stdio stream. + * The caller must have already opened the stream, and is responsible + * for closing it after finishing decompression. + */ + + GLOBAL(void) + jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile) + { + my_src_ptr src; + + /* The source object and input buffer are made permanent so that a series + * of JPEG images can be read from the same file by calling jpeg_stdio_src + * only before the first one. (If we discarded the buffer at the end of + * one image, we'd likely lose the start of the next one.) + * This makes it unsafe to use this manager and a different source + * manager serially with the same JPEG object. Caveat programmer. + */ + if (cinfo->src == NULL) { /* first time for this JPEG object? */ + cinfo->src = (struct jpeg_source_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_source_mgr)); + src = (my_src_ptr) cinfo->src; + src->buffer = (JOCTET *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + INPUT_BUF_SIZE * SIZEOF(JOCTET)); + } + + src = (my_src_ptr) cinfo->src; + src->pub.init_source = init_source; + src->pub.fill_input_buffer = fill_input_buffer; + src->pub.skip_input_data = skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ + src->pub.term_source = term_source; + src->infile = infile; + src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ + src->pub.next_input_byte = NULL; /* until buffer loaded */ + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdcoefct.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdcoefct.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdcoefct.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,735 ---- + /* + * jdcoefct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the coefficient buffer controller for decompression. + * This controller is the top level of the JPEG decompressor proper. + * The coefficient buffer lies between entropy decoding and inverse-DCT steps. + * + * In buffered-image mode, this controller is the interface between + * input-oriented processing and output-oriented processing. + * Also, the input side (only) is used when reading a file for transcoding. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + /* Block smoothing is only applicable for progressive JPEG, so: */ + #ifndef D_PROGRESSIVE_SUPPORTED + #undef BLOCK_SMOOTHING_SUPPORTED + #endif + + /* Private buffer controller object */ + + typedef struct { + struct jpeg_d_coef_controller pub; /* public fields */ + + /* These variables keep track of the current location of the input side. */ + /* cinfo->input_iMCU_row is also used for this. */ + JDIMENSION MCU_ctr; /* counts MCUs processed in current row */ + int MCU_vert_offset; /* counts MCU rows within iMCU row */ + int MCU_rows_per_iMCU_row; /* number of such rows needed */ + + /* The output side's location is represented by cinfo->output_iMCU_row. */ + + /* In single-pass modes, it's sufficient to buffer just one MCU. + * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks, + * and let the entropy decoder write into that workspace each time. + * (On 80x86, the workspace is FAR even though it's not really very big; + * this is to keep the module interfaces unchanged when a large coefficient + * buffer is necessary.) + * In multi-pass modes, this array points to the current MCU's blocks + * within the virtual arrays; it is used only by the input side. + */ + JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU]; + + #ifdef D_MULTISCAN_FILES_SUPPORTED + /* In multi-pass modes, we need a virtual block array for each component. */ + jvirt_barray_ptr whole_image[MAX_COMPONENTS]; + #endif + + #ifdef BLOCK_SMOOTHING_SUPPORTED + /* When doing block smoothing, we latch coefficient Al values here */ + int * coef_bits_latch; + #define SAVED_COEFS 6 /* we save coef_bits[0..5] */ + #endif + } my_coef_controller; + + typedef my_coef_controller * my_coef_ptr; + + /* Forward declarations */ + METHODDEF(int) decompress_onepass + JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); + #ifdef D_MULTISCAN_FILES_SUPPORTED + METHODDEF(int) decompress_data + JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); + #endif + #ifdef BLOCK_SMOOTHING_SUPPORTED + LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo)); + METHODDEF(int) decompress_smooth_data + JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); + #endif + + + LOCAL(void) + start_iMCU_row (j_decompress_ptr cinfo) + /* Reset within-iMCU-row counters for a new row (input side) */ + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* In an interleaved scan, an MCU row is the same as an iMCU row. + * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. + * But at the bottom of the image, process only what's left. + */ + if (cinfo->comps_in_scan > 1) { + coef->MCU_rows_per_iMCU_row = 1; + } else { + if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1)) + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; + else + coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; + } + + coef->MCU_ctr = 0; + coef->MCU_vert_offset = 0; + } + + + /* + * Initialize for an input processing pass. + */ + + METHODDEF(void) + start_input_pass (j_decompress_ptr cinfo) + { + cinfo->input_iMCU_row = 0; + start_iMCU_row(cinfo); + } + + + /* + * Initialize for an output processing pass. + */ + + METHODDEF(void) + start_output_pass (j_decompress_ptr cinfo) + { + #ifdef BLOCK_SMOOTHING_SUPPORTED + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + + /* If multipass, check to see whether to use block smoothing on this pass */ + if (coef->pub.coef_arrays != NULL) { + if (cinfo->do_block_smoothing && smoothing_ok(cinfo)) + coef->pub.decompress_data = decompress_smooth_data; + else + coef->pub.decompress_data = decompress_data; + } + #endif + cinfo->output_iMCU_row = 0; + } + + + /* + * Decompress and return some data in the single-pass case. + * Always attempts to emit one fully interleaved MCU row ("iMCU" row). + * Input and output must run in lockstep since we have only a one-MCU buffer. + * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. + * + * NB: output_buf contains a plane for each component in image. + * For single pass, this is the same as the components in the scan. + */ + + METHODDEF(int) + decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + int blkn, ci, xindex, yindex, yoffset, useful_width; + JSAMPARRAY output_ptr; + JDIMENSION start_col, output_col; + jpeg_component_info *compptr; + inverse_DCT_method_ptr inverse_DCT; + + /* Loop to process as much as one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; + MCU_col_num++) { + /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ + jzero_far((void FAR *) coef->MCU_buffer[0], + (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK))); + if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->MCU_ctr = MCU_col_num; + return JPEG_SUSPENDED; + } + /* Determine where data should go in output_buf and do the IDCT thing. + * We skip dummy blocks at the right and bottom edges (but blkn gets + * incremented past them!). Note the inner loop relies on having + * allocated the MCU_buffer[] blocks sequentially. + */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Don't bother to IDCT an uninteresting component. */ + if (! compptr->component_needed) { + blkn += compptr->MCU_blocks; + continue; + } + inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; + useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width + : compptr->last_col_width; + output_ptr = output_buf[ci] + yoffset * compptr->DCT_scaled_size; + start_col = MCU_col_num * compptr->MCU_sample_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + if (cinfo->input_iMCU_row < last_iMCU_row || + yoffset+yindex < compptr->last_row_height) { + output_col = start_col; + for (xindex = 0; xindex < useful_width; xindex++) { + (*inverse_DCT) (cinfo, compptr, + (JCOEFPTR) coef->MCU_buffer[blkn+xindex], + output_ptr, output_col); + output_col += compptr->DCT_scaled_size; + } + } + blkn += compptr->MCU_width; + output_ptr += compptr->DCT_scaled_size; + } + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->MCU_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + cinfo->output_iMCU_row++; + if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { + start_iMCU_row(cinfo); + return JPEG_ROW_COMPLETED; + } + /* Completed the scan */ + (*cinfo->inputctl->finish_input_pass) (cinfo); + return JPEG_SCAN_COMPLETED; + } + + + /* + * Dummy consume-input routine for single-pass operation. + */ + + METHODDEF(int) + dummy_consume_data (j_decompress_ptr cinfo) + { + return JPEG_SUSPENDED; /* Always indicate nothing was done */ + } + + + #ifdef D_MULTISCAN_FILES_SUPPORTED + + /* + * Consume input data and store it in the full-image coefficient buffer. + * We read as much as one fully interleaved MCU row ("iMCU" row) per call, + * ie, v_samp_factor block rows for each component in the scan. + * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. + */ + + METHODDEF(int) + consume_data (j_decompress_ptr cinfo) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION MCU_col_num; /* index of current MCU within row */ + int blkn, ci, xindex, yindex, yoffset; + JDIMENSION start_col; + JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; + JBLOCKROW buffer_ptr; + jpeg_component_info *compptr; + + /* Align the virtual buffers for the components used in this scan. */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + buffer[ci] = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], + cinfo->input_iMCU_row * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, TRUE); + /* Note: entropy decoder expects buffer to be zeroed, + * but this is handled automatically by the memory manager + * because we requested a pre-zeroed array. + */ + } + + /* Loop to process one whole iMCU row */ + for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; + yoffset++) { + for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; + MCU_col_num++) { + /* Construct list of pointers to DCT blocks belonging to this MCU */ + blkn = 0; /* index of current DCT block within MCU */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + start_col = MCU_col_num * compptr->MCU_width; + for (yindex = 0; yindex < compptr->MCU_height; yindex++) { + buffer_ptr = buffer[ci][yindex+yoffset] + start_col; + for (xindex = 0; xindex < compptr->MCU_width; xindex++) { + coef->MCU_buffer[blkn++] = buffer_ptr++; + } + } + } + /* Try to fetch the MCU. */ + if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { + /* Suspension forced; update state counters and exit */ + coef->MCU_vert_offset = yoffset; + coef->MCU_ctr = MCU_col_num; + return JPEG_SUSPENDED; + } + } + /* Completed an MCU row, but perhaps not an iMCU row */ + coef->MCU_ctr = 0; + } + /* Completed the iMCU row, advance counters for next one */ + if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { + start_iMCU_row(cinfo); + return JPEG_ROW_COMPLETED; + } + /* Completed the scan */ + (*cinfo->inputctl->finish_input_pass) (cinfo); + return JPEG_SCAN_COMPLETED; + } + + + /* + * Decompress and return some data in the multi-pass case. + * Always attempts to emit one fully interleaved MCU row ("iMCU" row). + * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. + * + * NB: output_buf contains a plane for each component in image. + */ + + METHODDEF(int) + decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + JDIMENSION block_num; + int ci, block_row, block_rows; + JBLOCKARRAY buffer; + JBLOCKROW buffer_ptr; + JSAMPARRAY output_ptr; + JDIMENSION output_col; + jpeg_component_info *compptr; + inverse_DCT_method_ptr inverse_DCT; + + /* Force some input to be done if we are getting ahead of the input. */ + while (cinfo->input_scan_number < cinfo->output_scan_number || + (cinfo->input_scan_number == cinfo->output_scan_number && + cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { + if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) + return JPEG_SUSPENDED; + } + + /* OK, output from the virtual arrays. */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Don't bother to IDCT an uninteresting component. */ + if (! compptr->component_needed) + continue; + /* Align the virtual buffer for this component. */ + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + cinfo->output_iMCU_row * compptr->v_samp_factor, + (JDIMENSION) compptr->v_samp_factor, FALSE); + /* Count non-dummy DCT block rows in this iMCU row. */ + if (cinfo->output_iMCU_row < last_iMCU_row) + block_rows = compptr->v_samp_factor; + else { + /* NB: can't use last_row_height here; it is input-side-dependent! */ + block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (block_rows == 0) block_rows = compptr->v_samp_factor; + } + inverse_DCT = cinfo->idct->inverse_DCT[ci]; + output_ptr = output_buf[ci]; + /* Loop over all DCT blocks to be processed. */ + for (block_row = 0; block_row < block_rows; block_row++) { + buffer_ptr = buffer[block_row]; + output_col = 0; + for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) { + (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, + output_ptr, output_col); + buffer_ptr++; + output_col += compptr->DCT_scaled_size; + } + output_ptr += compptr->DCT_scaled_size; + } + } + + if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) + return JPEG_ROW_COMPLETED; + return JPEG_SCAN_COMPLETED; + } + + #endif /* D_MULTISCAN_FILES_SUPPORTED */ + + + #ifdef BLOCK_SMOOTHING_SUPPORTED + + /* + * This code applies interblock smoothing as described by section K.8 + * of the JPEG standard: the first 5 AC coefficients are estimated from + * the DC values of a DCT block and its 8 neighboring blocks. + * We apply smoothing only for progressive JPEG decoding, and only if + * the coefficients it can estimate are not yet known to full precision. + */ + + /* Natural-order array positions of the first 5 zigzag-order coefficients */ + #define Q01_POS 1 + #define Q10_POS 8 + #define Q20_POS 16 + #define Q11_POS 9 + #define Q02_POS 2 + + /* + * Determine whether block smoothing is applicable and safe. + * We also latch the current states of the coef_bits[] entries for the + * AC coefficients; otherwise, if the input side of the decompressor + * advances into a new scan, we might think the coefficients are known + * more accurately than they really are. + */ + + LOCAL(boolean) + smoothing_ok (j_decompress_ptr cinfo) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + boolean smoothing_useful = FALSE; + int ci, coefi; + jpeg_component_info *compptr; + JQUANT_TBL * qtable; + int * coef_bits; + int * coef_bits_latch; + + if (! cinfo->progressive_mode || cinfo->coef_bits == NULL) + return FALSE; + + /* Allocate latch area if not already done */ + if (coef->coef_bits_latch == NULL) + coef->coef_bits_latch = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components * + (SAVED_COEFS * SIZEOF(int))); + coef_bits_latch = coef->coef_bits_latch; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* All components' quantization values must already be latched. */ + if ((qtable = compptr->quant_table) == NULL) + return FALSE; + /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ + if (qtable->quantval[0] == 0 || + qtable->quantval[Q01_POS] == 0 || + qtable->quantval[Q10_POS] == 0 || + qtable->quantval[Q20_POS] == 0 || + qtable->quantval[Q11_POS] == 0 || + qtable->quantval[Q02_POS] == 0) + return FALSE; + /* DC values must be at least partly known for all components. */ + coef_bits = cinfo->coef_bits[ci]; + if (coef_bits[0] < 0) + return FALSE; + /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ + for (coefi = 1; coefi <= 5; coefi++) { + coef_bits_latch[coefi] = coef_bits[coefi]; + if (coef_bits[coefi] != 0) + smoothing_useful = TRUE; + } + coef_bits_latch += SAVED_COEFS; + } + + return smoothing_useful; + } + + + /* + * Variant of decompress_data for use when doing block smoothing. + */ + + METHODDEF(int) + decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) + { + my_coef_ptr coef = (my_coef_ptr) cinfo->coef; + JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; + JDIMENSION block_num, last_block_column; + int ci, block_row, block_rows, access_rows; + JBLOCKARRAY buffer; + JBLOCKROW buffer_ptr, prev_block_row, next_block_row; + JSAMPARRAY output_ptr; + JDIMENSION output_col; + jpeg_component_info *compptr; + inverse_DCT_method_ptr inverse_DCT; + boolean first_row, last_row; + JBLOCK workspace; + int *coef_bits; + JQUANT_TBL *quanttbl; + INT32 Q00,Q01,Q02,Q10,Q11,Q20, num; + int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9; + int Al, pred; + + /* Force some input to be done if we are getting ahead of the input. */ + while (cinfo->input_scan_number <= cinfo->output_scan_number && + ! cinfo->inputctl->eoi_reached) { + if (cinfo->input_scan_number == cinfo->output_scan_number) { + /* If input is working on current scan, we ordinarily want it to + * have completed the current row. But if input scan is DC, + * we want it to keep one row ahead so that next block row's DC + * values are up to date. + */ + JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0; + if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta) + break; + } + if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) + return JPEG_SUSPENDED; + } + + /* OK, output from the virtual arrays. */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Don't bother to IDCT an uninteresting component. */ + if (! compptr->component_needed) + continue; + /* Count non-dummy DCT block rows in this iMCU row. */ + if (cinfo->output_iMCU_row < last_iMCU_row) { + block_rows = compptr->v_samp_factor; + access_rows = block_rows * 2; /* this and next iMCU row */ + last_row = FALSE; + } else { + /* NB: can't use last_row_height here; it is input-side-dependent! */ + block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (block_rows == 0) block_rows = compptr->v_samp_factor; + access_rows = block_rows; /* this iMCU row only */ + last_row = TRUE; + } + /* Align the virtual buffer for this component. */ + if (cinfo->output_iMCU_row > 0) { + access_rows += compptr->v_samp_factor; /* prior iMCU row too */ + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, + (JDIMENSION) access_rows, FALSE); + buffer += compptr->v_samp_factor; /* point to current iMCU row */ + first_row = FALSE; + } else { + buffer = (*cinfo->mem->access_virt_barray) + ((j_common_ptr) cinfo, coef->whole_image[ci], + (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE); + first_row = TRUE; + } + /* Fetch component-dependent info */ + coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); + quanttbl = compptr->quant_table; + Q00 = quanttbl->quantval[0]; + Q01 = quanttbl->quantval[Q01_POS]; + Q10 = quanttbl->quantval[Q10_POS]; + Q20 = quanttbl->quantval[Q20_POS]; + Q11 = quanttbl->quantval[Q11_POS]; + Q02 = quanttbl->quantval[Q02_POS]; + inverse_DCT = cinfo->idct->inverse_DCT[ci]; + output_ptr = output_buf[ci]; + /* Loop over all DCT blocks to be processed. */ + for (block_row = 0; block_row < block_rows; block_row++) { + buffer_ptr = buffer[block_row]; + if (first_row && block_row == 0) + prev_block_row = buffer_ptr; + else + prev_block_row = buffer[block_row-1]; + if (last_row && block_row == block_rows-1) + next_block_row = buffer_ptr; + else + next_block_row = buffer[block_row+1]; + /* We fetch the surrounding DC values using a sliding-register approach. + * Initialize all nine here so as to do the right thing on narrow pics. + */ + DC1 = DC2 = DC3 = (int) prev_block_row[0][0]; + DC4 = DC5 = DC6 = (int) buffer_ptr[0][0]; + DC7 = DC8 = DC9 = (int) next_block_row[0][0]; + output_col = 0; + last_block_column = compptr->width_in_blocks - 1; + for (block_num = 0; block_num <= last_block_column; block_num++) { + /* Fetch current DCT block into workspace so we can modify it. */ + jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1); + /* Update DC values */ + if (block_num < last_block_column) { + DC3 = (int) prev_block_row[1][0]; + DC6 = (int) buffer_ptr[1][0]; + DC9 = (int) next_block_row[1][0]; + } + /* Compute coefficient estimates per K.8. + * An estimate is applied only if coefficient is still zero, + * and is not known to be fully accurate. + */ + /* AC01 */ + if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) { + num = 36 * Q00 * (DC4 - DC6); + if (num >= 0) { + pred = (int) (((Q01<<7) + num) / (Q01<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + } else { + pred = (int) (((Q01<<7) - num) / (Q01<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + pred = -pred; + } + workspace[1] = (JCOEF) pred; + } + /* AC10 */ + if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) { + num = 36 * Q00 * (DC2 - DC8); + if (num >= 0) { + pred = (int) (((Q10<<7) + num) / (Q10<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + } else { + pred = (int) (((Q10<<7) - num) / (Q10<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + pred = -pred; + } + workspace[8] = (JCOEF) pred; + } + /* AC20 */ + if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) { + num = 9 * Q00 * (DC2 + DC8 - 2*DC5); + if (num >= 0) { + pred = (int) (((Q20<<7) + num) / (Q20<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + } else { + pred = (int) (((Q20<<7) - num) / (Q20<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + pred = -pred; + } + workspace[16] = (JCOEF) pred; + } + /* AC11 */ + if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) { + num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); + if (num >= 0) { + pred = (int) (((Q11<<7) + num) / (Q11<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + } else { + pred = (int) (((Q11<<7) - num) / (Q11<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + pred = -pred; + } + workspace[9] = (JCOEF) pred; + } + /* AC02 */ + if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) { + num = 9 * Q00 * (DC4 + DC6 - 2*DC5); + if (num >= 0) { + pred = (int) (((Q02<<7) + num) / (Q02<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + } else { + pred = (int) (((Q02<<7) - num) / (Q02<<8)); + if (Al > 0 && pred >= (1<<Al)) + pred = (1<<Al)-1; + pred = -pred; + } + workspace[2] = (JCOEF) pred; + } + /* OK, do the IDCT */ + (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace, + output_ptr, output_col); + /* Advance for next column */ + DC1 = DC2; DC2 = DC3; + DC4 = DC5; DC5 = DC6; + DC7 = DC8; DC8 = DC9; + buffer_ptr++, prev_block_row++, next_block_row++; + output_col += compptr->DCT_scaled_size; + } + output_ptr += compptr->DCT_scaled_size; + } + } + + if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) + return JPEG_ROW_COMPLETED; + return JPEG_SCAN_COMPLETED; + } + + #endif /* BLOCK_SMOOTHING_SUPPORTED */ + + + /* + * Initialize coefficient buffer controller. + */ + + GLOBAL(void) + jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer) + { + my_coef_ptr coef; + + coef = (my_coef_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_coef_controller)); + cinfo->coef = (struct jpeg_d_coef_controller *) coef; + coef->pub.start_input_pass = start_input_pass; + coef->pub.start_output_pass = start_output_pass; + #ifdef BLOCK_SMOOTHING_SUPPORTED + coef->coef_bits_latch = NULL; + #endif + + /* Create the coefficient buffer. */ + if (need_full_buffer) { + #ifdef D_MULTISCAN_FILES_SUPPORTED + /* Allocate a full-image virtual array for each component, */ + /* padded to a multiple of samp_factor DCT blocks in each direction. */ + /* Note we ask for a pre-zeroed array. */ + int ci, access_rows; + jpeg_component_info *compptr; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + access_rows = compptr->v_samp_factor; + #ifdef BLOCK_SMOOTHING_SUPPORTED + /* If block smoothing could be used, need a bigger window */ + if (cinfo->progressive_mode) + access_rows *= 3; + #endif + coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE, + (JDIMENSION) jround_up((long) compptr->width_in_blocks, + (long) compptr->h_samp_factor), + (JDIMENSION) jround_up((long) compptr->height_in_blocks, + (long) compptr->v_samp_factor), + (JDIMENSION) access_rows); + } + coef->pub.consume_data = consume_data; + coef->pub.decompress_data = decompress_data; + coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else { + /* We only need a single-MCU buffer. */ + JBLOCKROW buffer; + int i; + + buffer = (JBLOCKROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); + for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { + coef->MCU_buffer[i] = buffer + i; + } + coef->pub.consume_data = dummy_consume_data; + coef->pub.decompress_data = decompress_onepass; + coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdcolor.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdcolor.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdcolor.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,367 ---- + /* + * jdcolor.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains output colorspace conversion routines. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Private subobject */ + + typedef struct { + struct jpeg_color_deconverter pub; /* public fields */ + + /* Private state for YCC->RGB conversion */ + int * Cr_r_tab; /* => table for Cr to R conversion */ + int * Cb_b_tab; /* => table for Cb to B conversion */ + INT32 * Cr_g_tab; /* => table for Cr to G conversion */ + INT32 * Cb_g_tab; /* => table for Cb to G conversion */ + } my_color_deconverter; + + typedef my_color_deconverter * my_cconvert_ptr; + + + /**************** YCbCr -> RGB conversion: most common case **************/ + + /* + * YCbCr is defined per CCIR 601-1, except that Cb and Cr are + * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. + * The conversion equations to be implemented are therefore + * R = Y + 1.40200 * Cr + * G = Y - 0.34414 * Cb - 0.71414 * Cr + * B = Y + 1.77200 * Cb + * where Cb and Cr represent the incoming values less CENTERJSAMPLE. + * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) + * + * To avoid floating-point arithmetic, we represent the fractional constants + * as integers scaled up by 2^16 (about 4 digits precision); we have to divide + * the products by 2^16, with appropriate rounding, to get the correct answer. + * Notice that Y, being an integral input, does not contribute any fraction + * so it need not participate in the rounding. + * + * For even more speed, we avoid doing any multiplications in the inner loop + * by precalculating the constants times Cb and Cr for all possible values. + * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); + * for 12-bit samples it is still acceptable. It's not very reasonable for + * 16-bit samples, but if you want lossless storage you shouldn't be changing + * colorspace anyway. + * The Cr=>R and Cb=>B values can be rounded to integers in advance; the + * values for the G calculation are left scaled up, since we must add them + * together before rounding. + */ + + #define SCALEBITS 16 /* speediest right-shift on some machines */ + #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) + #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) + + + /* + * Initialize tables for YCC->RGB colorspace conversion. + */ + + LOCAL(void) + build_ycc_rgb_table (j_decompress_ptr cinfo) + { + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + int i; + INT32 x; + SHIFT_TEMPS + + cconvert->Cr_r_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + cconvert->Cb_b_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + cconvert->Cr_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + cconvert->Cb_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + + for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { + /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ + /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ + /* Cr=>R value is nearest int to 1.40200 * x */ + cconvert->Cr_r_tab[i] = (int) + RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); + /* Cb=>B value is nearest int to 1.77200 * x */ + cconvert->Cb_b_tab[i] = (int) + RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); + /* Cr=>G value is scaled-up -0.71414 * x */ + cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; + /* Cb=>G value is scaled-up -0.34414 * x */ + /* We also add in ONE_HALF so that need not do it in inner loop */ + cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; + } + } + + + /* + * Convert some rows of samples to the output colorspace. + * + * Note that we change from noninterleaved, one-plane-per-component format + * to interleaved-pixel format. The output buffer is therefore three times + * as wide as the input buffer. + * A starting row offset is provided only for the input buffer. The caller + * can easily adjust the passed output_buf value to accommodate any row + * offset required on that side. + */ + + METHODDEF(void) + ycc_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) + { + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int y, cb, cr; + register JSAMPROW outptr; + register JSAMPROW inptr0, inptr1, inptr2; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->output_width; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + register int * Crrtab = cconvert->Cr_r_tab; + register int * Cbbtab = cconvert->Cb_b_tab; + register INT32 * Crgtab = cconvert->Cr_g_tab; + register INT32 * Cbgtab = cconvert->Cb_g_tab; + SHIFT_TEMPS + + while (--num_rows >= 0) { + inptr0 = input_buf[0][input_row]; + inptr1 = input_buf[1][input_row]; + inptr2 = input_buf[2][input_row]; + input_row++; + outptr = *output_buf++; + for (col = 0; col < num_cols; col++) { + y = GETJSAMPLE(inptr0[col]); + cb = GETJSAMPLE(inptr1[col]); + cr = GETJSAMPLE(inptr2[col]); + /* Range-limiting is essential due to noise introduced by DCT losses. */ + outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; + outptr[RGB_GREEN] = range_limit[y + + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], + SCALEBITS))]; + outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; + outptr += RGB_PIXELSIZE; + } + } + } + + + /**************** Cases other than YCbCr -> RGB **************/ + + + /* + * Color conversion for no colorspace change: just copy the data, + * converting from separate-planes to interleaved representation. + */ + + METHODDEF(void) + null_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) + { + register JSAMPROW inptr, outptr; + register JDIMENSION count; + register int num_components = cinfo->num_components; + JDIMENSION num_cols = cinfo->output_width; + int ci; + + while (--num_rows >= 0) { + for (ci = 0; ci < num_components; ci++) { + inptr = input_buf[ci][input_row]; + outptr = output_buf[0] + ci; + for (count = num_cols; count > 0; count--) { + *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ + outptr += num_components; + } + } + input_row++; + output_buf++; + } + } + + + /* + * Color conversion for grayscale: just copy the data. + * This also works for YCbCr -> grayscale conversion, in which + * we just copy the Y (luminance) component and ignore chrominance. + */ + + METHODDEF(void) + grayscale_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) + { + jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, + num_rows, cinfo->output_width); + } + + + /* + * Adobe-style YCCK->CMYK conversion. + * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same + * conversion as above, while passing K (black) unchanged. + * We assume build_ycc_rgb_table has been called. + */ + + METHODDEF(void) + ycck_cmyk_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) + { + my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; + register int y, cb, cr; + register JSAMPROW outptr; + register JSAMPROW inptr0, inptr1, inptr2, inptr3; + register JDIMENSION col; + JDIMENSION num_cols = cinfo->output_width; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + register int * Crrtab = cconvert->Cr_r_tab; + register int * Cbbtab = cconvert->Cb_b_tab; + register INT32 * Crgtab = cconvert->Cr_g_tab; + register INT32 * Cbgtab = cconvert->Cb_g_tab; + SHIFT_TEMPS + + while (--num_rows >= 0) { + inptr0 = input_buf[0][input_row]; + inptr1 = input_buf[1][input_row]; + inptr2 = input_buf[2][input_row]; + inptr3 = input_buf[3][input_row]; + input_row++; + outptr = *output_buf++; + for (col = 0; col < num_cols; col++) { + y = GETJSAMPLE(inptr0[col]); + cb = GETJSAMPLE(inptr1[col]); + cr = GETJSAMPLE(inptr2[col]); + /* Range-limiting is essential due to noise introduced by DCT losses. */ + outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ + outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], + SCALEBITS)))]; + outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ + /* K passes through unchanged */ + outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ + outptr += 4; + } + } + } + + + /* + * Empty method for start_pass. + */ + + METHODDEF(void) + start_pass_dcolor (j_decompress_ptr cinfo) + { + /* no work needed */ + } + + + /* + * Module initialization routine for output colorspace conversion. + */ + + GLOBAL(void) + jinit_color_deconverter (j_decompress_ptr cinfo) + { + my_cconvert_ptr cconvert; + int ci; + + cconvert = (my_cconvert_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_color_deconverter)); + cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; + cconvert->pub.start_pass = start_pass_dcolor; + + /* Make sure num_components agrees with jpeg_color_space */ + switch (cinfo->jpeg_color_space) { + case JCS_GRAYSCALE: + if (cinfo->num_components != 1) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + + case JCS_RGB: + case JCS_YCbCr: + if (cinfo->num_components != 3) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + + case JCS_CMYK: + case JCS_YCCK: + if (cinfo->num_components != 4) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + + default: /* JCS_UNKNOWN can be anything */ + if (cinfo->num_components < 1) + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); + break; + } + + /* Set out_color_components and conversion method based on requested space. + * Also clear the component_needed flags for any unused components, + * so that earlier pipeline stages can avoid useless computation. + */ + + switch (cinfo->out_color_space) { + case JCS_GRAYSCALE: + cinfo->out_color_components = 1; + if (cinfo->jpeg_color_space == JCS_GRAYSCALE || + cinfo->jpeg_color_space == JCS_YCbCr) { + cconvert->pub.color_convert = grayscale_convert; + /* For color->grayscale conversion, only the Y (0) component is needed */ + for (ci = 1; ci < cinfo->num_components; ci++) + cinfo->comp_info[ci].component_needed = FALSE; + } else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_RGB: + cinfo->out_color_components = RGB_PIXELSIZE; + if (cinfo->jpeg_color_space == JCS_YCbCr) { + cconvert->pub.color_convert = ycc_rgb_convert; + build_ycc_rgb_table(cinfo); + } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) { + cconvert->pub.color_convert = null_convert; + } else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + case JCS_CMYK: + cinfo->out_color_components = 4; + if (cinfo->jpeg_color_space == JCS_YCCK) { + cconvert->pub.color_convert = ycck_cmyk_convert; + build_ycc_rgb_table(cinfo); + } else if (cinfo->jpeg_color_space == JCS_CMYK) { + cconvert->pub.color_convert = null_convert; + } else + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + + default: + /* Permit null conversion to same output space */ + if (cinfo->out_color_space == cinfo->jpeg_color_space) { + cinfo->out_color_components = cinfo->num_components; + cconvert->pub.color_convert = null_convert; + } else /* unsupported non-null conversion */ + ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); + break; + } + + if (cinfo->quantize_colors) + cinfo->output_components = 1; /* single colormapped output component */ + else + cinfo->output_components = cinfo->out_color_components; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdct.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdct.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdct.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,176 ---- + /* + * jdct.h + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This include file contains common declarations for the forward and + * inverse DCT modules. These declarations are private to the DCT managers + * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms. + * The individual DCT algorithms are kept in separate files to ease + * machine-dependent tuning (e.g., assembly coding). + */ + + + /* + * A forward DCT routine is given a pointer to a work area of type DCTELEM[]; + * the DCT is to be performed in-place in that buffer. Type DCTELEM is int + * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT + * implementations use an array of type FAST_FLOAT, instead.) + * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE). + * The DCT outputs are returned scaled up by a factor of 8; they therefore + * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This + * convention improves accuracy in integer implementations and saves some + * work in floating-point ones. + * Quantization of the output coefficients is done by jcdctmgr.c. + */ + + #if BITS_IN_JSAMPLE == 8 + typedef int DCTELEM; /* 16 or 32 bits is fine */ + #else + typedef INT32 DCTELEM; /* must have 32 bits */ + #endif + + typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data)); + typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data)); + + + /* + * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer + * to an output sample array. The routine must dequantize the input data as + * well as perform the IDCT; for dequantization, it uses the multiplier table + * pointed to by compptr->dct_table. The output data is to be placed into the + * sample array starting at a specified column. (Any row offset needed will + * be applied to the array pointer before it is passed to the IDCT code.) + * Note that the number of samples emitted by the IDCT routine is + * DCT_scaled_size * DCT_scaled_size. + */ + + /* typedef inverse_DCT_method_ptr is declared in jpegint.h */ + + /* + * Each IDCT routine has its own ideas about the best dct_table element type. + */ + + typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */ + #if BITS_IN_JSAMPLE == 8 + typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */ + #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */ + #else + typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */ + #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */ + #endif + typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */ + + + /* + * Each IDCT routine is responsible for range-limiting its results and + * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could + * be quite far out of range if the input data is corrupt, so a bulletproof + * range-limiting step is required. We use a mask-and-table-lookup method + * to do the combined operations quickly. See the comments with + * prepare_range_limit_table (in jdmaster.c) for more info. + */ + + #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE) + + #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ + + + /* Short forms of external names for systems with brain-damaged linkers. */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jpeg_fdct_islow jFDislow + #define jpeg_fdct_ifast jFDifast + #define jpeg_fdct_float jFDfloat + #define jpeg_idct_islow jRDislow + #define jpeg_idct_ifast jRDifast + #define jpeg_idct_float jRDfloat + #define jpeg_idct_4x4 jRD4x4 + #define jpeg_idct_2x2 jRD2x2 + #define jpeg_idct_1x1 jRD1x1 + #endif /* NEED_SHORT_EXTERNAL_NAMES */ + + /* Extern declarations for the forward and inverse DCT routines. */ + + EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data)); + EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data)); + EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data)); + + EXTERN(void) jpeg_idct_islow + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + EXTERN(void) jpeg_idct_ifast + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + EXTERN(void) jpeg_idct_float + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + EXTERN(void) jpeg_idct_4x4 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + EXTERN(void) jpeg_idct_2x2 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + EXTERN(void) jpeg_idct_1x1 + JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); + + + /* + * Macros for handling fixed-point arithmetic; these are used by many + * but not all of the DCT/IDCT modules. + * + * All values are expected to be of type INT32. + * Fractional constants are scaled left by CONST_BITS bits. + * CONST_BITS is defined within each module using these macros, + * and may differ from one module to the next. + */ + + #define ONE ((INT32) 1) + #define CONST_SCALE (ONE << CONST_BITS) + + /* Convert a positive real constant to an integer scaled by CONST_SCALE. + * Caution: some C compilers fail to reduce "FIX(constant)" at compile time, + * thus causing a lot of useless floating-point operations at run time. + */ + + #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) + + /* Descale and correctly round an INT32 value that's scaled by N bits. + * We assume RIGHT_SHIFT rounds towards minus infinity, so adding + * the fudge factor is correct for either sign of X. + */ + + #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) + + /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * This macro is used only when the two inputs will actually be no more than + * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a + * full 32x32 multiply. This provides a useful speedup on many machines. + * Unfortunately there is no way to specify a 16x16->32 multiply portably + * in C, but some C compilers will do the right thing if you provide the + * correct combination of casts. + */ + + #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ + #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const))) + #endif + #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ + #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const))) + #endif + + #ifndef MULTIPLY16C16 /* default definition */ + #define MULTIPLY16C16(var,const) ((var) * (const)) + #endif + + /* Same except both inputs are variables. */ + + #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ + #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2))) + #endif + + #ifndef MULTIPLY16V16 /* default definition */ + #define MULTIPLY16V16(var1,var2) ((var1) * (var2)) + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jddctmgr.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jddctmgr.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jddctmgr.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,269 ---- + /* + * jddctmgr.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the inverse-DCT management logic. + * This code selects a particular IDCT implementation to be used, + * and it performs related housekeeping chores. No code in this file + * is executed per IDCT step, only during output pass setup. + * + * Note that the IDCT routines are responsible for performing coefficient + * dequantization as well as the IDCT proper. This module sets up the + * dequantization multiplier table needed by the IDCT routine. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + + /* + * The decompressor input side (jdinput.c) saves away the appropriate + * quantization table for each component at the start of the first scan + * involving that component. (This is necessary in order to correctly + * decode files that reuse Q-table slots.) + * When we are ready to make an output pass, the saved Q-table is converted + * to a multiplier table that will actually be used by the IDCT routine. + * The multiplier table contents are IDCT-method-dependent. To support + * application changes in IDCT method between scans, we can remake the + * multiplier tables if necessary. + * In buffered-image mode, the first output pass may occur before any data + * has been seen for some components, and thus before their Q-tables have + * been saved away. To handle this case, multiplier tables are preset + * to zeroes; the result of the IDCT will be a neutral gray level. + */ + + + /* Private subobject for this module */ + + typedef struct { + struct jpeg_inverse_dct pub; /* public fields */ + + /* This array contains the IDCT method code that each multiplier table + * is currently set up for, or -1 if it's not yet set up. + * The actual multiplier tables are pointed to by dct_table in the + * per-component comp_info structures. + */ + int cur_method[MAX_COMPONENTS]; + } my_idct_controller; + + typedef my_idct_controller * my_idct_ptr; + + + /* Allocated multiplier tables: big enough for any supported variant */ + + typedef union { + ISLOW_MULT_TYPE islow_array[DCTSIZE2]; + #ifdef DCT_IFAST_SUPPORTED + IFAST_MULT_TYPE ifast_array[DCTSIZE2]; + #endif + #ifdef DCT_FLOAT_SUPPORTED + FLOAT_MULT_TYPE float_array[DCTSIZE2]; + #endif + } multiplier_table; + + + /* The current scaled-IDCT routines require ISLOW-style multiplier tables, + * so be sure to compile that code if either ISLOW or SCALING is requested. + */ + #ifdef DCT_ISLOW_SUPPORTED + #define PROVIDE_ISLOW_TABLES + #else + #ifdef IDCT_SCALING_SUPPORTED + #define PROVIDE_ISLOW_TABLES + #endif + #endif + + + /* + * Prepare for an output pass. + * Here we select the proper IDCT routine for each component and build + * a matching multiplier table. + */ + + METHODDEF(void) + start_pass (j_decompress_ptr cinfo) + { + my_idct_ptr idct = (my_idct_ptr) cinfo->idct; + int ci, i; + jpeg_component_info *compptr; + int method = 0; + inverse_DCT_method_ptr method_ptr = NULL; + JQUANT_TBL * qtbl; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Select the proper IDCT routine for this component's scaling */ + switch (compptr->DCT_scaled_size) { + #ifdef IDCT_SCALING_SUPPORTED + case 1: + method_ptr = jpeg_idct_1x1; + method = JDCT_ISLOW; /* jidctred uses islow-style table */ + break; + case 2: + method_ptr = jpeg_idct_2x2; + method = JDCT_ISLOW; /* jidctred uses islow-style table */ + break; + case 4: + method_ptr = jpeg_idct_4x4; + method = JDCT_ISLOW; /* jidctred uses islow-style table */ + break; + #endif + case DCTSIZE: + switch (cinfo->dct_method) { + #ifdef DCT_ISLOW_SUPPORTED + case JDCT_ISLOW: + method_ptr = jpeg_idct_islow; + method = JDCT_ISLOW; + break; + #endif + #ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + method_ptr = jpeg_idct_ifast; + method = JDCT_IFAST; + break; + #endif + #ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + method_ptr = jpeg_idct_float; + method = JDCT_FLOAT; + break; + #endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + break; + default: + ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size); + break; + } + idct->pub.inverse_DCT[ci] = method_ptr; + /* Create multiplier table from quant table. + * However, we can skip this if the component is uninteresting + * or if we already built the table. Also, if no quant table + * has yet been saved for the component, we leave the + * multiplier table all-zero; we'll be reading zeroes from the + * coefficient controller's buffer anyway. + */ + if (! compptr->component_needed || idct->cur_method[ci] == method) + continue; + qtbl = compptr->quant_table; + if (qtbl == NULL) /* happens if no data yet for component */ + continue; + idct->cur_method[ci] = method; + switch (method) { + #ifdef PROVIDE_ISLOW_TABLES + case JDCT_ISLOW: + { + /* For LL&M IDCT method, multipliers are equal to raw quantization + * coefficients, but are stored as ints to ensure access efficiency. + */ + ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table; + for (i = 0; i < DCTSIZE2; i++) { + ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i]; + } + } + break; + #endif + #ifdef DCT_IFAST_SUPPORTED + case JDCT_IFAST: + { + /* For AA&N IDCT method, multipliers are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + * For integer operation, the multiplier table is to be scaled by + * IFAST_SCALE_BITS. + */ + IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table; + #define CONST_BITS 14 + static const INT16 aanscales[DCTSIZE2] = { + /* precomputed values scaled up by 14 bits */ + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, + 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, + 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, + 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, + 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 + }; + SHIFT_TEMPS + + for (i = 0; i < DCTSIZE2; i++) { + ifmtbl[i] = (IFAST_MULT_TYPE) + DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], + (INT32) aanscales[i]), + CONST_BITS-IFAST_SCALE_BITS); + } + } + break; + #endif + #ifdef DCT_FLOAT_SUPPORTED + case JDCT_FLOAT: + { + /* For float AA&N IDCT method, multipliers are equal to quantization + * coefficients scaled by scalefactor[row]*scalefactor[col], where + * scalefactor[0] = 1 + * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 + */ + FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table; + int row, col; + static const double aanscalefactor[DCTSIZE] = { + 1.0, 1.387039845, 1.306562965, 1.175875602, + 1.0, 0.785694958, 0.541196100, 0.275899379 + }; + + i = 0; + for (row = 0; row < DCTSIZE; row++) { + for (col = 0; col < DCTSIZE; col++) { + fmtbl[i] = (FLOAT_MULT_TYPE) + ((double) qtbl->quantval[i] * + aanscalefactor[row] * aanscalefactor[col]); + i++; + } + } + } + break; + #endif + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + } + } + + + /* + * Initialize IDCT manager. + */ + + GLOBAL(void) + jinit_inverse_dct (j_decompress_ptr cinfo) + { + my_idct_ptr idct; + int ci; + jpeg_component_info *compptr; + + idct = (my_idct_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_idct_controller)); + cinfo->idct = (struct jpeg_inverse_dct *) idct; + idct->pub.start_pass = start_pass; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Allocate and pre-zero a multiplier table for each component */ + compptr->dct_table = + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(multiplier_table)); + MEMZERO(compptr->dct_table, SIZEOF(multiplier_table)); + /* Mark multiplier table not yet set up for any method */ + idct->cur_method[ci] = -1; + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdhuff.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdhuff.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdhuff.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,574 ---- + /* + * jdhuff.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy decoding routines. + * + * Much of the complexity here has to do with supporting input suspension. + * If the data source module demands suspension, we want to be able to back + * up to the start of the current MCU. To do this, we copy state variables + * into local working storage, and update them back to the permanent + * storage only upon successful completion of an MCU. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdhuff.h" /* Declarations shared with jdphuff.c */ + + + /* + * Expanded entropy decoder object for Huffman decoding. + * + * The savable_state subrecord contains fields that change within an MCU, + * but must not be updated permanently until we complete the MCU. + */ + + typedef struct { + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ + } savable_state; + + /* This macro is to work around compilers with missing or broken + * structure assignment. You'll need to fix this code if you have + * such a compiler and you change MAX_COMPS_IN_SCAN. + */ + + #ifndef NO_STRUCT_ASSIGN + #define ASSIGN_STATE(dest,src) ((dest) = (src)) + #else + #if MAX_COMPS_IN_SCAN == 4 + #define ASSIGN_STATE(dest,src) \ + ((dest).last_dc_val[0] = (src).last_dc_val[0], \ + (dest).last_dc_val[1] = (src).last_dc_val[1], \ + (dest).last_dc_val[2] = (src).last_dc_val[2], \ + (dest).last_dc_val[3] = (src).last_dc_val[3]) + #endif + #endif + + + typedef struct { + struct jpeg_entropy_decoder pub; /* public fields */ + + /* These fields are loaded into local variables at start of each MCU. + * In case of suspension, we exit WITHOUT updating them. + */ + bitread_perm_state bitstate; /* Bit buffer at start of MCU */ + savable_state saved; /* Other state at start of MCU */ + + /* These fields are NOT loaded into local working state. */ + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + + /* Pointers to derived tables (these workspaces have image lifespan) */ + d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; + d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]; + } huff_entropy_decoder; + + typedef huff_entropy_decoder * huff_entropy_ptr; + + + /* + * Initialize for a Huffman-compressed scan. + */ + + METHODDEF(void) + start_pass_huff_decoder (j_decompress_ptr cinfo) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci, dctbl, actbl; + jpeg_component_info * compptr; + + /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. + * This ought to be an error condition, but we make it a warning because + * there are some baseline files out there with all zeroes in these bytes. + */ + if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 || + cinfo->Ah != 0 || cinfo->Al != 0) + WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + dctbl = compptr->dc_tbl_no; + actbl = compptr->ac_tbl_no; + /* Make sure requested tables are present */ + if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS || + cinfo->dc_huff_tbl_ptrs[dctbl] == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); + if (actbl < 0 || actbl >= NUM_HUFF_TBLS || + cinfo->ac_huff_tbl_ptrs[actbl] == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); + /* Compute derived values for Huffman tables */ + /* We may do this more than once for a table, but it's not expensive */ + jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl], + & entropy->dc_derived_tbls[dctbl]); + jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl], + & entropy->ac_derived_tbls[actbl]); + /* Initialize DC predictions to 0 */ + entropy->saved.last_dc_val[ci] = 0; + } + + /* Initialize bitread state variables */ + entropy->bitstate.bits_left = 0; + entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ + entropy->bitstate.printed_eod = FALSE; + + /* Initialize restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; + } + + + /* + * Compute the derived values for a Huffman table. + * Note this is also used by jdphuff.c. + */ + + GLOBAL(void) + jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl, + d_derived_tbl ** pdtbl) + { + d_derived_tbl *dtbl; + int p, i, l, si; + int lookbits, ctr; + char huffsize[257]; + unsigned int huffcode[257]; + unsigned int code; + + /* Allocate a workspace if we haven't already done so. */ + if (*pdtbl == NULL) + *pdtbl = (d_derived_tbl *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(d_derived_tbl)); + dtbl = *pdtbl; + dtbl->pub = htbl; /* fill in back link */ + + /* Figure C.1: make table of Huffman code length for each symbol */ + /* Note that this is in code-length order. */ + + p = 0; + for (l = 1; l <= 16; l++) { + for (i = 1; i <= (int) htbl->bits[l]; i++) + huffsize[p++] = (char) l; + } + huffsize[p] = 0; + + /* Figure C.2: generate the codes themselves */ + /* Note that this is in code-length order. */ + + code = 0; + si = huffsize[0]; + p = 0; + while (huffsize[p]) { + while (((int) huffsize[p]) == si) { + huffcode[p++] = code; + code++; + } + code <<= 1; + si++; + } + + /* Figure F.15: generate decoding tables for bit-sequential decoding */ + + p = 0; + for (l = 1; l <= 16; l++) { + if (htbl->bits[l]) { + dtbl->valptr[l] = p; /* huffval[] index of 1st symbol of code length l */ + dtbl->mincode[l] = huffcode[p]; /* minimum code of length l */ + p += htbl->bits[l]; + dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */ + } else { + dtbl->maxcode[l] = -1; /* -1 if no codes of this length */ + } + } + dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */ + + /* Compute lookahead tables to speed up decoding. + * First we set all the table entries to 0, indicating "too long"; + * then we iterate through the Huffman codes that are short enough and + * fill in all the entries that correspond to bit sequences starting + * with that code. + */ + + MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits)); + + p = 0; + for (l = 1; l <= HUFF_LOOKAHEAD; l++) { + for (i = 1; i <= (int) htbl->bits[l]; i++, p++) { + /* l = current code's length, p = its index in huffcode[] & huffval[]. */ + /* Generate left-justified code followed by all possible bit sequences */ + lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l); + for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) { + dtbl->look_nbits[lookbits] = l; + dtbl->look_sym[lookbits] = htbl->huffval[p]; + lookbits++; + } + } + } + } + + + /* + * Out-of-line code for bit fetching (shared with jdphuff.c). + * See jdhuff.h for info about usage. + * Note: current values of get_buffer and bits_left are passed as parameters, + * but are returned in the corresponding fields of the state struct. + * + * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width + * of get_buffer to be used. (On machines with wider words, an even larger + * buffer could be used.) However, on some machines 32-bit shifts are + * quite slow and take time proportional to the number of places shifted. + * (This is true with most PC compilers, for instance.) In this case it may + * be a win to set MIN_GET_BITS to the minimum value of 15. This reduces the + * average shift distance at the cost of more calls to jpeg_fill_bit_buffer. + */ + + #ifdef SLOW_SHIFT_32 + #define MIN_GET_BITS 15 /* minimum allowable value */ + #else + #define MIN_GET_BITS (BIT_BUF_SIZE-7) + #endif + + + GLOBAL(boolean) + jpeg_fill_bit_buffer (bitread_working_state * state, + register bit_buf_type get_buffer, register int bits_left, + int nbits) + /* Load up the bit buffer to a depth of at least nbits */ + { + /* Copy heavily used state fields into locals (hopefully registers) */ + register const JOCTET * next_input_byte = state->next_input_byte; + register size_t bytes_in_buffer = state->bytes_in_buffer; + register int c; + + /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */ + /* (It is assumed that no request will be for more than that many bits.) */ + + while (bits_left < MIN_GET_BITS) { + /* Attempt to read a byte */ + if (state->unread_marker != 0) + goto no_more_data; /* can't advance past a marker */ + + if (bytes_in_buffer == 0) { + if (! (*state->cinfo->src->fill_input_buffer) (state->cinfo)) + return FALSE; + next_input_byte = state->cinfo->src->next_input_byte; + bytes_in_buffer = state->cinfo->src->bytes_in_buffer; + } + bytes_in_buffer--; + c = GETJOCTET(*next_input_byte++); + + /* If it's 0xFF, check and discard stuffed zero byte */ + if (c == 0xFF) { + do { + if (bytes_in_buffer == 0) { + if (! (*state->cinfo->src->fill_input_buffer) (state->cinfo)) + return FALSE; + next_input_byte = state->cinfo->src->next_input_byte; + bytes_in_buffer = state->cinfo->src->bytes_in_buffer; + } + bytes_in_buffer--; + c = GETJOCTET(*next_input_byte++); + } while (c == 0xFF); + + if (c == 0) { + /* Found FF/00, which represents an FF data byte */ + c = 0xFF; + } else { + /* Oops, it's actually a marker indicating end of compressed data. */ + /* Better put it back for use later */ + state->unread_marker = c; + + no_more_data: + /* There should be enough bits still left in the data segment; */ + /* if so, just break out of the outer while loop. */ + if (bits_left >= nbits) + break; + /* Uh-oh. Report corrupted data to user and stuff zeroes into + * the data stream, so that we can produce some kind of image. + * Note that this code will be repeated for each byte demanded + * for the rest of the segment. We use a nonvolatile flag to ensure + * that only one warning message appears. + */ + if (! *(state->printed_eod_ptr)) { + WARNMS(state->cinfo, JWRN_HIT_MARKER); + *(state->printed_eod_ptr) = TRUE; + } + c = 0; /* insert a zero byte into bit buffer */ + } + } + + /* OK, load c into get_buffer */ + get_buffer = (get_buffer << 8) | c; + bits_left += 8; + } + + /* Unload the local registers */ + state->next_input_byte = next_input_byte; + state->bytes_in_buffer = bytes_in_buffer; + state->get_buffer = get_buffer; + state->bits_left = bits_left; + + return TRUE; + } + + + /* + * Out-of-line code for Huffman code decoding. + * See jdhuff.h for info about usage. + */ + + GLOBAL(int) + jpeg_huff_decode (bitread_working_state * state, + register bit_buf_type get_buffer, register int bits_left, + d_derived_tbl * htbl, int min_bits) + { + register int l = min_bits; + register INT32 code; + + /* HUFF_DECODE has determined that the code is at least min_bits */ + /* bits long, so fetch that many bits in one swoop. */ + + CHECK_BIT_BUFFER(*state, l, return -1); + code = GET_BITS(l); + + /* Collect the rest of the Huffman code one bit at a time. */ + /* This is per Figure F.16 in the JPEG spec. */ + + while (code > htbl->maxcode[l]) { + code <<= 1; + CHECK_BIT_BUFFER(*state, 1, return -1); + code |= GET_BITS(1); + l++; + } + + /* Unload the local registers */ + state->get_buffer = get_buffer; + state->bits_left = bits_left; + + /* With garbage input we may reach the sentinel value l = 17. */ + + if (l > 16) { + WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE); + return 0; /* fake a zero as the safest result */ + } + + return htbl->pub->huffval[ htbl->valptr[l] + + ((int) (code - htbl->mincode[l])) ]; + } + + + /* + * Figure F.12: extend sign bit. + * On some machines, a shift and add will be faster than a table lookup. + */ + + #ifdef AVOID_TABLES + + #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) + + #else + + #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) + + static const int extend_test[16] = /* entry n is 2**(n-1) */ + { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; + + static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ + { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, + ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, + ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, + ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }; + + #endif /* AVOID_TABLES */ + + + /* + * Check for a restart marker & resynchronize decoder. + * Returns FALSE if must suspend. + */ + + LOCAL(boolean) + process_restart (j_decompress_ptr cinfo) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + int ci; + + /* Throw away any unused bits remaining in bit buffer; */ + /* include any full bytes in next_marker's count of discarded bytes */ + cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; + entropy->bitstate.bits_left = 0; + + /* Advance past the RSTn marker */ + if (! (*cinfo->marker->read_restart_marker) (cinfo)) + return FALSE; + + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) + entropy->saved.last_dc_val[ci] = 0; + + /* Reset restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; + + /* Next segment can get another out-of-data warning */ + entropy->bitstate.printed_eod = FALSE; + + return TRUE; + } + + + /* + * Decode and return one MCU's worth of Huffman-compressed coefficients. + * The coefficients are reordered from zigzag order into natural array order, + * but are not dequantized. + * + * The i'th block of the MCU is stored into the block pointed to by + * MCU_data[i]. WE ASSUME THIS AREA HAS BEEN ZEROED BY THE CALLER. + * (Wholesale zeroing is usually a little faster than retail...) + * + * Returns FALSE if data source requested suspension. In that case no + * changes have been made to permanent state. (Exception: some output + * coefficients may already have been assigned. This is harmless for + * this module, since we'll just re-assign them on the next call.) + */ + + METHODDEF(boolean) + decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) + { + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + register int s, k, r; + int blkn, ci; + JBLOCKROW block; + BITREAD_STATE_VARS; + savable_state state; + d_derived_tbl * dctbl; + d_derived_tbl * actbl; + jpeg_component_info * compptr; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(state, entropy->saved); + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + dctbl = entropy->dc_derived_tbls[compptr->dc_tbl_no]; + actbl = entropy->ac_derived_tbls[compptr->ac_tbl_no]; + + /* Decode a single block's worth of coefficients */ + + /* Section F.2.2.1: decode the DC coefficient difference */ + HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); + if (s) { + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + } + + /* Shortcut if component's values are not interesting */ + if (! compptr->component_needed) + goto skip_ACs; + + /* Convert DC difference to actual value, update last_dc_val */ + s += state.last_dc_val[ci]; + state.last_dc_val[ci] = s; + /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ + (*block)[0] = (JCOEF) s; + + /* Do we need to decode the AC coefficients for this component? */ + if (compptr->DCT_scaled_size > 1) { + + /* Section F.2.2.2: decode the AC coefficients */ + /* Since zeroes are skipped, output area must be cleared beforehand */ + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE(s, br_state, actbl, return FALSE, label2); + + r = s >> 4; + s &= 15; + + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + /* Output coefficient in natural (dezigzagged) order. + * Note: the extra entries in jpeg_natural_order[] will save us + * if k >= DCTSIZE2, which could happen if the data is corrupted. + */ + (*block)[jpeg_natural_order[k]] = (JCOEF) s; + } else { + if (r != 15) + break; + k += 15; + } + } + + } else { + skip_ACs: + + /* Section F.2.2.2: decode the AC coefficients */ + /* In this path we just discard the values */ + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE(s, br_state, actbl, return FALSE, label3); + + r = s >> 4; + s &= 15; + + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + DROP_BITS(s); + } else { + if (r != 15) + break; + k += 15; + } + } + + } + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(entropy->saved, state); + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; + } + + + /* + * Module initialization routine for Huffman entropy decoding. + */ + + GLOBAL(void) + jinit_huff_decoder (j_decompress_ptr cinfo) + { + huff_entropy_ptr entropy; + int i; + + entropy = (huff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(huff_entropy_decoder)); + cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; + entropy->pub.start_pass = start_pass_huff_decoder; + entropy->pub.decode_mcu = decode_mcu; + + /* Mark tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL; + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdhuff.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdhuff.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdhuff.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,202 ---- + /* + * jdhuff.h + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains declarations for Huffman entropy decoding routines + * that are shared between the sequential decoder (jdhuff.c) and the + * progressive decoder (jdphuff.c). No other modules need to see these. + */ + + /* Short forms of external names for systems with brain-damaged linkers. */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jpeg_make_d_derived_tbl jMkDDerived + #define jpeg_fill_bit_buffer jFilBitBuf + #define jpeg_huff_decode jHufDecode + #endif /* NEED_SHORT_EXTERNAL_NAMES */ + + + /* Derived data constructed for each Huffman table */ + + #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */ + + typedef struct { + /* Basic tables: (element [0] of each array is unused) */ + INT32 mincode[17]; /* smallest code of length k */ + INT32 maxcode[18]; /* largest code of length k (-1 if none) */ + /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ + int valptr[17]; /* huffval[] index of 1st symbol of length k */ + + /* Link to public Huffman table (needed only in jpeg_huff_decode) */ + JHUFF_TBL *pub; + + /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of + * the input data stream. If the next Huffman code is no more + * than HUFF_LOOKAHEAD bits long, we can obtain its length and + * the corresponding symbol directly from these tables. + */ + int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */ + UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */ + } d_derived_tbl; + + /* Expand a Huffman table definition into the derived format */ + EXTERN(void) jpeg_make_d_derived_tbl JPP((j_decompress_ptr cinfo, + JHUFF_TBL * htbl, d_derived_tbl ** pdtbl)); + + + /* + * Fetching the next N bits from the input stream is a time-critical operation + * for the Huffman decoders. We implement it with a combination of inline + * macros and out-of-line subroutines. Note that N (the number of bits + * demanded at one time) never exceeds 15 for JPEG use. + * + * We read source bytes into get_buffer and dole out bits as needed. + * If get_buffer already contains enough bits, they are fetched in-line + * by the macros CHECK_BIT_BUFFER and GET_BITS. When there aren't enough + * bits, jpeg_fill_bit_buffer is called; it will attempt to fill get_buffer + * as full as possible (not just to the number of bits needed; this + * prefetching reduces the overhead cost of calling jpeg_fill_bit_buffer). + * Note that jpeg_fill_bit_buffer may return FALSE to indicate suspension. + * On TRUE return, jpeg_fill_bit_buffer guarantees that get_buffer contains + * at least the requested number of bits --- dummy zeroes are inserted if + * necessary. + */ + + typedef INT32 bit_buf_type; /* type of bit-extraction buffer */ + #define BIT_BUF_SIZE 32 /* size of buffer in bits */ + + /* If long is > 32 bits on your machine, and shifting/masking longs is + * reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE + * appropriately should be a win. Unfortunately we can't do this with + * something like #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8) + * because not all machines measure sizeof in 8-bit bytes. + */ + + typedef struct { /* Bitreading state saved across MCUs */ + bit_buf_type get_buffer; /* current bit-extraction buffer */ + int bits_left; /* # of unused bits in it */ + boolean printed_eod; /* flag to suppress multiple warning msgs */ + } bitread_perm_state; + + typedef struct { /* Bitreading working state within an MCU */ + /* current data source state */ + const JOCTET * next_input_byte; /* => next byte to read from source */ + size_t bytes_in_buffer; /* # of bytes remaining in source buffer */ + int unread_marker; /* nonzero if we have hit a marker */ + /* bit input buffer --- note these values are kept in register variables, + * not in this struct, inside the inner loops. + */ + bit_buf_type get_buffer; /* current bit-extraction buffer */ + int bits_left; /* # of unused bits in it */ + /* pointers needed by jpeg_fill_bit_buffer */ + j_decompress_ptr cinfo; /* back link to decompress master record */ + boolean * printed_eod_ptr; /* => flag in permanent state */ + } bitread_working_state; + + /* Macros to declare and load/save bitread local variables. */ + #define BITREAD_STATE_VARS \ + register bit_buf_type get_buffer; \ + register int bits_left; \ + bitread_working_state br_state + + #define BITREAD_LOAD_STATE(cinfop,permstate) \ + br_state.cinfo = cinfop; \ + br_state.next_input_byte = cinfop->src->next_input_byte; \ + br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \ + br_state.unread_marker = cinfop->unread_marker; \ + get_buffer = permstate.get_buffer; \ + bits_left = permstate.bits_left; \ + br_state.printed_eod_ptr = & permstate.printed_eod + + #define BITREAD_SAVE_STATE(cinfop,permstate) \ + cinfop->src->next_input_byte = br_state.next_input_byte; \ + cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \ + cinfop->unread_marker = br_state.unread_marker; \ + permstate.get_buffer = get_buffer; \ + permstate.bits_left = bits_left + + /* + * These macros provide the in-line portion of bit fetching. + * Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer + * before using GET_BITS, PEEK_BITS, or DROP_BITS. + * The variables get_buffer and bits_left are assumed to be locals, + * but the state struct might not be (jpeg_huff_decode needs this). + * CHECK_BIT_BUFFER(state,n,action); + * Ensure there are N bits in get_buffer; if suspend, take action. + * val = GET_BITS(n); + * Fetch next N bits. + * val = PEEK_BITS(n); + * Fetch next N bits without removing them from the buffer. + * DROP_BITS(n); + * Discard next N bits. + * The value N should be a simple variable, not an expression, because it + * is evaluated multiple times. + */ + + #define CHECK_BIT_BUFFER(state,nbits,action) \ + { if (bits_left < (nbits)) { \ + if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \ + { action; } \ + get_buffer = (state).get_buffer; bits_left = (state).bits_left; } } + + #define GET_BITS(nbits) \ + (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1)) + + #define PEEK_BITS(nbits) \ + (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1)) + + #define DROP_BITS(nbits) \ + (bits_left -= (nbits)) + + /* Load up the bit buffer to a depth of at least nbits */ + EXTERN(boolean) jpeg_fill_bit_buffer + JPP((bitread_working_state * state, register bit_buf_type get_buffer, + register int bits_left, int nbits)); + + + /* + * Code for extracting next Huffman-coded symbol from input bit stream. + * Again, this is time-critical and we make the main paths be macros. + * + * We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits + * without looping. Usually, more than 95% of the Huffman codes will be 8 + * or fewer bits long. The few overlength codes are handled with a loop, + * which need not be inline code. + * + * Notes about the HUFF_DECODE macro: + * 1. Near the end of the data segment, we may fail to get enough bits + * for a lookahead. In that case, we do it the hard way. + * 2. If the lookahead table contains no entry, the next code must be + * more than HUFF_LOOKAHEAD bits long. + * 3. jpeg_huff_decode returns -1 if forced to suspend. + */ + + #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \ + { register int nb, look; \ + if (bits_left < HUFF_LOOKAHEAD) { \ + if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \ + get_buffer = state.get_buffer; bits_left = state.bits_left; \ + if (bits_left < HUFF_LOOKAHEAD) { \ + nb = 1; goto slowlabel; \ + } \ + } \ + look = PEEK_BITS(HUFF_LOOKAHEAD); \ + if ((nb = htbl->look_nbits[look]) != 0) { \ + DROP_BITS(nb); \ + result = htbl->look_sym[look]; \ + } else { \ + nb = HUFF_LOOKAHEAD+1; \ + slowlabel: \ + if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \ + { failaction; } \ + get_buffer = state.get_buffer; bits_left = state.bits_left; \ + } \ + } + + /* Out-of-line case for Huffman code fetching */ + EXTERN(int) jpeg_huff_decode + JPP((bitread_working_state * state, register bit_buf_type get_buffer, + register int bits_left, d_derived_tbl * htbl, int min_bits)); Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdinput.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdinput.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdinput.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,381 ---- + /* + * jdinput.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains input control logic for the JPEG decompressor. + * These routines are concerned with controlling the decompressor's input + * processing (marker reading and coefficient decoding). The actual input + * reading is done in jdmarker.c, jdhuff.c, and jdphuff.c. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Private state */ + + typedef struct { + struct jpeg_input_controller pub; /* public fields */ + + boolean inheaders; /* TRUE until first SOS is reached */ + } my_input_controller; + + typedef my_input_controller * my_inputctl_ptr; + + + /* Forward declarations */ + METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo)); + + + /* + * Routines to calculate various quantities related to the size of the image. + */ + + LOCAL(void) + initial_setup (j_decompress_ptr cinfo) + /* Called once, when first SOS marker is reached */ + { + int ci; + jpeg_component_info *compptr; + + /* Make sure image isn't bigger than I can handle */ + if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || + (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) + ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); + + /* For now, precision must match compiled-in value... */ + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + + /* Check that number of components won't exceed internal array sizes */ + if (cinfo->num_components > MAX_COMPONENTS) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, + MAX_COMPONENTS); + + /* Compute maximum sampling factors; check factor validity */ + cinfo->max_h_samp_factor = 1; + cinfo->max_v_samp_factor = 1; + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || + compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) + ERREXIT(cinfo, JERR_BAD_SAMPLING); + cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, + compptr->h_samp_factor); + cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, + compptr->v_samp_factor); + } + + /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. + * In the full decompressor, this will be overridden by jdmaster.c; + * but in the transcoder, jdmaster.c is not used, so we must do it here. + */ + cinfo->min_DCT_scaled_size = DCTSIZE; + + /* Compute dimensions of components */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + compptr->DCT_scaled_size = DCTSIZE; + /* Size in DCT blocks */ + compptr->width_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, + (long) (cinfo->max_h_samp_factor * DCTSIZE)); + compptr->height_in_blocks = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, + (long) (cinfo->max_v_samp_factor * DCTSIZE)); + /* downsampled_width and downsampled_height will also be overridden by + * jdmaster.c if we are doing full decompression. The transcoder library + * doesn't use these values, but the calling application might. + */ + /* Size in samples */ + compptr->downsampled_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, + (long) cinfo->max_h_samp_factor); + compptr->downsampled_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, + (long) cinfo->max_v_samp_factor); + /* Mark component needed, until color conversion says otherwise */ + compptr->component_needed = TRUE; + /* Mark no quantization table yet saved for component */ + compptr->quant_table = NULL; + } + + /* Compute number of fully interleaved MCU rows. */ + cinfo->total_iMCU_rows = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); + + /* Decide whether file contains multiple scans */ + if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode) + cinfo->inputctl->has_multiple_scans = TRUE; + else + cinfo->inputctl->has_multiple_scans = FALSE; + } + + + LOCAL(void) + per_scan_setup (j_decompress_ptr cinfo) + /* Do computations that are needed before processing a JPEG scan */ + /* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */ + { + int ci, mcublks, tmp; + jpeg_component_info *compptr; + + if (cinfo->comps_in_scan == 1) { + + /* Noninterleaved (single-component) scan */ + compptr = cinfo->cur_comp_info[0]; + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = compptr->width_in_blocks; + cinfo->MCU_rows_in_scan = compptr->height_in_blocks; + + /* For noninterleaved scan, always one block per MCU */ + compptr->MCU_width = 1; + compptr->MCU_height = 1; + compptr->MCU_blocks = 1; + compptr->MCU_sample_width = compptr->DCT_scaled_size; + compptr->last_col_width = 1; + /* For noninterleaved scans, it is convenient to define last_row_height + * as the number of block rows present in the last iMCU row. + */ + tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); + if (tmp == 0) tmp = compptr->v_samp_factor; + compptr->last_row_height = tmp; + + /* Prepare array describing MCU composition */ + cinfo->blocks_in_MCU = 1; + cinfo->MCU_membership[0] = 0; + + } else { + + /* Interleaved (multi-component) scan */ + if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, + MAX_COMPS_IN_SCAN); + + /* Overall image size in MCUs */ + cinfo->MCUs_per_row = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width, + (long) (cinfo->max_h_samp_factor*DCTSIZE)); + cinfo->MCU_rows_in_scan = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, + (long) (cinfo->max_v_samp_factor*DCTSIZE)); + + cinfo->blocks_in_MCU = 0; + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Sampling factors give # of blocks of component in each MCU */ + compptr->MCU_width = compptr->h_samp_factor; + compptr->MCU_height = compptr->v_samp_factor; + compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; + compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size; + /* Figure number of non-dummy blocks in last MCU column & row */ + tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); + if (tmp == 0) tmp = compptr->MCU_width; + compptr->last_col_width = tmp; + tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); + if (tmp == 0) tmp = compptr->MCU_height; + compptr->last_row_height = tmp; + /* Prepare array describing MCU composition */ + mcublks = compptr->MCU_blocks; + if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) + ERREXIT(cinfo, JERR_BAD_MCU_SIZE); + while (mcublks-- > 0) { + cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; + } + } + + } + } + + + /* + * Save away a copy of the Q-table referenced by each component present + * in the current scan, unless already saved during a prior scan. + * + * In a multiple-scan JPEG file, the encoder could assign different components + * the same Q-table slot number, but change table definitions between scans + * so that each component uses a different Q-table. (The IJG encoder is not + * currently capable of doing this, but other encoders might.) Since we want + * to be able to dequantize all the components at the end of the file, this + * means that we have to save away the table actually used for each component. + * We do this by copying the table at the start of the first scan containing + * the component. + * The JPEG spec prohibits the encoder from changing the contents of a Q-table + * slot between scans of a component using that slot. If the encoder does so + * anyway, this decoder will simply use the Q-table values that were current + * at the start of the first scan for the component. + * + * The decompressor output side looks only at the saved quant tables, + * not at the current Q-table slots. + */ + + LOCAL(void) + latch_quant_tables (j_decompress_ptr cinfo) + { + int ci, qtblno; + jpeg_component_info *compptr; + JQUANT_TBL * qtbl; + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* No work if we already saved Q-table for this component */ + if (compptr->quant_table != NULL) + continue; + /* Make sure specified quantization table is present */ + qtblno = compptr->quant_tbl_no; + if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || + cinfo->quant_tbl_ptrs[qtblno] == NULL) + ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); + /* OK, save away the quantization table */ + qtbl = (JQUANT_TBL *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(JQUANT_TBL)); + MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL)); + compptr->quant_table = qtbl; + } + } + + + /* + * Initialize the input modules to read a scan of compressed data. + * The first call to this is done by jdmaster.c after initializing + * the entire decompressor (during jpeg_start_decompress). + * Subsequent calls come from consume_markers, below. + */ + + METHODDEF(void) + start_input_pass (j_decompress_ptr cinfo) + { + per_scan_setup(cinfo); + latch_quant_tables(cinfo); + (*cinfo->entropy->start_pass) (cinfo); + (*cinfo->coef->start_input_pass) (cinfo); + cinfo->inputctl->consume_input = cinfo->coef->consume_data; + } + + + /* + * Finish up after inputting a compressed-data scan. + * This is called by the coefficient controller after it's read all + * the expected data of the scan. + */ + + METHODDEF(void) + finish_input_pass (j_decompress_ptr cinfo) + { + cinfo->inputctl->consume_input = consume_markers; + } + + + /* + * Read JPEG markers before, between, or after compressed-data scans. + * Change state as necessary when a new scan is reached. + * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. + * + * The consume_input method pointer points either here or to the + * coefficient controller's consume_data routine, depending on whether + * we are reading a compressed data segment or inter-segment markers. + */ + + METHODDEF(int) + consume_markers (j_decompress_ptr cinfo) + { + my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; + int val; + + if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */ + return JPEG_REACHED_EOI; + + val = (*cinfo->marker->read_markers) (cinfo); + + switch (val) { + case JPEG_REACHED_SOS: /* Found SOS */ + if (inputctl->inheaders) { /* 1st SOS */ + initial_setup(cinfo); + inputctl->inheaders = FALSE; + /* Note: start_input_pass must be called by jdmaster.c + * before any more input can be consumed. jdapi.c is + * responsible for enforcing this sequencing. + */ + } else { /* 2nd or later SOS marker */ + if (! inputctl->pub.has_multiple_scans) + ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ + start_input_pass(cinfo); + } + break; + case JPEG_REACHED_EOI: /* Found EOI */ + inputctl->pub.eoi_reached = TRUE; + if (inputctl->inheaders) { /* Tables-only datastream, apparently */ + if (cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOF_NO_SOS); + } else { + /* Prevent infinite loop in coef ctlr's decompress_data routine + * if user set output_scan_number larger than number of scans. + */ + if (cinfo->output_scan_number > cinfo->input_scan_number) + cinfo->output_scan_number = cinfo->input_scan_number; + } + break; + case JPEG_SUSPENDED: + break; + } + + return val; + } + + + /* + * Reset state to begin a fresh datastream. + */ + + METHODDEF(void) + reset_input_controller (j_decompress_ptr cinfo) + { + my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; + + inputctl->pub.consume_input = consume_markers; + inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ + inputctl->pub.eoi_reached = FALSE; + inputctl->inheaders = TRUE; + /* Reset other modules */ + (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); + (*cinfo->marker->reset_marker_reader) (cinfo); + /* Reset progression state -- would be cleaner if entropy decoder did this */ + cinfo->coef_bits = NULL; + } + + + /* + * Initialize the input controller module. + * This is called only once, when the decompression object is created. + */ + + GLOBAL(void) + jinit_input_controller (j_decompress_ptr cinfo) + { + my_inputctl_ptr inputctl; + + /* Create subobject in permanent pool */ + inputctl = (my_inputctl_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(my_input_controller)); + cinfo->inputctl = (struct jpeg_input_controller *) inputctl; + /* Initialize method pointers */ + inputctl->pub.consume_input = consume_markers; + inputctl->pub.reset_input_controller = reset_input_controller; + inputctl->pub.start_input_pass = start_input_pass; + inputctl->pub.finish_input_pass = finish_input_pass; + /* Initialize state: can't use reset_input_controller since we don't + * want to try to reset other modules yet. + */ + inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ + inputctl->pub.eoi_reached = FALSE; + inputctl->inheaders = TRUE; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmainct.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmainct.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmainct.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,512 ---- + /* + * jdmainct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the main buffer controller for decompression. + * The main buffer lies between the JPEG decompressor proper and the + * post-processor; it holds downsampled data in the JPEG colorspace. + * + * Note that this code is bypassed in raw-data mode, since the application + * supplies the equivalent of the main buffer in that case. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * In the current system design, the main buffer need never be a full-image + * buffer; any full-height buffers will be found inside the coefficient or + * postprocessing controllers. Nonetheless, the main controller is not + * trivial. Its responsibility is to provide context rows for upsampling/ + * rescaling, and doing this in an efficient fashion is a bit tricky. + * + * Postprocessor input data is counted in "row groups". A row group + * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) + * sample rows of each component. (We require DCT_scaled_size values to be + * chosen such that these numbers are integers. In practice DCT_scaled_size + * values will likely be powers of two, so we actually have the stronger + * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.) + * Upsampling will typically produce max_v_samp_factor pixel rows from each + * row group (times any additional scale factor that the upsampler is + * applying). + * + * The coefficient controller will deliver data to us one iMCU row at a time; + * each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or + * exactly min_DCT_scaled_size row groups. (This amount of data corresponds + * to one row of MCUs when the image is fully interleaved.) Note that the + * number of sample rows varies across components, but the number of row + * groups does not. Some garbage sample rows may be included in the last iMCU + * row at the bottom of the image. + * + * Depending on the vertical scaling algorithm used, the upsampler may need + * access to the sample row(s) above and below its current input row group. + * The upsampler is required to set need_context_rows TRUE at global selection + * time if so. When need_context_rows is FALSE, this controller can simply + * obtain one iMCU row at a time from the coefficient controller and dole it + * out as row groups to the postprocessor. + * + * When need_context_rows is TRUE, this controller guarantees that the buffer + * passed to postprocessing contains at least one row group's worth of samples + * above and below the row group(s) being processed. Note that the context + * rows "above" the first passed row group appear at negative row offsets in + * the passed buffer. At the top and bottom of the image, the required + * context rows are manufactured by duplicating the first or last real sample + * row; this avoids having special cases in the upsampling inner loops. + * + * The amount of context is fixed at one row group just because that's a + * convenient number for this controller to work with. The existing + * upsamplers really only need one sample row of context. An upsampler + * supporting arbitrary output rescaling might wish for more than one row + * group of context when shrinking the image; tough, we don't handle that. + * (This is justified by the assumption that downsizing will be handled mostly + * by adjusting the DCT_scaled_size values, so that the actual scale factor at + * the upsample step needn't be much less than one.) + * + * To provide the desired context, we have to retain the last two row groups + * of one iMCU row while reading in the next iMCU row. (The last row group + * can't be processed until we have another row group for its below-context, + * and so we have to save the next-to-last group too for its above-context.) + * We could do this most simply by copying data around in our buffer, but + * that'd be very slow. We can avoid copying any data by creating a rather + * strange pointer structure. Here's how it works. We allocate a workspace + * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number + * of row groups per iMCU row). We create two sets of redundant pointers to + * the workspace. Labeling the physical row groups 0 to M+1, the synthesized + * pointer lists look like this: + * M+1 M-1 + * master pointer --> 0 master pointer --> 0 + * 1 1 + * ... ... + * M-3 M-3 + * M-2 M + * M-1 M+1 + * M M-2 + * M+1 M-1 + * 0 0 + * We read alternate iMCU rows using each master pointer; thus the last two + * row groups of the previous iMCU row remain un-overwritten in the workspace. + * The pointer lists are set up so that the required context rows appear to + * be adjacent to the proper places when we pass the pointer lists to the + * upsampler. + * + * The above pictures describe the normal state of the pointer lists. + * At top and bottom of the image, we diddle the pointer lists to duplicate + * the first or last sample row as necessary (this is cheaper than copying + * sample rows around). + * + * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that + * situation each iMCU row provides only one row group so the buffering logic + * must be different (eg, we must read two iMCU rows before we can emit the + * first row group). For now, we simply do not support providing context + * rows when min_DCT_scaled_size is 1. That combination seems unlikely to + * be worth providing --- if someone wants a 1/8th-size preview, they probably + * want it quick and dirty, so a context-free upsampler is sufficient. + */ + + + /* Private buffer controller object */ + + typedef struct { + struct jpeg_d_main_controller pub; /* public fields */ + + /* Pointer to allocated workspace (M or M+2 row groups). */ + JSAMPARRAY buffer[MAX_COMPONENTS]; + + boolean buffer_full; /* Have we gotten an iMCU row from decoder? */ + JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */ + + /* Remaining fields are only used in the context case. */ + + /* These are the master pointers to the funny-order pointer lists. */ + JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */ + + int whichptr; /* indicates which pointer set is now in use */ + int context_state; /* process_data state machine status */ + JDIMENSION rowgroups_avail; /* row groups available to postprocessor */ + JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ + } my_main_controller; + + typedef my_main_controller * my_main_ptr; + + /* context_state values: */ + #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */ + #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */ + #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */ + + + /* Forward declarations */ + METHODDEF(void) process_data_simple_main + JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); + METHODDEF(void) process_data_context_main + JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); + #ifdef QUANT_2PASS_SUPPORTED + METHODDEF(void) process_data_crank_post + JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); + #endif + + + LOCAL(void) + alloc_funny_pointers (j_decompress_ptr cinfo) + /* Allocate space for the funny pointer lists. + * This is done only once, not once per pass. + */ + { + my_main_ptr main = (my_main_ptr) cinfo->main; + int ci, rgroup; + int M = cinfo->min_DCT_scaled_size; + jpeg_component_info *compptr; + JSAMPARRAY xbuf; + + /* Get top-level space for component array pointers. + * We alloc both arrays with one call to save a few cycles. + */ + main->xbuffer[0] = (JSAMPIMAGE) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components * 2 * SIZEOF(JSAMPARRAY)); + main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / + cinfo->min_DCT_scaled_size; /* height of a row group of component */ + /* Get space for pointer lists --- M+4 row groups in each list. + * We alloc both pointer lists with one call to save a few cycles. + */ + xbuf = (JSAMPARRAY) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW)); + xbuf += rgroup; /* want one row group at negative offsets */ + main->xbuffer[0][ci] = xbuf; + xbuf += rgroup * (M + 4); + main->xbuffer[1][ci] = xbuf; + } + } + + + LOCAL(void) + make_funny_pointers (j_decompress_ptr cinfo) + /* Create the funny pointer lists discussed in the comments above. + * The actual workspace is already allocated (in main->buffer), + * and the space for the pointer lists is allocated too. + * This routine just fills in the curiously ordered lists. + * This will be repeated at the beginning of each pass. + */ + { + my_main_ptr main = (my_main_ptr) cinfo->main; + int ci, i, rgroup; + int M = cinfo->min_DCT_scaled_size; + jpeg_component_info *compptr; + JSAMPARRAY buf, xbuf0, xbuf1; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / + cinfo->min_DCT_scaled_size; /* height of a row group of component */ + xbuf0 = main->xbuffer[0][ci]; + xbuf1 = main->xbuffer[1][ci]; + /* First copy the workspace pointers as-is */ + buf = main->buffer[ci]; + for (i = 0; i < rgroup * (M + 2); i++) { + xbuf0[i] = xbuf1[i] = buf[i]; + } + /* In the second list, put the last four row groups in swapped order */ + for (i = 0; i < rgroup * 2; i++) { + xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i]; + xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i]; + } + /* The wraparound pointers at top and bottom will be filled later + * (see set_wraparound_pointers, below). Initially we want the "above" + * pointers to duplicate the first actual data line. This only needs + * to happen in xbuffer[0]. + */ + for (i = 0; i < rgroup; i++) { + xbuf0[i - rgroup] = xbuf0[0]; + } + } + } + + + LOCAL(void) + set_wraparound_pointers (j_decompress_ptr cinfo) + /* Set up the "wraparound" pointers at top and bottom of the pointer lists. + * This changes the pointer list state from top-of-image to the normal state. + */ + { + my_main_ptr main = (my_main_ptr) cinfo->main; + int ci, i, rgroup; + int M = cinfo->min_DCT_scaled_size; + jpeg_component_info *compptr; + JSAMPARRAY xbuf0, xbuf1; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / + cinfo->min_DCT_scaled_size; /* height of a row group of component */ + xbuf0 = main->xbuffer[0][ci]; + xbuf1 = main->xbuffer[1][ci]; + for (i = 0; i < rgroup; i++) { + xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i]; + xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i]; + xbuf0[rgroup*(M+2) + i] = xbuf0[i]; + xbuf1[rgroup*(M+2) + i] = xbuf1[i]; + } + } + } + + + LOCAL(void) + set_bottom_pointers (j_decompress_ptr cinfo) + /* Change the pointer lists to duplicate the last sample row at the bottom + * of the image. whichptr indicates which xbuffer holds the final iMCU row. + * Also sets rowgroups_avail to indicate number of nondummy row groups in row. + */ + { + my_main_ptr main = (my_main_ptr) cinfo->main; + int ci, i, rgroup, iMCUheight, rows_left; + jpeg_component_info *compptr; + JSAMPARRAY xbuf; + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Count sample rows in one iMCU row and in one row group */ + iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size; + rgroup = iMCUheight / cinfo->min_DCT_scaled_size; + /* Count nondummy sample rows remaining for this component */ + rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight); + if (rows_left == 0) rows_left = iMCUheight; + /* Count nondummy row groups. Should get same answer for each component, + * so we need only do it once. + */ + if (ci == 0) { + main->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1); + } + /* Duplicate the last real sample row rgroup*2 times; this pads out the + * last partial rowgroup and ensures at least one full rowgroup of context. + */ + xbuf = main->xbuffer[main->whichptr][ci]; + for (i = 0; i < rgroup * 2; i++) { + xbuf[rows_left + i] = xbuf[rows_left-1]; + } + } + } + + + /* + * Initialize for a processing pass. + */ + + METHODDEF(void) + start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) + { + my_main_ptr main = (my_main_ptr) cinfo->main; + + switch (pass_mode) { + case JBUF_PASS_THRU: + if (cinfo->upsample->need_context_rows) { + main->pub.process_data = process_data_context_main; + make_funny_pointers(cinfo); /* Create the xbuffer[] lists */ + main->whichptr = 0; /* Read first iMCU row into xbuffer[0] */ + main->context_state = CTX_PREPARE_FOR_IMCU; + main->iMCU_row_ctr = 0; + } else { + /* Simple case with no context needed */ + main->pub.process_data = process_data_simple_main; + } + main->buffer_full = FALSE; /* Mark buffer empty */ + main->rowgroup_ctr = 0; + break; + #ifdef QUANT_2PASS_SUPPORTED + case JBUF_CRANK_DEST: + /* For last pass of 2-pass quantization, just crank the postprocessor */ + main->pub.process_data = process_data_crank_post; + break; + #endif + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } + } + + + /* + * Process some data. + * This handles the simple case where no context is required. + */ + + METHODDEF(void) + process_data_simple_main (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + { + my_main_ptr main = (my_main_ptr) cinfo->main; + JDIMENSION rowgroups_avail; + + /* Read input data if we haven't filled the main buffer yet */ + if (! main->buffer_full) { + if (! (*cinfo->coef->decompress_data) (cinfo, main->buffer)) + return; /* suspension forced, can do nothing more */ + main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ + } + + /* There are always min_DCT_scaled_size row groups in an iMCU row. */ + rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size; + /* Note: at the bottom of the image, we may pass extra garbage row groups + * to the postprocessor. The postprocessor has to check for bottom + * of image anyway (at row resolution), so no point in us doing it too. + */ + + /* Feed the postprocessor */ + (*cinfo->post->post_process_data) (cinfo, main->buffer, + &main->rowgroup_ctr, rowgroups_avail, + output_buf, out_row_ctr, out_rows_avail); + + /* Has postprocessor consumed all the data yet? If so, mark buffer empty */ + if (main->rowgroup_ctr >= rowgroups_avail) { + main->buffer_full = FALSE; + main->rowgroup_ctr = 0; + } + } + + + /* + * Process some data. + * This handles the case where context rows must be provided. + */ + + METHODDEF(void) + process_data_context_main (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + { + my_main_ptr main = (my_main_ptr) cinfo->main; + + /* Read input data if we haven't filled the main buffer yet */ + if (! main->buffer_full) { + if (! (*cinfo->coef->decompress_data) (cinfo, + main->xbuffer[main->whichptr])) + return; /* suspension forced, can do nothing more */ + main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ + main->iMCU_row_ctr++; /* count rows received */ + } + + /* Postprocessor typically will not swallow all the input data it is handed + * in one call (due to filling the output buffer first). Must be prepared + * to exit and restart. This switch lets us keep track of how far we got. + * Note that each case falls through to the next on successful completion. + */ + switch (main->context_state) { + case CTX_POSTPONED_ROW: + /* Call postprocessor using previously set pointers for postponed row */ + (*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr], + &main->rowgroup_ctr, main->rowgroups_avail, + output_buf, out_row_ctr, out_rows_avail); + if (main->rowgroup_ctr < main->rowgroups_avail) + return; /* Need to suspend */ + main->context_state = CTX_PREPARE_FOR_IMCU; + if (*out_row_ctr >= out_rows_avail) + return; /* Postprocessor exactly filled output buf */ + /*FALLTHROUGH*/ + case CTX_PREPARE_FOR_IMCU: + /* Prepare to process first M-1 row groups of this iMCU row */ + main->rowgroup_ctr = 0; + main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1); + /* Check for bottom of image: if so, tweak pointers to "duplicate" + * the last sample row, and adjust rowgroups_avail to ignore padding rows. + */ + if (main->iMCU_row_ctr == cinfo->total_iMCU_rows) + set_bottom_pointers(cinfo); + main->context_state = CTX_PROCESS_IMCU; + /*FALLTHROUGH*/ + case CTX_PROCESS_IMCU: + /* Call postprocessor using previously set pointers */ + (*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr], + &main->rowgroup_ctr, main->rowgroups_avail, + output_buf, out_row_ctr, out_rows_avail); + if (main->rowgroup_ctr < main->rowgroups_avail) + return; /* Need to suspend */ + /* After the first iMCU, change wraparound pointers to normal state */ + if (main->iMCU_row_ctr == 1) + set_wraparound_pointers(cinfo); + /* Prepare to load new iMCU row using other xbuffer list */ + main->whichptr ^= 1; /* 0=>1 or 1=>0 */ + main->buffer_full = FALSE; + /* Still need to process last row group of this iMCU row, */ + /* which is saved at index M+1 of the other xbuffer */ + main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1); + main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2); + main->context_state = CTX_POSTPONED_ROW; + } + } + + + /* + * Process some data. + * Final pass of two-pass quantization: just call the postprocessor. + * Source data will be the postprocessor controller's internal buffer. + */ + + #ifdef QUANT_2PASS_SUPPORTED + + METHODDEF(void) + process_data_crank_post (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + { + (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL, + (JDIMENSION *) NULL, (JDIMENSION) 0, + output_buf, out_row_ctr, out_rows_avail); + } + + #endif /* QUANT_2PASS_SUPPORTED */ + + + /* + * Initialize main buffer controller. + */ + + GLOBAL(void) + jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer) + { + my_main_ptr main; + int ci, rgroup, ngroups; + jpeg_component_info *compptr; + + main = (my_main_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_main_controller)); + cinfo->main = (struct jpeg_d_main_controller *) main; + main->pub.start_pass = start_pass_main; + + if (need_full_buffer) /* shouldn't happen */ + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + + /* Allocate the workspace. + * ngroups is the number of row groups we need. + */ + if (cinfo->upsample->need_context_rows) { + if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */ + ERREXIT(cinfo, JERR_NOTIMPL); + alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */ + ngroups = cinfo->min_DCT_scaled_size + 2; + } else { + ngroups = cinfo->min_DCT_scaled_size; + } + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / + cinfo->min_DCT_scaled_size; /* height of a row group of component */ + main->buffer[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + compptr->width_in_blocks * compptr->DCT_scaled_size, + (JDIMENSION) (rgroup * ngroups)); + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmarker.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmarker.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmarker.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,1055 ---- + /* + * jdmarker.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to decode JPEG datastream markers. + * Most of the complexity arises from our desire to support input + * suspension: if not all of the data for a marker is available, + * we must exit back to the application. On resumption, we reprocess + * the marker. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + typedef enum { /* JPEG marker codes */ + M_SOF0 = 0xc0, + M_SOF1 = 0xc1, + M_SOF2 = 0xc2, + M_SOF3 = 0xc3, + + M_SOF5 = 0xc5, + M_SOF6 = 0xc6, + M_SOF7 = 0xc7, + + M_JPG = 0xc8, + M_SOF9 = 0xc9, + M_SOF10 = 0xca, + M_SOF11 = 0xcb, + + M_SOF13 = 0xcd, + M_SOF14 = 0xce, + M_SOF15 = 0xcf, + + M_DHT = 0xc4, + + M_DAC = 0xcc, + + M_RST0 = 0xd0, + M_RST1 = 0xd1, + M_RST2 = 0xd2, + M_RST3 = 0xd3, + M_RST4 = 0xd4, + M_RST5 = 0xd5, + M_RST6 = 0xd6, + M_RST7 = 0xd7, + + M_SOI = 0xd8, + M_EOI = 0xd9, + M_SOS = 0xda, + M_DQT = 0xdb, + M_DNL = 0xdc, + M_DRI = 0xdd, + M_DHP = 0xde, + M_EXP = 0xdf, + + M_APP0 = 0xe0, + M_APP1 = 0xe1, + M_APP2 = 0xe2, + M_APP3 = 0xe3, + M_APP4 = 0xe4, + M_APP5 = 0xe5, + M_APP6 = 0xe6, + M_APP7 = 0xe7, + M_APP8 = 0xe8, + M_APP9 = 0xe9, + M_APP10 = 0xea, + M_APP11 = 0xeb, + M_APP12 = 0xec, + M_APP13 = 0xed, + M_APP14 = 0xee, + M_APP15 = 0xef, + + M_JPG0 = 0xf0, + M_JPG13 = 0xfd, + M_COM = 0xfe, + + M_TEM = 0x01, + + M_ERROR = 0x100 + } JPEG_MARKER; + + + /* + * Macros for fetching data from the data source module. + * + * At all times, cinfo->src->next_input_byte and ->bytes_in_buffer reflect + * the current restart point; we update them only when we have reached a + * suitable place to restart if a suspension occurs. + */ + + /* Declare and initialize local copies of input pointer/count */ + #define INPUT_VARS(cinfo) \ + struct jpeg_source_mgr * datasrc = (cinfo)->src; \ + const JOCTET * next_input_byte = datasrc->next_input_byte; \ + size_t bytes_in_buffer = datasrc->bytes_in_buffer + + /* Unload the local copies --- do this only at a restart boundary */ + #define INPUT_SYNC(cinfo) \ + ( datasrc->next_input_byte = next_input_byte, \ + datasrc->bytes_in_buffer = bytes_in_buffer ) + + /* Reload the local copies --- seldom used except in MAKE_BYTE_AVAIL */ + #define INPUT_RELOAD(cinfo) \ + ( next_input_byte = datasrc->next_input_byte, \ + bytes_in_buffer = datasrc->bytes_in_buffer ) + + /* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available. + * Note we do *not* do INPUT_SYNC before calling fill_input_buffer, + * but we must reload the local copies after a successful fill. + */ + #define MAKE_BYTE_AVAIL(cinfo,action) \ + if (bytes_in_buffer == 0) { \ + if (! (*datasrc->fill_input_buffer) (cinfo)) \ + { action; } \ + INPUT_RELOAD(cinfo); \ + } \ + bytes_in_buffer-- + + /* Read a byte into variable V. + * If must suspend, take the specified action (typically "return FALSE"). + */ + #define INPUT_BYTE(cinfo,V,action) \ + MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ + V = GETJOCTET(*next_input_byte++); ) + + /* As above, but read two bytes interpreted as an unsigned 16-bit integer. + * V should be declared unsigned int or perhaps INT32. + */ + #define INPUT_2BYTES(cinfo,V,action) \ + MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ + V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \ + MAKE_BYTE_AVAIL(cinfo,action); \ + V += GETJOCTET(*next_input_byte++); ) + + + /* + * Routines to process JPEG markers. + * + * Entry condition: JPEG marker itself has been read and its code saved + * in cinfo->unread_marker; input restart point is just after the marker. + * + * Exit: if return TRUE, have read and processed any parameters, and have + * updated the restart point to point after the parameters. + * If return FALSE, was forced to suspend before reaching end of + * marker parameters; restart point has not been moved. Same routine + * will be called again after application supplies more input data. + * + * This approach to suspension assumes that all of a marker's parameters can + * fit into a single input bufferload. This should hold for "normal" + * markers. Some COM/APPn markers might have large parameter segments, + * but we use skip_input_data to get past those, and thereby put the problem + * on the source manager's shoulders. + * + * Note that we don't bother to avoid duplicate trace messages if a + * suspension occurs within marker parameters. Other side effects + * require more care. + */ + + + LOCAL(boolean) + get_soi (j_decompress_ptr cinfo) + /* Process an SOI marker */ + { + int i; + + TRACEMS(cinfo, 1, JTRC_SOI); + + if (cinfo->marker->saw_SOI) + ERREXIT(cinfo, JERR_SOI_DUPLICATE); + + /* Reset all parameters that are defined to be reset by SOI */ + + for (i = 0; i < NUM_ARITH_TBLS; i++) { + cinfo->arith_dc_L[i] = 0; + cinfo->arith_dc_U[i] = 1; + cinfo->arith_ac_K[i] = 5; + } + cinfo->restart_interval = 0; + + /* Set initial assumptions for colorspace etc */ + + cinfo->jpeg_color_space = JCS_UNKNOWN; + cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */ + + cinfo->saw_JFIF_marker = FALSE; + cinfo->density_unit = 0; /* set default JFIF APP0 values */ + cinfo->X_density = 1; + cinfo->Y_density = 1; + cinfo->saw_Adobe_marker = FALSE; + cinfo->Adobe_transform = 0; + + cinfo->marker->saw_SOI = TRUE; + + return TRUE; + } + + + LOCAL(boolean) + get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith) + /* Process a SOFn marker */ + { + INT32 length; + int c, ci; + jpeg_component_info * compptr; + INPUT_VARS(cinfo); + + cinfo->progressive_mode = is_prog; + cinfo->arith_code = is_arith; + + INPUT_2BYTES(cinfo, length, return FALSE); + + INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE); + INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE); + INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE); + INPUT_BYTE(cinfo, cinfo->num_components, return FALSE); + + length -= 8; + + TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker, + (int) cinfo->image_width, (int) cinfo->image_height, + cinfo->num_components); + + if (cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOF_DUPLICATE); + + /* We don't support files in which the image height is initially specified */ + /* as 0 and is later redefined by DNL. As long as we have to check that, */ + /* might as well have a general sanity check. */ + if (cinfo->image_height <= 0 || cinfo->image_width <= 0 + || cinfo->num_components <= 0) + ERREXIT(cinfo, JERR_EMPTY_IMAGE); + + if (length != (cinfo->num_components * 3)) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + if (cinfo->comp_info == NULL) /* do only once, even if suspend */ + cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components * SIZEOF(jpeg_component_info)); + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + compptr->component_index = ci; + INPUT_BYTE(cinfo, compptr->component_id, return FALSE); + INPUT_BYTE(cinfo, c, return FALSE); + compptr->h_samp_factor = (c >> 4) & 15; + compptr->v_samp_factor = (c ) & 15; + INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE); + + TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT, + compptr->component_id, compptr->h_samp_factor, + compptr->v_samp_factor, compptr->quant_tbl_no); + } + + cinfo->marker->saw_SOF = TRUE; + + INPUT_SYNC(cinfo); + return TRUE; + } + + + LOCAL(boolean) + get_sos (j_decompress_ptr cinfo) + /* Process a SOS marker */ + { + INT32 length; + int i, ci, n, c, cc; + jpeg_component_info * compptr; + INPUT_VARS(cinfo); + + if (! cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOS_NO_SOF); + + INPUT_2BYTES(cinfo, length, return FALSE); + + INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */ + + if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + TRACEMS1(cinfo, 1, JTRC_SOS, n); + + cinfo->comps_in_scan = n; + + /* Collect the component-spec parameters */ + + for (i = 0; i < n; i++) { + INPUT_BYTE(cinfo, cc, return FALSE); + INPUT_BYTE(cinfo, c, return FALSE); + + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + if (cc == compptr->component_id) + goto id_found; + } + + ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); + + id_found: + + cinfo->cur_comp_info[i] = compptr; + compptr->dc_tbl_no = (c >> 4) & 15; + compptr->ac_tbl_no = (c ) & 15; + + TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, + compptr->dc_tbl_no, compptr->ac_tbl_no); + } + + /* Collect the additional scan parameters Ss, Se, Ah/Al. */ + INPUT_BYTE(cinfo, c, return FALSE); + cinfo->Ss = c; + INPUT_BYTE(cinfo, c, return FALSE); + cinfo->Se = c; + INPUT_BYTE(cinfo, c, return FALSE); + cinfo->Ah = (c >> 4) & 15; + cinfo->Al = (c ) & 15; + + TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se, + cinfo->Ah, cinfo->Al); + + /* Prepare to scan data & restart markers */ + cinfo->marker->next_restart_num = 0; + + /* Count another SOS marker */ + cinfo->input_scan_number++; + + INPUT_SYNC(cinfo); + return TRUE; + } + + + METHODDEF(boolean) + get_app0 (j_decompress_ptr cinfo) + /* Process an APP0 marker */ + { + #define JFIF_LEN 14 + INT32 length; + UINT8 b[JFIF_LEN]; + int buffp; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + /* See if a JFIF APP0 marker is present */ + + if (length >= JFIF_LEN) { + for (buffp = 0; buffp < JFIF_LEN; buffp++) + INPUT_BYTE(cinfo, b[buffp], return FALSE); + length -= JFIF_LEN; + + if (b[0]==0x4A && b[1]==0x46 && b[2]==0x49 && b[3]==0x46 && b[4]==0) { + /* Found JFIF APP0 marker: check version */ + /* Major version must be 1, anything else signals an incompatible change. + * We used to treat this as an error, but now it's a nonfatal warning, + * because some bozo at Hijaak couldn't read the spec. + * Minor version should be 0..2, but process anyway if newer. + */ + if (b[5] != 1) + WARNMS2(cinfo, JWRN_JFIF_MAJOR, b[5], b[6]); + else if (b[6] > 2) + TRACEMS2(cinfo, 1, JTRC_JFIF_MINOR, b[5], b[6]); + /* Save info */ + cinfo->saw_JFIF_marker = TRUE; + cinfo->density_unit = b[7]; + cinfo->X_density = (b[8] << 8) + b[9]; + cinfo->Y_density = (b[10] << 8) + b[11]; + TRACEMS3(cinfo, 1, JTRC_JFIF, + cinfo->X_density, cinfo->Y_density, cinfo->density_unit); + if (b[12] | b[13]) + TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, b[12], b[13]); + if (length != ((INT32) b[12] * (INT32) b[13] * (INT32) 3)) + TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) length); + } else { + /* Start of APP0 does not match "JFIF" */ + TRACEMS1(cinfo, 1, JTRC_APP0, (int) length + JFIF_LEN); + } + } else { + /* Too short to be JFIF marker */ + TRACEMS1(cinfo, 1, JTRC_APP0, (int) length); + } + + INPUT_SYNC(cinfo); + if (length > 0) /* skip any remaining data -- could be lots */ + (*cinfo->src->skip_input_data) (cinfo, (long) length); + + return TRUE; + } + + + METHODDEF(boolean) + get_app14 (j_decompress_ptr cinfo) + /* Process an APP14 marker */ + { + #define ADOBE_LEN 12 + INT32 length; + UINT8 b[ADOBE_LEN]; + int buffp; + unsigned int version, flags0, flags1, transform; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + /* See if an Adobe APP14 marker is present */ + + if (length >= ADOBE_LEN) { + for (buffp = 0; buffp < ADOBE_LEN; buffp++) + INPUT_BYTE(cinfo, b[buffp], return FALSE); + length -= ADOBE_LEN; + + if (b[0]==0x41 && b[1]==0x64 && b[2]==0x6F && b[3]==0x62 && b[4]==0x65) { + /* Found Adobe APP14 marker */ + version = (b[5] << 8) + b[6]; + flags0 = (b[7] << 8) + b[8]; + flags1 = (b[9] << 8) + b[10]; + transform = b[11]; + TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform); + cinfo->saw_Adobe_marker = TRUE; + cinfo->Adobe_transform = (UINT8) transform; + } else { + /* Start of APP14 does not match "Adobe" */ + TRACEMS1(cinfo, 1, JTRC_APP14, (int) length + ADOBE_LEN); + } + } else { + /* Too short to be Adobe marker */ + TRACEMS1(cinfo, 1, JTRC_APP14, (int) length); + } + + INPUT_SYNC(cinfo); + if (length > 0) /* skip any remaining data -- could be lots */ + (*cinfo->src->skip_input_data) (cinfo, (long) length); + + return TRUE; + } + + + LOCAL(boolean) + get_dac (j_decompress_ptr cinfo) + /* Process a DAC marker */ + { + INT32 length; + int index, val; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + while (length > 0) { + INPUT_BYTE(cinfo, index, return FALSE); + INPUT_BYTE(cinfo, val, return FALSE); + + length -= 2; + + TRACEMS2(cinfo, 1, JTRC_DAC, index, val); + + if (index < 0 || index >= (2*NUM_ARITH_TBLS)) + ERREXIT1(cinfo, JERR_DAC_INDEX, index); + + if (index >= NUM_ARITH_TBLS) { /* define AC table */ + cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val; + } else { /* define DC table */ + cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F); + cinfo->arith_dc_U[index] = (UINT8) (val >> 4); + if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index]) + ERREXIT1(cinfo, JERR_DAC_VALUE, val); + } + } + + INPUT_SYNC(cinfo); + return TRUE; + } + + + LOCAL(boolean) + get_dht (j_decompress_ptr cinfo) + /* Process a DHT marker */ + { + INT32 length; + UINT8 bits[17]; + UINT8 huffval[256]; + int i, index, count; + JHUFF_TBL **htblptr; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + while (length > 0) { + INPUT_BYTE(cinfo, index, return FALSE); + + TRACEMS1(cinfo, 1, JTRC_DHT, index); + + bits[0] = 0; + count = 0; + for (i = 1; i <= 16; i++) { + INPUT_BYTE(cinfo, bits[i], return FALSE); + count += bits[i]; + } + + length -= 1 + 16; + + TRACEMS8(cinfo, 2, JTRC_HUFFBITS, + bits[1], bits[2], bits[3], bits[4], + bits[5], bits[6], bits[7], bits[8]); + TRACEMS8(cinfo, 2, JTRC_HUFFBITS, + bits[9], bits[10], bits[11], bits[12], + bits[13], bits[14], bits[15], bits[16]); + + if (count > 256 || ((INT32) count) > length) + ERREXIT(cinfo, JERR_DHT_COUNTS); + + for (i = 0; i < count; i++) + INPUT_BYTE(cinfo, huffval[i], return FALSE); + + length -= count; + + if (index & 0x10) { /* AC table definition */ + index -= 0x10; + htblptr = &cinfo->ac_huff_tbl_ptrs[index]; + } else { /* DC table definition */ + htblptr = &cinfo->dc_huff_tbl_ptrs[index]; + } + + if (index < 0 || index >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_DHT_INDEX, index); + + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); + + MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); + MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval)); + } + + INPUT_SYNC(cinfo); + return TRUE; + } + + + LOCAL(boolean) + get_dqt (j_decompress_ptr cinfo) + /* Process a DQT marker */ + { + INT32 length; + int n, i, prec; + unsigned int tmp; + JQUANT_TBL *quant_ptr; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + length -= 2; + + while (length > 0) { + INPUT_BYTE(cinfo, n, return FALSE); + prec = n >> 4; + n &= 0x0F; + + TRACEMS2(cinfo, 1, JTRC_DQT, n, prec); + + if (n >= NUM_QUANT_TBLS) + ERREXIT1(cinfo, JERR_DQT_INDEX, n); + + if (cinfo->quant_tbl_ptrs[n] == NULL) + cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo); + quant_ptr = cinfo->quant_tbl_ptrs[n]; + + for (i = 0; i < DCTSIZE2; i++) { + if (prec) + INPUT_2BYTES(cinfo, tmp, return FALSE); + else + INPUT_BYTE(cinfo, tmp, return FALSE); + /* We convert the zigzag-order table to natural array order. */ + quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp; + } + + if (cinfo->err->trace_level >= 2) { + for (i = 0; i < DCTSIZE2; i += 8) { + TRACEMS8(cinfo, 2, JTRC_QUANTVALS, + quant_ptr->quantval[i], quant_ptr->quantval[i+1], + quant_ptr->quantval[i+2], quant_ptr->quantval[i+3], + quant_ptr->quantval[i+4], quant_ptr->quantval[i+5], + quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]); + } + } + + length -= DCTSIZE2+1; + if (prec) length -= DCTSIZE2; + } + + INPUT_SYNC(cinfo); + return TRUE; + } + + + LOCAL(boolean) + get_dri (j_decompress_ptr cinfo) + /* Process a DRI marker */ + { + INT32 length; + unsigned int tmp; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + + if (length != 4) + ERREXIT(cinfo, JERR_BAD_LENGTH); + + INPUT_2BYTES(cinfo, tmp, return FALSE); + + TRACEMS1(cinfo, 1, JTRC_DRI, tmp); + + cinfo->restart_interval = tmp; + + INPUT_SYNC(cinfo); + return TRUE; + } + + + METHODDEF(boolean) + skip_variable (j_decompress_ptr cinfo) + /* Skip over an unknown or uninteresting variable-length marker */ + { + INT32 length; + INPUT_VARS(cinfo); + + INPUT_2BYTES(cinfo, length, return FALSE); + + TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length); + + INPUT_SYNC(cinfo); /* do before skip_input_data */ + (*cinfo->src->skip_input_data) (cinfo, (long) length - 2L); + + return TRUE; + } + + + /* + * Find the next JPEG marker, save it in cinfo->unread_marker. + * Returns FALSE if had to suspend before reaching a marker; + * in that case cinfo->unread_marker is unchanged. + * + * Note that the result might not be a valid marker code, + * but it will never be 0 or FF. + */ + + LOCAL(boolean) + next_marker (j_decompress_ptr cinfo) + { + int c; + INPUT_VARS(cinfo); + + for (;;) { + INPUT_BYTE(cinfo, c, return FALSE); + /* Skip any non-FF bytes. + * This may look a bit inefficient, but it will not occur in a valid file. + * We sync after each discarded byte so that a suspending data source + * can discard the byte from its buffer. + */ + while (c != 0xFF) { + cinfo->marker->discarded_bytes++; + INPUT_SYNC(cinfo); + INPUT_BYTE(cinfo, c, return FALSE); + } + /* This loop swallows any duplicate FF bytes. Extra FFs are legal as + * pad bytes, so don't count them in discarded_bytes. We assume there + * will not be so many consecutive FF bytes as to overflow a suspending + * data source's input buffer. + */ + do { + INPUT_BYTE(cinfo, c, return FALSE); + } while (c == 0xFF); + if (c != 0) + break; /* found a valid marker, exit loop */ + /* Reach here if we found a stuffed-zero data sequence (FF/00). + * Discard it and loop back to try again. + */ + cinfo->marker->discarded_bytes += 2; + INPUT_SYNC(cinfo); + } + + if (cinfo->marker->discarded_bytes != 0) { + WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c); + cinfo->marker->discarded_bytes = 0; + } + + cinfo->unread_marker = c; + + INPUT_SYNC(cinfo); + return TRUE; + } + + + LOCAL(boolean) + first_marker (j_decompress_ptr cinfo) + /* Like next_marker, but used to obtain the initial SOI marker. */ + /* For this marker, we do not allow preceding garbage or fill; otherwise, + * we might well scan an entire input file before realizing it ain't JPEG. + * If an application wants to process non-JFIF files, it must seek to the + * SOI before calling the JPEG library. + */ + { + int c, c2; + INPUT_VARS(cinfo); + + INPUT_BYTE(cinfo, c, return FALSE); + INPUT_BYTE(cinfo, c2, return FALSE); + if (c != 0xFF || c2 != (int) M_SOI) + ERREXIT2(cinfo, JERR_NO_SOI, c, c2); + + cinfo->unread_marker = c2; + + INPUT_SYNC(cinfo); + return TRUE; + } + + + /* + * Read markers until SOS or EOI. + * + * Returns same codes as are defined for jpeg_consume_input: + * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. + */ + + METHODDEF(int) + read_markers (j_decompress_ptr cinfo) + { + /* Outer loop repeats once for each marker. */ + for (;;) { + /* Collect the marker proper, unless we already did. */ + /* NB: first_marker() enforces the requirement that SOI appear first. */ + if (cinfo->unread_marker == 0) { + if (! cinfo->marker->saw_SOI) { + if (! first_marker(cinfo)) + return JPEG_SUSPENDED; + } else { + if (! next_marker(cinfo)) + return JPEG_SUSPENDED; + } + } + /* At this point cinfo->unread_marker contains the marker code and the + * input point is just past the marker proper, but before any parameters. + * A suspension will cause us to return with this state still true. + */ + switch (cinfo->unread_marker) { + case M_SOI: + if (! get_soi(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_SOF0: /* Baseline */ + case M_SOF1: /* Extended sequential, Huffman */ + if (! get_sof(cinfo, FALSE, FALSE)) + return JPEG_SUSPENDED; + break; + + case M_SOF2: /* Progressive, Huffman */ + if (! get_sof(cinfo, TRUE, FALSE)) + return JPEG_SUSPENDED; + break; + + case M_SOF9: /* Extended sequential, arithmetic */ + if (! get_sof(cinfo, FALSE, TRUE)) + return JPEG_SUSPENDED; + break; + + case M_SOF10: /* Progressive, arithmetic */ + if (! get_sof(cinfo, TRUE, TRUE)) + return JPEG_SUSPENDED; + break; + + /* Currently unsupported SOFn types */ + case M_SOF3: /* Lossless, Huffman */ + case M_SOF5: /* Differential sequential, Huffman */ + case M_SOF6: /* Differential progressive, Huffman */ + case M_SOF7: /* Differential lossless, Huffman */ + case M_JPG: /* Reserved for JPEG extensions */ + case M_SOF11: /* Lossless, arithmetic */ + case M_SOF13: /* Differential sequential, arithmetic */ + case M_SOF14: /* Differential progressive, arithmetic */ + case M_SOF15: /* Differential lossless, arithmetic */ + ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker); + break; + + case M_SOS: + if (! get_sos(cinfo)) + return JPEG_SUSPENDED; + cinfo->unread_marker = 0; /* processed the marker */ + return JPEG_REACHED_SOS; + + case M_EOI: + TRACEMS(cinfo, 1, JTRC_EOI); + cinfo->unread_marker = 0; /* processed the marker */ + return JPEG_REACHED_EOI; + + case M_DAC: + if (! get_dac(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_DHT: + if (! get_dht(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_DQT: + if (! get_dqt(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_DRI: + if (! get_dri(cinfo)) + return JPEG_SUSPENDED; + break; + + case M_APP0: + case M_APP1: + case M_APP2: + case M_APP3: + case M_APP4: + case M_APP5: + case M_APP6: + case M_APP7: + case M_APP8: + case M_APP9: + case M_APP10: + case M_APP11: + case M_APP12: + case M_APP13: + case M_APP14: + case M_APP15: + if (! (*cinfo->marker->process_APPn[cinfo->unread_marker - (int) M_APP0]) (cinfo)) + return JPEG_SUSPENDED; + break; + + case M_COM: + if (! (*cinfo->marker->process_COM) (cinfo)) + return JPEG_SUSPENDED; + break; + + case M_RST0: /* these are all parameterless */ + case M_RST1: + case M_RST2: + case M_RST3: + case M_RST4: + case M_RST5: + case M_RST6: + case M_RST7: + case M_TEM: + TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker); + break; + + case M_DNL: /* Ignore DNL ... perhaps the wrong thing */ + if (! skip_variable(cinfo)) + return JPEG_SUSPENDED; + break; + + default: /* must be DHP, EXP, JPGn, or RESn */ + /* For now, we treat the reserved markers as fatal errors since they are + * likely to be used to signal incompatible JPEG Part 3 extensions. + * Once the JPEG 3 version-number marker is well defined, this code + * ought to change! + */ + ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker); + break; + } + /* Successfully processed marker, so reset state variable */ + cinfo->unread_marker = 0; + } /* end loop */ + } + + + /* + * Read a restart marker, which is expected to appear next in the datastream; + * if the marker is not there, take appropriate recovery action. + * Returns FALSE if suspension is required. + * + * This is called by the entropy decoder after it has read an appropriate + * number of MCUs. cinfo->unread_marker may be nonzero if the entropy decoder + * has already read a marker from the data source. Under normal conditions + * cinfo->unread_marker will be reset to 0 before returning; if not reset, + * it holds a marker which the decoder will be unable to read past. + */ + + METHODDEF(boolean) + read_restart_marker (j_decompress_ptr cinfo) + { + /* Obtain a marker unless we already did. */ + /* Note that next_marker will complain if it skips any data. */ + if (cinfo->unread_marker == 0) { + if (! next_marker(cinfo)) + return FALSE; + } + + if (cinfo->unread_marker == + ((int) M_RST0 + cinfo->marker->next_restart_num)) { + /* Normal case --- swallow the marker and let entropy decoder continue */ + TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num); + cinfo->unread_marker = 0; + } else { + /* Uh-oh, the restart markers have been messed up. */ + /* Let the data source manager determine how to resync. */ + if (! (*cinfo->src->resync_to_restart) (cinfo, + cinfo->marker->next_restart_num)) + return FALSE; + } + + /* Update next-restart state */ + cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7; + + return TRUE; + } + + + /* + * This is the default resync_to_restart method for data source managers + * to use if they don't have any better approach. Some data source managers + * may be able to back up, or may have additional knowledge about the data + * which permits a more intelligent recovery strategy; such managers would + * presumably supply their own resync method. + * + * read_restart_marker calls resync_to_restart if it finds a marker other than + * the restart marker it was expecting. (This code is *not* used unless + * a nonzero restart interval has been declared.) cinfo->unread_marker is + * the marker code actually found (might be anything, except 0 or FF). + * The desired restart marker number (0..7) is passed as a parameter. + * This routine is supposed to apply whatever error recovery strategy seems + * appropriate in order to position the input stream to the next data segment. + * Note that cinfo->unread_marker is treated as a marker appearing before + * the current data-source input point; usually it should be reset to zero + * before returning. + * Returns FALSE if suspension is required. + * + * This implementation is substantially constrained by wanting to treat the + * input as a data stream; this means we can't back up. Therefore, we have + * only the following actions to work with: + * 1. Simply discard the marker and let the entropy decoder resume at next + * byte of file. + * 2. Read forward until we find another marker, discarding intervening + * data. (In theory we could look ahead within the current bufferload, + * without having to discard data if we don't find the desired marker. + * This idea is not implemented here, in part because it makes behavior + * dependent on buffer size and chance buffer-boundary positions.) + * 3. Leave the marker unread (by failing to zero cinfo->unread_marker). + * This will cause the entropy decoder to process an empty data segment, + * inserting dummy zeroes, and then we will reprocess the marker. + * + * #2 is appropriate if we think the desired marker lies ahead, while #3 is + * appropriate if the found marker is a future restart marker (indicating + * that we have missed the desired restart marker, probably because it got + * corrupted). + * We apply #2 or #3 if the found marker is a restart marker no more than + * two counts behind or ahead of the expected one. We also apply #2 if the + * found marker is not a legal JPEG marker code (it's certainly bogus data). + * If the found marker is a restart marker more than 2 counts away, we do #1 + * (too much risk that the marker is erroneous; with luck we will be able to + * resync at some future point). + * For any valid non-restart JPEG marker, we apply #3. This keeps us from + * overrunning the end of a scan. An implementation limited to single-scan + * files might find it better to apply #2 for markers other than EOI, since + * any other marker would have to be bogus data in that case. + */ + + GLOBAL(boolean) + jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired) + { + int marker = cinfo->unread_marker; + int action = 1; + + /* Always put up a warning. */ + WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired); + + /* Outer loop handles repeated decision after scanning forward. */ + for (;;) { + if (marker < (int) M_SOF0) + action = 2; /* invalid marker */ + else if (marker < (int) M_RST0 || marker > (int) M_RST7) + action = 3; /* valid non-restart marker */ + else { + if (marker == ((int) M_RST0 + ((desired+1) & 7)) || + marker == ((int) M_RST0 + ((desired+2) & 7))) + action = 3; /* one of the next two expected restarts */ + else if (marker == ((int) M_RST0 + ((desired-1) & 7)) || + marker == ((int) M_RST0 + ((desired-2) & 7))) + action = 2; /* a prior restart, so advance */ + else + action = 1; /* desired restart or too far away */ + } + TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action); + switch (action) { + case 1: + /* Discard marker and let entropy decoder resume processing. */ + cinfo->unread_marker = 0; + return TRUE; + case 2: + /* Scan to the next marker, and repeat the decision loop. */ + if (! next_marker(cinfo)) + return FALSE; + marker = cinfo->unread_marker; + break; + case 3: + /* Return without advancing past this marker. */ + /* Entropy decoder will be forced to process an empty segment. */ + return TRUE; + } + } /* end loop */ + } + + + /* + * Reset marker processing state to begin a fresh datastream. + */ + + METHODDEF(void) + reset_marker_reader (j_decompress_ptr cinfo) + { + cinfo->comp_info = NULL; /* until allocated by get_sof */ + cinfo->input_scan_number = 0; /* no SOS seen yet */ + cinfo->unread_marker = 0; /* no pending marker */ + cinfo->marker->saw_SOI = FALSE; /* set internal state too */ + cinfo->marker->saw_SOF = FALSE; + cinfo->marker->discarded_bytes = 0; + } + + + /* + * Initialize the marker reader module. + * This is called only once, when the decompression object is created. + */ + + GLOBAL(void) + jinit_marker_reader (j_decompress_ptr cinfo) + { + int i; + + /* Create subobject in permanent pool */ + cinfo->marker = (struct jpeg_marker_reader *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + SIZEOF(struct jpeg_marker_reader)); + /* Initialize method pointers */ + cinfo->marker->reset_marker_reader = reset_marker_reader; + cinfo->marker->read_markers = read_markers; + cinfo->marker->read_restart_marker = read_restart_marker; + cinfo->marker->process_COM = skip_variable; + for (i = 0; i < 16; i++) + cinfo->marker->process_APPn[i] = skip_variable; + cinfo->marker->process_APPn[0] = get_app0; + cinfo->marker->process_APPn[14] = get_app14; + /* Reset marker processing state */ + reset_marker_reader(cinfo); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmaster.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmaster.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmaster.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,555 ---- + /* + * jdmaster.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains master control logic for the JPEG decompressor. + * These routines are concerned with selecting the modules to be executed + * and with determining the number of passes and the work to be done in each + * pass. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Private state */ + + typedef struct { + struct jpeg_decomp_master pub; /* public fields */ + + int pass_number; /* # of passes completed */ + + boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */ + + /* Saved references to initialized quantizer modules, + * in case we need to switch modes. + */ + struct jpeg_color_quantizer * quantizer_1pass; + struct jpeg_color_quantizer * quantizer_2pass; + } my_decomp_master; + + typedef my_decomp_master * my_master_ptr; + + + /* + * Determine whether merged upsample/color conversion should be used. + * CRUCIAL: this must match the actual capabilities of jdmerge.c! + */ + + LOCAL(boolean) + use_merged_upsample (j_decompress_ptr cinfo) + { + #ifdef UPSAMPLE_MERGING_SUPPORTED + /* Merging is the equivalent of plain box-filter upsampling */ + if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling) + return FALSE; + /* jdmerge.c only supports YCC=>RGB color conversion */ + if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 || + cinfo->out_color_space != JCS_RGB || + cinfo->out_color_components != RGB_PIXELSIZE) + return FALSE; + /* and it only handles 2h1v or 2h2v sampling ratios */ + if (cinfo->comp_info[0].h_samp_factor != 2 || + cinfo->comp_info[1].h_samp_factor != 1 || + cinfo->comp_info[2].h_samp_factor != 1 || + cinfo->comp_info[0].v_samp_factor > 2 || + cinfo->comp_info[1].v_samp_factor != 1 || + cinfo->comp_info[2].v_samp_factor != 1) + return FALSE; + /* furthermore, it doesn't work if we've scaled the IDCTs differently */ + if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size || + cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size || + cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size) + return FALSE; + /* ??? also need to test for upsample-time rescaling, when & if supported */ + return TRUE; /* by golly, it'll work... */ + #else + return FALSE; + #endif + } + + + /* + * Compute output image dimensions and related values. + * NOTE: this is exported for possible use by application. + * Hence it mustn't do anything that can't be done twice. + * Also note that it may be called before the master module is initialized! + */ + + GLOBAL(void) + jpeg_calc_output_dimensions (j_decompress_ptr cinfo) + /* Do computations that are needed before master selection phase */ + { + int ci; + jpeg_component_info *compptr; + + /* Prevent application from calling me at wrong times */ + if (cinfo->global_state != DSTATE_READY) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + #ifdef IDCT_SCALING_SUPPORTED + + /* Compute actual output image dimensions and DCT scaling choices. */ + if (cinfo->scale_num * 8 <= cinfo->scale_denom) { + /* Provide 1/8 scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width, 8L); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, 8L); + cinfo->min_DCT_scaled_size = 1; + } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) { + /* Provide 1/4 scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width, 4L); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, 4L); + cinfo->min_DCT_scaled_size = 2; + } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) { + /* Provide 1/2 scaling */ + cinfo->output_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width, 2L); + cinfo->output_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height, 2L); + cinfo->min_DCT_scaled_size = 4; + } else { + /* Provide 1/1 scaling */ + cinfo->output_width = cinfo->image_width; + cinfo->output_height = cinfo->image_height; + cinfo->min_DCT_scaled_size = DCTSIZE; + } + /* In selecting the actual DCT scaling for each component, we try to + * scale up the chroma components via IDCT scaling rather than upsampling. + * This saves time if the upsampler gets to use 1:1 scaling. + * Note this code assumes that the supported DCT scalings are powers of 2. + */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + int ssize = cinfo->min_DCT_scaled_size; + while (ssize < DCTSIZE && + (compptr->h_samp_factor * ssize * 2 <= + cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) && + (compptr->v_samp_factor * ssize * 2 <= + cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) { + ssize = ssize * 2; + } + compptr->DCT_scaled_size = ssize; + } + + /* Recompute downsampled dimensions of components; + * application needs to know these if using raw downsampled data. + */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Size in samples, after IDCT scaling */ + compptr->downsampled_width = (JDIMENSION) + jdiv_round_up((long) cinfo->image_width * + (long) (compptr->h_samp_factor * compptr->DCT_scaled_size), + (long) (cinfo->max_h_samp_factor * DCTSIZE)); + compptr->downsampled_height = (JDIMENSION) + jdiv_round_up((long) cinfo->image_height * + (long) (compptr->v_samp_factor * compptr->DCT_scaled_size), + (long) (cinfo->max_v_samp_factor * DCTSIZE)); + } + + #else /* !IDCT_SCALING_SUPPORTED */ + + /* Hardwire it to "no scaling" */ + cinfo->output_width = cinfo->image_width; + cinfo->output_height = cinfo->image_height; + /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE, + * and has computed unscaled downsampled_width and downsampled_height. + */ + + #endif /* IDCT_SCALING_SUPPORTED */ + + /* Report number of components in selected colorspace. */ + /* Probably this should be in the color conversion module... */ + switch (cinfo->out_color_space) { + case JCS_GRAYSCALE: + cinfo->out_color_components = 1; + break; + case JCS_RGB: + #if RGB_PIXELSIZE != 3 + cinfo->out_color_components = RGB_PIXELSIZE; + break; + #endif /* else share code with YCbCr */ + case JCS_YCbCr: + cinfo->out_color_components = 3; + break; + case JCS_CMYK: + case JCS_YCCK: + cinfo->out_color_components = 4; + break; + default: /* else must be same colorspace as in file */ + cinfo->out_color_components = cinfo->num_components; + break; + } + cinfo->output_components = (cinfo->quantize_colors ? 1 : + cinfo->out_color_components); + + /* See if upsampler will want to emit more than one row at a time */ + if (use_merged_upsample(cinfo)) + cinfo->rec_outbuf_height = cinfo->max_v_samp_factor; + else + cinfo->rec_outbuf_height = 1; + } + + + /* + * Several decompression processes need to range-limit values to the range + * 0..MAXJSAMPLE; the input value may fall somewhat outside this range + * due to noise introduced by quantization, roundoff error, etc. These + * processes are inner loops and need to be as fast as possible. On most + * machines, particularly CPUs with pipelines or instruction prefetch, + * a (subscript-check-less) C table lookup + * x = sample_range_limit[x]; + * is faster than explicit tests + * if (x < 0) x = 0; + * else if (x > MAXJSAMPLE) x = MAXJSAMPLE; + * These processes all use a common table prepared by the routine below. + * + * For most steps we can mathematically guarantee that the initial value + * of x is within MAXJSAMPLE+1 of the legal range, so a table running from + * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial + * limiting step (just after the IDCT), a wildly out-of-range value is + * possible if the input data is corrupt. To avoid any chance of indexing + * off the end of memory and getting a bad-pointer trap, we perform the + * post-IDCT limiting thus: + * x = range_limit[x & MASK]; + * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit + * samples. Under normal circumstances this is more than enough range and + * a correct output will be generated; with bogus input data the mask will + * cause wraparound, and we will safely generate a bogus-but-in-range output. + * For the post-IDCT step, we want to convert the data from signed to unsigned + * representation by adding CENTERJSAMPLE at the same time that we limit it. + * So the post-IDCT limiting table ends up looking like this: + * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE, + * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), + * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), + * 0,1,...,CENTERJSAMPLE-1 + * Negative inputs select values from the upper half of the table after + * masking. + * + * We can save some space by overlapping the start of the post-IDCT table + * with the simpler range limiting table. The post-IDCT table begins at + * sample_range_limit + CENTERJSAMPLE. + * + * Note that the table is allocated in near data space on PCs; it's small + * enough and used often enough to justify this. + */ + + LOCAL(void) + prepare_range_limit_table (j_decompress_ptr cinfo) + /* Allocate and fill in the sample_range_limit table */ + { + JSAMPLE * table; + int i; + + table = (JSAMPLE *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE)); + table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */ + cinfo->sample_range_limit = table; + /* First segment of "simple" table: limit[x] = 0 for x < 0 */ + MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE)); + /* Main part of "simple" table: limit[x] = x */ + for (i = 0; i <= MAXJSAMPLE; i++) + table[i] = (JSAMPLE) i; + table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ + /* End of simple table, rest of first half of post-IDCT table */ + for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) + table[i] = MAXJSAMPLE; + /* Second half of post-IDCT table */ + MEMZERO(table + (2 * (MAXJSAMPLE+1)), + (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE)); + MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), + cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE)); + } + + + /* + * Master selection of decompression modules. + * This is done once at jpeg_start_decompress time. We determine + * which modules will be used and give them appropriate initialization calls. + * We also initialize the decompressor input side to begin consuming data. + * + * Since jpeg_read_header has finished, we know what is in the SOF + * and (first) SOS markers. We also have all the application parameter + * settings. + */ + + LOCAL(void) + master_selection (j_decompress_ptr cinfo) + { + my_master_ptr master = (my_master_ptr) cinfo->master; + boolean use_c_buffer; + long samplesperrow; + JDIMENSION jd_samplesperrow; + + /* Initialize dimensions and other stuff */ + jpeg_calc_output_dimensions(cinfo); + prepare_range_limit_table(cinfo); + + /* Width of an output scanline must be representable as JDIMENSION. */ + samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components; + jd_samplesperrow = (JDIMENSION) samplesperrow; + if ((long) jd_samplesperrow != samplesperrow) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + + /* Initialize my private state */ + master->pass_number = 0; + master->using_merged_upsample = use_merged_upsample(cinfo); + + /* Color quantizer selection */ + master->quantizer_1pass = NULL; + master->quantizer_2pass = NULL; + /* No mode changes if not using buffered-image mode. */ + if (! cinfo->quantize_colors || ! cinfo->buffered_image) { + cinfo->enable_1pass_quant = FALSE; + cinfo->enable_external_quant = FALSE; + cinfo->enable_2pass_quant = FALSE; + } + if (cinfo->quantize_colors) { + if (cinfo->raw_data_out) + ERREXIT(cinfo, JERR_NOTIMPL); + /* 2-pass quantizer only works in 3-component color space. */ + if (cinfo->out_color_components != 3) { + cinfo->enable_1pass_quant = TRUE; + cinfo->enable_external_quant = FALSE; + cinfo->enable_2pass_quant = FALSE; + cinfo->colormap = NULL; + } else if (cinfo->colormap != NULL) { + cinfo->enable_external_quant = TRUE; + } else if (cinfo->two_pass_quantize) { + cinfo->enable_2pass_quant = TRUE; + } else { + cinfo->enable_1pass_quant = TRUE; + } + + if (cinfo->enable_1pass_quant) { + #ifdef QUANT_1PASS_SUPPORTED + jinit_1pass_quantizer(cinfo); + master->quantizer_1pass = cinfo->cquantize; + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } + + /* We use the 2-pass code to map to external colormaps. */ + if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) { + #ifdef QUANT_2PASS_SUPPORTED + jinit_2pass_quantizer(cinfo); + master->quantizer_2pass = cinfo->cquantize; + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } + /* If both quantizers are initialized, the 2-pass one is left active; + * this is necessary for starting with quantization to an external map. + */ + } + + /* Post-processing: in particular, color conversion first */ + if (! cinfo->raw_data_out) { + if (master->using_merged_upsample) { + #ifdef UPSAMPLE_MERGING_SUPPORTED + jinit_merged_upsampler(cinfo); /* does color conversion too */ + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else { + jinit_color_deconverter(cinfo); + jinit_upsampler(cinfo); + } + jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); + } + /* Inverse DCT */ + jinit_inverse_dct(cinfo); + /* Entropy decoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); + } else { + if (cinfo->progressive_mode) { + #ifdef D_PROGRESSIVE_SUPPORTED + jinit_phuff_decoder(cinfo); + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else + jinit_huff_decoder(cinfo); + } + + /* Initialize principal buffer controllers. */ + use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image; + jinit_d_coef_controller(cinfo, use_c_buffer); + + if (! cinfo->raw_data_out) + jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Initialize input side of decompressor to consume first scan. */ + (*cinfo->inputctl->start_input_pass) (cinfo); + + #ifdef D_MULTISCAN_FILES_SUPPORTED + /* If jpeg_start_decompress will read the whole file, initialize + * progress monitoring appropriately. The input step is counted + * as one pass. + */ + if (cinfo->progress != NULL && ! cinfo->buffered_image && + cinfo->inputctl->has_multiple_scans) { + int nscans; + /* Estimate number of scans to set pass_limit. */ + if (cinfo->progressive_mode) { + /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ + nscans = 2 + 3 * cinfo->num_components; + } else { + /* For a nonprogressive multiscan file, estimate 1 scan per component. */ + nscans = cinfo->num_components; + } + cinfo->progress->pass_counter = 0L; + cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; + cinfo->progress->completed_passes = 0; + cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2); + /* Count the input pass as done */ + master->pass_number++; + } + #endif /* D_MULTISCAN_FILES_SUPPORTED */ + } + + + /* + * Per-pass setup. + * This is called at the beginning of each output pass. We determine which + * modules will be active during this pass and give them appropriate + * start_pass calls. We also set is_dummy_pass to indicate whether this + * is a "real" output pass or a dummy pass for color quantization. + * (In the latter case, jdapi.c will crank the pass to completion.) + */ + + METHODDEF(void) + prepare_for_output_pass (j_decompress_ptr cinfo) + { + my_master_ptr master = (my_master_ptr) cinfo->master; + + if (master->pub.is_dummy_pass) { + #ifdef QUANT_2PASS_SUPPORTED + /* Final pass of 2-pass quantization */ + master->pub.is_dummy_pass = FALSE; + (*cinfo->cquantize->start_pass) (cinfo, FALSE); + (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST); + (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST); + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif /* QUANT_2PASS_SUPPORTED */ + } else { + if (cinfo->quantize_colors && cinfo->colormap == NULL) { + /* Select new quantization method */ + if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) { + cinfo->cquantize = master->quantizer_2pass; + master->pub.is_dummy_pass = TRUE; + } else if (cinfo->enable_1pass_quant) { + cinfo->cquantize = master->quantizer_1pass; + } else { + ERREXIT(cinfo, JERR_MODE_CHANGE); + } + } + (*cinfo->idct->start_pass) (cinfo); + (*cinfo->coef->start_output_pass) (cinfo); + if (! cinfo->raw_data_out) { + if (! master->using_merged_upsample) + (*cinfo->cconvert->start_pass) (cinfo); + (*cinfo->upsample->start_pass) (cinfo); + if (cinfo->quantize_colors) + (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass); + (*cinfo->post->start_pass) (cinfo, + (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); + (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); + } + } + + /* Set up progress monitor's pass info if present */ + if (cinfo->progress != NULL) { + cinfo->progress->completed_passes = master->pass_number; + cinfo->progress->total_passes = master->pass_number + + (master->pub.is_dummy_pass ? 2 : 1); + /* In buffered-image mode, we assume one more output pass if EOI not + * yet reached, but no more passes if EOI has been reached. + */ + if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) { + cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1); + } + } + } + + + /* + * Finish up at end of an output pass. + */ + + METHODDEF(void) + finish_output_pass (j_decompress_ptr cinfo) + { + my_master_ptr master = (my_master_ptr) cinfo->master; + + if (cinfo->quantize_colors) + (*cinfo->cquantize->finish_pass) (cinfo); + master->pass_number++; + } + + + #ifdef D_MULTISCAN_FILES_SUPPORTED + + /* + * Switch to a new external colormap between output passes. + */ + + GLOBAL(void) + jpeg_new_colormap (j_decompress_ptr cinfo) + { + my_master_ptr master = (my_master_ptr) cinfo->master; + + /* Prevent application from calling me at wrong times */ + if (cinfo->global_state != DSTATE_BUFIMAGE) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + + if (cinfo->quantize_colors && cinfo->enable_external_quant && + cinfo->colormap != NULL) { + /* Select 2-pass quantizer for external colormap use */ + cinfo->cquantize = master->quantizer_2pass; + /* Notify quantizer of colormap change */ + (*cinfo->cquantize->new_color_map) (cinfo); + master->pub.is_dummy_pass = FALSE; /* just in case */ + } else + ERREXIT(cinfo, JERR_MODE_CHANGE); + } + + #endif /* D_MULTISCAN_FILES_SUPPORTED */ + + + /* + * Initialize master decompression control and select active modules. + * This is performed at the start of jpeg_start_decompress. + */ + + GLOBAL(void) + jinit_master_decompress (j_decompress_ptr cinfo) + { + my_master_ptr master; + + master = (my_master_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_decomp_master)); + cinfo->master = (struct jpeg_decomp_master *) master; + master->pub.prepare_for_output_pass = prepare_for_output_pass; + master->pub.finish_output_pass = finish_output_pass; + + master->pub.is_dummy_pass = FALSE; + + master_selection(cinfo); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmerge.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmerge.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdmerge.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,400 ---- + /* + * jdmerge.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains code for merged upsampling/color conversion. + * + * This file combines functions from jdsample.c and jdcolor.c; + * read those files first to understand what's going on. + * + * When the chroma components are to be upsampled by simple replication + * (ie, box filtering), we can save some work in color conversion by + * calculating all the output pixels corresponding to a pair of chroma + * samples at one time. In the conversion equations + * R = Y + K1 * Cr + * G = Y + K2 * Cb + K3 * Cr + * B = Y + K4 * Cb + * only the Y term varies among the group of pixels corresponding to a pair + * of chroma samples, so the rest of the terms can be calculated just once. + * At typical sampling ratios, this eliminates half or three-quarters of the + * multiplications needed for color conversion. + * + * This file currently provides implementations for the following cases: + * YCbCr => RGB color conversion only. + * Sampling ratios of 2h1v or 2h2v. + * No scaling needed at upsample time. + * Corner-aligned (non-CCIR601) sampling alignment. + * Other special cases could be added, but in most applications these are + * the only common cases. (For uncommon cases we fall back on the more + * general code in jdsample.c and jdcolor.c.) + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + #ifdef UPSAMPLE_MERGING_SUPPORTED + + + /* Private subobject */ + + typedef struct { + struct jpeg_upsampler pub; /* public fields */ + + /* Pointer to routine to do actual upsampling/conversion of one row group */ + JMETHOD(void, upmethod, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf)); + + /* Private state for YCC->RGB conversion */ + int * Cr_r_tab; /* => table for Cr to R conversion */ + int * Cb_b_tab; /* => table for Cb to B conversion */ + INT32 * Cr_g_tab; /* => table for Cr to G conversion */ + INT32 * Cb_g_tab; /* => table for Cb to G conversion */ + + /* For 2:1 vertical sampling, we produce two output rows at a time. + * We need a "spare" row buffer to hold the second output row if the + * application provides just a one-row buffer; we also use the spare + * to discard the dummy last row if the image height is odd. + */ + JSAMPROW spare_row; + boolean spare_full; /* T if spare buffer is occupied */ + + JDIMENSION out_row_width; /* samples per output row */ + JDIMENSION rows_to_go; /* counts rows remaining in image */ + } my_upsampler; + + typedef my_upsampler * my_upsample_ptr; + + #define SCALEBITS 16 /* speediest right-shift on some machines */ + #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) + #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) + + + /* + * Initialize tables for YCC->RGB colorspace conversion. + * This is taken directly from jdcolor.c; see that file for more info. + */ + + LOCAL(void) + build_ycc_rgb_table (j_decompress_ptr cinfo) + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + int i; + INT32 x; + SHIFT_TEMPS + + upsample->Cr_r_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + upsample->Cb_b_tab = (int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(int)); + upsample->Cr_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + upsample->Cb_g_tab = (INT32 *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (MAXJSAMPLE+1) * SIZEOF(INT32)); + + for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { + /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ + /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ + /* Cr=>R value is nearest int to 1.40200 * x */ + upsample->Cr_r_tab[i] = (int) + RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); + /* Cb=>B value is nearest int to 1.77200 * x */ + upsample->Cb_b_tab[i] = (int) + RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); + /* Cr=>G value is scaled-up -0.71414 * x */ + upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x; + /* Cb=>G value is scaled-up -0.34414 * x */ + /* We also add in ONE_HALF so that need not do it in inner loop */ + upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; + } + } + + + /* + * Initialize for an upsampling pass. + */ + + METHODDEF(void) + start_pass_merged_upsample (j_decompress_ptr cinfo) + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + + /* Mark the spare buffer empty */ + upsample->spare_full = FALSE; + /* Initialize total-height counter for detecting bottom of image */ + upsample->rows_to_go = cinfo->output_height; + } + + + /* + * Control routine to do upsampling (and color conversion). + * + * The control routine just handles the row buffering considerations. + */ + + METHODDEF(void) + merged_2v_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + /* 2:1 vertical sampling case: may need a spare row. */ + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + JSAMPROW work_ptrs[2]; + JDIMENSION num_rows; /* number of rows returned to caller */ + + if (upsample->spare_full) { + /* If we have a spare row saved from a previous cycle, just return it. */ + jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0, + 1, upsample->out_row_width); + num_rows = 1; + upsample->spare_full = FALSE; + } else { + /* Figure number of rows to return to caller. */ + num_rows = 2; + /* Not more than the distance to the end of the image. */ + if (num_rows > upsample->rows_to_go) + num_rows = upsample->rows_to_go; + /* And not more than what the client can accept: */ + out_rows_avail -= *out_row_ctr; + if (num_rows > out_rows_avail) + num_rows = out_rows_avail; + /* Create output pointer array for upsampler. */ + work_ptrs[0] = output_buf[*out_row_ctr]; + if (num_rows > 1) { + work_ptrs[1] = output_buf[*out_row_ctr + 1]; + } else { + work_ptrs[1] = upsample->spare_row; + upsample->spare_full = TRUE; + } + /* Now do the upsampling. */ + (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs); + } + + /* Adjust counts */ + *out_row_ctr += num_rows; + upsample->rows_to_go -= num_rows; + /* When the buffer is emptied, declare this input row group consumed */ + if (! upsample->spare_full) + (*in_row_group_ctr)++; + } + + + METHODDEF(void) + merged_1v_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + /* 1:1 vertical sampling case: much easier, never need a spare row. */ + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + + /* Just do the upsampling. */ + (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, + output_buf + *out_row_ctr); + /* Adjust counts */ + (*out_row_ctr)++; + (*in_row_group_ctr)++; + } + + + /* + * These are the routines invoked by the control routines to do + * the actual upsampling/conversion. One row group is processed per call. + * + * Note: since we may be writing directly into application-supplied buffers, + * we have to be honest about the output width; we can't assume the buffer + * has been rounded up to an even width. + */ + + + /* + * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. + */ + + METHODDEF(void) + h2v1_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + register int y, cred, cgreen, cblue; + int cb, cr; + register JSAMPROW outptr; + JSAMPROW inptr0, inptr1, inptr2; + JDIMENSION col; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + int * Crrtab = upsample->Cr_r_tab; + int * Cbbtab = upsample->Cb_b_tab; + INT32 * Crgtab = upsample->Cr_g_tab; + INT32 * Cbgtab = upsample->Cb_g_tab; + SHIFT_TEMPS + + inptr0 = input_buf[0][in_row_group_ctr]; + inptr1 = input_buf[1][in_row_group_ctr]; + inptr2 = input_buf[2][in_row_group_ctr]; + outptr = output_buf[0]; + /* Loop for each pair of output pixels */ + for (col = cinfo->output_width >> 1; col > 0; col--) { + /* Do the chroma part of the calculation */ + cb = GETJSAMPLE(*inptr1++); + cr = GETJSAMPLE(*inptr2++); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + /* Fetch 2 Y values and emit 2 pixels */ + y = GETJSAMPLE(*inptr0++); + outptr[RGB_RED] = range_limit[y + cred]; + outptr[RGB_GREEN] = range_limit[y + cgreen]; + outptr[RGB_BLUE] = range_limit[y + cblue]; + outptr += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr0++); + outptr[RGB_RED] = range_limit[y + cred]; + outptr[RGB_GREEN] = range_limit[y + cgreen]; + outptr[RGB_BLUE] = range_limit[y + cblue]; + outptr += RGB_PIXELSIZE; + } + /* If image width is odd, do the last output column separately */ + if (cinfo->output_width & 1) { + cb = GETJSAMPLE(*inptr1); + cr = GETJSAMPLE(*inptr2); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + y = GETJSAMPLE(*inptr0); + outptr[RGB_RED] = range_limit[y + cred]; + outptr[RGB_GREEN] = range_limit[y + cgreen]; + outptr[RGB_BLUE] = range_limit[y + cblue]; + } + } + + + /* + * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. + */ + + METHODDEF(void) + h2v2_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + register int y, cred, cgreen, cblue; + int cb, cr; + register JSAMPROW outptr0, outptr1; + JSAMPROW inptr00, inptr01, inptr1, inptr2; + JDIMENSION col; + /* copy these pointers into registers if possible */ + register JSAMPLE * range_limit = cinfo->sample_range_limit; + int * Crrtab = upsample->Cr_r_tab; + int * Cbbtab = upsample->Cb_b_tab; + INT32 * Crgtab = upsample->Cr_g_tab; + INT32 * Cbgtab = upsample->Cb_g_tab; + SHIFT_TEMPS + + inptr00 = input_buf[0][in_row_group_ctr*2]; + inptr01 = input_buf[0][in_row_group_ctr*2 + 1]; + inptr1 = input_buf[1][in_row_group_ctr]; + inptr2 = input_buf[2][in_row_group_ctr]; + outptr0 = output_buf[0]; + outptr1 = output_buf[1]; + /* Loop for each group of output pixels */ + for (col = cinfo->output_width >> 1; col > 0; col--) { + /* Do the chroma part of the calculation */ + cb = GETJSAMPLE(*inptr1++); + cr = GETJSAMPLE(*inptr2++); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + /* Fetch 4 Y values and emit 4 pixels */ + y = GETJSAMPLE(*inptr00++); + outptr0[RGB_RED] = range_limit[y + cred]; + outptr0[RGB_GREEN] = range_limit[y + cgreen]; + outptr0[RGB_BLUE] = range_limit[y + cblue]; + outptr0 += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr00++); + outptr0[RGB_RED] = range_limit[y + cred]; + outptr0[RGB_GREEN] = range_limit[y + cgreen]; + outptr0[RGB_BLUE] = range_limit[y + cblue]; + outptr0 += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr01++); + outptr1[RGB_RED] = range_limit[y + cred]; + outptr1[RGB_GREEN] = range_limit[y + cgreen]; + outptr1[RGB_BLUE] = range_limit[y + cblue]; + outptr1 += RGB_PIXELSIZE; + y = GETJSAMPLE(*inptr01++); + outptr1[RGB_RED] = range_limit[y + cred]; + outptr1[RGB_GREEN] = range_limit[y + cgreen]; + outptr1[RGB_BLUE] = range_limit[y + cblue]; + outptr1 += RGB_PIXELSIZE; + } + /* If image width is odd, do the last output column separately */ + if (cinfo->output_width & 1) { + cb = GETJSAMPLE(*inptr1); + cr = GETJSAMPLE(*inptr2); + cred = Crrtab[cr]; + cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS); + cblue = Cbbtab[cb]; + y = GETJSAMPLE(*inptr00); + outptr0[RGB_RED] = range_limit[y + cred]; + outptr0[RGB_GREEN] = range_limit[y + cgreen]; + outptr0[RGB_BLUE] = range_limit[y + cblue]; + y = GETJSAMPLE(*inptr01); + outptr1[RGB_RED] = range_limit[y + cred]; + outptr1[RGB_GREEN] = range_limit[y + cgreen]; + outptr1[RGB_BLUE] = range_limit[y + cblue]; + } + } + + + /* + * Module initialization routine for merged upsampling/color conversion. + * + * NB: this is called under the conditions determined by use_merged_upsample() + * in jdmaster.c. That routine MUST correspond to the actual capabilities + * of this module; no safety checks are made here. + */ + + GLOBAL(void) + jinit_merged_upsampler (j_decompress_ptr cinfo) + { + my_upsample_ptr upsample; + + upsample = (my_upsample_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_upsampler)); + cinfo->upsample = (struct jpeg_upsampler *) upsample; + upsample->pub.start_pass = start_pass_merged_upsample; + upsample->pub.need_context_rows = FALSE; + + upsample->out_row_width = cinfo->output_width * cinfo->out_color_components; + + if (cinfo->max_v_samp_factor == 2) { + upsample->pub.upsample = merged_2v_upsample; + upsample->upmethod = h2v2_merged_upsample; + /* Allocate a spare row buffer */ + upsample->spare_row = (JSAMPROW) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE))); + } else { + upsample->pub.upsample = merged_1v_upsample; + upsample->upmethod = h2v1_merged_upsample; + /* No spare row needed */ + upsample->spare_row = NULL; + } + + build_ycc_rgb_table(cinfo); + } + + #endif /* UPSAMPLE_MERGING_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdphuff.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdphuff.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdphuff.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,642 ---- + /* + * jdphuff.c + * + * Copyright (C) 1995-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains Huffman entropy decoding routines for progressive JPEG. + * + * Much of the complexity here has to do with supporting input suspension. + * If the data source module demands suspension, we want to be able to back + * up to the start of the current MCU. To do this, we copy state variables + * into local working storage, and update them back to the permanent + * storage only upon successful completion of an MCU. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdhuff.h" /* Declarations shared with jdhuff.c */ + + + #ifdef D_PROGRESSIVE_SUPPORTED + + /* + * Expanded entropy decoder object for progressive Huffman decoding. + * + * The savable_state subrecord contains fields that change within an MCU, + * but must not be updated permanently until we complete the MCU. + */ + + typedef struct { + unsigned int EOBRUN; /* remaining EOBs in EOBRUN */ + int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ + } savable_state; + + /* This macro is to work around compilers with missing or broken + * structure assignment. You'll need to fix this code if you have + * such a compiler and you change MAX_COMPS_IN_SCAN. + */ + + #ifndef NO_STRUCT_ASSIGN + #define ASSIGN_STATE(dest,src) ((dest) = (src)) + #else + #if MAX_COMPS_IN_SCAN == 4 + #define ASSIGN_STATE(dest,src) \ + ((dest).EOBRUN = (src).EOBRUN, \ + (dest).last_dc_val[0] = (src).last_dc_val[0], \ + (dest).last_dc_val[1] = (src).last_dc_val[1], \ + (dest).last_dc_val[2] = (src).last_dc_val[2], \ + (dest).last_dc_val[3] = (src).last_dc_val[3]) + #endif + #endif + + + typedef struct { + struct jpeg_entropy_decoder pub; /* public fields */ + + /* These fields are loaded into local variables at start of each MCU. + * In case of suspension, we exit WITHOUT updating them. + */ + bitread_perm_state bitstate; /* Bit buffer at start of MCU */ + savable_state saved; /* Other state at start of MCU */ + + /* These fields are NOT loaded into local working state. */ + unsigned int restarts_to_go; /* MCUs left in this restart interval */ + + /* Pointers to derived tables (these workspaces have image lifespan) */ + d_derived_tbl * derived_tbls[NUM_HUFF_TBLS]; + + d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */ + } phuff_entropy_decoder; + + typedef phuff_entropy_decoder * phuff_entropy_ptr; + + /* Forward declarations */ + METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); + METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); + + + /* + * Initialize for a Huffman-compressed scan. + */ + + METHODDEF(void) + start_pass_phuff_decoder (j_decompress_ptr cinfo) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + boolean is_DC_band, bad; + int ci, coefi, tbl; + int *coef_bit_ptr; + jpeg_component_info * compptr; + + is_DC_band = (cinfo->Ss == 0); + + /* Validate scan parameters */ + bad = FALSE; + if (is_DC_band) { + if (cinfo->Se != 0) + bad = TRUE; + } else { + /* need not check Ss/Se < 0 since they came from unsigned bytes */ + if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2) + bad = TRUE; + /* AC scans may have only one component */ + if (cinfo->comps_in_scan != 1) + bad = TRUE; + } + if (cinfo->Ah != 0) { + /* Successive approximation refinement scan: must have Al = Ah-1. */ + if (cinfo->Al != cinfo->Ah-1) + bad = TRUE; + } + if (cinfo->Al > 13) /* need not check for < 0 */ + bad = TRUE; + if (bad) + ERREXIT4(cinfo, JERR_BAD_PROGRESSION, + cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); + /* Update progression status, and verify that scan order is legal. + * Note that inter-scan inconsistencies are treated as warnings + * not fatal errors ... not clear if this is right way to behave. + */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + int cindex = cinfo->cur_comp_info[ci]->component_index; + coef_bit_ptr = & cinfo->coef_bits[cindex][0]; + if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ + WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); + for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { + int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; + if (cinfo->Ah != expected) + WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); + coef_bit_ptr[coefi] = cinfo->Al; + } + } + + /* Select MCU decoding routine */ + if (cinfo->Ah == 0) { + if (is_DC_band) + entropy->pub.decode_mcu = decode_mcu_DC_first; + else + entropy->pub.decode_mcu = decode_mcu_AC_first; + } else { + if (is_DC_band) + entropy->pub.decode_mcu = decode_mcu_DC_refine; + else + entropy->pub.decode_mcu = decode_mcu_AC_refine; + } + + for (ci = 0; ci < cinfo->comps_in_scan; ci++) { + compptr = cinfo->cur_comp_info[ci]; + /* Make sure requested tables are present, and compute derived tables. + * We may build same derived table more than once, but it's not expensive. + */ + if (is_DC_band) { + if (cinfo->Ah == 0) { /* DC refinement needs no table */ + tbl = compptr->dc_tbl_no; + if (tbl < 0 || tbl >= NUM_HUFF_TBLS || + cinfo->dc_huff_tbl_ptrs[tbl] == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl); + jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[tbl], + & entropy->derived_tbls[tbl]); + } + } else { + tbl = compptr->ac_tbl_no; + if (tbl < 0 || tbl >= NUM_HUFF_TBLS || + cinfo->ac_huff_tbl_ptrs[tbl] == NULL) + ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl); + jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[tbl], + & entropy->derived_tbls[tbl]); + /* remember the single active table */ + entropy->ac_derived_tbl = entropy->derived_tbls[tbl]; + } + /* Initialize DC predictions to 0 */ + entropy->saved.last_dc_val[ci] = 0; + } + + /* Initialize bitread state variables */ + entropy->bitstate.bits_left = 0; + entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ + entropy->bitstate.printed_eod = FALSE; + + /* Initialize private state variables */ + entropy->saved.EOBRUN = 0; + + /* Initialize restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; + } + + + /* + * Figure F.12: extend sign bit. + * On some machines, a shift and add will be faster than a table lookup. + */ + + #ifdef AVOID_TABLES + + #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) + + #else + + #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) + + static const int extend_test[16] = /* entry n is 2**(n-1) */ + { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; + + static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ + { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, + ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, + ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, + ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }; + + #endif /* AVOID_TABLES */ + + + /* + * Check for a restart marker & resynchronize decoder. + * Returns FALSE if must suspend. + */ + + LOCAL(boolean) + process_restart (j_decompress_ptr cinfo) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int ci; + + /* Throw away any unused bits remaining in bit buffer; */ + /* include any full bytes in next_marker's count of discarded bytes */ + cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; + entropy->bitstate.bits_left = 0; + + /* Advance past the RSTn marker */ + if (! (*cinfo->marker->read_restart_marker) (cinfo)) + return FALSE; + + /* Re-initialize DC predictions to 0 */ + for (ci = 0; ci < cinfo->comps_in_scan; ci++) + entropy->saved.last_dc_val[ci] = 0; + /* Re-init EOB run count, too */ + entropy->saved.EOBRUN = 0; + + /* Reset restart counter */ + entropy->restarts_to_go = cinfo->restart_interval; + + /* Next segment can get another out-of-data warning */ + entropy->bitstate.printed_eod = FALSE; + + return TRUE; + } + + + /* + * Huffman MCU decoding. + * Each of these routines decodes and returns one MCU's worth of + * Huffman-compressed coefficients. + * The coefficients are reordered from zigzag order into natural array order, + * but are not dequantized. + * + * The i'th block of the MCU is stored into the block pointed to by + * MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER. + * + * We return FALSE if data source requested suspension. In that case no + * changes have been made to permanent state. (Exception: some output + * coefficients may already have been assigned. This is harmless for + * spectral selection, since we'll just re-assign them on the next call. + * Successive approximation AC refinement has to be more careful, however.) + */ + + /* + * MCU decoding for DC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + + METHODDEF(boolean) + decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int Al = cinfo->Al; + register int s, r; + int blkn, ci; + JBLOCKROW block; + BITREAD_STATE_VARS; + savable_state state; + d_derived_tbl * tbl; + jpeg_component_info * compptr; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(state, entropy->saved); + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + ci = cinfo->MCU_membership[blkn]; + compptr = cinfo->cur_comp_info[ci]; + tbl = entropy->derived_tbls[compptr->dc_tbl_no]; + + /* Decode a single block's worth of coefficients */ + + /* Section F.2.2.1: decode the DC coefficient difference */ + HUFF_DECODE(s, br_state, tbl, return FALSE, label1); + if (s) { + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + } + + /* Convert DC difference to actual value, update last_dc_val */ + s += state.last_dc_val[ci]; + state.last_dc_val[ci] = s; + /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */ + (*block)[0] = (JCOEF) (s << Al); + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + ASSIGN_STATE(entropy->saved, state); + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; + } + + + /* + * MCU decoding for AC initial scan (either spectral selection, + * or first pass of successive approximation). + */ + + METHODDEF(boolean) + decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int Se = cinfo->Se; + int Al = cinfo->Al; + register int s, k, r; + unsigned int EOBRUN; + JBLOCKROW block; + BITREAD_STATE_VARS; + d_derived_tbl * tbl; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* Load up working state. + * We can avoid loading/saving bitread state if in an EOB run. + */ + EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we care about */ + + /* There is always only one block per MCU */ + + if (EOBRUN > 0) /* if it's a band of zeroes... */ + EOBRUN--; /* ...process it now (we do nothing) */ + else { + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + block = MCU_data[0]; + tbl = entropy->ac_derived_tbl; + + for (k = cinfo->Ss; k <= Se; k++) { + HUFF_DECODE(s, br_state, tbl, return FALSE, label2); + r = s >> 4; + s &= 15; + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + /* Scale and output coefficient in natural (dezigzagged) order */ + (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al); + } else { + if (r == 15) { /* ZRL */ + k += 15; /* skip 15 zeroes in band */ + } else { /* EOBr, run length is 2^r + appended bits */ + EOBRUN = 1 << r; + if (r) { /* EOBr, r > 0 */ + CHECK_BIT_BUFFER(br_state, r, return FALSE); + r = GET_BITS(r); + EOBRUN += r; + } + EOBRUN--; /* this band is processed at this moment */ + break; /* force end-of-band */ + } + } + } + + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + } + + /* Completed MCU, so update state */ + entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we care about */ + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; + } + + + /* + * MCU decoding for DC successive approximation refinement scan. + * Note: we assume such scans can be multi-component, although the spec + * is not very clear on the point. + */ + + METHODDEF(boolean) + decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ + int blkn; + JBLOCKROW block; + BITREAD_STATE_VARS; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + + /* Outer loop handles each block in the MCU */ + + for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { + block = MCU_data[blkn]; + + /* Encoded data is simply the next bit of the two's-complement DC value */ + CHECK_BIT_BUFFER(br_state, 1, return FALSE); + if (GET_BITS(1)) + (*block)[0] |= p1; + /* Note: since we use |=, repeating the assignment later is safe */ + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; + } + + + /* + * MCU decoding for AC successive approximation refinement scan. + */ + + METHODDEF(boolean) + decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) + { + phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; + int Se = cinfo->Se; + int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ + int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ + register int s, k, r; + unsigned int EOBRUN; + JBLOCKROW block; + JCOEFPTR thiscoef; + BITREAD_STATE_VARS; + d_derived_tbl * tbl; + int num_newnz; + int newnz_pos[DCTSIZE2]; + + /* Process restart marker if needed; may have to suspend */ + if (cinfo->restart_interval) { + if (entropy->restarts_to_go == 0) + if (! process_restart(cinfo)) + return FALSE; + } + + /* Load up working state */ + BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we care about */ + + /* There is always only one block per MCU */ + block = MCU_data[0]; + tbl = entropy->ac_derived_tbl; + + /* If we are forced to suspend, we must undo the assignments to any newly + * nonzero coefficients in the block, because otherwise we'd get confused + * next time about which coefficients were already nonzero. + * But we need not undo addition of bits to already-nonzero coefficients; + * instead, we can test the current bit position to see if we already did it. + */ + num_newnz = 0; + + /* initialize coefficient loop counter to start of band */ + k = cinfo->Ss; + + if (EOBRUN == 0) { + for (; k <= Se; k++) { + HUFF_DECODE(s, br_state, tbl, goto undoit, label3); + r = s >> 4; + s &= 15; + if (s) { + if (s != 1) /* size of new coef should always be 1 */ + WARNMS(cinfo, JWRN_HUFF_BAD_CODE); + CHECK_BIT_BUFFER(br_state, 1, goto undoit); + if (GET_BITS(1)) + s = p1; /* newly nonzero coef is positive */ + else + s = m1; /* newly nonzero coef is negative */ + } else { + if (r != 15) { + EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */ + if (r) { + CHECK_BIT_BUFFER(br_state, r, goto undoit); + r = GET_BITS(r); + EOBRUN += r; + } + break; /* rest of block is handled by EOB logic */ + } + /* note s = 0 for processing ZRL */ + } + /* Advance over already-nonzero coefs and r still-zero coefs, + * appending correction bits to the nonzeroes. A correction bit is 1 + * if the absolute value of the coefficient must be increased. + */ + do { + thiscoef = *block + jpeg_natural_order[k]; + if (*thiscoef != 0) { + CHECK_BIT_BUFFER(br_state, 1, goto undoit); + if (GET_BITS(1)) { + if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */ + if (*thiscoef >= 0) + *thiscoef += p1; + else + *thiscoef += m1; + } + } + } else { + if (--r < 0) + break; /* reached target zero coefficient */ + } + k++; + } while (k <= Se); + if (s) { + int pos = jpeg_natural_order[k]; + /* Output newly nonzero coefficient */ + (*block)[pos] = (JCOEF) s; + /* Remember its position in case we have to suspend */ + newnz_pos[num_newnz++] = pos; + } + } + } + + if (EOBRUN > 0) { + /* Scan any remaining coefficient positions after the end-of-band + * (the last newly nonzero coefficient, if any). Append a correction + * bit to each already-nonzero coefficient. A correction bit is 1 + * if the absolute value of the coefficient must be increased. + */ + for (; k <= Se; k++) { + thiscoef = *block + jpeg_natural_order[k]; + if (*thiscoef != 0) { + CHECK_BIT_BUFFER(br_state, 1, goto undoit); + if (GET_BITS(1)) { + if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */ + if (*thiscoef >= 0) + *thiscoef += p1; + else + *thiscoef += m1; + } + } + } + } + /* Count one block completed in EOB run */ + EOBRUN--; + } + + /* Completed MCU, so update state */ + BITREAD_SAVE_STATE(cinfo,entropy->bitstate); + entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we care about */ + + /* Account for restart interval (no-op if not using restarts) */ + entropy->restarts_to_go--; + + return TRUE; + + undoit: + /* Re-zero any output coefficients that we made newly nonzero */ + while (num_newnz > 0) + (*block)[newnz_pos[--num_newnz]] = 0; + + return FALSE; + } + + + /* + * Module initialization routine for progressive Huffman entropy decoding. + */ + + GLOBAL(void) + jinit_phuff_decoder (j_decompress_ptr cinfo) + { + phuff_entropy_ptr entropy; + int *coef_bit_ptr; + int ci, i; + + entropy = (phuff_entropy_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(phuff_entropy_decoder)); + cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; + entropy->pub.start_pass = start_pass_phuff_decoder; + + /* Mark derived tables unallocated */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + entropy->derived_tbls[i] = NULL; + } + + /* Create progression status table */ + cinfo->coef_bits = (int (*)[DCTSIZE2]) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->num_components*DCTSIZE2*SIZEOF(int)); + coef_bit_ptr = & cinfo->coef_bits[0][0]; + for (ci = 0; ci < cinfo->num_components; ci++) + for (i = 0; i < DCTSIZE2; i++) + *coef_bit_ptr++ = -1; + } + + #endif /* D_PROGRESSIVE_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdpostct.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdpostct.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdpostct.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,290 ---- + /* + * jdpostct.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the decompression postprocessing controller. + * This controller manages the upsampling, color conversion, and color + * quantization/reduction steps; specifically, it controls the buffering + * between upsample/color conversion and color quantization/reduction. + * + * If no color quantization/reduction is required, then this module has no + * work to do, and it just hands off to the upsample/color conversion code. + * An integrated upsample/convert/quantize process would replace this module + * entirely. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Private buffer controller object */ + + typedef struct { + struct jpeg_d_post_controller pub; /* public fields */ + + /* Color quantization source buffer: this holds output data from + * the upsample/color conversion step to be passed to the quantizer. + * For two-pass color quantization, we need a full-image buffer; + * for one-pass operation, a strip buffer is sufficient. + */ + jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */ + JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */ + JDIMENSION strip_height; /* buffer size in rows */ + /* for two-pass mode only: */ + JDIMENSION starting_row; /* row # of first row in current strip */ + JDIMENSION next_row; /* index of next row to fill/empty in strip */ + } my_post_controller; + + typedef my_post_controller * my_post_ptr; + + + /* Forward declarations */ + METHODDEF(void) post_process_1pass + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); + #ifdef QUANT_2PASS_SUPPORTED + METHODDEF(void) post_process_prepass + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); + METHODDEF(void) post_process_2pass + JPP((j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); + #endif + + + /* + * Initialize for a processing pass. + */ + + METHODDEF(void) + start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) + { + my_post_ptr post = (my_post_ptr) cinfo->post; + + switch (pass_mode) { + case JBUF_PASS_THRU: + if (cinfo->quantize_colors) { + /* Single-pass processing with color quantization. */ + post->pub.post_process_data = post_process_1pass; + /* We could be doing buffered-image output before starting a 2-pass + * color quantization; in that case, jinit_d_post_controller did not + * allocate a strip buffer. Use the virtual-array buffer as workspace. + */ + if (post->buffer == NULL) { + post->buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, post->whole_image, + (JDIMENSION) 0, post->strip_height, TRUE); + } + } else { + /* For single-pass processing without color quantization, + * I have no work to do; just call the upsampler directly. + */ + post->pub.post_process_data = cinfo->upsample->upsample; + } + break; + #ifdef QUANT_2PASS_SUPPORTED + case JBUF_SAVE_AND_PASS: + /* First pass of 2-pass quantization */ + if (post->whole_image == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + post->pub.post_process_data = post_process_prepass; + break; + case JBUF_CRANK_DEST: + /* Second pass of 2-pass quantization */ + if (post->whole_image == NULL) + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + post->pub.post_process_data = post_process_2pass; + break; + #endif /* QUANT_2PASS_SUPPORTED */ + default: + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + break; + } + post->starting_row = post->next_row = 0; + } + + + /* + * Process some data in the one-pass (strip buffer) case. + * This is used for color precision reduction as well as one-pass quantization. + */ + + METHODDEF(void) + post_process_1pass (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + { + my_post_ptr post = (my_post_ptr) cinfo->post; + JDIMENSION num_rows, max_rows; + + /* Fill the buffer, but not more than what we can dump out in one go. */ + /* Note we rely on the upsampler to detect bottom of image. */ + max_rows = out_rows_avail - *out_row_ctr; + if (max_rows > post->strip_height) + max_rows = post->strip_height; + num_rows = 0; + (*cinfo->upsample->upsample) (cinfo, + input_buf, in_row_group_ctr, in_row_groups_avail, + post->buffer, &num_rows, max_rows); + /* Quantize and emit data. */ + (*cinfo->cquantize->color_quantize) (cinfo, + post->buffer, output_buf + *out_row_ctr, (int) num_rows); + *out_row_ctr += num_rows; + } + + + #ifdef QUANT_2PASS_SUPPORTED + + /* + * Process some data in the first pass of 2-pass quantization. + */ + + METHODDEF(void) + post_process_prepass (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + { + my_post_ptr post = (my_post_ptr) cinfo->post; + JDIMENSION old_next_row, num_rows; + + /* Reposition virtual buffer if at start of strip. */ + if (post->next_row == 0) { + post->buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, post->whole_image, + post->starting_row, post->strip_height, TRUE); + } + + /* Upsample some data (up to a strip height's worth). */ + old_next_row = post->next_row; + (*cinfo->upsample->upsample) (cinfo, + input_buf, in_row_group_ctr, in_row_groups_avail, + post->buffer, &post->next_row, post->strip_height); + + /* Allow quantizer to scan new data. No data is emitted, */ + /* but we advance out_row_ctr so outer loop can tell when we're done. */ + if (post->next_row > old_next_row) { + num_rows = post->next_row - old_next_row; + (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row, + (JSAMPARRAY) NULL, (int) num_rows); + *out_row_ctr += num_rows; + } + + /* Advance if we filled the strip. */ + if (post->next_row >= post->strip_height) { + post->starting_row += post->strip_height; + post->next_row = 0; + } + } + + + /* + * Process some data in the second pass of 2-pass quantization. + */ + + METHODDEF(void) + post_process_2pass (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + { + my_post_ptr post = (my_post_ptr) cinfo->post; + JDIMENSION num_rows, max_rows; + + /* Reposition virtual buffer if at start of strip. */ + if (post->next_row == 0) { + post->buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, post->whole_image, + post->starting_row, post->strip_height, FALSE); + } + + /* Determine number of rows to emit. */ + num_rows = post->strip_height - post->next_row; /* available in strip */ + max_rows = out_rows_avail - *out_row_ctr; /* available in output area */ + if (num_rows > max_rows) + num_rows = max_rows; + /* We have to check bottom of image here, can't depend on upsampler. */ + max_rows = cinfo->output_height - post->starting_row; + if (num_rows > max_rows) + num_rows = max_rows; + + /* Quantize and emit data. */ + (*cinfo->cquantize->color_quantize) (cinfo, + post->buffer + post->next_row, output_buf + *out_row_ctr, + (int) num_rows); + *out_row_ctr += num_rows; + + /* Advance if we filled the strip. */ + post->next_row += num_rows; + if (post->next_row >= post->strip_height) { + post->starting_row += post->strip_height; + post->next_row = 0; + } + } + + #endif /* QUANT_2PASS_SUPPORTED */ + + + /* + * Initialize postprocessing controller. + */ + + GLOBAL(void) + jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer) + { + my_post_ptr post; + + post = (my_post_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_post_controller)); + cinfo->post = (struct jpeg_d_post_controller *) post; + post->pub.start_pass = start_pass_dpost; + post->whole_image = NULL; /* flag for no virtual arrays */ + post->buffer = NULL; /* flag for no strip buffer */ + + /* Create the quantization buffer, if needed */ + if (cinfo->quantize_colors) { + /* The buffer strip height is max_v_samp_factor, which is typically + * an efficient number of rows for upsampling to return. + * (In the presence of output rescaling, we might want to be smarter?) + */ + post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor; + if (need_full_buffer) { + /* Two-pass color quantization: need full-image storage. */ + /* We round up the number of rows to a multiple of the strip height. */ + #ifdef QUANT_2PASS_SUPPORTED + post->whole_image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + cinfo->output_width * cinfo->out_color_components, + (JDIMENSION) jround_up((long) cinfo->output_height, + (long) post->strip_height), + post->strip_height); + #else + ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); + #endif /* QUANT_2PASS_SUPPORTED */ + } else { + /* One-pass color quantization: just make a strip buffer. */ + post->buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->output_width * cinfo->out_color_components, + post->strip_height); + } + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdsample.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdsample.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdsample.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,478 ---- + /* + * jdsample.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains upsampling routines. + * + * Upsampling input data is counted in "row groups". A row group + * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) + * sample rows of each component. Upsampling will normally produce + * max_v_samp_factor pixel rows from each row group (but this could vary + * if the upsampler is applying a scale factor of its own). + * + * An excellent reference for image resampling is + * Digital Image Warping, George Wolberg, 1990. + * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Pointer to routine to upsample a single component */ + typedef JMETHOD(void, upsample1_ptr, + (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); + + /* Private subobject */ + + typedef struct { + struct jpeg_upsampler pub; /* public fields */ + + /* Color conversion buffer. When using separate upsampling and color + * conversion steps, this buffer holds one upsampled row group until it + * has been color converted and output. + * Note: we do not allocate any storage for component(s) which are full-size, + * ie do not need rescaling. The corresponding entry of color_buf[] is + * simply set to point to the input data array, thereby avoiding copying. + */ + JSAMPARRAY color_buf[MAX_COMPONENTS]; + + /* Per-component upsampling method pointers */ + upsample1_ptr methods[MAX_COMPONENTS]; + + int next_row_out; /* counts rows emitted from color_buf */ + JDIMENSION rows_to_go; /* counts rows remaining in image */ + + /* Height of an input row group for each component. */ + int rowgroup_height[MAX_COMPONENTS]; + + /* These arrays save pixel expansion factors so that int_expand need not + * recompute them each time. They are unused for other upsampling methods. + */ + UINT8 h_expand[MAX_COMPONENTS]; + UINT8 v_expand[MAX_COMPONENTS]; + } my_upsampler; + + typedef my_upsampler * my_upsample_ptr; + + + /* + * Initialize for an upsampling pass. + */ + + METHODDEF(void) + start_pass_upsample (j_decompress_ptr cinfo) + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + + /* Mark the conversion buffer empty */ + upsample->next_row_out = cinfo->max_v_samp_factor; + /* Initialize total-height counter for detecting bottom of image */ + upsample->rows_to_go = cinfo->output_height; + } + + + /* + * Control routine to do upsampling (and color conversion). + * + * In this version we upsample each component independently. + * We upsample one row group into the conversion buffer, then apply + * color conversion a row at a time. + */ + + METHODDEF(void) + sep_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail) + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + int ci; + jpeg_component_info * compptr; + JDIMENSION num_rows; + + /* Fill the conversion buffer, if it's empty */ + if (upsample->next_row_out >= cinfo->max_v_samp_factor) { + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Invoke per-component upsample method. Notice we pass a POINTER + * to color_buf[ci], so that fullsize_upsample can change it. + */ + (*upsample->methods[ci]) (cinfo, compptr, + input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), + upsample->color_buf + ci); + } + upsample->next_row_out = 0; + } + + /* Color-convert and emit rows */ + + /* How many we have in the buffer: */ + num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out); + /* Not more than the distance to the end of the image. Need this test + * in case the image height is not a multiple of max_v_samp_factor: + */ + if (num_rows > upsample->rows_to_go) + num_rows = upsample->rows_to_go; + /* And not more than what the client can accept: */ + out_rows_avail -= *out_row_ctr; + if (num_rows > out_rows_avail) + num_rows = out_rows_avail; + + (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf, + (JDIMENSION) upsample->next_row_out, + output_buf + *out_row_ctr, + (int) num_rows); + + /* Adjust counts */ + *out_row_ctr += num_rows; + upsample->rows_to_go -= num_rows; + upsample->next_row_out += num_rows; + /* When the buffer is emptied, declare this input row group consumed */ + if (upsample->next_row_out >= cinfo->max_v_samp_factor) + (*in_row_group_ctr)++; + } + + + /* + * These are the routines invoked by sep_upsample to upsample pixel values + * of a single component. One row group is processed per call. + */ + + + /* + * For full-size components, we just make color_buf[ci] point at the + * input buffer, and thus avoid copying any data. Note that this is + * safe only because sep_upsample doesn't declare the input row group + * "consumed" until we are done color converting and emitting it. + */ + + METHODDEF(void) + fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) + { + *output_data_ptr = input_data; + } + + + /* + * This is a no-op version used for "uninteresting" components. + * These components will not be referenced by color conversion. + */ + + METHODDEF(void) + noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) + { + *output_data_ptr = NULL; /* safety check */ + } + + + /* + * This version handles any integral sampling ratios. + * This is not used for typical JPEG files, so it need not be fast. + * Nor, for that matter, is it particularly accurate: the algorithm is + * simple replication of the input pixel onto the corresponding output + * pixels. The hi-falutin sampling literature refers to this as a + * "box filter". A box filter tends to introduce visible artifacts, + * so if you are actually going to use 3:1 or 4:1 sampling ratios + * you would be well advised to improve this code. + */ + + METHODDEF(void) + int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) + { + my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register JSAMPLE invalue; + register int h; + JSAMPROW outend; + int h_expand, v_expand; + int inrow, outrow; + + h_expand = upsample->h_expand[compptr->component_index]; + v_expand = upsample->v_expand[compptr->component_index]; + + inrow = outrow = 0; + while (outrow < cinfo->max_v_samp_factor) { + /* Generate one output row with proper horizontal expansion */ + inptr = input_data[inrow]; + outptr = output_data[outrow]; + outend = outptr + cinfo->output_width; + while (outptr < outend) { + invalue = *inptr++; /* don't need GETJSAMPLE() here */ + for (h = h_expand; h > 0; h--) { + *outptr++ = invalue; + } + } + /* Generate any additional output rows by duplicating the first one */ + if (v_expand > 1) { + jcopy_sample_rows(output_data, outrow, output_data, outrow+1, + v_expand-1, cinfo->output_width); + } + inrow++; + outrow += v_expand; + } + } + + + /* + * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. + * It's still a box filter. + */ + + METHODDEF(void) + h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) + { + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register JSAMPLE invalue; + JSAMPROW outend; + int inrow; + + for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { + inptr = input_data[inrow]; + outptr = output_data[inrow]; + outend = outptr + cinfo->output_width; + while (outptr < outend) { + invalue = *inptr++; /* don't need GETJSAMPLE() here */ + *outptr++ = invalue; + *outptr++ = invalue; + } + } + } + + + /* + * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. + * It's still a box filter. + */ + + METHODDEF(void) + h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) + { + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register JSAMPLE invalue; + JSAMPROW outend; + int inrow, outrow; + + inrow = outrow = 0; + while (outrow < cinfo->max_v_samp_factor) { + inptr = input_data[inrow]; + outptr = output_data[outrow]; + outend = outptr + cinfo->output_width; + while (outptr < outend) { + invalue = *inptr++; /* don't need GETJSAMPLE() here */ + *outptr++ = invalue; + *outptr++ = invalue; + } + jcopy_sample_rows(output_data, outrow, output_data, outrow+1, + 1, cinfo->output_width); + inrow++; + outrow += 2; + } + } + + + /* + * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical. + * + * The upsampling algorithm is linear interpolation between pixel centers, + * also known as a "triangle filter". This is a good compromise between + * speed and visual quality. The centers of the output pixels are 1/4 and 3/4 + * of the way between input pixel centers. + * + * A note about the "bias" calculations: when rounding fractional values to + * integer, we do not want to always round 0.5 up to the next integer. + * If we did that, we'd introduce a noticeable bias towards larger values. + * Instead, this code is arranged so that 0.5 will be rounded up or down at + * alternate pixel locations (a simple ordered dither pattern). + */ + + METHODDEF(void) + h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) + { + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr, outptr; + register int invalue; + register JDIMENSION colctr; + int inrow; + + for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) { + inptr = input_data[inrow]; + outptr = output_data[inrow]; + /* Special case for first column */ + invalue = GETJSAMPLE(*inptr++); + *outptr++ = (JSAMPLE) invalue; + *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2); + + for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { + /* General case: 3/4 * nearer pixel + 1/4 * further pixel */ + invalue = GETJSAMPLE(*inptr++) * 3; + *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2); + *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2); + } + + /* Special case for last column */ + invalue = GETJSAMPLE(*inptr); + *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2); + *outptr++ = (JSAMPLE) invalue; + } + } + + + /* + * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical. + * Again a triangle filter; see comments for h2v1 case, above. + * + * It is OK for us to reference the adjacent input rows because we demanded + * context from the main buffer controller (see initialization code). + */ + + METHODDEF(void) + h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) + { + JSAMPARRAY output_data = *output_data_ptr; + register JSAMPROW inptr0, inptr1, outptr; + #if BITS_IN_JSAMPLE == 8 + register int thiscolsum, lastcolsum, nextcolsum; + #else + register INT32 thiscolsum, lastcolsum, nextcolsum; + #endif + register JDIMENSION colctr; + int inrow, outrow, v; + + inrow = outrow = 0; + while (outrow < cinfo->max_v_samp_factor) { + for (v = 0; v < 2; v++) { + /* inptr0 points to nearest input row, inptr1 points to next nearest */ + inptr0 = input_data[inrow]; + if (v == 0) /* next nearest is row above */ + inptr1 = input_data[inrow-1]; + else /* next nearest is row below */ + inptr1 = input_data[inrow+1]; + outptr = output_data[outrow++]; + + /* Special case for first column */ + thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); + nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); + *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4); + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4); + lastcolsum = thiscolsum; thiscolsum = nextcolsum; + + for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { + /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ + /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ + nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4); + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4); + lastcolsum = thiscolsum; thiscolsum = nextcolsum; + } + + /* Special case for last column */ + *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4); + *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4); + } + inrow++; + } + } + + + /* + * Module initialization routine for upsampling. + */ + + GLOBAL(void) + jinit_upsampler (j_decompress_ptr cinfo) + { + my_upsample_ptr upsample; + int ci; + jpeg_component_info * compptr; + boolean need_buffer, do_fancy; + int h_in_group, v_in_group, h_out_group, v_out_group; + + upsample = (my_upsample_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_upsampler)); + cinfo->upsample = (struct jpeg_upsampler *) upsample; + upsample->pub.start_pass = start_pass_upsample; + upsample->pub.upsample = sep_upsample; + upsample->pub.need_context_rows = FALSE; /* until we find out differently */ + + if (cinfo->CCIR601_sampling) /* this isn't supported */ + ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); + + /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, + * so don't ask for it. + */ + do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1; + + /* Verify we can handle the sampling factors, select per-component methods, + * and create storage as needed. + */ + for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; + ci++, compptr++) { + /* Compute size of an "input group" after IDCT scaling. This many samples + * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. + */ + h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) / + cinfo->min_DCT_scaled_size; + v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) / + cinfo->min_DCT_scaled_size; + h_out_group = cinfo->max_h_samp_factor; + v_out_group = cinfo->max_v_samp_factor; + upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ + need_buffer = TRUE; + if (! compptr->component_needed) { + /* Don't bother to upsample an uninteresting component. */ + upsample->methods[ci] = noop_upsample; + need_buffer = FALSE; + } else if (h_in_group == h_out_group && v_in_group == v_out_group) { + /* Fullsize components can be processed without any work. */ + upsample->methods[ci] = fullsize_upsample; + need_buffer = FALSE; + } else if (h_in_group * 2 == h_out_group && + v_in_group == v_out_group) { + /* Special cases for 2h1v upsampling */ + if (do_fancy && compptr->downsampled_width > 2) + upsample->methods[ci] = h2v1_fancy_upsample; + else + upsample->methods[ci] = h2v1_upsample; + } else if (h_in_group * 2 == h_out_group && + v_in_group * 2 == v_out_group) { + /* Special cases for 2h2v upsampling */ + if (do_fancy && compptr->downsampled_width > 2) { + upsample->methods[ci] = h2v2_fancy_upsample; + upsample->pub.need_context_rows = TRUE; + } else + upsample->methods[ci] = h2v2_upsample; + } else if ((h_out_group % h_in_group) == 0 && + (v_out_group % v_in_group) == 0) { + /* Generic integral-factors upsampling method */ + upsample->methods[ci] = int_upsample; + upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); + upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group); + } else + ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); + if (need_buffer) { + upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) jround_up((long) cinfo->output_width, + (long) cinfo->max_h_samp_factor), + (JDIMENSION) cinfo->max_v_samp_factor); + } + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdtrans.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdtrans.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jdtrans.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,122 ---- + /* + * jdtrans.c + * + * Copyright (C) 1995-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains library routines for transcoding decompression, + * that is, reading raw DCT coefficient arrays from an input JPEG file. + * The routines in jdapimin.c will also be needed by a transcoder. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* Forward declarations */ + LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo)); + + + /* + * Read the coefficient arrays from a JPEG file. + * jpeg_read_header must be completed before calling this. + * + * The entire image is read into a set of virtual coefficient-block arrays, + * one per component. The return value is a pointer to the array of + * virtual-array descriptors. These can be manipulated directly via the + * JPEG memory manager, or handed off to jpeg_write_coefficients(). + * To release the memory occupied by the virtual arrays, call + * jpeg_finish_decompress() when done with the data. + * + * Returns NULL if suspended. This case need be checked only if + * a suspending data source is used. + */ + + GLOBAL(jvirt_barray_ptr *) + jpeg_read_coefficients (j_decompress_ptr cinfo) + { + if (cinfo->global_state == DSTATE_READY) { + /* First call: initialize active modules */ + transdecode_master_selection(cinfo); + cinfo->global_state = DSTATE_RDCOEFS; + } else if (cinfo->global_state != DSTATE_RDCOEFS) + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); + /* Absorb whole file into the coef buffer */ + for (;;) { + int retcode; + /* Call progress monitor hook if present */ + if (cinfo->progress != NULL) + (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); + /* Absorb some more input */ + retcode = (*cinfo->inputctl->consume_input) (cinfo); + if (retcode == JPEG_SUSPENDED) + return NULL; + if (retcode == JPEG_REACHED_EOI) + break; + /* Advance progress counter if appropriate */ + if (cinfo->progress != NULL && + (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { + if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { + /* startup underestimated number of scans; ratchet up one scan */ + cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; + } + } + } + /* Set state so that jpeg_finish_decompress does the right thing */ + cinfo->global_state = DSTATE_STOPPING; + return cinfo->coef->coef_arrays; + } + + + /* + * Master selection of decompression modules for transcoding. + * This substitutes for jdmaster.c's initialization of the full decompressor. + */ + + LOCAL(void) + transdecode_master_selection (j_decompress_ptr cinfo) + { + /* Entropy decoding: either Huffman or arithmetic coding. */ + if (cinfo->arith_code) { + ERREXIT(cinfo, JERR_ARITH_NOTIMPL); + } else { + if (cinfo->progressive_mode) { + #ifdef D_PROGRESSIVE_SUPPORTED + jinit_phuff_decoder(cinfo); + #else + ERREXIT(cinfo, JERR_NOT_COMPILED); + #endif + } else + jinit_huff_decoder(cinfo); + } + + /* Always get a full-image coefficient buffer. */ + jinit_d_coef_controller(cinfo, TRUE); + + /* We can now tell the memory manager to allocate virtual arrays. */ + (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); + + /* Initialize input side of decompressor to consume first scan. */ + (*cinfo->inputctl->start_input_pass) (cinfo); + + /* Initialize progress monitoring. */ + if (cinfo->progress != NULL) { + int nscans; + /* Estimate number of scans to set pass_limit. */ + if (cinfo->progressive_mode) { + /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ + nscans = 2 + 3 * cinfo->num_components; + } else if (cinfo->inputctl->has_multiple_scans) { + /* For a nonprogressive multiscan file, estimate 1 scan per component. */ + nscans = cinfo->num_components; + } else { + nscans = 1; + } + cinfo->progress->pass_counter = 0L; + cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; + cinfo->progress->completed_passes = 0; + cinfo->progress->total_passes = 1; + } + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jerror.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jerror.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jerror.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,228 ---- + /* + * jerror.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains simple error-reporting and trace-message routines. + * These are suitable for Unix-like systems and others where writing to + * stderr is the right thing to do. Many applications will want to replace + * some or all of these routines. + * + * These routines are used by both the compression and decompression code. + */ + + /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ + #include "jinclude.h" + #include "jpeglib.h" + #include "jversion.h" + #include "jerror.h" + + #ifndef EXIT_FAILURE /* define exit() codes if not provided */ + #define EXIT_FAILURE 1 + #endif + + + /* + * Create the message string table. + * We do this from the master message list in jerror.h by re-reading + * jerror.h with a suitable definition for macro JMESSAGE. + * The message table is made an external symbol just in case any applications + * want to refer to it directly. + */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jpeg_std_message_table jMsgTable + #endif + + #define JMESSAGE(code,string) string , + + const char * const jpeg_std_message_table[] = { + #include "jerror.h" + NULL + }; + + + /* + * Error exit handler: must not return to caller. + * + * Applications may override this if they want to get control back after + * an error. Typically one would longjmp somewhere instead of exiting. + * The setjmp buffer can be made a private field within an expanded error + * handler object. Note that the info needed to generate an error message + * is stored in the error object, so you can generate the message now or + * later, at your convenience. + * You should make sure that the JPEG object is cleaned up (with jpeg_abort + * or jpeg_destroy) at some point. + */ + + METHODDEF(void) + error_exit (j_common_ptr cinfo) + { + /* Always display the message */ + (*cinfo->err->output_message) (cinfo); + + /* Let the memory manager delete any temp files before we die */ + jpeg_destroy(cinfo); + + exit(EXIT_FAILURE); + } + + + /* + * Actual output of an error or trace message. + * Applications may override this method to send JPEG messages somewhere + * other than stderr. + */ + + METHODDEF(void) + output_message (j_common_ptr cinfo) + { + char buffer[JMSG_LENGTH_MAX]; + + /* Create the message */ + (*cinfo->err->format_message) (cinfo, buffer); + + /* Send it to stderr, adding a newline */ + fprintf(stderr, "%s\n", buffer); + } + + + /* + * Decide whether to emit a trace or warning message. + * msg_level is one of: + * -1: recoverable corrupt-data warning, may want to abort. + * 0: important advisory messages (always display to user). + * 1: first level of tracing detail. + * 2,3,...: successively more detailed tracing messages. + * An application might override this method if it wanted to abort on warnings + * or change the policy about which messages to display. + */ + + METHODDEF(void) + emit_message (j_common_ptr cinfo, int msg_level) + { + struct jpeg_error_mgr * err = cinfo->err; + + if (msg_level < 0) { + /* It's a warning message. Since corrupt files may generate many warnings, + * the policy implemented here is to show only the first warning, + * unless trace_level >= 3. + */ + if (err->num_warnings == 0 || err->trace_level >= 3) + (*err->output_message) (cinfo); + /* Always count warnings in num_warnings. */ + err->num_warnings++; + } else { + /* It's a trace message. Show it if trace_level >= msg_level. */ + if (err->trace_level >= msg_level) + (*err->output_message) (cinfo); + } + } + + + /* + * Format a message string for the most recent JPEG error or message. + * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX + * characters. Note that no '\n' character is added to the string. + * Few applications should need to override this method. + */ + + METHODDEF(void) + format_message (j_common_ptr cinfo, char * buffer) + { + struct jpeg_error_mgr * err = cinfo->err; + int msg_code = err->msg_code; + const char * msgtext = NULL; + const char * msgptr; + char ch; + boolean isstring; + + /* Look up message string in proper table */ + if (msg_code > 0 && msg_code <= err->last_jpeg_message) { + msgtext = err->jpeg_message_table[msg_code]; + } else if (err->addon_message_table != NULL && + msg_code >= err->first_addon_message && + msg_code <= err->last_addon_message) { + msgtext = err->addon_message_table[msg_code - err->first_addon_message]; + } + + /* Defend against bogus message number */ + if (msgtext == NULL) { + err->msg_parm.i[0] = msg_code; + msgtext = err->jpeg_message_table[0]; + } + + /* Check for string parameter, as indicated by %s in the message text */ + isstring = FALSE; + msgptr = msgtext; + while ((ch = *msgptr++) != '\0') { + if (ch == '%') { + if (*msgptr == 's') isstring = TRUE; + break; + } + } + + /* Format the message into the passed buffer */ + if (isstring) + sprintf(buffer, msgtext, err->msg_parm.s); + else + sprintf(buffer, msgtext, + err->msg_parm.i[0], err->msg_parm.i[1], + err->msg_parm.i[2], err->msg_parm.i[3], + err->msg_parm.i[4], err->msg_parm.i[5], + err->msg_parm.i[6], err->msg_parm.i[7]); + } + + + /* + * Reset error state variables at start of a new image. + * This is called during compression startup to reset trace/error + * processing to default state, without losing any application-specific + * method pointers. An application might possibly want to override + * this method if it has additional error processing state. + */ + + METHODDEF(void) + reset_error_mgr (j_common_ptr cinfo) + { + cinfo->err->num_warnings = 0; + /* trace_level is not reset since it is an application-supplied parameter */ + cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ + } + + + /* + * Fill in the standard error-handling methods in a jpeg_error_mgr object. + * Typical call is: + * struct jpeg_compress_struct cinfo; + * struct jpeg_error_mgr err; + * + * cinfo.err = jpeg_std_error(&err); + * after which the application may override some of the methods. + */ + + GLOBAL(struct jpeg_error_mgr *) + jpeg_std_error (struct jpeg_error_mgr * err) + { + err->error_exit = error_exit; + err->emit_message = emit_message; + err->output_message = output_message; + err->format_message = format_message; + err->reset_error_mgr = reset_error_mgr; + + err->trace_level = 0; /* default = no tracing */ + err->num_warnings = 0; /* no warnings emitted yet */ + err->msg_code = 0; /* may be useful as a flag for "no error" */ + + /* Initialize message table pointers */ + err->jpeg_message_table = jpeg_std_message_table; + err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; + + err->addon_message_table = NULL; + err->first_addon_message = 0; /* for safety */ + err->last_addon_message = 0; + + return err; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jerror.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jerror.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jerror.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,277 ---- + /* + * jerror.h + * + * Copyright (C) 1994-1995, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the error and message codes for the JPEG library. + * Edit this file to add new codes, or to translate the message strings to + * some other language. + * A set of error-reporting macros are defined too. Some applications using + * the JPEG library may wish to include this file to get the error codes + * and/or the macros. + */ + + /* + * To define the enum list of message codes, include this file without + * defining macro JMESSAGE. To create a message string table, include it + * again with a suitable JMESSAGE definition (see jerror.c for an example). + */ + #ifndef JMESSAGE + #ifndef JERROR_H + /* First time through, define the enum list */ + #define JMAKE_ENUM_LIST + #else + /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ + #define JMESSAGE(code,string) + #endif /* JERROR_H */ + #endif /* JMESSAGE */ + + #ifdef JMAKE_ENUM_LIST + + typedef enum { + + #define JMESSAGE(code,string) code , + + #endif /* JMAKE_ENUM_LIST */ + + JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */ + + /* For maintenance convenience, list is alphabetical by message code name */ + JMESSAGE(JERR_ARITH_NOTIMPL, + "Sorry, there are legal restrictions on arithmetic coding") + JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") + JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") + JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode") + JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") + JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") + JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") + JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") + JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") + JMESSAGE(JERR_BAD_LIB_VERSION, + "Wrong JPEG library version: library is %d, caller expects %d") + JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") + JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") + JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") + JMESSAGE(JERR_BAD_PROGRESSION, + "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") + JMESSAGE(JERR_BAD_PROG_SCRIPT, + "Invalid progressive parameters at scan script entry %d") + JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") + JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") + JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") + JMESSAGE(JERR_BAD_STRUCT_SIZE, + "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") + JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") + JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") + JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") + JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet") + JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d") + JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request") + JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d") + JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x") + JMESSAGE(JERR_DHT_COUNTS, "Bogus DHT counts") + JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d") + JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d") + JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)") + JMESSAGE(JERR_EMS_READ, "Read from EMS failed") + JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed") + JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan") + JMESSAGE(JERR_FILE_READ, "Input file read error") + JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") + JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") + JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow") + JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") + JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") + JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") + JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") + JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, + "Cannot transcode due to multiple use of quantization table %d") + JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") + JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") + JMESSAGE(JERR_NOTIMPL, "Not implemented yet") + JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") + JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") + JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined") + JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image") + JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined") + JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") + JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") + JMESSAGE(JERR_QUANT_COMPONENTS, + "Cannot quantize more than %d color components") + JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") + JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") + JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") + JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") + JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") + JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") + JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF") + JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") + JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") + JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") + JMESSAGE(JERR_TFILE_WRITE, + "Write failed on temporary file --- out of disk space?") + JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") + JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") + JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") + JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") + JMESSAGE(JERR_XMS_READ, "Read from XMS failed") + JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") + JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) + JMESSAGE(JMSG_VERSION, JVERSION) + JMESSAGE(JTRC_16BIT_TABLES, + "Caution: quantization tables are too coarse for baseline JPEG") + JMESSAGE(JTRC_ADOBE, + "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") + JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") + JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") + JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") + JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x") + JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d") + JMESSAGE(JTRC_DRI, "Define Restart Interval %u") + JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u") + JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u") + JMESSAGE(JTRC_EOI, "End Of Image") + JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") + JMESSAGE(JTRC_JFIF, "JFIF APP0 marker, density %dx%d %d") + JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, + "Warning: thumbnail image size does not match data length %u") + JMESSAGE(JTRC_JFIF_MINOR, "Unknown JFIF minor revision number %d.%02d") + JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") + JMESSAGE(JTRC_MISC_MARKER, "Skipping marker 0x%02x, length %u") + JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") + JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u") + JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors") + JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors") + JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization") + JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") + JMESSAGE(JTRC_RST, "RST%d") + JMESSAGE(JTRC_SMOOTH_NOTIMPL, + "Smoothing not supported with nonstandard sampling ratios") + JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") + JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") + JMESSAGE(JTRC_SOI, "Start of Image") + JMESSAGE(JTRC_SOS, "Start Of Scan: %d components") + JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d") + JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d") + JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") + JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") + JMESSAGE(JTRC_UNKNOWN_IDS, + "Unrecognized component IDs %d %d %d, assuming YCbCr") + JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") + JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") + JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") + JMESSAGE(JWRN_BOGUS_PROGRESSION, + "Inconsistent progression sequence for component %d coefficient %d") + JMESSAGE(JWRN_EXTRANEOUS_DATA, + "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") + JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") + JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") + JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") + JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") + JMESSAGE(JWRN_MUST_RESYNC, + "Corrupt JPEG data: found marker 0x%02x instead of RST%d") + JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") + JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") + + #ifdef JMAKE_ENUM_LIST + + JMSG_LASTMSGCODE + } J_MESSAGE_CODE; + + #undef JMAKE_ENUM_LIST + #endif /* JMAKE_ENUM_LIST */ + + /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ + #undef JMESSAGE + + + #ifndef JERROR_H + #define JERROR_H + + /* Macros to simplify using the error and trace message stuff */ + /* The first parameter is either type of cinfo pointer */ + + /* Fatal errors (print message and exit) */ + #define ERREXIT(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + #define ERREXIT1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + #define ERREXIT2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + #define ERREXIT3(cinfo,code,p1,p2,p3) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (cinfo)->err->msg_parm.i[2] = (p3), \ + (cinfo)->err->msg_parm.i[3] = (p4), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + #define ERREXITS(cinfo,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) + + #define MAKESTMT(stuff) do { stuff } while (0) + + /* Nonfatal errors (we can keep going, but the data is probably corrupt) */ + #define WARNMS(cinfo,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) + #define WARNMS1(cinfo,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) + #define WARNMS2(cinfo,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) + + /* Informational/debugging messages */ + #define TRACEMS(cinfo,lvl,code) \ + ((cinfo)->err->msg_code = (code), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) + #define TRACEMS1(cinfo,lvl,code,p1) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) + #define TRACEMS2(cinfo,lvl,code,p1,p2) \ + ((cinfo)->err->msg_code = (code), \ + (cinfo)->err->msg_parm.i[0] = (p1), \ + (cinfo)->err->msg_parm.i[1] = (p2), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) + #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) + #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) + #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ + MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ + _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ + _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ + (cinfo)->err->msg_code = (code); \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) + #define TRACEMSS(cinfo,lvl,code,str) \ + ((cinfo)->err->msg_code = (code), \ + strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ + (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) + + #endif /* JERROR_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctflt.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctflt.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctflt.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,168 ---- + /* + * jfdctflt.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a floating-point implementation of the + * forward DCT (Discrete Cosine Transform). + * + * This implementation should be more accurate than either of the integer + * DCT implementations. However, it may not give the same results on all + * machines because of differences in roundoff behavior. Speed will depend + * on the hardware's floating point capacity. + * + * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT + * on each column. Direct algorithms are also available, but they are + * much more complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with a fixed-point + * implementation, accuracy is lost due to imprecise representation of the + * scaled quantization values. However, that problem does not arise if + * we use floating point arithmetic. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + #ifdef DCT_FLOAT_SUPPORTED + + + /* + * This module is specialized to the case DCTSIZE = 8. + */ + + #if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ + #endif + + + /* + * Perform the forward DCT on one block of samples. + */ + + GLOBAL(void) + jpeg_fdct_float (FAST_FLOAT * data) + { + FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + FAST_FLOAT tmp10, tmp11, tmp12, tmp13; + FAST_FLOAT z1, z2, z3, z4, z5, z11, z13; + FAST_FLOAT *dataptr; + int ctr; + + /* Pass 1: process rows. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[0] + dataptr[7]; + tmp7 = dataptr[0] - dataptr[7]; + tmp1 = dataptr[1] + dataptr[6]; + tmp6 = dataptr[1] - dataptr[6]; + tmp2 = dataptr[2] + dataptr[5]; + tmp5 = dataptr[2] - dataptr[5]; + tmp3 = dataptr[3] + dataptr[4]; + tmp4 = dataptr[3] - dataptr[4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[0] = tmp10 + tmp11; /* phase 3 */ + dataptr[4] = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ + dataptr[2] = tmp13 + z1; /* phase 5 */ + dataptr[6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ + z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ + z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ + z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[5] = z13 + z2; /* phase 6 */ + dataptr[3] = z13 - z2; + dataptr[1] = z11 + z4; + dataptr[7] = z11 - z4; + + dataptr += DCTSIZE; /* advance pointer to next row */ + } + + /* Pass 2: process columns. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; + tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; + tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; + tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; + tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; + tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; + tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; + tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ + dataptr[DCTSIZE*4] = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ + dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ + dataptr[DCTSIZE*6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ + z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ + z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ + z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ + dataptr[DCTSIZE*3] = z13 - z2; + dataptr[DCTSIZE*1] = z11 + z4; + dataptr[DCTSIZE*7] = z11 - z4; + + dataptr++; /* advance pointer to next column */ + } + } + + #endif /* DCT_FLOAT_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctfst.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctfst.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctfst.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,224 ---- + /* + * jfdctfst.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a fast, not so accurate integer implementation of the + * forward DCT (Discrete Cosine Transform). + * + * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT + * on each column. Direct algorithms are also available, but they are + * much more complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with fixed-point math, + * accuracy is lost due to imprecise representation of the scaled + * quantization values. The smaller the quantization table entry, the less + * precise the scaled value, so this implementation does worse with high- + * quality-setting files than with low-quality ones. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + #ifdef DCT_IFAST_SUPPORTED + + + /* + * This module is specialized to the case DCTSIZE = 8. + */ + + #if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ + #endif + + + /* Scaling decisions are generally the same as in the LL&M algorithm; + * see jfdctint.c for more details. However, we choose to descale + * (right shift) multiplication products as soon as they are formed, + * rather than carrying additional fractional bits into subsequent additions. + * This compromises accuracy slightly, but it lets us save a few shifts. + * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) + * everywhere except in the multiplications proper; this saves a good deal + * of work on 16-bit-int machines. + * + * Again to save a few shifts, the intermediate results between pass 1 and + * pass 2 are not upscaled, but are represented only to integral precision. + * + * A final compromise is to represent the multiplicative constants to only + * 8 fractional bits, rather than 13. This saves some shifting work on some + * machines, and may also reduce the cost of multiplication (since there + * are fewer one-bits in the constants). + */ + + #define CONST_BITS 8 + + + /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + + #if CONST_BITS == 8 + #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */ + #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */ + #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */ + #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */ + #else + #define FIX_0_382683433 FIX(0.382683433) + #define FIX_0_541196100 FIX(0.541196100) + #define FIX_0_707106781 FIX(0.707106781) + #define FIX_1_306562965 FIX(1.306562965) + #endif + + + /* We can gain a little more speed, with a further compromise in accuracy, + * by omitting the addition in a descaling shift. This yields an incorrectly + * rounded result half the time... + */ + + #ifndef USE_ACCURATE_ROUNDING + #undef DESCALE + #define DESCALE(x,n) RIGHT_SHIFT(x, n) + #endif + + + /* Multiply a DCTELEM variable by an INT32 constant, and immediately + * descale to yield a DCTELEM result. + */ + + #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) + + + /* + * Perform the forward DCT on one block of samples. + */ + + GLOBAL(void) + jpeg_fdct_ifast (DCTELEM * data) + { + DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + DCTELEM tmp10, tmp11, tmp12, tmp13; + DCTELEM z1, z2, z3, z4, z5, z11, z13; + DCTELEM *dataptr; + int ctr; + SHIFT_TEMPS + + /* Pass 1: process rows. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[0] + dataptr[7]; + tmp7 = dataptr[0] - dataptr[7]; + tmp1 = dataptr[1] + dataptr[6]; + tmp6 = dataptr[1] - dataptr[6]; + tmp2 = dataptr[2] + dataptr[5]; + tmp5 = dataptr[2] - dataptr[5]; + tmp3 = dataptr[3] + dataptr[4]; + tmp4 = dataptr[3] - dataptr[4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[0] = tmp10 + tmp11; /* phase 3 */ + dataptr[4] = tmp10 - tmp11; + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ + dataptr[2] = tmp13 + z1; /* phase 5 */ + dataptr[6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */ + z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ + z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ + z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[5] = z13 + z2; /* phase 6 */ + dataptr[3] = z13 - z2; + dataptr[1] = z11 + z4; + dataptr[7] = z11 - z4; + + dataptr += DCTSIZE; /* advance pointer to next row */ + } + + /* Pass 2: process columns. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; + tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; + tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; + tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; + tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; + tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; + tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; + tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; + + /* Even part */ + + tmp10 = tmp0 + tmp3; /* phase 2 */ + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ + dataptr[DCTSIZE*4] = tmp10 - tmp11; + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ + dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ + dataptr[DCTSIZE*6] = tmp13 - z1; + + /* Odd part */ + + tmp10 = tmp4 + tmp5; /* phase 2 */ + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + /* The rotator is modified from fig 4-8 to avoid extra negations. */ + z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */ + z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */ + z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ + z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ + + z11 = tmp7 + z3; /* phase 5 */ + z13 = tmp7 - z3; + + dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ + dataptr[DCTSIZE*3] = z13 - z2; + dataptr[DCTSIZE*1] = z11 + z4; + dataptr[DCTSIZE*7] = z11 - z4; + + dataptr++; /* advance pointer to next column */ + } + } + + #endif /* DCT_IFAST_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctint.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctint.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jfdctint.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,283 ---- + /* + * jfdctint.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a slow-but-accurate integer implementation of the + * forward DCT (Discrete Cosine Transform). + * + * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT + * on each column. Direct algorithms are also available, but they are + * much more complex and seem not to be any faster when reduced to code. + * + * This implementation is based on an algorithm described in + * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT + * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, + * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. + * The primary algorithm described there uses 11 multiplies and 29 adds. + * We use their alternate method with 12 multiplies and 32 adds. + * The advantage of this method is that no data path contains more than one + * multiplication; this allows a very simple and accurate implementation in + * scaled fixed-point arithmetic, with a minimal number of shifts. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + #ifdef DCT_ISLOW_SUPPORTED + + + /* + * This module is specialized to the case DCTSIZE = 8. + */ + + #if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ + #endif + + + /* + * The poop on this scaling stuff is as follows: + * + * Each 1-D DCT step produces outputs which are a factor of sqrt(N) + * larger than the true DCT outputs. The final outputs are therefore + * a factor of N larger than desired; since N=8 this can be cured by + * a simple right shift at the end of the algorithm. The advantage of + * this arrangement is that we save two multiplications per 1-D DCT, + * because the y0 and y4 outputs need not be divided by sqrt(N). + * In the IJG code, this factor of 8 is removed by the quantization step + * (in jcdctmgr.c), NOT in this module. + * + * We have to do addition and subtraction of the integer inputs, which + * is no problem, and multiplication by fractional constants, which is + * a problem to do in integer arithmetic. We multiply all the constants + * by CONST_SCALE and convert them to integer constants (thus retaining + * CONST_BITS bits of precision in the constants). After doing a + * multiplication we have to divide the product by CONST_SCALE, with proper + * rounding, to produce the correct output. This division can be done + * cheaply as a right shift of CONST_BITS bits. We postpone shifting + * as long as possible so that partial sums can be added together with + * full fractional precision. + * + * The outputs of the first pass are scaled up by PASS1_BITS bits so that + * they are represented to better-than-integral precision. These outputs + * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word + * with the recommended scaling. (For 12-bit sample data, the intermediate + * array is INT32 anyway.) + * + * To avoid overflow of the 32-bit intermediate results in pass 2, we must + * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis + * shows that the values given below are the most effective. + */ + + #if BITS_IN_JSAMPLE == 8 + #define CONST_BITS 13 + #define PASS1_BITS 2 + #else + #define CONST_BITS 13 + #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ + #endif + + /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + + #if CONST_BITS == 13 + #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ + #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ + #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */ + #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ + #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ + #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */ + #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */ + #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ + #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */ + #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */ + #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ + #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */ + #else + #define FIX_0_298631336 FIX(0.298631336) + #define FIX_0_390180644 FIX(0.390180644) + #define FIX_0_541196100 FIX(0.541196100) + #define FIX_0_765366865 FIX(0.765366865) + #define FIX_0_899976223 FIX(0.899976223) + #define FIX_1_175875602 FIX(1.175875602) + #define FIX_1_501321110 FIX(1.501321110) + #define FIX_1_847759065 FIX(1.847759065) + #define FIX_1_961570560 FIX(1.961570560) + #define FIX_2_053119869 FIX(2.053119869) + #define FIX_2_562915447 FIX(2.562915447) + #define FIX_3_072711026 FIX(3.072711026) + #endif + + + /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * For 8-bit samples with the recommended scaling, all the variable + * and constant values involved are no more than 16 bits wide, so a + * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. + * For 12-bit samples, a full 32-bit multiplication will be needed. + */ + + #if BITS_IN_JSAMPLE == 8 + #define MULTIPLY(var,const) MULTIPLY16C16(var,const) + #else + #define MULTIPLY(var,const) ((var) * (const)) + #endif + + + /* + * Perform the forward DCT on one block of samples. + */ + + GLOBAL(void) + jpeg_fdct_islow (DCTELEM * data) + { + INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + INT32 tmp10, tmp11, tmp12, tmp13; + INT32 z1, z2, z3, z4, z5; + DCTELEM *dataptr; + int ctr; + SHIFT_TEMPS + + /* Pass 1: process rows. */ + /* Note results are scaled up by sqrt(8) compared to a true DCT; */ + /* furthermore, we scale the results by 2**PASS1_BITS. */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[0] + dataptr[7]; + tmp7 = dataptr[0] - dataptr[7]; + tmp1 = dataptr[1] + dataptr[6]; + tmp6 = dataptr[1] - dataptr[6]; + tmp2 = dataptr[2] + dataptr[5]; + tmp5 = dataptr[2] - dataptr[5]; + tmp3 = dataptr[3] + dataptr[4]; + tmp4 = dataptr[3] - dataptr[4]; + + /* Even part per LL&M figure 1 --- note that published figure is faulty; + * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". + */ + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); + dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); + dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), + CONST_BITS-PASS1_BITS); + dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), + CONST_BITS-PASS1_BITS); + + /* Odd part per figure 8 --- note paper omits factor of sqrt(2). + * cK represents cos(K*pi/16). + * i0..i3 in the paper are tmp4..tmp7 here. + */ + + z1 = tmp4 + tmp7; + z2 = tmp5 + tmp6; + z3 = tmp4 + tmp6; + z4 = tmp5 + tmp7; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); + dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); + dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); + dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); + + dataptr += DCTSIZE; /* advance pointer to next row */ + } + + /* Pass 2: process columns. + * We remove the PASS1_BITS scaling, but leave the results scaled up + * by an overall factor of 8. + */ + + dataptr = data; + for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { + tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; + tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; + tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; + tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; + tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; + tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; + tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; + tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; + + /* Even part per LL&M figure 1 --- note that published figure is faulty; + * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". + */ + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); + dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); + + z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); + dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), + CONST_BITS+PASS1_BITS); + + /* Odd part per figure 8 --- note paper omits factor of sqrt(2). + * cK represents cos(K*pi/16). + * i0..i3 in the paper are tmp4..tmp7 here. + */ + + z1 = tmp4 + tmp7; + z2 = tmp5 + tmp6; + z3 = tmp4 + tmp6; + z4 = tmp5 + tmp7; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, + CONST_BITS+PASS1_BITS); + dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, + CONST_BITS+PASS1_BITS); + + dataptr++; /* advance pointer to next column */ + } + } + + #endif /* DCT_ISLOW_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctflt.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctflt.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctflt.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,241 ---- + /* + * jidctflt.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a floating-point implementation of the + * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine + * must also perform dequantization of the input coefficients. + * + * This implementation should be more accurate than either of the integer + * IDCT implementations. However, it may not give the same results on all + * machines because of differences in roundoff behavior. Speed will depend + * on the hardware's floating point capacity. + * + * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT + * on each row (or vice versa, but it's more convenient to emit a row at + * a time). Direct algorithms are also available, but they are much more + * complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with a fixed-point + * implementation, accuracy is lost due to imprecise representation of the + * scaled quantization values. However, that problem does not arise if + * we use floating point arithmetic. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + #ifdef DCT_FLOAT_SUPPORTED + + + /* + * This module is specialized to the case DCTSIZE = 8. + */ + + #if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ + #endif + + + /* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce a float result. + */ + + #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval)) + + + /* + * Perform dequantization and inverse DCT on one block of coefficients. + */ + + GLOBAL(void) + jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) + { + FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + FAST_FLOAT tmp10, tmp11, tmp12, tmp13; + FAST_FLOAT z5, z10, z11, z12, z13; + JCOEFPTR inptr; + FLOAT_MULT_TYPE * quantptr; + FAST_FLOAT * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; ctr--) { + /* Due to quantization, we will usually find that many of the input + * coefficients are zero, especially the AC terms. We can exploit this + * by short-circuiting the IDCT calculation for any column in which all + * the AC terms are zero. In that case each output is equal to the + * DC coefficient (with scale factor as needed). + * With typical images and quantization tables, half or more of the + * column DCT calculations can be simplified this way. + */ + + if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] | + inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] | + inptr[DCTSIZE*7]) == 0) { + /* AC terms all zero */ + FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + wsptr[DCTSIZE*4] = dcval; + wsptr[DCTSIZE*5] = dcval; + wsptr[DCTSIZE*6] = dcval; + wsptr[DCTSIZE*7] = dcval; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + continue; + } + + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp10 = tmp0 + tmp2; /* phase 3 */ + tmp11 = tmp0 - tmp2; + + tmp13 = tmp1 + tmp3; /* phases 5-3 */ + tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ + + tmp0 = tmp10 + tmp13; /* phase 2 */ + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + z13 = tmp6 + tmp5; /* phase 6 */ + z10 = tmp6 - tmp5; + z11 = tmp4 + tmp7; + z12 = tmp4 - tmp7; + + tmp7 = z11 + z13; /* phase 5 */ + tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ + + z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ + tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ + tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; /* phase 2 */ + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + wsptr[DCTSIZE*0] = tmp0 + tmp7; + wsptr[DCTSIZE*7] = tmp0 - tmp7; + wsptr[DCTSIZE*1] = tmp1 + tmp6; + wsptr[DCTSIZE*6] = tmp1 - tmp6; + wsptr[DCTSIZE*2] = tmp2 + tmp5; + wsptr[DCTSIZE*5] = tmp2 - tmp5; + wsptr[DCTSIZE*4] = tmp3 + tmp4; + wsptr[DCTSIZE*3] = tmp3 - tmp4; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + } + + /* Pass 2: process rows from work array, store into output array. */ + /* Note that we must descale the results by a factor of 8 == 2**3. */ + + wsptr = workspace; + for (ctr = 0; ctr < DCTSIZE; ctr++) { + outptr = output_buf[ctr] + output_col; + /* Rows of zeroes can be exploited in the same way as we did with columns. + * However, the column calculation has created many nonzero AC terms, so + * the simplification applies less often (typically 5% to 10% of the time). + * And testing floats for zero is relatively expensive, so we don't bother. + */ + + /* Even part */ + + tmp10 = wsptr[0] + wsptr[4]; + tmp11 = wsptr[0] - wsptr[4]; + + tmp13 = wsptr[2] + wsptr[6]; + tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13; + + tmp0 = tmp10 + tmp13; + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + z13 = wsptr[5] + wsptr[3]; + z10 = wsptr[5] - wsptr[3]; + z11 = wsptr[1] + wsptr[7]; + z12 = wsptr[1] - wsptr[7]; + + tmp7 = z11 + z13; + tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); + + z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ + tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ + tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + /* Final output stage: scale down by a factor of 8 and range-limit */ + + outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } + } + + #endif /* DCT_FLOAT_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctfst.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctfst.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctfst.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,367 ---- + /* + * jidctfst.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a fast, not so accurate integer implementation of the + * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine + * must also perform dequantization of the input coefficients. + * + * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT + * on each row (or vice versa, but it's more convenient to emit a row at + * a time). Direct algorithms are also available, but they are much more + * complex and seem not to be any faster when reduced to code. + * + * This implementation is based on Arai, Agui, and Nakajima's algorithm for + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in + * Japanese, but the algorithm is described in the Pennebaker & Mitchell + * JPEG textbook (see REFERENCES section in file README). The following code + * is based directly on figure 4-8 in P&M. + * While an 8-point DCT cannot be done in less than 11 multiplies, it is + * possible to arrange the computation so that many of the multiplies are + * simple scalings of the final outputs. These multiplies can then be + * folded into the multiplications or divisions by the JPEG quantization + * table entries. The AA&N method leaves only 5 multiplies and 29 adds + * to be done in the DCT itself. + * The primary disadvantage of this method is that with fixed-point math, + * accuracy is lost due to imprecise representation of the scaled + * quantization values. The smaller the quantization table entry, the less + * precise the scaled value, so this implementation does worse with high- + * quality-setting files than with low-quality ones. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + #ifdef DCT_IFAST_SUPPORTED + + + /* + * This module is specialized to the case DCTSIZE = 8. + */ + + #if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ + #endif + + + /* Scaling decisions are generally the same as in the LL&M algorithm; + * see jidctint.c for more details. However, we choose to descale + * (right shift) multiplication products as soon as they are formed, + * rather than carrying additional fractional bits into subsequent additions. + * This compromises accuracy slightly, but it lets us save a few shifts. + * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) + * everywhere except in the multiplications proper; this saves a good deal + * of work on 16-bit-int machines. + * + * The dequantized coefficients are not integers because the AA&N scaling + * factors have been incorporated. We represent them scaled up by PASS1_BITS, + * so that the first and second IDCT rounds have the same input scaling. + * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to + * avoid a descaling shift; this compromises accuracy rather drastically + * for small quantization table entries, but it saves a lot of shifts. + * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway, + * so we use a much larger scaling factor to preserve accuracy. + * + * A final compromise is to represent the multiplicative constants to only + * 8 fractional bits, rather than 13. This saves some shifting work on some + * machines, and may also reduce the cost of multiplication (since there + * are fewer one-bits in the constants). + */ + + #if BITS_IN_JSAMPLE == 8 + #define CONST_BITS 8 + #define PASS1_BITS 2 + #else + #define CONST_BITS 8 + #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ + #endif + + /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + + #if CONST_BITS == 8 + #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ + #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ + #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ + #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ + #else + #define FIX_1_082392200 FIX(1.082392200) + #define FIX_1_414213562 FIX(1.414213562) + #define FIX_1_847759065 FIX(1.847759065) + #define FIX_2_613125930 FIX(2.613125930) + #endif + + + /* We can gain a little more speed, with a further compromise in accuracy, + * by omitting the addition in a descaling shift. This yields an incorrectly + * rounded result half the time... + */ + + #ifndef USE_ACCURATE_ROUNDING + #undef DESCALE + #define DESCALE(x,n) RIGHT_SHIFT(x, n) + #endif + + + /* Multiply a DCTELEM variable by an INT32 constant, and immediately + * descale to yield a DCTELEM result. + */ + + #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) + + + /* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce a DCTELEM result. For 8-bit data a 16x16->16 + * multiplication will do. For 12-bit data, the multiplier table is + * declared INT32, so a 32-bit multiply will be used. + */ + + #if BITS_IN_JSAMPLE == 8 + #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) + #else + #define DEQUANTIZE(coef,quantval) \ + DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) + #endif + + + /* Like DESCALE, but applies to a DCTELEM and produces an int. + * We assume that int right shift is unsigned if INT32 right shift is. + */ + + #ifdef RIGHT_SHIFT_IS_UNSIGNED + #define ISHIFT_TEMPS DCTELEM ishift_temp; + #if BITS_IN_JSAMPLE == 8 + #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */ + #else + #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */ + #endif + #define IRIGHT_SHIFT(x,shft) \ + ((ishift_temp = (x)) < 0 ? \ + (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \ + (ishift_temp >> (shft))) + #else + #define ISHIFT_TEMPS + #define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) + #endif + + #ifdef USE_ACCURATE_ROUNDING + #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n)) + #else + #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n)) + #endif + + + /* + * Perform dequantization and inverse DCT on one block of coefficients. + */ + + GLOBAL(void) + jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) + { + DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; + DCTELEM tmp10, tmp11, tmp12, tmp13; + DCTELEM z5, z10, z11, z12, z13; + JCOEFPTR inptr; + IFAST_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE2]; /* buffers data between passes */ + SHIFT_TEMPS /* for DESCALE */ + ISHIFT_TEMPS /* for IDESCALE */ + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (IFAST_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; ctr--) { + /* Due to quantization, we will usually find that many of the input + * coefficients are zero, especially the AC terms. We can exploit this + * by short-circuiting the IDCT calculation for any column in which all + * the AC terms are zero. In that case each output is equal to the + * DC coefficient (with scale factor as needed). + * With typical images and quantization tables, half or more of the + * column DCT calculations can be simplified this way. + */ + + if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] | + inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] | + inptr[DCTSIZE*7]) == 0) { + /* AC terms all zero */ + int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + wsptr[DCTSIZE*4] = dcval; + wsptr[DCTSIZE*5] = dcval; + wsptr[DCTSIZE*6] = dcval; + wsptr[DCTSIZE*7] = dcval; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + continue; + } + + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp10 = tmp0 + tmp2; /* phase 3 */ + tmp11 = tmp0 - tmp2; + + tmp13 = tmp1 + tmp3; /* phases 5-3 */ + tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ + + tmp0 = tmp10 + tmp13; /* phase 2 */ + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + + z13 = tmp6 + tmp5; /* phase 6 */ + z10 = tmp6 - tmp5; + z11 = tmp4 + tmp7; + z12 = tmp4 - tmp7; + + tmp7 = z11 + z13; /* phase 5 */ + tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ + + z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ + tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ + tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; /* phase 2 */ + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7); + wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7); + wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6); + wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6); + wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5); + wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5); + wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4); + wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4); + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + } + + /* Pass 2: process rows from work array, store into output array. */ + /* Note that we must descale the results by a factor of 8 == 2**3, */ + /* and also undo the PASS1_BITS scaling. */ + + wsptr = workspace; + for (ctr = 0; ctr < DCTSIZE; ctr++) { + outptr = output_buf[ctr] + output_col; + /* Rows of zeroes can be exploited in the same way as we did with columns. + * However, the column calculation has created many nonzero AC terms, so + * the simplification applies less often (typically 5% to 10% of the time). + * On machines with very fast multiplication, it's possible that the + * test takes more time than it's worth. In that case this section + * may be commented out. + */ + + #ifndef NO_ZERO_ROW_TEST + if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[4] | wsptr[5] | wsptr[6] | + wsptr[7]) == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + outptr[2] = dcval; + outptr[3] = dcval; + outptr[4] = dcval; + outptr[5] = dcval; + outptr[6] = dcval; + outptr[7] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } + #endif + + /* Even part */ + + tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]); + tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]); + + tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]); + tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) + - tmp13; + + tmp0 = tmp10 + tmp13; + tmp3 = tmp10 - tmp13; + tmp1 = tmp11 + tmp12; + tmp2 = tmp11 - tmp12; + + /* Odd part */ + + z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3]; + z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3]; + z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; + z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; + + tmp7 = z11 + z13; /* phase 5 */ + tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ + + z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ + tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ + tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ + + tmp6 = tmp12 - tmp7; /* phase 2 */ + tmp5 = tmp11 - tmp6; + tmp4 = tmp10 + tmp5; + + /* Final output stage: scale down by a factor of 8 and range-limit */ + + outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } + } + + #endif /* DCT_IFAST_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctint.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctint.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctint.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,388 ---- + /* + * jidctint.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains a slow-but-accurate integer implementation of the + * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine + * must also perform dequantization of the input coefficients. + * + * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT + * on each row (or vice versa, but it's more convenient to emit a row at + * a time). Direct algorithms are also available, but they are much more + * complex and seem not to be any faster when reduced to code. + * + * This implementation is based on an algorithm described in + * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT + * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, + * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. + * The primary algorithm described there uses 11 multiplies and 29 adds. + * We use their alternate method with 12 multiplies and 32 adds. + * The advantage of this method is that no data path contains more than one + * multiplication; this allows a very simple and accurate implementation in + * scaled fixed-point arithmetic, with a minimal number of shifts. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + #ifdef DCT_ISLOW_SUPPORTED + + + /* + * This module is specialized to the case DCTSIZE = 8. + */ + + #if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ + #endif + + + /* + * The poop on this scaling stuff is as follows: + * + * Each 1-D IDCT step produces outputs which are a factor of sqrt(N) + * larger than the true IDCT outputs. The final outputs are therefore + * a factor of N larger than desired; since N=8 this can be cured by + * a simple right shift at the end of the algorithm. The advantage of + * this arrangement is that we save two multiplications per 1-D IDCT, + * because the y0 and y4 inputs need not be divided by sqrt(N). + * + * We have to do addition and subtraction of the integer inputs, which + * is no problem, and multiplication by fractional constants, which is + * a problem to do in integer arithmetic. We multiply all the constants + * by CONST_SCALE and convert them to integer constants (thus retaining + * CONST_BITS bits of precision in the constants). After doing a + * multiplication we have to divide the product by CONST_SCALE, with proper + * rounding, to produce the correct output. This division can be done + * cheaply as a right shift of CONST_BITS bits. We postpone shifting + * as long as possible so that partial sums can be added together with + * full fractional precision. + * + * The outputs of the first pass are scaled up by PASS1_BITS bits so that + * they are represented to better-than-integral precision. These outputs + * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word + * with the recommended scaling. (To scale up 12-bit sample data further, an + * intermediate INT32 array would be needed.) + * + * To avoid overflow of the 32-bit intermediate results in pass 2, we must + * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis + * shows that the values given below are the most effective. + */ + + #if BITS_IN_JSAMPLE == 8 + #define CONST_BITS 13 + #define PASS1_BITS 2 + #else + #define CONST_BITS 13 + #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ + #endif + + /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + + #if CONST_BITS == 13 + #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ + #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ + #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */ + #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ + #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ + #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */ + #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */ + #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ + #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */ + #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */ + #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ + #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */ + #else + #define FIX_0_298631336 FIX(0.298631336) + #define FIX_0_390180644 FIX(0.390180644) + #define FIX_0_541196100 FIX(0.541196100) + #define FIX_0_765366865 FIX(0.765366865) + #define FIX_0_899976223 FIX(0.899976223) + #define FIX_1_175875602 FIX(1.175875602) + #define FIX_1_501321110 FIX(1.501321110) + #define FIX_1_847759065 FIX(1.847759065) + #define FIX_1_961570560 FIX(1.961570560) + #define FIX_2_053119869 FIX(2.053119869) + #define FIX_2_562915447 FIX(2.562915447) + #define FIX_3_072711026 FIX(3.072711026) + #endif + + + /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * For 8-bit samples with the recommended scaling, all the variable + * and constant values involved are no more than 16 bits wide, so a + * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. + * For 12-bit samples, a full 32-bit multiplication will be needed. + */ + + #if BITS_IN_JSAMPLE == 8 + #define MULTIPLY(var,const) MULTIPLY16C16(var,const) + #else + #define MULTIPLY(var,const) ((var) * (const)) + #endif + + + /* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce an int result. In this module, both inputs and result + * are 16 bits or less, so either int or short multiply will work. + */ + + #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval)) + + + /* + * Perform dequantization and inverse DCT on one block of coefficients. + */ + + GLOBAL(void) + jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) + { + INT32 tmp0, tmp1, tmp2, tmp3; + INT32 tmp10, tmp11, tmp12, tmp13; + INT32 z1, z2, z3, z4, z5; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE2]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ + /* furthermore, we scale the results by 2**PASS1_BITS. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; ctr--) { + /* Due to quantization, we will usually find that many of the input + * coefficients are zero, especially the AC terms. We can exploit this + * by short-circuiting the IDCT calculation for any column in which all + * the AC terms are zero. In that case each output is equal to the + * DC coefficient (with scale factor as needed). + * With typical images and quantization tables, half or more of the + * column DCT calculations can be simplified this way. + */ + + if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] | + inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] | + inptr[DCTSIZE*7]) == 0) { + /* AC terms all zero */ + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + wsptr[DCTSIZE*4] = dcval; + wsptr[DCTSIZE*5] = dcval; + wsptr[DCTSIZE*6] = dcval; + wsptr[DCTSIZE*7] = dcval; + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + continue; + } + + /* Even part: reverse the even part of the forward DCT. */ + /* The rotator is sqrt(2)*c(-6). */ + + z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + z1 = MULTIPLY(z2 + z3, FIX_0_541196100); + tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); + tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + + z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); + + tmp0 = (z2 + z3) << CONST_BITS; + tmp1 = (z2 - z3) << CONST_BITS; + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + /* Odd part per figure 8; the matrix is unitary and hence its + * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. + */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + + z1 = tmp0 + tmp3; + z2 = tmp1 + tmp2; + z3 = tmp0 + tmp2; + z4 = tmp1 + tmp3; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + tmp0 += z1 + z3; + tmp1 += z2 + z4; + tmp2 += z2 + z3; + tmp3 += z1 + z4; + + /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ + + wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); + wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); + + inptr++; /* advance pointers to next column */ + quantptr++; + wsptr++; + } + + /* Pass 2: process rows from work array, store into output array. */ + /* Note that we must descale the results by a factor of 8 == 2**3, */ + /* and also undo the PASS1_BITS scaling. */ + + wsptr = workspace; + for (ctr = 0; ctr < DCTSIZE; ctr++) { + outptr = output_buf[ctr] + output_col; + /* Rows of zeroes can be exploited in the same way as we did with columns. + * However, the column calculation has created many nonzero AC terms, so + * the simplification applies less often (typically 5% to 10% of the time). + * On machines with very fast multiplication, it's possible that the + * test takes more time than it's worth. In that case this section + * may be commented out. + */ + + #ifndef NO_ZERO_ROW_TEST + if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[4] | wsptr[5] | wsptr[6] | + wsptr[7]) == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + outptr[2] = dcval; + outptr[3] = dcval; + outptr[4] = dcval; + outptr[5] = dcval; + outptr[6] = dcval; + outptr[7] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } + #endif + + /* Even part: reverse the even part of the forward DCT. */ + /* The rotator is sqrt(2)*c(-6). */ + + z2 = (INT32) wsptr[2]; + z3 = (INT32) wsptr[6]; + + z1 = MULTIPLY(z2 + z3, FIX_0_541196100); + tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); + tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); + + tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS; + tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS; + + tmp10 = tmp0 + tmp3; + tmp13 = tmp0 - tmp3; + tmp11 = tmp1 + tmp2; + tmp12 = tmp1 - tmp2; + + /* Odd part per figure 8; the matrix is unitary and hence its + * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. + */ + + tmp0 = (INT32) wsptr[7]; + tmp1 = (INT32) wsptr[5]; + tmp2 = (INT32) wsptr[3]; + tmp3 = (INT32) wsptr[1]; + + z1 = tmp0 + tmp3; + z2 = tmp1 + tmp2; + z3 = tmp0 + tmp2; + z4 = tmp1 + tmp3; + z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ + + tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ + tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ + tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ + tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ + z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ + z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ + z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ + z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ + + z3 += z5; + z4 += z5; + + tmp0 += z1 + z3; + tmp1 += z2 + z4; + tmp2 += z2 + z3; + tmp3 += z1 + z4; + + /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ + + outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0, + CONST_BITS+PASS1_BITS+3) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } + } + + #endif /* DCT_ISLOW_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctred.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctred.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jidctred.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,397 ---- + /* + * jidctred.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains inverse-DCT routines that produce reduced-size output: + * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block. + * + * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M) + * algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step + * with an 8-to-4 step that produces the four averages of two adjacent outputs + * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output). + * These steps were derived by computing the corresponding values at the end + * of the normal LL&M code, then simplifying as much as possible. + * + * 1x1 is trivial: just take the DC coefficient divided by 8. + * + * See jidctint.c for additional comments. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jdct.h" /* Private declarations for DCT subsystem */ + + #ifdef IDCT_SCALING_SUPPORTED + + + /* + * This module is specialized to the case DCTSIZE = 8. + */ + + #if DCTSIZE != 8 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ + #endif + + + /* Scaling is the same as in jidctint.c. */ + + #if BITS_IN_JSAMPLE == 8 + #define CONST_BITS 13 + #define PASS1_BITS 2 + #else + #define CONST_BITS 13 + #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ + #endif + + /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus + * causing a lot of useless floating-point operations at run time. + * To get around this we use the following pre-calculated constants. + * If you change CONST_BITS you may want to add appropriate values. + * (With a reasonable C compiler, you can just rely on the FIX() macro...) + */ + + #if CONST_BITS == 13 + #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */ + #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */ + #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */ + #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */ + #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ + #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */ + #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ + #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */ + #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */ + #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */ + #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ + #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */ + #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ + #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */ + #else + #define FIX_0_211164243 FIX(0.211164243) + #define FIX_0_509795579 FIX(0.509795579) + #define FIX_0_601344887 FIX(0.601344887) + #define FIX_0_720959822 FIX(0.720959822) + #define FIX_0_765366865 FIX(0.765366865) + #define FIX_0_850430095 FIX(0.850430095) + #define FIX_0_899976223 FIX(0.899976223) + #define FIX_1_061594337 FIX(1.061594337) + #define FIX_1_272758580 FIX(1.272758580) + #define FIX_1_451774981 FIX(1.451774981) + #define FIX_1_847759065 FIX(1.847759065) + #define FIX_2_172734803 FIX(2.172734803) + #define FIX_2_562915447 FIX(2.562915447) + #define FIX_3_624509785 FIX(3.624509785) + #endif + + + /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. + * For 8-bit samples with the recommended scaling, all the variable + * and constant values involved are no more than 16 bits wide, so a + * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. + * For 12-bit samples, a full 32-bit multiplication will be needed. + */ + + #if BITS_IN_JSAMPLE == 8 + #define MULTIPLY(var,const) MULTIPLY16C16(var,const) + #else + #define MULTIPLY(var,const) ((var) * (const)) + #endif + + + /* Dequantize a coefficient by multiplying it by the multiplier-table + * entry; produce an int result. In this module, both inputs and result + * are 16 bits or less, so either int or short multiply will work. + */ + + #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval)) + + + /* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 4x4 output block. + */ + + GLOBAL(void) + jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) + { + INT32 tmp0, tmp2, tmp10, tmp12; + INT32 z1, z2, z3, z4; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE*4]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { + /* Don't bother to process column 4, because second pass won't use it */ + if (ctr == DCTSIZE-4) + continue; + if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] | + inptr[DCTSIZE*5] | inptr[DCTSIZE*6] | inptr[DCTSIZE*7]) == 0) { + /* AC terms all zero; we need not examine term 4 for 4x4 output */ + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + wsptr[DCTSIZE*2] = dcval; + wsptr[DCTSIZE*3] = dcval; + + continue; + } + + /* Even part */ + + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp0 <<= (CONST_BITS+1); + + z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); + z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); + + tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865); + + tmp10 = tmp0 + tmp2; + tmp12 = tmp0 - tmp2; + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + + tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ + + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ + + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ + + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ + + tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ + + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ + + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ + + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ + + /* Final output stage */ + + wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1); + wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1); + wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1); + wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1); + } + + /* Pass 2: process 4 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 4; ctr++) { + outptr = output_buf[ctr] + output_col; + /* It's not clear whether a zero row test is worthwhile here ... */ + + #ifndef NO_ZERO_ROW_TEST + if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[5] | wsptr[6] | + wsptr[7]) == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + outptr[2] = dcval; + outptr[3] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } + #endif + + /* Even part */ + + tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1); + + tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065) + + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865); + + tmp10 = tmp0 + tmp2; + tmp12 = tmp0 - tmp2; + + /* Odd part */ + + z1 = (INT32) wsptr[7]; + z2 = (INT32) wsptr[5]; + z3 = (INT32) wsptr[3]; + z4 = (INT32) wsptr[1]; + + tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ + + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ + + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ + + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ + + tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ + + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ + + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ + + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0, + CONST_BITS+PASS1_BITS+3+1) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } + } + + + /* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 2x2 output block. + */ + + GLOBAL(void) + jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) + { + INT32 tmp0, tmp10, z1; + JCOEFPTR inptr; + ISLOW_MULT_TYPE * quantptr; + int * wsptr; + JSAMPROW outptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + int ctr; + int workspace[DCTSIZE*2]; /* buffers data between passes */ + SHIFT_TEMPS + + /* Pass 1: process columns from input, store into work array. */ + + inptr = coef_block; + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + wsptr = workspace; + for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) { + /* Don't bother to process columns 2,4,6 */ + if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6) + continue; + if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*3] | + inptr[DCTSIZE*5] | inptr[DCTSIZE*7]) == 0) { + /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */ + int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; + + wsptr[DCTSIZE*0] = dcval; + wsptr[DCTSIZE*1] = dcval; + + continue; + } + + /* Even part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); + tmp10 = z1 << (CONST_BITS+2); + + /* Odd part */ + + z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); + tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */ + z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); + tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */ + z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); + tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */ + z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); + tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ + + /* Final output stage */ + + wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2); + wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2); + } + + /* Pass 2: process 2 rows from work array, store into output array. */ + + wsptr = workspace; + for (ctr = 0; ctr < 2; ctr++) { + outptr = output_buf[ctr] + output_col; + /* It's not clear whether a zero row test is worthwhile here ... */ + + #ifndef NO_ZERO_ROW_TEST + if ((wsptr[1] | wsptr[3] | wsptr[5] | wsptr[7]) == 0) { + /* AC terms all zero */ + JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) + & RANGE_MASK]; + + outptr[0] = dcval; + outptr[1] = dcval; + + wsptr += DCTSIZE; /* advance pointer to next row */ + continue; + } + #endif + + /* Even part */ + + tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2); + + /* Odd part */ + + tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */ + + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */ + + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */ + + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ + + /* Final output stage */ + + outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0, + CONST_BITS+PASS1_BITS+3+2) + & RANGE_MASK]; + outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0, + CONST_BITS+PASS1_BITS+3+2) + & RANGE_MASK]; + + wsptr += DCTSIZE; /* advance pointer to next row */ + } + } + + + /* + * Perform dequantization and inverse DCT on one block of coefficients, + * producing a reduced-size 1x1 output block. + */ + + GLOBAL(void) + jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col) + { + int dcval; + ISLOW_MULT_TYPE * quantptr; + JSAMPLE *range_limit = IDCT_range_limit(cinfo); + SHIFT_TEMPS + + /* We hardly need an inverse DCT routine for this: just take the + * average pixel value, which is one-eighth of the DC coefficient. + */ + quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; + dcval = DEQUANTIZE(coef_block[0], quantptr[0]); + dcval = (int) DESCALE((INT32) dcval, 3); + + output_buf[0][output_col] = range_limit[dcval & RANGE_MASK]; + } + + #endif /* IDCT_SCALING_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jinclude.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jinclude.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jinclude.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,91 ---- + /* + * jinclude.h + * + * Copyright (C) 1991-1994, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file exists to provide a single place to fix any problems with + * including the wrong system include files. (Common problems are taken + * care of by the standard jconfig symbols, but on really weird systems + * you may have to edit this file.) + * + * NOTE: this file is NOT intended to be included by applications using the + * JPEG library. Most applications need only include jpeglib.h. + */ + + + /* Include auto-config file to find out which system include files we need. */ + + #include "jconfig.h" /* auto configuration options */ + #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ + + /* + * We need the NULL macro and size_t typedef. + * On an ANSI-conforming system it is sufficient to include <stddef.h>. + * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to + * pull in <sys/types.h> as well. + * Note that the core JPEG library does not require <stdio.h>; + * only the default error handler and data source/destination modules do. + * But we must pull it in because of the references to FILE in jpeglib.h. + * You can remove those references if you want to compile without <stdio.h>. + */ + + #ifdef HAVE_STDDEF_H + #include <stddef.h> + #endif + + #ifdef HAVE_STDLIB_H + #include <stdlib.h> + #endif + + #ifdef NEED_SYS_TYPES_H + #include <sys/types.h> + #endif + + #include <stdio.h> + + /* + * We need memory copying and zeroing functions, plus strncpy(). + * ANSI and System V implementations declare these in <string.h>. + * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). + * Some systems may declare memset and memcpy in <memory.h>. + * + * NOTE: we assume the size parameters to these functions are of type size_t. + * Change the casts in these macros if not! + */ + + #ifdef NEED_BSD_STRINGS + + #include <strings.h> + #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) + #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) + + #else /* not BSD, assume ANSI/SysV string lib */ + + #include <string.h> + #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) + #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) + + #endif + + /* + * In ANSI C, and indeed any rational implementation, size_t is also the + * type returned by sizeof(). However, it seems there are some irrational + * implementations out there, in which sizeof() returns an int even though + * size_t is defined as long or unsigned long. To ensure consistent results + * we always use this SIZEOF() macro in place of using sizeof() directly. + */ + + #define SIZEOF(object) ((size_t) sizeof(object)) + + /* + * The modules that use fread() and fwrite() always invoke them through + * these macros. On some systems you may need to twiddle the argument casts. + * CAUTION: argument order is different from underlying functions! + */ + + #define JFREAD(file,buf,sizeofbuf) \ + ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) + #define JFWRITE(file,buf,sizeofbuf) \ + ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemmgr.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemmgr.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemmgr.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,1115 ---- + /* + * jmemmgr.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains the JPEG system-independent memory management + * routines. This code is usable across a wide variety of machines; most + * of the system dependencies have been isolated in a separate file. + * The major functions provided here are: + * * pool-based allocation and freeing of memory; + * * policy decisions about how to divide available memory among the + * virtual arrays; + * * control logic for swapping virtual arrays between main memory and + * backing storage. + * The separate system-dependent file provides the actual backing-storage + * access code, and it contains the policy decision about how much total + * main memory to use. + * This file is system-dependent in the sense that some of its functions + * are unnecessary in some systems. For example, if there is enough virtual + * memory so that backing storage will never be used, much of the virtual + * array control logic could be removed. (Of course, if you have that much + * memory then you shouldn't care about a little bit of unused code...) + */ + + #define JPEG_INTERNALS + #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */ + #include "jinclude.h" + #include "jpeglib.h" + #include "jmemsys.h" /* import the system-dependent declarations */ + + #ifndef NO_GETENV + #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */ + extern char * getenv JPP((const char * name)); + #endif + #endif + + + /* + * Some important notes: + * The allocation routines provided here must never return NULL. + * They should exit to error_exit if unsuccessful. + * + * It's not a good idea to try to merge the sarray and barray routines, + * even though they are textually almost the same, because samples are + * usually stored as bytes while coefficients are shorts or ints. Thus, + * in machines where byte pointers have a different representation from + * word pointers, the resulting machine code could not be the same. + */ + + + /* + * Many machines require storage alignment: longs must start on 4-byte + * boundaries, doubles on 8-byte boundaries, etc. On such machines, malloc() + * always returns pointers that are multiples of the worst-case alignment + * requirement, and we had better do so too. + * There isn't any really portable way to determine the worst-case alignment + * requirement. This module assumes that the alignment requirement is + * multiples of sizeof(ALIGN_TYPE). + * By default, we define ALIGN_TYPE as double. This is necessary on some + * workstations (where doubles really do need 8-byte alignment) and will work + * fine on nearly everything. If your machine has lesser alignment needs, + * you can save a few bytes by making ALIGN_TYPE smaller. + * The only place I know of where this will NOT work is certain Macintosh + * 680x0 compilers that define double as a 10-byte IEEE extended float. + * Doing 10-byte alignment is counterproductive because longwords won't be + * aligned well. Put "#define ALIGN_TYPE long" in jconfig.h if you have + * such a compiler. + */ + + #ifndef ALIGN_TYPE /* so can override from jconfig.h */ + #define ALIGN_TYPE double + #endif + + + /* + * We allocate objects from "pools", where each pool is gotten with a single + * request to jpeg_get_small() or jpeg_get_large(). There is no per-object + * overhead within a pool, except for alignment padding. Each pool has a + * header with a link to the next pool of the same class. + * Small and large pool headers are identical except that the latter's + * link pointer must be FAR on 80x86 machines. + * Notice that the "real" header fields are union'ed with a dummy ALIGN_TYPE + * field. This forces the compiler to make SIZEOF(small_pool_hdr) a multiple + * of the alignment requirement of ALIGN_TYPE. + */ + + typedef union small_pool_struct * small_pool_ptr; + + typedef union small_pool_struct { + struct { + small_pool_ptr next; /* next in list of pools */ + size_t bytes_used; /* how many bytes already used within pool */ + size_t bytes_left; /* bytes still available in this pool */ + } hdr; + ALIGN_TYPE dummy; /* included in union to ensure alignment */ + } small_pool_hdr; + + typedef union large_pool_struct FAR * large_pool_ptr; + + typedef union large_pool_struct { + struct { + large_pool_ptr next; /* next in list of pools */ + size_t bytes_used; /* how many bytes already used within pool */ + size_t bytes_left; /* bytes still available in this pool */ + } hdr; + ALIGN_TYPE dummy; /* included in union to ensure alignment */ + } large_pool_hdr; + + + /* + * Here is the full definition of a memory manager object. + */ + + typedef struct { + struct jpeg_memory_mgr pub; /* public fields */ + + /* Each pool identifier (lifetime class) names a linked list of pools. */ + small_pool_ptr small_list[JPOOL_NUMPOOLS]; + large_pool_ptr large_list[JPOOL_NUMPOOLS]; + + /* Since we only have one lifetime class of virtual arrays, only one + * linked list is necessary (for each datatype). Note that the virtual + * array control blocks being linked together are actually stored somewhere + * in the small-pool list. + */ + jvirt_sarray_ptr virt_sarray_list; + jvirt_barray_ptr virt_barray_list; + + /* This counts total space obtained from jpeg_get_small/large */ + long total_space_allocated; + + /* alloc_sarray and alloc_barray set this value for use by virtual + * array routines. + */ + JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */ + } my_memory_mgr; + + typedef my_memory_mgr * my_mem_ptr; + + + /* + * The control blocks for virtual arrays. + * Note that these blocks are allocated in the "small" pool area. + * System-dependent info for the associated backing store (if any) is hidden + * inside the backing_store_info struct. + */ + + struct jvirt_sarray_control { + JSAMPARRAY mem_buffer; /* => the in-memory buffer */ + JDIMENSION rows_in_array; /* total virtual array height */ + JDIMENSION samplesperrow; /* width of array (and of memory buffer) */ + JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */ + JDIMENSION rows_in_mem; /* height of memory buffer */ + JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ + JDIMENSION cur_start_row; /* first logical row # in the buffer */ + JDIMENSION first_undef_row; /* row # of first uninitialized row */ + boolean pre_zero; /* pre-zero mode requested? */ + boolean dirty; /* do current buffer contents need written? */ + boolean b_s_open; /* is backing-store data valid? */ + jvirt_sarray_ptr next; /* link to next virtual sarray control block */ + backing_store_info b_s_info; /* System-dependent control info */ + }; + + struct jvirt_barray_control { + JBLOCKARRAY mem_buffer; /* => the in-memory buffer */ + JDIMENSION rows_in_array; /* total virtual array height */ + JDIMENSION blocksperrow; /* width of array (and of memory buffer) */ + JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */ + JDIMENSION rows_in_mem; /* height of memory buffer */ + JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ + JDIMENSION cur_start_row; /* first logical row # in the buffer */ + JDIMENSION first_undef_row; /* row # of first uninitialized row */ + boolean pre_zero; /* pre-zero mode requested? */ + boolean dirty; /* do current buffer contents need written? */ + boolean b_s_open; /* is backing-store data valid? */ + jvirt_barray_ptr next; /* link to next virtual barray control block */ + backing_store_info b_s_info; /* System-dependent control info */ + }; + + + #ifdef MEM_STATS /* optional extra stuff for statistics */ + + LOCAL(void) + print_mem_stats (j_common_ptr cinfo, int pool_id) + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + small_pool_ptr shdr_ptr; + large_pool_ptr lhdr_ptr; + + /* Since this is only a debugging stub, we can cheat a little by using + * fprintf directly rather than going through the trace message code. + * This is helpful because message parm array can't handle longs. + */ + fprintf(stderr, "Freeing pool %d, total space = %ld\n", + pool_id, mem->total_space_allocated); + + for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL; + lhdr_ptr = lhdr_ptr->hdr.next) { + fprintf(stderr, " Large chunk used %ld\n", + (long) lhdr_ptr->hdr.bytes_used); + } + + for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL; + shdr_ptr = shdr_ptr->hdr.next) { + fprintf(stderr, " Small chunk used %ld free %ld\n", + (long) shdr_ptr->hdr.bytes_used, + (long) shdr_ptr->hdr.bytes_left); + } + } + + #endif /* MEM_STATS */ + + + LOCAL(void) + out_of_memory (j_common_ptr cinfo, int which) + /* Report an out-of-memory error and stop execution */ + /* If we compiled MEM_STATS support, report alloc requests before dying */ + { + #ifdef MEM_STATS + cinfo->err->trace_level = 2; /* force self_destruct to report stats */ + #endif + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which); + } + + + /* + * Allocation of "small" objects. + * + * For these, we use pooled storage. When a new pool must be created, + * we try to get enough space for the current request plus a "slop" factor, + * where the slop will be the amount of leftover space in the new pool. + * The speed vs. space tradeoff is largely determined by the slop values. + * A different slop value is provided for each pool class (lifetime), + * and we also distinguish the first pool of a class from later ones. + * NOTE: the values given work fairly well on both 16- and 32-bit-int + * machines, but may be too small if longs are 64 bits or more. + */ + + static const size_t first_pool_slop[JPOOL_NUMPOOLS] = + { + 1600, /* first PERMANENT pool */ + 16000 /* first IMAGE pool */ + }; + + static const size_t extra_pool_slop[JPOOL_NUMPOOLS] = + { + 0, /* additional PERMANENT pools */ + 5000 /* additional IMAGE pools */ + }; + + #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */ + + + METHODDEF(void *) + alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject) + /* Allocate a "small" object */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + small_pool_ptr hdr_ptr, prev_hdr_ptr; + char * data_ptr; + size_t odd_bytes, min_request, slop; + + /* Check for unsatisfiable request (do now to ensure no overflow below) */ + if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr))) + out_of_memory(cinfo, 1); /* request exceeds malloc's ability */ + + /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */ + odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE); + if (odd_bytes > 0) + sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes; + + /* See if space is available in any existing pool */ + if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + prev_hdr_ptr = NULL; + hdr_ptr = mem->small_list[pool_id]; + while (hdr_ptr != NULL) { + if (hdr_ptr->hdr.bytes_left >= sizeofobject) + break; /* found pool with enough space */ + prev_hdr_ptr = hdr_ptr; + hdr_ptr = hdr_ptr->hdr.next; + } + + /* Time to make a new pool? */ + if (hdr_ptr == NULL) { + /* min_request is what we need now, slop is what will be leftover */ + min_request = sizeofobject + SIZEOF(small_pool_hdr); + if (prev_hdr_ptr == NULL) /* first pool in class? */ + slop = first_pool_slop[pool_id]; + else + slop = extra_pool_slop[pool_id]; + /* Don't ask for more than MAX_ALLOC_CHUNK */ + if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request)) + slop = (size_t) (MAX_ALLOC_CHUNK-min_request); + /* Try to get space, if fail reduce slop and try again */ + for (;;) { + hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop); + if (hdr_ptr != NULL) + break; + slop /= 2; + if (slop < MIN_SLOP) /* give up when it gets real small */ + out_of_memory(cinfo, 2); /* jpeg_get_small failed */ + } + mem->total_space_allocated += min_request + slop; + /* Success, initialize the new pool header and add to end of list */ + hdr_ptr->hdr.next = NULL; + hdr_ptr->hdr.bytes_used = 0; + hdr_ptr->hdr.bytes_left = sizeofobject + slop; + if (prev_hdr_ptr == NULL) /* first pool in class? */ + mem->small_list[pool_id] = hdr_ptr; + else + prev_hdr_ptr->hdr.next = hdr_ptr; + } + + /* OK, allocate the object from the current pool */ + data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */ + data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */ + hdr_ptr->hdr.bytes_used += sizeofobject; + hdr_ptr->hdr.bytes_left -= sizeofobject; + + return (void *) data_ptr; + } + + + /* + * Allocation of "large" objects. + * + * The external semantics of these are the same as "small" objects, + * except that FAR pointers are used on 80x86. However the pool + * management heuristics are quite different. We assume that each + * request is large enough that it may as well be passed directly to + * jpeg_get_large; the pool management just links everything together + * so that we can free it all on demand. + * Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY + * structures. The routines that create these structures (see below) + * deliberately bunch rows together to ensure a large request size. + */ + + METHODDEF(void FAR *) + alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject) + /* Allocate a "large" object */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + large_pool_ptr hdr_ptr; + size_t odd_bytes; + + /* Check for unsatisfiable request (do now to ensure no overflow below) */ + if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr))) + out_of_memory(cinfo, 3); /* request exceeds malloc's ability */ + + /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */ + odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE); + if (odd_bytes > 0) + sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes; + + /* Always make a new pool */ + if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + + hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject + + SIZEOF(large_pool_hdr)); + if (hdr_ptr == NULL) + out_of_memory(cinfo, 4); /* jpeg_get_large failed */ + mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr); + + /* Success, initialize the new pool header and add to list */ + hdr_ptr->hdr.next = mem->large_list[pool_id]; + /* We maintain space counts in each pool header for statistical purposes, + * even though they are not needed for allocation. + */ + hdr_ptr->hdr.bytes_used = sizeofobject; + hdr_ptr->hdr.bytes_left = 0; + mem->large_list[pool_id] = hdr_ptr; + + return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */ + } + + + /* + * Creation of 2-D sample arrays. + * The pointers are in near heap, the samples themselves in FAR heap. + * + * To minimize allocation overhead and to allow I/O of large contiguous + * blocks, we allocate the sample rows in groups of as many rows as possible + * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request. + * NB: the virtual array control routines, later in this file, know about + * this chunking of rows. The rowsperchunk value is left in the mem manager + * object so that it can be saved away if this sarray is the workspace for + * a virtual array. + */ + + METHODDEF(JSAMPARRAY) + alloc_sarray (j_common_ptr cinfo, int pool_id, + JDIMENSION samplesperrow, JDIMENSION numrows) + /* Allocate a 2-D sample array */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + JSAMPARRAY result; + JSAMPROW workspace; + JDIMENSION rowsperchunk, currow, i; + long ltemp; + + /* Calculate max # of rows allowed in one allocation chunk */ + ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / + ((long) samplesperrow * SIZEOF(JSAMPLE)); + if (ltemp <= 0) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + if (ltemp < (long) numrows) + rowsperchunk = (JDIMENSION) ltemp; + else + rowsperchunk = numrows; + mem->last_rowsperchunk = rowsperchunk; + + /* Get space for row pointers (small object) */ + result = (JSAMPARRAY) alloc_small(cinfo, pool_id, + (size_t) (numrows * SIZEOF(JSAMPROW))); + + /* Get the rows themselves (large objects) */ + currow = 0; + while (currow < numrows) { + rowsperchunk = MIN(rowsperchunk, numrows - currow); + workspace = (JSAMPROW) alloc_large(cinfo, pool_id, + (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow + * SIZEOF(JSAMPLE))); + for (i = rowsperchunk; i > 0; i--) { + result[currow++] = workspace; + workspace += samplesperrow; + } + } + + return result; + } + + + /* + * Creation of 2-D coefficient-block arrays. + * This is essentially the same as the code for sample arrays, above. + */ + + METHODDEF(JBLOCKARRAY) + alloc_barray (j_common_ptr cinfo, int pool_id, + JDIMENSION blocksperrow, JDIMENSION numrows) + /* Allocate a 2-D coefficient-block array */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + JBLOCKARRAY result; + JBLOCKROW workspace; + JDIMENSION rowsperchunk, currow, i; + long ltemp; + + /* Calculate max # of rows allowed in one allocation chunk */ + ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / + ((long) blocksperrow * SIZEOF(JBLOCK)); + if (ltemp <= 0) + ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + if (ltemp < (long) numrows) + rowsperchunk = (JDIMENSION) ltemp; + else + rowsperchunk = numrows; + mem->last_rowsperchunk = rowsperchunk; + + /* Get space for row pointers (small object) */ + result = (JBLOCKARRAY) alloc_small(cinfo, pool_id, + (size_t) (numrows * SIZEOF(JBLOCKROW))); + + /* Get the rows themselves (large objects) */ + currow = 0; + while (currow < numrows) { + rowsperchunk = MIN(rowsperchunk, numrows - currow); + workspace = (JBLOCKROW) alloc_large(cinfo, pool_id, + (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow + * SIZEOF(JBLOCK))); + for (i = rowsperchunk; i > 0; i--) { + result[currow++] = workspace; + workspace += blocksperrow; + } + } + + return result; + } + + + /* + * About virtual array management: + * + * The above "normal" array routines are only used to allocate strip buffers + * (as wide as the image, but just a few rows high). Full-image-sized buffers + * are handled as "virtual" arrays. The array is still accessed a strip at a + * time, but the memory manager must save the whole array for repeated + * accesses. The intended implementation is that there is a strip buffer in + * memory (as high as is possible given the desired memory limit), plus a + * backing file that holds the rest of the array. + * + * The request_virt_array routines are told the total size of the image and + * the maximum number of rows that will be accessed at once. The in-memory + * buffer must be at least as large as the maxaccess value. + * + * The request routines create control blocks but not the in-memory buffers. + * That is postponed until realize_virt_arrays is called. At that time the + * total amount of space needed is known (approximately, anyway), so free + * memory can be divided up fairly. + * + * The access_virt_array routines are responsible for making a specific strip + * area accessible (after reading or writing the backing file, if necessary). + * Note that the access routines are told whether the caller intends to modify + * the accessed strip; during a read-only pass this saves having to rewrite + * data to disk. The access routines are also responsible for pre-zeroing + * any newly accessed rows, if pre-zeroing was requested. + * + * In current usage, the access requests are usually for nonoverlapping + * strips; that is, successive access start_row numbers differ by exactly + * num_rows = maxaccess. This means we can get good performance with simple + * buffer dump/reload logic, by making the in-memory buffer be a multiple + * of the access height; then there will never be accesses across bufferload + * boundaries. The code will still work with overlapping access requests, + * but it doesn't handle bufferload overlaps very efficiently. + */ + + + METHODDEF(jvirt_sarray_ptr) + request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero, + JDIMENSION samplesperrow, JDIMENSION numrows, + JDIMENSION maxaccess) + /* Request a virtual 2-D sample array */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + jvirt_sarray_ptr result; + + /* Only IMAGE-lifetime virtual arrays are currently supported */ + if (pool_id != JPOOL_IMAGE) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + + /* get control block */ + result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id, + SIZEOF(struct jvirt_sarray_control)); + + result->mem_buffer = NULL; /* marks array not yet realized */ + result->rows_in_array = numrows; + result->samplesperrow = samplesperrow; + result->maxaccess = maxaccess; + result->pre_zero = pre_zero; + result->b_s_open = FALSE; /* no associated backing-store object */ + result->next = mem->virt_sarray_list; /* add to list of virtual arrays */ + mem->virt_sarray_list = result; + + return result; + } + + + METHODDEF(jvirt_barray_ptr) + request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero, + JDIMENSION blocksperrow, JDIMENSION numrows, + JDIMENSION maxaccess) + /* Request a virtual 2-D coefficient-block array */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + jvirt_barray_ptr result; + + /* Only IMAGE-lifetime virtual arrays are currently supported */ + if (pool_id != JPOOL_IMAGE) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + + /* get control block */ + result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id, + SIZEOF(struct jvirt_barray_control)); + + result->mem_buffer = NULL; /* marks array not yet realized */ + result->rows_in_array = numrows; + result->blocksperrow = blocksperrow; + result->maxaccess = maxaccess; + result->pre_zero = pre_zero; + result->b_s_open = FALSE; /* no associated backing-store object */ + result->next = mem->virt_barray_list; /* add to list of virtual arrays */ + mem->virt_barray_list = result; + + return result; + } + + + METHODDEF(void) + realize_virt_arrays (j_common_ptr cinfo) + /* Allocate the in-memory buffers for any unrealized virtual arrays */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + long space_per_minheight, maximum_space, avail_mem; + long minheights, max_minheights; + jvirt_sarray_ptr sptr; + jvirt_barray_ptr bptr; + + /* Compute the minimum space needed (maxaccess rows in each buffer) + * and the maximum space needed (full image height in each buffer). + * These may be of use to the system-dependent jpeg_mem_available routine. + */ + space_per_minheight = 0; + maximum_space = 0; + for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { + if (sptr->mem_buffer == NULL) { /* if not realized yet */ + space_per_minheight += (long) sptr->maxaccess * + (long) sptr->samplesperrow * SIZEOF(JSAMPLE); + maximum_space += (long) sptr->rows_in_array * + (long) sptr->samplesperrow * SIZEOF(JSAMPLE); + } + } + for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { + if (bptr->mem_buffer == NULL) { /* if not realized yet */ + space_per_minheight += (long) bptr->maxaccess * + (long) bptr->blocksperrow * SIZEOF(JBLOCK); + maximum_space += (long) bptr->rows_in_array * + (long) bptr->blocksperrow * SIZEOF(JBLOCK); + } + } + + if (space_per_minheight <= 0) + return; /* no unrealized arrays, no work */ + + /* Determine amount of memory to actually use; this is system-dependent. */ + avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space, + mem->total_space_allocated); + + /* If the maximum space needed is available, make all the buffers full + * height; otherwise parcel it out with the same number of minheights + * in each buffer. + */ + if (avail_mem >= maximum_space) + max_minheights = 1000000000L; + else { + max_minheights = avail_mem / space_per_minheight; + /* If there doesn't seem to be enough space, try to get the minimum + * anyway. This allows a "stub" implementation of jpeg_mem_available(). + */ + if (max_minheights <= 0) + max_minheights = 1; + } + + /* Allocate the in-memory buffers and initialize backing store as needed. */ + + for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { + if (sptr->mem_buffer == NULL) { /* if not realized yet */ + minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L; + if (minheights <= max_minheights) { + /* This buffer fits in memory */ + sptr->rows_in_mem = sptr->rows_in_array; + } else { + /* It doesn't fit in memory, create backing store. */ + sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess); + jpeg_open_backing_store(cinfo, & sptr->b_s_info, + (long) sptr->rows_in_array * + (long) sptr->samplesperrow * + (long) SIZEOF(JSAMPLE)); + sptr->b_s_open = TRUE; + } + sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE, + sptr->samplesperrow, sptr->rows_in_mem); + sptr->rowsperchunk = mem->last_rowsperchunk; + sptr->cur_start_row = 0; + sptr->first_undef_row = 0; + sptr->dirty = FALSE; + } + } + + for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { + if (bptr->mem_buffer == NULL) { /* if not realized yet */ + minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L; + if (minheights <= max_minheights) { + /* This buffer fits in memory */ + bptr->rows_in_mem = bptr->rows_in_array; + } else { + /* It doesn't fit in memory, create backing store. */ + bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess); + jpeg_open_backing_store(cinfo, & bptr->b_s_info, + (long) bptr->rows_in_array * + (long) bptr->blocksperrow * + (long) SIZEOF(JBLOCK)); + bptr->b_s_open = TRUE; + } + bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE, + bptr->blocksperrow, bptr->rows_in_mem); + bptr->rowsperchunk = mem->last_rowsperchunk; + bptr->cur_start_row = 0; + bptr->first_undef_row = 0; + bptr->dirty = FALSE; + } + } + } + + + LOCAL(void) + do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing) + /* Do backing store read or write of a virtual sample array */ + { + long bytesperrow, file_offset, byte_count, rows, thisrow, i; + + bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE); + file_offset = ptr->cur_start_row * bytesperrow; + /* Loop to read or write each allocation chunk in mem_buffer */ + for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { + /* One chunk, but check for short chunk at end of buffer */ + rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i); + /* Transfer no more than is currently defined */ + thisrow = (long) ptr->cur_start_row + i; + rows = MIN(rows, (long) ptr->first_undef_row - thisrow); + /* Transfer no more than fits in file */ + rows = MIN(rows, (long) ptr->rows_in_array - thisrow); + if (rows <= 0) /* this chunk might be past end of file! */ + break; + byte_count = rows * bytesperrow; + if (writing) + (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + else + (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + file_offset += byte_count; + } + } + + + LOCAL(void) + do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing) + /* Do backing store read or write of a virtual coefficient-block array */ + { + long bytesperrow, file_offset, byte_count, rows, thisrow, i; + + bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK); + file_offset = ptr->cur_start_row * bytesperrow; + /* Loop to read or write each allocation chunk in mem_buffer */ + for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) { + /* One chunk, but check for short chunk at end of buffer */ + rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i); + /* Transfer no more than is currently defined */ + thisrow = (long) ptr->cur_start_row + i; + rows = MIN(rows, (long) ptr->first_undef_row - thisrow); + /* Transfer no more than fits in file */ + rows = MIN(rows, (long) ptr->rows_in_array - thisrow); + if (rows <= 0) /* this chunk might be past end of file! */ + break; + byte_count = rows * bytesperrow; + if (writing) + (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + else + (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, + (void FAR *) ptr->mem_buffer[i], + file_offset, byte_count); + file_offset += byte_count; + } + } + + + METHODDEF(JSAMPARRAY) + access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr, + JDIMENSION start_row, JDIMENSION num_rows, + boolean writable) + /* Access the part of a virtual sample array starting at start_row */ + /* and extending for num_rows rows. writable is true if */ + /* caller intends to modify the accessed area. */ + { + JDIMENSION end_row = start_row + num_rows; + JDIMENSION undef_row; + + /* debugging check */ + if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess || + ptr->mem_buffer == NULL) + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + + /* Make the desired part of the virtual array accessible */ + if (start_row < ptr->cur_start_row || + end_row > ptr->cur_start_row+ptr->rows_in_mem) { + if (! ptr->b_s_open) + ERREXIT(cinfo, JERR_VIRTUAL_BUG); + /* Flush old buffer contents if necessary */ + if (ptr->dirty) { + do_sarray_io(cinfo, ptr, TRUE); + ptr->dirty = FALSE; + } + /* Decide what part of virtual array to access. + * Algorithm: if target address > current window, assume forward scan, + * load starting at target address. If target address < current window, + * assume backward scan, load so that target area is top of window. + * Note that when switching from forward write to forward read, will have + * start_row = 0, so the limiting case applies and we load from 0 anyway. + */ + if (start_row > ptr->cur_start_row) { + ptr->cur_start_row = start_row; + } else { + /* use long arithmetic here to avoid overflow & unsigned problems */ + long ltemp; + + ltemp = (long) end_row - (long) ptr->rows_in_mem; + if (ltemp < 0) + ltemp = 0; /* don't fall off front end of file */ + ptr->cur_start_row = (JDIMENSION) ltemp; + } + /* Read in the selected part of the array. + * During the initial write pass, we will do no actual read + * because the selected part is all undefined. + */ + do_sarray_io(cinfo, ptr, FALSE); + } + /* Ensure the accessed part of the array is defined; prezero if needed. + * To improve locality of access, we only prezero the part of the array + * that the caller is about to access, not the entire in-memory array. + */ + if (ptr->first_undef_row < end_row) { + if (ptr->first_undef_row < start_row) { + if (writable) /* writer skipped over a section of array */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + undef_row = start_row; /* but reader is allowed to read ahead */ + } else { + undef_row = ptr->first_undef_row; + } + if (writable) + ptr->first_undef_row = end_row; + if (ptr->pre_zero) { + size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE); + undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ + end_row -= ptr->cur_start_row; + while (undef_row < end_row) { + jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); + undef_row++; + } + } else { + if (! writable) /* reader looking at undefined data */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + } + } + /* Flag the buffer dirty if caller will write in it */ + if (writable) + ptr->dirty = TRUE; + /* Return address of proper part of the buffer */ + return ptr->mem_buffer + (start_row - ptr->cur_start_row); + } + + + METHODDEF(JBLOCKARRAY) + access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr, + JDIMENSION start_row, JDIMENSION num_rows, + boolean writable) + /* Access the part of a virtual block array starting at start_row */ + /* and extending for num_rows rows. writable is true if */ + /* caller intends to modify the accessed area. */ + { + JDIMENSION end_row = start_row + num_rows; + JDIMENSION undef_row; + + /* debugging check */ + if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess || + ptr->mem_buffer == NULL) + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + + /* Make the desired part of the virtual array accessible */ + if (start_row < ptr->cur_start_row || + end_row > ptr->cur_start_row+ptr->rows_in_mem) { + if (! ptr->b_s_open) + ERREXIT(cinfo, JERR_VIRTUAL_BUG); + /* Flush old buffer contents if necessary */ + if (ptr->dirty) { + do_barray_io(cinfo, ptr, TRUE); + ptr->dirty = FALSE; + } + /* Decide what part of virtual array to access. + * Algorithm: if target address > current window, assume forward scan, + * load starting at target address. If target address < current window, + * assume backward scan, load so that target area is top of window. + * Note that when switching from forward write to forward read, will have + * start_row = 0, so the limiting case applies and we load from 0 anyway. + */ + if (start_row > ptr->cur_start_row) { + ptr->cur_start_row = start_row; + } else { + /* use long arithmetic here to avoid overflow & unsigned problems */ + long ltemp; + + ltemp = (long) end_row - (long) ptr->rows_in_mem; + if (ltemp < 0) + ltemp = 0; /* don't fall off front end of file */ + ptr->cur_start_row = (JDIMENSION) ltemp; + } + /* Read in the selected part of the array. + * During the initial write pass, we will do no actual read + * because the selected part is all undefined. + */ + do_barray_io(cinfo, ptr, FALSE); + } + /* Ensure the accessed part of the array is defined; prezero if needed. + * To improve locality of access, we only prezero the part of the array + * that the caller is about to access, not the entire in-memory array. + */ + if (ptr->first_undef_row < end_row) { + if (ptr->first_undef_row < start_row) { + if (writable) /* writer skipped over a section of array */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + undef_row = start_row; /* but reader is allowed to read ahead */ + } else { + undef_row = ptr->first_undef_row; + } + if (writable) + ptr->first_undef_row = end_row; + if (ptr->pre_zero) { + size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK); + undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ + end_row -= ptr->cur_start_row; + while (undef_row < end_row) { + jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); + undef_row++; + } + } else { + if (! writable) /* reader looking at undefined data */ + ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); + } + } + /* Flag the buffer dirty if caller will write in it */ + if (writable) + ptr->dirty = TRUE; + /* Return address of proper part of the buffer */ + return ptr->mem_buffer + (start_row - ptr->cur_start_row); + } + + + /* + * Release all objects belonging to a specified pool. + */ + + METHODDEF(void) + free_pool (j_common_ptr cinfo, int pool_id) + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; + small_pool_ptr shdr_ptr; + large_pool_ptr lhdr_ptr; + size_t space_freed; + + if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) + ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ + + #ifdef MEM_STATS + if (cinfo->err->trace_level > 1) + print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */ + #endif + + /* If freeing IMAGE pool, close any virtual arrays first */ + if (pool_id == JPOOL_IMAGE) { + jvirt_sarray_ptr sptr; + jvirt_barray_ptr bptr; + + for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { + if (sptr->b_s_open) { /* there may be no backing store */ + sptr->b_s_open = FALSE; /* prevent recursive close if error */ + (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info); + } + } + mem->virt_sarray_list = NULL; + for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { + if (bptr->b_s_open) { /* there may be no backing store */ + bptr->b_s_open = FALSE; /* prevent recursive close if error */ + (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info); + } + } + mem->virt_barray_list = NULL; + } + + /* Release large objects */ + lhdr_ptr = mem->large_list[pool_id]; + mem->large_list[pool_id] = NULL; + + while (lhdr_ptr != NULL) { + large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next; + space_freed = lhdr_ptr->hdr.bytes_used + + lhdr_ptr->hdr.bytes_left + + SIZEOF(large_pool_hdr); + jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed); + mem->total_space_allocated -= space_freed; + lhdr_ptr = next_lhdr_ptr; + } + + /* Release small objects */ + shdr_ptr = mem->small_list[pool_id]; + mem->small_list[pool_id] = NULL; + + while (shdr_ptr != NULL) { + small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next; + space_freed = shdr_ptr->hdr.bytes_used + + shdr_ptr->hdr.bytes_left + + SIZEOF(small_pool_hdr); + jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed); + mem->total_space_allocated -= space_freed; + shdr_ptr = next_shdr_ptr; + } + } + + + /* + * Close up shop entirely. + * Note that this cannot be called unless cinfo->mem is non-NULL. + */ + + METHODDEF(void) + self_destruct (j_common_ptr cinfo) + { + int pool; + + /* Close all backing store, release all memory. + * Releasing pools in reverse order might help avoid fragmentation + * with some (brain-damaged) malloc libraries. + */ + for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) { + free_pool(cinfo, pool); + } + + /* Release the memory manager control block too. */ + jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr)); + cinfo->mem = NULL; /* ensures I will be called only once */ + + jpeg_mem_term(cinfo); /* system-dependent cleanup */ + } + + + /* + * Memory manager initialization. + * When this is called, only the error manager pointer is valid in cinfo! + */ + + GLOBAL(void) + jinit_memory_mgr (j_common_ptr cinfo) + { + my_mem_ptr mem; + long max_to_use; + int pool; + size_t test_mac; + + cinfo->mem = NULL; /* for safety if init fails */ + + /* Check for configuration errors. + * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably + * doesn't reflect any real hardware alignment requirement. + * The test is a little tricky: for X>0, X and X-1 have no one-bits + * in common if and only if X is a power of 2, ie has only one one-bit. + * Some compilers may give an "unreachable code" warning here; ignore it. + */ + if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0) + ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE); + /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be + * a multiple of SIZEOF(ALIGN_TYPE). + * Again, an "unreachable code" warning may be ignored here. + * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK. + */ + test_mac = (size_t) MAX_ALLOC_CHUNK; + if ((long) test_mac != MAX_ALLOC_CHUNK || + (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0) + ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK); + + max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */ + + /* Attempt to allocate memory manager's control block */ + mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr)); + + if (mem == NULL) { + jpeg_mem_term(cinfo); /* system-dependent cleanup */ + ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0); + } + + /* OK, fill in the method pointers */ + mem->pub.alloc_small = alloc_small; + mem->pub.alloc_large = alloc_large; + mem->pub.alloc_sarray = alloc_sarray; + mem->pub.alloc_barray = alloc_barray; + mem->pub.request_virt_sarray = request_virt_sarray; + mem->pub.request_virt_barray = request_virt_barray; + mem->pub.realize_virt_arrays = realize_virt_arrays; + mem->pub.access_virt_sarray = access_virt_sarray; + mem->pub.access_virt_barray = access_virt_barray; + mem->pub.free_pool = free_pool; + mem->pub.self_destruct = self_destruct; + + /* Initialize working state */ + mem->pub.max_memory_to_use = max_to_use; + + for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) { + mem->small_list[pool] = NULL; + mem->large_list[pool] = NULL; + } + mem->virt_sarray_list = NULL; + mem->virt_barray_list = NULL; + + mem->total_space_allocated = SIZEOF(my_memory_mgr); + + /* Declare ourselves open for business */ + cinfo->mem = & mem->pub; + + /* Check for an environment variable JPEGMEM; if found, override the + * default max_memory setting from jpeg_mem_init. Note that the + * surrounding application may again override this value. + * If your system doesn't support getenv(), define NO_GETENV to disable + * this feature. + */ + #ifndef NO_GETENV + { char * memenv; + + if ((memenv = getenv("JPEGMEM")) != NULL) { + char ch = 'x'; + + if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) { + if (ch == 'm' || ch == 'M') + max_to_use *= 1000L; + mem->pub.max_memory_to_use = max_to_use * 1000L; + } + } + } + #endif + + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemnobs.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemnobs.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemnobs.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,109 ---- + /* + * jmemnobs.c + * + * Copyright (C) 1992-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file provides a really simple implementation of the system- + * dependent portion of the JPEG memory manager. This implementation + * assumes that no backing-store files are needed: all required space + * can be obtained from malloc(). + * This is very portable in the sense that it'll compile on almost anything, + * but you'd better have lots of main memory (or virtual memory) if you want + * to process big images. + * Note that the max_memory_to_use option is ignored by this implementation. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + #include "jmemsys.h" /* import the system-dependent declarations */ + + #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ + extern void * malloc JPP((size_t size)); + extern void free JPP((void *ptr)); + #endif + + + /* + * Memory allocation and freeing are controlled by the regular library + * routines malloc() and free(). + */ + + GLOBAL(void *) + jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) + { + return (void *) malloc(sizeofobject); + } + + GLOBAL(void) + jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) + { + free(object); + } + + + /* + * "Large" objects are treated the same as "small" ones. + * NB: although we include FAR keywords in the routine declarations, + * this file won't actually work in 80x86 small/medium model; at least, + * you probably won't be able to process useful-size images in only 64KB. + */ + + GLOBAL(void FAR *) + jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) + { + return (void FAR *) malloc(sizeofobject); + } + + GLOBAL(void) + jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) + { + free(object); + } + + + /* + * This routine computes the total memory space available for allocation. + * Here we always say, "we got all you want bud!" + */ + + GLOBAL(long) + jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, + long max_bytes_needed, long already_allocated) + { + return max_bytes_needed; + } + + + /* + * Backing store (temporary file) management. + * Since jpeg_mem_available always promised the moon, + * this should never be called and we can just error out. + */ + + GLOBAL(void) + jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, + long total_bytes_needed) + { + ERREXIT(cinfo, JERR_NO_BACKING_STORE); + } + + + /* + * These routines take care of any system-dependent initialization and + * cleanup required. Here, there isn't any. + */ + + GLOBAL(long) + jpeg_mem_init (j_common_ptr cinfo) + { + return 0; /* just set max_memory_to_use to 0 */ + } + + GLOBAL(void) + jpeg_mem_term (j_common_ptr cinfo) + { + /* no work */ + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemsys.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemsys.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmemsys.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,183 ---- + /* + * jmemsys.h + * + * Copyright (C) 1992-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This include file defines the interface between the system-independent + * and system-dependent portions of the JPEG memory manager. No other + * modules need include it. (The system-independent portion is jmemmgr.c; + * there are several different versions of the system-dependent portion.) + * + * This file works as-is for the system-dependent memory managers supplied + * in the IJG distribution. You may need to modify it if you write a + * custom memory manager. If system-dependent changes are needed in + * this file, the best method is to #ifdef them based on a configuration + * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR. + */ + + + /* Short forms of external names for systems with brain-damaged linkers. */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jpeg_get_small jGetSmall + #define jpeg_free_small jFreeSmall + #define jpeg_get_large jGetLarge + #define jpeg_free_large jFreeLarge + #define jpeg_mem_available jMemAvail + #define jpeg_open_backing_store jOpenBackStore + #define jpeg_mem_init jMemInit + #define jpeg_mem_term jMemTerm + #endif /* NEED_SHORT_EXTERNAL_NAMES */ + + + /* + * These two functions are used to allocate and release small chunks of + * memory. (Typically the total amount requested through jpeg_get_small is + * no more than 20K or so; this will be requested in chunks of a few K each.) + * Behavior should be the same as for the standard library functions malloc + * and free; in particular, jpeg_get_small must return NULL on failure. + * On most systems, these ARE malloc and free. jpeg_free_small is passed the + * size of the object being freed, just in case it's needed. + * On an 80x86 machine using small-data memory model, these manage near heap. + */ + + EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject)); + EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object, + size_t sizeofobject)); + + /* + * These two functions are used to allocate and release large chunks of + * memory (up to the total free space designated by jpeg_mem_available). + * The interface is the same as above, except that on an 80x86 machine, + * far pointers are used. On most other machines these are identical to + * the jpeg_get/free_small routines; but we keep them separate anyway, + * in case a different allocation strategy is desirable for large chunks. + */ + + EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo, + size_t sizeofobject)); + EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object, + size_t sizeofobject)); + + /* + * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may + * be requested in a single call to jpeg_get_large (and jpeg_get_small for that + * matter, but that case should never come into play). This macro is needed + * to model the 64Kb-segment-size limit of far addressing on 80x86 machines. + * On those machines, we expect that jconfig.h will provide a proper value. + * On machines with 32-bit flat address spaces, any large constant may be used. + * + * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type + * size_t and will be a multiple of sizeof(align_type). + */ + + #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */ + #define MAX_ALLOC_CHUNK 1000000000L + #endif + + /* + * This routine computes the total space still available for allocation by + * jpeg_get_large. If more space than this is needed, backing store will be + * used. NOTE: any memory already allocated must not be counted. + * + * There is a minimum space requirement, corresponding to the minimum + * feasible buffer sizes; jmemmgr.c will request that much space even if + * jpeg_mem_available returns zero. The maximum space needed, enough to hold + * all working storage in memory, is also passed in case it is useful. + * Finally, the total space already allocated is passed. If no better + * method is available, cinfo->mem->max_memory_to_use - already_allocated + * is often a suitable calculation. + * + * It is OK for jpeg_mem_available to underestimate the space available + * (that'll just lead to more backing-store access than is really necessary). + * However, an overestimate will lead to failure. Hence it's wise to subtract + * a slop factor from the true available space. 5% should be enough. + * + * On machines with lots of virtual memory, any large constant may be returned. + * Conversely, zero may be returned to always use the minimum amount of memory. + */ + + EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo, + long min_bytes_needed, + long max_bytes_needed, + long already_allocated)); + + + /* + * This structure holds whatever state is needed to access a single + * backing-store object. The read/write/close method pointers are called + * by jmemmgr.c to manipulate the backing-store object; all other fields + * are private to the system-dependent backing store routines. + */ + + #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */ + + #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */ + + typedef unsigned short XMSH; /* type of extended-memory handles */ + typedef unsigned short EMSH; /* type of expanded-memory handles */ + + typedef union { + short file_handle; /* DOS file handle if it's a temp file */ + XMSH xms_handle; /* handle if it's a chunk of XMS */ + EMSH ems_handle; /* handle if it's a chunk of EMS */ + } handle_union; + + #endif /* USE_MSDOS_MEMMGR */ + + typedef struct backing_store_struct * backing_store_ptr; + + typedef struct backing_store_struct { + /* Methods for reading/writing/closing this backing-store object */ + JMETHOD(void, read_backing_store, (j_common_ptr cinfo, + backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count)); + JMETHOD(void, write_backing_store, (j_common_ptr cinfo, + backing_store_ptr info, + void FAR * buffer_address, + long file_offset, long byte_count)); + JMETHOD(void, close_backing_store, (j_common_ptr cinfo, + backing_store_ptr info)); + + /* Private fields for system-dependent backing-store management */ + #ifdef USE_MSDOS_MEMMGR + /* For the MS-DOS manager (jmemdos.c), we need: */ + handle_union handle; /* reference to backing-store storage object */ + char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ + #else + /* For a typical implementation with temp files, we need: */ + FILE * temp_file; /* stdio reference to temp file */ + char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */ + #endif + } backing_store_info; + + /* + * Initial opening of a backing-store object. This must fill in the + * read/write/close pointers in the object. The read/write routines + * may take an error exit if the specified maximum file size is exceeded. + * (If jpeg_mem_available always returns a large value, this routine can + * just take an error exit.) + */ + + EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo, + backing_store_ptr info, + long total_bytes_needed)); + + + /* + * These routines take care of any system-dependent initialization and + * cleanup required. jpeg_mem_init will be called before anything is + * allocated (and, therefore, nothing in cinfo is of use except the error + * manager pointer). It should return a suitable default value for + * max_memory_to_use; this may subsequently be overridden by the surrounding + * application. (Note that max_memory_to_use is only important if + * jpeg_mem_available chooses to consult it ... no one else will.) + * jpeg_mem_term may assume that all requested memory has been freed and that + * all opened backing-store objects have been closed. + */ + + EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo)); + EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo)); Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmorecfg.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmorecfg.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jmorecfg.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,362 ---- + /* + * jmorecfg.h + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains additional configuration options that customize the + * JPEG software for special applications or support machine-dependent + * optimizations. Most users will not need to touch this file. + */ + + + /* + * Define BITS_IN_JSAMPLE as either + * 8 for 8-bit sample values (the usual setting) + * 12 for 12-bit sample values + * Only 8 and 12 are legal data precisions for lossy JPEG according to the + * JPEG standard, and the IJG code does not support anything else! + * We do not support run-time selection of data precision, sorry. + */ + + #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ + + + /* + * Maximum number of components (color channels) allowed in JPEG image. + * To meet the letter of the JPEG spec, set this to 255. However, darn + * few applications need more than 4 channels (maybe 5 for CMYK + alpha + * mask). We recommend 10 as a reasonable compromise; use 4 if you are + * really short on memory. (Each allowed component costs a hundred or so + * bytes of storage, whether actually used in an image or not.) + */ + + #define MAX_COMPONENTS 10 /* maximum number of image components */ + + + /* + * Basic data types. + * You may need to change these if you have a machine with unusual data + * type sizes; for example, "char" not 8 bits, "short" not 16 bits, + * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits, + * but it had better be at least 16. + */ + + /* Representation of a single sample (pixel element value). + * We frequently allocate large arrays of these, so it's important to keep + * them small. But if you have memory to burn and access to char or short + * arrays is very slow on your hardware, you might want to change these. + */ + + #if BITS_IN_JSAMPLE == 8 + /* JSAMPLE should be the smallest type that will hold the values 0..255. + * You can use a signed char by having GETJSAMPLE mask it with 0xFF. + */ + + #ifdef HAVE_UNSIGNED_CHAR + + typedef unsigned char JSAMPLE; + #define GETJSAMPLE(value) ((int) (value)) + + #else /* not HAVE_UNSIGNED_CHAR */ + + typedef char JSAMPLE; + #ifdef CHAR_IS_UNSIGNED + #define GETJSAMPLE(value) ((int) (value)) + #else + #define GETJSAMPLE(value) ((int) (value) & 0xFF) + #endif /* CHAR_IS_UNSIGNED */ + + #endif /* HAVE_UNSIGNED_CHAR */ + + #define MAXJSAMPLE 255 + #define CENTERJSAMPLE 128 + + #endif /* BITS_IN_JSAMPLE == 8 */ + + + #if BITS_IN_JSAMPLE == 12 + /* JSAMPLE should be the smallest type that will hold the values 0..4095. + * On nearly all machines "short" will do nicely. + */ + + typedef short JSAMPLE; + #define GETJSAMPLE(value) ((int) (value)) + + #define MAXJSAMPLE 4095 + #define CENTERJSAMPLE 2048 + + #endif /* BITS_IN_JSAMPLE == 12 */ + + + /* Representation of a DCT frequency coefficient. + * This should be a signed value of at least 16 bits; "short" is usually OK. + * Again, we allocate large arrays of these, but you can change to int + * if you have memory to burn and "short" is really slow. + */ + + typedef short JCOEF; + + + /* Compressed datastreams are represented as arrays of JOCTET. + * These must be EXACTLY 8 bits wide, at least once they are written to + * external storage. Note that when using the stdio data source/destination + * managers, this is also the data type passed to fread/fwrite. + */ + + #ifdef HAVE_UNSIGNED_CHAR + + typedef unsigned char JOCTET; + #define GETJOCTET(value) (value) + + #else /* not HAVE_UNSIGNED_CHAR */ + + typedef char JOCTET; + #ifdef CHAR_IS_UNSIGNED + #define GETJOCTET(value) (value) + #else + #define GETJOCTET(value) ((value) & 0xFF) + #endif /* CHAR_IS_UNSIGNED */ + + #endif /* HAVE_UNSIGNED_CHAR */ + + + /* These typedefs are used for various table entries and so forth. + * They must be at least as wide as specified; but making them too big + * won't cost a huge amount of memory, so we don't provide special + * extraction code like we did for JSAMPLE. (In other words, these + * typedefs live at a different point on the speed/space tradeoff curve.) + */ + + /* UINT8 must hold at least the values 0..255. */ + + #ifdef HAVE_UNSIGNED_CHAR + typedef unsigned char UINT8; + #else /* not HAVE_UNSIGNED_CHAR */ + #ifdef CHAR_IS_UNSIGNED + typedef char UINT8; + #else /* not CHAR_IS_UNSIGNED */ + typedef short UINT8; + #endif /* CHAR_IS_UNSIGNED */ + #endif /* HAVE_UNSIGNED_CHAR */ + + /* UINT16 must hold at least the values 0..65535. */ + + #ifdef HAVE_UNSIGNED_SHORT + typedef unsigned short UINT16; + #else /* not HAVE_UNSIGNED_SHORT */ + typedef unsigned int UINT16; + #endif /* HAVE_UNSIGNED_SHORT */ + + /* INT16 must hold at least the values -32768..32767. */ + + #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ + typedef short INT16; + #endif + + /* INT32 must hold at least signed 32-bit values. */ + + #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ + typedef long INT32; + #endif + + /* Datatype used for image dimensions. The JPEG standard only supports + * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore + * "unsigned int" is sufficient on all machines. However, if you need to + * handle larger images and you don't mind deviating from the spec, you + * can change this datatype. + */ + + typedef unsigned int JDIMENSION; + + #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */ + + + /* These macros are used in all function definitions and extern declarations. + * You could modify them if you need to change function linkage conventions; + * in particular, you'll need to do that to make the library a Windows DLL. + * Another application is to make all functions global for use with debuggers + * or code profilers that require it. + */ + + /* a function called through method pointers: */ + #define METHODDEF(type) static type + /* a function used only in its module: */ + #define LOCAL(type) static type + /* a function referenced thru EXTERNs: */ + #define GLOBAL(type) type + /* a reference to a GLOBAL function: */ + #define EXTERN(type) extern type + + + /* This macro is used to declare a "method", that is, a function pointer. + * We want to supply prototype parameters if the compiler can cope. + * Note that the arglist parameter must be parenthesized! + * Again, you can customize this if you need special linkage keywords. + */ + + #ifdef HAVE_PROTOTYPES + #define JMETHOD(type,methodname,arglist) type (*methodname) arglist + #else + #define JMETHOD(type,methodname,arglist) type (*methodname) () + #endif + + + /* Here is the pseudo-keyword for declaring pointers that must be "far" + * on 80x86 machines. Most of the specialized coding for 80x86 is handled + * by just saying "FAR *" where such a pointer is needed. In a few places + * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol. + */ + + #ifdef NEED_FAR_POINTERS + #define FAR far + #else + #define FAR + #endif + + + /* + * On a few systems, type boolean and/or its values FALSE, TRUE may appear + * in standard header files. Or you may have conflicts with application- + * specific header files that you want to include together with these files. + * Defining HAVE_BOOLEAN before including jpeglib.h should make it work. + */ + + #ifndef HAVE_BOOLEAN + typedef int boolean; + #endif + #ifndef FALSE /* in case these macros already exist */ + #define FALSE 0 /* values of boolean */ + #endif + #ifndef TRUE + #define TRUE 1 + #endif + + + /* + * The remaining options affect code selection within the JPEG library, + * but they don't need to be visible to most applications using the library. + * To minimize application namespace pollution, the symbols won't be + * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined. + */ + + #ifdef JPEG_INTERNALS + #define JPEG_INTERNAL_OPTIONS + #endif + + #ifdef JPEG_INTERNAL_OPTIONS + + + /* + * These defines indicate whether to include various optional functions. + * Undefining some of these symbols will produce a smaller but less capable + * library. Note that you can leave certain source files out of the + * compilation/linking process if you've #undef'd the corresponding symbols. + * (You may HAVE to do that if your compiler doesn't like null source files.) + */ + + /* Arithmetic coding is unsupported for legal reasons. Complaints to IBM. */ + + /* Capability options common to encoder and decoder: */ + + #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ + #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ + #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ + + /* Encoder capability options: */ + + #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ + #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ + #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ + #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ + /* Note: if you selected 12-bit data precision, it is dangerous to turn off + * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit + * precision, so jchuff.c normally uses entropy optimization to compute + * usable tables for higher precision. If you don't want to do optimization, + * you'll have to supply different default Huffman tables. + * The exact same statements apply for progressive JPEG: the default tables + * don't work for progressive mode. (This may get fixed, however.) + */ + #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */ + + /* Decoder capability options: */ + + #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ + #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ + #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ + #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ + #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ + #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ + #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ + #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ + #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ + + /* more capability options later, no doubt */ + + + /* + * Ordering of RGB data in scanlines passed to or from the application. + * If your application wants to deal with data in the order B,G,R, just + * change these macros. You can also deal with formats such as R,G,B,X + * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing + * the offsets will also change the order in which colormap data is organized. + * RESTRICTIONS: + * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. + * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not + * useful if you are using JPEG color spaces other than YCbCr or grayscale. + * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE + * is not 3 (they don't understand about dummy color components!). So you + * can't use color quantization if you change that value. + */ + + #define RGB_RED 0 /* Offset of Red in an RGB scanline element */ + #define RGB_GREEN 1 /* Offset of Green */ + #define RGB_BLUE 2 /* Offset of Blue */ + #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ + + + /* Definitions for speed-related optimizations. */ + + + /* If your compiler supports inline functions, define INLINE + * as the inline keyword; otherwise define it as empty. + */ + + #ifndef INLINE + #ifdef __GNUC__ /* for instance, GNU C knows about inline */ + #define INLINE __inline__ + #endif + #ifndef INLINE + #define INLINE /* default is to define it as empty */ + #endif + #endif + + + /* On some machines (notably 68000 series) "int" is 32 bits, but multiplying + * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER + * as short on such a machine. MULTIPLIER must be at least 16 bits wide. + */ + + #ifndef MULTIPLIER + #define MULTIPLIER int /* type for fastest integer multiply */ + #endif + + + /* FAST_FLOAT should be either float or double, whichever is done faster + * by your compiler. (Note that this type is only used in the floating point + * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) + * Typically, float is faster in ANSI C compilers, while double is faster in + * pre-ANSI compilers (because they insist on converting to double anyway). + * The code below therefore chooses float if we have ANSI-style prototypes. + */ + + #ifndef FAST_FLOAT + #ifdef HAVE_PROTOTYPES + #define FAST_FLOAT float + #else + #define FAST_FLOAT double + #endif + #endif + + #endif /* JPEG_INTERNAL_OPTIONS */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jpegint.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jpegint.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jpegint.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,388 ---- + /* + * jpegint.h + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file provides common declarations for the various JPEG modules. + * These declarations are considered internal to the JPEG library; most + * applications using the library shouldn't need to include this file. + */ + + + /* Declarations for both compression & decompression */ + + typedef enum { /* Operating modes for buffer controllers */ + JBUF_PASS_THRU, /* Plain stripwise operation */ + /* Remaining modes require a full-image buffer to have been created */ + JBUF_SAVE_SOURCE, /* Run source subobject only, save output */ + JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */ + JBUF_SAVE_AND_PASS /* Run both subobjects, save output */ + } J_BUF_MODE; + + /* Values of global_state field (jdapi.c has some dependencies on ordering!) */ + #define CSTATE_START 100 /* after create_compress */ + #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */ + #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */ + #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */ + #define DSTATE_START 200 /* after create_decompress */ + #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */ + #define DSTATE_READY 202 /* found SOS, ready for start_decompress */ + #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/ + #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */ + #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */ + #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */ + #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */ + #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */ + #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */ + #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */ + + + /* Declarations for compression modules */ + + /* Master control module */ + struct jpeg_comp_master { + JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo)); + JMETHOD(void, pass_startup, (j_compress_ptr cinfo)); + JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); + + /* State variables made visible to other modules */ + boolean call_pass_startup; /* True if pass_startup must be called */ + boolean is_last_pass; /* True during last pass */ + }; + + /* Main buffer control (downsampled-data buffer) */ + struct jpeg_c_main_controller { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, process_data, (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail)); + }; + + /* Compression preprocessing (downsampling input buffer control) */ + struct jpeg_c_prep_controller { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, pre_process_data, (j_compress_ptr cinfo, + JSAMPARRAY input_buf, + JDIMENSION *in_row_ctr, + JDIMENSION in_rows_avail, + JSAMPIMAGE output_buf, + JDIMENSION *out_row_group_ctr, + JDIMENSION out_row_groups_avail)); + }; + + /* Coefficient buffer control */ + struct jpeg_c_coef_controller { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(boolean, compress_data, (j_compress_ptr cinfo, + JSAMPIMAGE input_buf)); + }; + + /* Colorspace conversion */ + struct jpeg_color_converter { + JMETHOD(void, start_pass, (j_compress_ptr cinfo)); + JMETHOD(void, color_convert, (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows)); + }; + + /* Downsampling */ + struct jpeg_downsampler { + JMETHOD(void, start_pass, (j_compress_ptr cinfo)); + JMETHOD(void, downsample, (j_compress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION in_row_index, + JSAMPIMAGE output_buf, + JDIMENSION out_row_group_index)); + + boolean need_context_rows; /* TRUE if need rows above & below */ + }; + + /* Forward DCT (also controls coefficient quantization) */ + struct jpeg_forward_dct { + JMETHOD(void, start_pass, (j_compress_ptr cinfo)); + /* perhaps this should be an array??? */ + JMETHOD(void, forward_DCT, (j_compress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY sample_data, JBLOCKROW coef_blocks, + JDIMENSION start_row, JDIMENSION start_col, + JDIMENSION num_blocks)); + }; + + /* Entropy encoding */ + struct jpeg_entropy_encoder { + JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics)); + JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data)); + JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); + }; + + /* Marker writing */ + struct jpeg_marker_writer { + /* write_any_marker is exported for use by applications */ + /* Probably only COM and APPn markers should be written */ + JMETHOD(void, write_any_marker, (j_compress_ptr cinfo, int marker, + const JOCTET *dataptr, unsigned int datalen)); + JMETHOD(void, write_file_header, (j_compress_ptr cinfo)); + JMETHOD(void, write_frame_header, (j_compress_ptr cinfo)); + JMETHOD(void, write_scan_header, (j_compress_ptr cinfo)); + JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo)); + JMETHOD(void, write_tables_only, (j_compress_ptr cinfo)); + }; + + + /* Declarations for decompression modules */ + + /* Master control module */ + struct jpeg_decomp_master { + JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); + + /* State variables made visible to other modules */ + boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ + }; + + /* Input control module */ + struct jpeg_input_controller { + JMETHOD(int, consume_input, (j_decompress_ptr cinfo)); + JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo)); + JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo)); + + /* State variables made visible to other modules */ + boolean has_multiple_scans; /* True if file has multiple scans */ + boolean eoi_reached; /* True when EOI has been consumed */ + }; + + /* Main buffer control (downsampled-data buffer) */ + struct jpeg_d_main_controller { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, process_data, (j_decompress_ptr cinfo, + JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); + }; + + /* Coefficient buffer control */ + struct jpeg_d_coef_controller { + JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo)); + JMETHOD(int, consume_data, (j_decompress_ptr cinfo)); + JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo)); + JMETHOD(int, decompress_data, (j_decompress_ptr cinfo, + JSAMPIMAGE output_buf)); + /* Pointer to array of coefficient virtual arrays, or NULL if none */ + jvirt_barray_ptr *coef_arrays; + }; + + /* Decompression postprocessing (color quantization buffer control) */ + struct jpeg_d_post_controller { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); + JMETHOD(void, post_process_data, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); + }; + + /* Marker reading & parsing */ + struct jpeg_marker_reader { + JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo)); + /* Read markers until SOS or EOI. + * Returns same codes as are defined for jpeg_consume_input: + * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. + */ + JMETHOD(int, read_markers, (j_decompress_ptr cinfo)); + /* Read a restart marker --- exported for use by entropy decoder only */ + jpeg_marker_parser_method read_restart_marker; + /* Application-overridable marker processing methods */ + jpeg_marker_parser_method process_COM; + jpeg_marker_parser_method process_APPn[16]; + + /* State of marker reader --- nominally internal, but applications + * supplying COM or APPn handlers might like to know the state. + */ + boolean saw_SOI; /* found SOI? */ + boolean saw_SOF; /* found SOF? */ + int next_restart_num; /* next restart number expected (0-7) */ + unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ + }; + + /* Entropy decoding */ + struct jpeg_entropy_decoder { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, + JBLOCKROW *MCU_data)); + }; + + /* Inverse DCT (also performs dequantization) */ + typedef JMETHOD(void, inverse_DCT_method_ptr, + (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, + JSAMPARRAY output_buf, JDIMENSION output_col)); + + struct jpeg_inverse_dct { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + /* It is useful to allow each component to have a separate IDCT method. */ + inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; + }; + + /* Upsampling (note that upsampler must also call color converter) */ + struct jpeg_upsampler { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, upsample, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION *in_row_group_ctr, + JDIMENSION in_row_groups_avail, + JSAMPARRAY output_buf, + JDIMENSION *out_row_ctr, + JDIMENSION out_rows_avail)); + + boolean need_context_rows; /* TRUE if need rows above & below */ + }; + + /* Colorspace conversion */ + struct jpeg_color_deconverter { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, color_convert, (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows)); + }; + + /* Color quantization or color precision reduction */ + struct jpeg_color_quantizer { + JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); + JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPARRAY output_buf, + int num_rows)); + JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); + JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); + }; + + + /* Miscellaneous useful macros */ + + #undef MAX + #define MAX(a,b) ((a) > (b) ? (a) : (b)) + #undef MIN + #define MIN(a,b) ((a) < (b) ? (a) : (b)) + + + /* We assume that right shift corresponds to signed division by 2 with + * rounding towards minus infinity. This is correct for typical "arithmetic + * shift" instructions that shift in copies of the sign bit. But some + * C compilers implement >> with an unsigned shift. For these machines you + * must define RIGHT_SHIFT_IS_UNSIGNED. + * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity. + * It is only applied with constant shift counts. SHIFT_TEMPS must be + * included in the variables of any routine using RIGHT_SHIFT. + */ + + #ifdef RIGHT_SHIFT_IS_UNSIGNED + #define SHIFT_TEMPS INT32 shift_temp; + #define RIGHT_SHIFT(x,shft) \ + ((shift_temp = (x)) < 0 ? \ + (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \ + (shift_temp >> (shft))) + #else + #define SHIFT_TEMPS + #define RIGHT_SHIFT(x,shft) ((x) >> (shft)) + #endif + + + /* Short forms of external names for systems with brain-damaged linkers. */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jinit_compress_master jICompress + #define jinit_c_master_control jICMaster + #define jinit_c_main_controller jICMainC + #define jinit_c_prep_controller jICPrepC + #define jinit_c_coef_controller jICCoefC + #define jinit_color_converter jICColor + #define jinit_downsampler jIDownsampler + #define jinit_forward_dct jIFDCT + #define jinit_huff_encoder jIHEncoder + #define jinit_phuff_encoder jIPHEncoder + #define jinit_marker_writer jIMWriter + #define jinit_master_decompress jIDMaster + #define jinit_d_main_controller jIDMainC + #define jinit_d_coef_controller jIDCoefC + #define jinit_d_post_controller jIDPostC + #define jinit_input_controller jIInCtlr + #define jinit_marker_reader jIMReader + #define jinit_huff_decoder jIHDecoder + #define jinit_phuff_decoder jIPHDecoder + #define jinit_inverse_dct jIIDCT + #define jinit_upsampler jIUpsampler + #define jinit_color_deconverter jIDColor + #define jinit_1pass_quantizer jI1Quant + #define jinit_2pass_quantizer jI2Quant + #define jinit_merged_upsampler jIMUpsampler + #define jinit_memory_mgr jIMemMgr + #define jdiv_round_up jDivRound + #define jround_up jRound + #define jcopy_sample_rows jCopySamples + #define jcopy_block_row jCopyBlocks + #define jzero_far jZeroFar + #define jpeg_zigzag_order jZIGTable + #define jpeg_natural_order jZAGTable + #endif /* NEED_SHORT_EXTERNAL_NAMES */ + + + /* Compression module initialization routines */ + EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); + EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, + boolean transcode_only)); + EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo, + boolean need_full_buffer)); + EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo, + boolean need_full_buffer)); + EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo, + boolean need_full_buffer)); + EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo)); + EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); + EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); + EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo)); + EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo)); + EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo)); + /* Decompression module initialization routines */ + EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo, + boolean need_full_buffer)); + EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo, + boolean need_full_buffer)); + EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo, + boolean need_full_buffer)); + EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo)); + EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo)); + /* Memory manager initialization */ + EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo)); + + /* Utility routines in jutils.c */ + EXTERN(long) jdiv_round_up JPP((long a, long b)); + EXTERN(long) jround_up JPP((long a, long b)); + EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row, + JSAMPARRAY output_array, int dest_row, + int num_rows, JDIMENSION num_cols)); + EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, + JDIMENSION num_blocks)); + EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero)); + /* Constant tables in jutils.c */ + extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ + extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ + + /* Suppress undefined-structure complaints if necessary. */ + + #ifdef INCOMPLETE_TYPES_BROKEN + #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ + struct jvirt_sarray_control { long dummy; }; + struct jvirt_barray_control { long dummy; }; + #endif + #endif /* INCOMPLETE_TYPES_BROKEN */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jpeglib.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jpeglib.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jpeglib.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,1055 ---- + /* + * jpeglib.h + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file defines the application interface for the JPEG library. + * Most applications using the library need only include this file, + * and perhaps jerror.h if they want to know the exact error codes. + */ + + #ifndef JPEGLIB_H + #define JPEGLIB_H + + /* + * First we include the configuration files that record how this + * installation of the JPEG library is set up. jconfig.h can be + * generated automatically for many systems. jmorecfg.h contains + * manual configuration options that most people need not worry about. + */ + + #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ + #include "jconfig.h" /* widely used configuration options */ + #endif + #include "jmorecfg.h" /* seldom changed options */ + + + /* Version ID for the JPEG library. + * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". + */ + + #define JPEG_LIB_VERSION 61 /* Version 6a */ + + + /* Various constants determining the sizes of things. + * All of these are specified by the JPEG standard, so don't change them + * if you want to be compatible. + */ + + #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ + #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ + #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */ + #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */ + #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */ + #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */ + #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */ + /* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard; + * the PostScript DCT filter can emit files with many more than 10 blocks/MCU. + * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU + * to handle it. We even let you do this from the jconfig.h file. However, + * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe + * sometimes emits noncompliant files doesn't mean you should too. + */ + #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */ + #ifndef D_MAX_BLOCKS_IN_MCU + #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */ + #endif + + + /* Data structures for images (arrays of samples and of DCT coefficients). + * On 80x86 machines, the image arrays are too big for near pointers, + * but the pointer arrays can fit in near memory. + */ + + typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */ + typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ + typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ + + typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ + typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */ + typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */ + typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */ + + typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */ + + + /* Types for JPEG compression parameters and working tables. */ + + + /* DCT coefficient quantization tables. */ + + typedef struct { + /* This array gives the coefficient quantizers in natural array order + * (not the zigzag order in which they are stored in a JPEG DQT marker). + * CAUTION: IJG versions prior to v6a kept this array in zigzag order. + */ + UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ + } JQUANT_TBL; + + + /* Huffman coding tables. */ + + typedef struct { + /* These two fields directly represent the contents of a JPEG DHT marker */ + UINT8 bits[17]; /* bits[k] = # of symbols with codes of */ + /* length k bits; bits[0] is unused */ + UINT8 huffval[256]; /* The symbols, in order of incr code length */ + /* This field is used only during compression. It's initialized FALSE when + * the table is created, and set TRUE when it's been output to the file. + * You could suppress output of a table by setting this to TRUE. + * (See jpeg_suppress_tables for an example.) + */ + boolean sent_table; /* TRUE when table has been output */ + } JHUFF_TBL; + + + /* Basic info about one component (color channel). */ + + typedef struct { + /* These values are fixed over the whole image. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOF marker. */ + int component_id; /* identifier for this component (0..255) */ + int component_index; /* its index in SOF or cinfo->comp_info[] */ + int h_samp_factor; /* horizontal sampling factor (1..4) */ + int v_samp_factor; /* vertical sampling factor (1..4) */ + int quant_tbl_no; /* quantization table selector (0..3) */ + /* These values may vary between scans. */ + /* For compression, they must be supplied by parameter setup; */ + /* for decompression, they are read from the SOS marker. */ + /* The decompressor output side may not use these variables. */ + int dc_tbl_no; /* DC entropy table selector (0..3) */ + int ac_tbl_no; /* AC entropy table selector (0..3) */ + + /* Remaining fields should be treated as private by applications. */ + + /* These values are computed during compression or decompression startup: */ + /* Component's size in DCT blocks. + * Any dummy blocks added to complete an MCU are not counted; therefore + * these values do not depend on whether a scan is interleaved or not. + */ + JDIMENSION width_in_blocks; + JDIMENSION height_in_blocks; + /* Size of a DCT block in samples. Always DCTSIZE for compression. + * For decompression this is the size of the output from one DCT block, + * reflecting any scaling we choose to apply during the IDCT step. + * Values of 1,2,4,8 are likely to be supported. Note that different + * components may receive different IDCT scalings. + */ + int DCT_scaled_size; + /* The downsampled dimensions are the component's actual, unpadded number + * of samples at the main buffer (preprocessing/compression interface), thus + * downsampled_width = ceil(image_width * Hi/Hmax) + * and similarly for height. For decompression, IDCT scaling is included, so + * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE) + */ + JDIMENSION downsampled_width; /* actual width in samples */ + JDIMENSION downsampled_height; /* actual height in samples */ + /* This flag is used only for decompression. In cases where some of the + * components will be ignored (eg grayscale output from YCbCr image), + * we can skip most computations for the unused components. + */ + boolean component_needed; /* do we need the value of this component? */ + + /* These values are computed before starting a scan of the component. */ + /* The decompressor output side may not use these variables. */ + int MCU_width; /* number of blocks per MCU, horizontally */ + int MCU_height; /* number of blocks per MCU, vertically */ + int MCU_blocks; /* MCU_width * MCU_height */ + int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */ + int last_col_width; /* # of non-dummy blocks across in last MCU */ + int last_row_height; /* # of non-dummy blocks down in last MCU */ + + /* Saved quantization table for component; NULL if none yet saved. + * See jdinput.c comments about the need for this information. + * This field is currently used only for decompression. + */ + JQUANT_TBL * quant_table; + + /* Private per-component storage for DCT or IDCT subsystem. */ + void * dct_table; + } jpeg_component_info; + + + /* The script for encoding a multiple-scan file is an array of these: */ + + typedef struct { + int comps_in_scan; /* number of components encoded in this scan */ + int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */ + int Ss, Se; /* progressive JPEG spectral selection parms */ + int Ah, Al; /* progressive JPEG successive approx. parms */ + } jpeg_scan_info; + + + /* Known color spaces. */ + + typedef enum { + JCS_UNKNOWN, /* error/unspecified */ + JCS_GRAYSCALE, /* monochrome */ + JCS_RGB, /* red/green/blue */ + JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ + JCS_CMYK, /* C/M/Y/K */ + JCS_YCCK /* Y/Cb/Cr/K */ + } J_COLOR_SPACE; + + /* DCT/IDCT algorithm options. */ + + typedef enum { + JDCT_ISLOW, /* slow but accurate integer algorithm */ + JDCT_IFAST, /* faster, less accurate integer method */ + JDCT_FLOAT /* floating-point: accurate, fast on fast HW */ + } J_DCT_METHOD; + + #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */ + #define JDCT_DEFAULT JDCT_ISLOW + #endif + #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */ + #define JDCT_FASTEST JDCT_IFAST + #endif + + /* Dithering options for decompression. */ + + typedef enum { + JDITHER_NONE, /* no dithering */ + JDITHER_ORDERED, /* simple ordered dither */ + JDITHER_FS /* Floyd-Steinberg error diffusion dither */ + } J_DITHER_MODE; + + + /* Common fields between JPEG compression and decompression master structs. */ + + #define jpeg_common_fields \ + struct jpeg_error_mgr * err; /* Error handler module */\ + struct jpeg_memory_mgr * mem; /* Memory manager module */\ + struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\ + boolean is_decompressor; /* so common code can tell which is which */\ + int global_state /* for checking call sequence validity */ + + /* Routines that are to be used by both halves of the library are declared + * to receive a pointer to this structure. There are no actual instances of + * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct. + */ + struct jpeg_common_struct { + jpeg_common_fields; /* Fields common to both master struct types */ + /* Additional fields follow in an actual jpeg_compress_struct or + * jpeg_decompress_struct. All three structs must agree on these + * initial fields! (This would be a lot cleaner in C++.) + */ + }; + + typedef struct jpeg_common_struct * j_common_ptr; + typedef struct jpeg_compress_struct * j_compress_ptr; + typedef struct jpeg_decompress_struct * j_decompress_ptr; + + + /* Master record for a compression instance */ + + struct jpeg_compress_struct { + jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */ + + /* Destination for compressed data */ + struct jpeg_destination_mgr * dest; + + /* Description of source image --- these fields must be filled in by + * outer application before starting compression. in_color_space must + * be correct before you can even call jpeg_set_defaults(). + */ + + JDIMENSION image_width; /* input image width */ + JDIMENSION image_height; /* input image height */ + int input_components; /* # of color components in input image */ + J_COLOR_SPACE in_color_space; /* colorspace of input image */ + + double input_gamma; /* image gamma of input image */ + + /* Compression parameters --- these fields must be set before calling + * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to + * initialize everything to reasonable defaults, then changing anything + * the application specifically wants to change. That way you won't get + * burnt when new parameters are added. Also note that there are several + * helper routines to simplify changing parameters. + */ + + int data_precision; /* bits of precision in image data */ + + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; + /* ptrs to coefficient quantization tables, or NULL if not defined */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + int num_scans; /* # of entries in scan_info array */ + const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */ + /* The default value of scan_info is NULL, which causes a single-scan + * sequential JPEG file to be emitted. To create a multi-scan file, + * set num_scans and scan_info to point to an array of scan definitions. + */ + + boolean raw_data_in; /* TRUE=caller supplies downsampled data */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + boolean optimize_coding; /* TRUE=optimize entropy encoding parms */ + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ + int smoothing_factor; /* 1..100, or 0 for no input smoothing */ + J_DCT_METHOD dct_method; /* DCT algorithm selector */ + + /* The restart interval can be specified in absolute MCUs by setting + * restart_interval, or in MCU rows by setting restart_in_rows + * (in which case the correct restart_interval will be figured + * for each scan). + */ + unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */ + int restart_in_rows; /* if > 0, MCU rows per restart interval */ + + /* Parameters controlling emission of special markers. */ + + boolean write_JFIF_header; /* should a JFIF marker be written? */ + /* These three values are not used by the JPEG code, merely copied */ + /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */ + /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */ + /* ratio is defined by X_density/Y_density even when density_unit=0. */ + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean write_Adobe_marker; /* should an Adobe marker be written? */ + + /* State variable: index of next scanline to be written to + * jpeg_write_scanlines(). Application may use this to control its + * processing loop, e.g., "while (next_scanline < image_height)". + */ + + JDIMENSION next_scanline; /* 0 .. image_height-1 */ + + /* Remaining fields are known throughout compressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during compression startup + */ + boolean progressive_mode; /* TRUE if scan script uses progressive mode */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + + JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ + /* The coefficient controller receives data in units of MCU rows as defined + * for fully interleaved scans (whether the JPEG file is interleaved or not). + * There are v_samp_factor * DCTSIZE sample rows of each component in an + * "iMCU" (interleaved MCU) row. + */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[C_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + + /* + * Links to compression subobjects (methods and private variables of modules) + */ + struct jpeg_comp_master * master; + struct jpeg_c_main_controller * main; + struct jpeg_c_prep_controller * prep; + struct jpeg_c_coef_controller * coef; + struct jpeg_marker_writer * marker; + struct jpeg_color_converter * cconvert; + struct jpeg_downsampler * downsample; + struct jpeg_forward_dct * fdct; + struct jpeg_entropy_encoder * entropy; + }; + + + /* Master record for a decompression instance */ + + struct jpeg_decompress_struct { + jpeg_common_fields; /* Fields shared with jpeg_compress_struct */ + + /* Source of compressed data */ + struct jpeg_source_mgr * src; + + /* Basic description of image --- filled in by jpeg_read_header(). */ + /* Application may inspect these values to decide how to process image. */ + + JDIMENSION image_width; /* nominal image width (from SOF marker) */ + JDIMENSION image_height; /* nominal image height */ + int num_components; /* # of color components in JPEG image */ + J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ + + /* Decompression processing parameters --- these fields must be set before + * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes + * them to default values. + */ + + J_COLOR_SPACE out_color_space; /* colorspace for output */ + + unsigned int scale_num, scale_denom; /* fraction by which to scale image */ + + double output_gamma; /* image gamma wanted in output */ + + boolean buffered_image; /* TRUE=multiple output passes */ + boolean raw_data_out; /* TRUE=downsampled data wanted */ + + J_DCT_METHOD dct_method; /* IDCT algorithm selector */ + boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */ + boolean do_block_smoothing; /* TRUE=apply interblock smoothing */ + + boolean quantize_colors; /* TRUE=colormapped output wanted */ + /* the following are ignored if not quantize_colors: */ + J_DITHER_MODE dither_mode; /* type of color dithering to use */ + boolean two_pass_quantize; /* TRUE=use two-pass color quantization */ + int desired_number_of_colors; /* max # colors to use in created colormap */ + /* these are significant only in buffered-image mode: */ + boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */ + boolean enable_external_quant;/* enable future use of external colormap */ + boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */ + + /* Description of actual output image that will be returned to application. + * These fields are computed by jpeg_start_decompress(). + * You can also use jpeg_calc_output_dimensions() to determine these values + * in advance of calling jpeg_start_decompress(). + */ + + JDIMENSION output_width; /* scaled image width */ + JDIMENSION output_height; /* scaled image height */ + int out_color_components; /* # of color components in out_color_space */ + int output_components; /* # of color components returned */ + /* output_components is 1 (a colormap index) when quantizing colors; + * otherwise it equals out_color_components. + */ + int rec_outbuf_height; /* min recommended height of scanline buffer */ + /* If the buffer passed to jpeg_read_scanlines() is less than this many rows + * high, space and time will be wasted due to unnecessary data copying. + * Usually rec_outbuf_height will be 1 or 2, at most 4. + */ + + /* When quantizing colors, the output colormap is described by these fields. + * The application can supply a colormap by setting colormap non-NULL before + * calling jpeg_start_decompress; otherwise a colormap is created during + * jpeg_start_decompress or jpeg_start_output. + * The map has out_color_components rows and actual_number_of_colors columns. + */ + int actual_number_of_colors; /* number of entries in use */ + JSAMPARRAY colormap; /* The color map as a 2-D pixel array */ + + /* State variables: these variables indicate the progress of decompression. + * The application may examine these but must not modify them. + */ + + /* Row index of next scanline to be read from jpeg_read_scanlines(). + * Application may use this to control its processing loop, e.g., + * "while (output_scanline < output_height)". + */ + JDIMENSION output_scanline; /* 0 .. output_height-1 */ + + /* Current input scan number and number of iMCU rows completed in scan. + * These indicate the progress of the decompressor input side. + */ + int input_scan_number; /* Number of SOS markers seen so far */ + JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */ + + /* The "output scan number" is the notional scan being displayed by the + * output side. The decompressor will not allow output scan/row number + * to get ahead of input scan/row, but it can fall arbitrarily far behind. + */ + int output_scan_number; /* Nominal scan number being displayed */ + JDIMENSION output_iMCU_row; /* Number of iMCU rows read */ + + /* Current progression status. coef_bits[c][i] indicates the precision + * with which component c's DCT coefficient i (in zigzag order) is known. + * It is -1 when no data has yet been received, otherwise it is the point + * transform (shift) value for the most recent scan of the coefficient + * (thus, 0 at completion of the progression). + * This pointer is NULL when reading a non-progressive file. + */ + int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */ + + /* Internal JPEG parameters --- the application usually need not look at + * these fields. Note that the decompressor output side may not use + * any parameters that can change between scans. + */ + + /* Quantization and Huffman tables are carried forward across input + * datastreams when processing abbreviated JPEG datastreams. + */ + + JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; + /* ptrs to coefficient quantization tables, or NULL if not defined */ + + JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; + JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; + /* ptrs to Huffman coding tables, or NULL if not defined */ + + /* These parameters are never carried across datastreams, since they + * are given in SOF/SOS markers or defined to be reset by SOI. + */ + + int data_precision; /* bits of precision in image data */ + + jpeg_component_info * comp_info; + /* comp_info[i] describes component that appears i'th in SOF */ + + boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */ + boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ + + UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ + UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ + UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ + + unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */ + + /* These fields record data obtained from optional markers recognized by + * the JPEG library. + */ + boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */ + /* Data copied from JFIF marker: */ + UINT8 density_unit; /* JFIF code for pixel size units */ + UINT16 X_density; /* Horizontal pixel density */ + UINT16 Y_density; /* Vertical pixel density */ + boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */ + UINT8 Adobe_transform; /* Color transform code from Adobe marker */ + + boolean CCIR601_sampling; /* TRUE=first samples are cosited */ + + /* Remaining fields are known throughout decompressor, but generally + * should not be touched by a surrounding application. + */ + + /* + * These fields are computed during decompression startup + */ + int max_h_samp_factor; /* largest h_samp_factor */ + int max_v_samp_factor; /* largest v_samp_factor */ + + int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */ + + JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */ + /* The coefficient controller's input and output progress is measured in + * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows + * in fully interleaved JPEG scans, but are used whether the scan is + * interleaved or not. We define an iMCU row as v_samp_factor DCT block + * rows of each component. Therefore, the IDCT output contains + * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row. + */ + + JSAMPLE * sample_range_limit; /* table for fast range-limiting */ + + /* + * These fields are valid during any one scan. + * They describe the components and MCUs actually appearing in the scan. + * Note that the decompressor output side must not use these fields. + */ + int comps_in_scan; /* # of JPEG components in this scan */ + jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]; + /* *cur_comp_info[i] describes component that appears i'th in SOS */ + + JDIMENSION MCUs_per_row; /* # of MCUs across the image */ + JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */ + + int blocks_in_MCU; /* # of DCT blocks per MCU */ + int MCU_membership[D_MAX_BLOCKS_IN_MCU]; + /* MCU_membership[i] is index in cur_comp_info of component owning */ + /* i'th block in an MCU */ + + int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ + + /* This field is shared between entropy decoder and marker parser. + * It is either zero or the code of a JPEG marker that has been + * read from the data source, but has not yet been processed. + */ + int unread_marker; + + /* + * Links to decompression subobjects (methods, private variables of modules) + */ + struct jpeg_decomp_master * master; + struct jpeg_d_main_controller * main; + struct jpeg_d_coef_controller * coef; + struct jpeg_d_post_controller * post; + struct jpeg_input_controller * inputctl; + struct jpeg_marker_reader * marker; + struct jpeg_entropy_decoder * entropy; + struct jpeg_inverse_dct * idct; + struct jpeg_upsampler * upsample; + struct jpeg_color_deconverter * cconvert; + struct jpeg_color_quantizer * cquantize; + }; + + + /* "Object" declarations for JPEG modules that may be supplied or called + * directly by the surrounding application. + * As with all objects in the JPEG library, these structs only define the + * publicly visible methods and state variables of a module. Additional + * private fields may exist after the public ones. + */ + + + /* Error handler object */ + + struct jpeg_error_mgr { + /* Error exit handler: does not return to caller */ + JMETHOD(void, error_exit, (j_common_ptr cinfo)); + /* Conditionally emit a trace or warning message */ + JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); + /* Routine that actually outputs a trace or error message */ + JMETHOD(void, output_message, (j_common_ptr cinfo)); + /* Format a message string for the most recent JPEG error or message */ + JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer)); + #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */ + /* Reset error state variables at start of a new image */ + JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); + + /* The message ID code and any parameters are saved here. + * A message can have one string parameter or up to 8 int parameters. + */ + int msg_code; + #define JMSG_STR_PARM_MAX 80 + union { + int i[8]; + char s[JMSG_STR_PARM_MAX]; + } msg_parm; + + /* Standard state variables for error facility */ + + int trace_level; /* max msg_level that will be displayed */ + + /* For recoverable corrupt-data errors, we emit a warning message, + * but keep going unless emit_message chooses to abort. emit_message + * should count warnings in num_warnings. The surrounding application + * can check for bad data by seeing if num_warnings is nonzero at the + * end of processing. + */ + long num_warnings; /* number of corrupt-data warnings */ + + /* These fields point to the table(s) of error message strings. + * An application can change the table pointer to switch to a different + * message list (typically, to change the language in which errors are + * reported). Some applications may wish to add additional error codes + * that will be handled by the JPEG library error mechanism; the second + * table pointer is used for this purpose. + * + * First table includes all errors generated by JPEG library itself. + * Error code 0 is reserved for a "no such error string" message. + */ + const char * const * jpeg_message_table; /* Library errors */ + int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */ + /* Second table can be added by application (see cjpeg/djpeg for example). + * It contains strings numbered first_addon_message..last_addon_message. + */ + const char * const * addon_message_table; /* Non-library errors */ + int first_addon_message; /* code for first string in addon table */ + int last_addon_message; /* code for last string in addon table */ + }; + + + /* Progress monitor object */ + + struct jpeg_progress_mgr { + JMETHOD(void, progress_monitor, (j_common_ptr cinfo)); + + long pass_counter; /* work units completed in this pass */ + long pass_limit; /* total number of work units in this pass */ + int completed_passes; /* passes completed so far */ + int total_passes; /* total number of passes expected */ + }; + + + /* Data destination object for compression */ + + struct jpeg_destination_mgr { + JOCTET * next_output_byte; /* => next byte to write in buffer */ + size_t free_in_buffer; /* # of byte spaces remaining in buffer */ + + JMETHOD(void, init_destination, (j_compress_ptr cinfo)); + JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo)); + JMETHOD(void, term_destination, (j_compress_ptr cinfo)); + }; + + + /* Data source object for decompression */ + + struct jpeg_source_mgr { + const JOCTET * next_input_byte; /* => next byte to read from buffer */ + size_t bytes_in_buffer; /* # of bytes remaining in buffer */ + + JMETHOD(void, init_source, (j_decompress_ptr cinfo)); + JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo)); + JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes)); + JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired)); + JMETHOD(void, term_source, (j_decompress_ptr cinfo)); + }; + + + /* Memory manager object. + * Allocates "small" objects (a few K total), "large" objects (tens of K), + * and "really big" objects (virtual arrays with backing store if needed). + * The memory manager does not allow individual objects to be freed; rather, + * each created object is assigned to a pool, and whole pools can be freed + * at once. This is faster and more convenient than remembering exactly what + * to free, especially where malloc()/free() are not too speedy. + * NB: alloc routines never return NULL. They exit to error_exit if not + * successful. + */ + + #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */ + #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */ + #define JPOOL_NUMPOOLS 2 + + typedef struct jvirt_sarray_control * jvirt_sarray_ptr; + typedef struct jvirt_barray_control * jvirt_barray_ptr; + + + struct jpeg_memory_mgr { + /* Method pointers */ + JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, + size_t sizeofobject)); + JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, + JDIMENSION samplesperrow, + JDIMENSION numrows)); + JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, + JDIMENSION blocksperrow, + JDIMENSION numrows)); + JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION samplesperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, + int pool_id, + boolean pre_zero, + JDIMENSION blocksperrow, + JDIMENSION numrows, + JDIMENSION maxaccess)); + JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo)); + JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, + jvirt_sarray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, + jvirt_barray_ptr ptr, + JDIMENSION start_row, + JDIMENSION num_rows, + boolean writable)); + JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id)); + JMETHOD(void, self_destruct, (j_common_ptr cinfo)); + + /* Limit on memory allocation for this JPEG object. (Note that this is + * merely advisory, not a guaranteed maximum; it only affects the space + * used for virtual-array buffers.) May be changed by outer application + * after creating the JPEG object. + */ + long max_memory_to_use; + }; + + + /* Routine signature for application-supplied marker processing methods. + * Need not pass marker code since it is stored in cinfo->unread_marker. + */ + typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo)); + + + /* Declarations for routines called by application. + * The JPP macro hides prototype parameters from compilers that can't cope. + * Note JPP requires double parentheses. + */ + + #ifdef HAVE_PROTOTYPES + #define JPP(arglist) arglist + #else + #define JPP(arglist) () + #endif + + + /* Short forms of external names for systems with brain-damaged linkers. + * We shorten external names to be unique in the first six letters, which + * is good enough for all known systems. + * (If your compiler itself needs names to be unique in less than 15 + * characters, you are out of luck. Get a better compiler.) + */ + + #ifdef NEED_SHORT_EXTERNAL_NAMES + #define jpeg_std_error jStdError + #define jpeg_CreateCompress jCreaCompress + #define jpeg_CreateDecompress jCreaDecompress + #define jpeg_destroy_compress jDestCompress + #define jpeg_destroy_decompress jDestDecompress + #define jpeg_stdio_dest jStdDest + #define jpeg_stdio_src jStdSrc + #define jpeg_set_defaults jSetDefaults + #define jpeg_set_colorspace jSetColorspace + #define jpeg_default_colorspace jDefColorspace + #define jpeg_set_quality jSetQuality + #define jpeg_set_linear_quality jSetLQuality + #define jpeg_add_quant_table jAddQuantTable + #define jpeg_quality_scaling jQualityScaling + #define jpeg_simple_progression jSimProgress + #define jpeg_suppress_tables jSuppressTables + #define jpeg_alloc_quant_table jAlcQTable + #define jpeg_alloc_huff_table jAlcHTable + #define jpeg_start_compress jStrtCompress + #define jpeg_write_scanlines jWrtScanlines + #define jpeg_finish_compress jFinCompress + #define jpeg_write_raw_data jWrtRawData + #define jpeg_write_marker jWrtMarker + #define jpeg_write_tables jWrtTables + #define jpeg_read_header jReadHeader + #define jpeg_start_decompress jStrtDecompress + #define jpeg_read_scanlines jReadScanlines + #define jpeg_finish_decompress jFinDecompress + #define jpeg_read_raw_data jReadRawData + #define jpeg_has_multiple_scans jHasMultScn + #define jpeg_start_output jStrtOutput + #define jpeg_finish_output jFinOutput + #define jpeg_input_complete jInComplete + #define jpeg_new_colormap jNewCMap + #define jpeg_consume_input jConsumeInput + #define jpeg_calc_output_dimensions jCalcDimensions + #define jpeg_set_marker_processor jSetMarker + #define jpeg_read_coefficients jReadCoefs + #define jpeg_write_coefficients jWrtCoefs + #define jpeg_copy_critical_parameters jCopyCrit + #define jpeg_abort_compress jAbrtCompress + #define jpeg_abort_decompress jAbrtDecompress + #define jpeg_abort jAbort + #define jpeg_destroy jDestroy + #define jpeg_resync_to_restart jResyncRestart + #endif /* NEED_SHORT_EXTERNAL_NAMES */ + + + /* Default error-management setup */ + EXTERN(struct jpeg_error_mgr *) jpeg_std_error + JPP((struct jpeg_error_mgr * err)); + + /* Initialization of JPEG compression objects. + * jpeg_create_compress() and jpeg_create_decompress() are the exported + * names that applications should call. These expand to calls on + * jpeg_CreateCompress and jpeg_CreateDecompress with additional information + * passed for version mismatch checking. + * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx. + */ + #define jpeg_create_compress(cinfo) \ + jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_compress_struct)) + #define jpeg_create_decompress(cinfo) \ + jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \ + (size_t) sizeof(struct jpeg_decompress_struct)) + EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo, + int version, size_t structsize)); + EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo, + int version, size_t structsize)); + /* Destruction of JPEG compression objects */ + EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); + EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); + + /* Standard data source and destination managers: stdio streams. */ + /* Caller is responsible for opening the file before and closing after. */ + EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); + EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); + + /* Default parameter setup for compression */ + EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); + /* Compression parameter setup aids */ + EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, + J_COLOR_SPACE colorspace)); + EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); + EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, + boolean force_baseline)); + EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, + int scale_factor, + boolean force_baseline)); + EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, + const unsigned int *basic_table, + int scale_factor, + boolean force_baseline)); + EXTERN(int) jpeg_quality_scaling JPP((int quality)); + EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); + EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, + boolean suppress)); + EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo)); + EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo)); + + /* Main entry points for compression */ + EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, + boolean write_all_tables)); + EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION num_lines)); + EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); + + /* Replaces jpeg_write_scanlines when writing raw downsampled data. */ + EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION num_lines)); + + /* Write a special marker. See libjpeg.doc concerning safe usage. */ + EXTERN(void) jpeg_write_marker + JPP((j_compress_ptr cinfo, int marker, + const JOCTET * dataptr, unsigned int datalen)); + + /* Alternate compression function: just write an abbreviated table file */ + EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo)); + + /* Decompression startup: read start of JPEG datastream to see what's there */ + EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo, + boolean require_image)); + /* Return value is one of: */ + #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */ + #define JPEG_HEADER_OK 1 /* Found valid image datastream */ + #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */ + /* If you pass require_image = TRUE (normal case), you need not check for + * a TABLES_ONLY return code; an abbreviated file will cause an error exit. + * JPEG_SUSPENDED is only possible if you use a data source module that can + * give a suspension return (the stdio source module doesn't). + */ + + /* Main entry points for decompression */ + EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo)); + EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo, + JSAMPARRAY scanlines, + JDIMENSION max_lines)); + EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo)); + + /* Replaces jpeg_read_scanlines when reading raw downsampled data. */ + EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, + JSAMPIMAGE data, + JDIMENSION max_lines)); + + /* Additional entry points for buffered-image mode. */ + EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo)); + EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo, + int scan_number)); + EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo)); + EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo)); + EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo)); + EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo)); + /* Return value is one of: */ + /* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ + #define JPEG_REACHED_SOS 1 /* Reached start of new scan */ + #define JPEG_REACHED_EOI 2 /* Reached end of image */ + #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */ + #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */ + + /* Precalculate output dimensions for current decompression parameters. */ + EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); + + /* Install a special processing method for COM or APPn markers. */ + EXTERN(void) jpeg_set_marker_processor + JPP((j_decompress_ptr cinfo, int marker_code, + jpeg_marker_parser_method routine)); + + /* Read or write raw DCT coefficients --- useful for lossless transcoding. */ + EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo)); + EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo, + jvirt_barray_ptr * coef_arrays)); + EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo, + j_compress_ptr dstinfo)); + + /* If you choose to abort compression or decompression before completing + * jpeg_finish_(de)compress, then you need to clean up to release memory, + * temporary files, etc. You can just call jpeg_destroy_(de)compress + * if you're done with the JPEG object, but if you want to clean it up and + * reuse it, call this: + */ + EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo)); + EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo)); + + /* Generic versions of jpeg_abort and jpeg_destroy that work on either + * flavor of JPEG object. These may be more convenient in some places. + */ + EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo)); + EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo)); + + /* Default restart-marker-resync procedure for use by data source modules */ + EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo, + int desired)); + + + /* These marker codes are exported since applications and data source modules + * are likely to want to use them. + */ + + #define JPEG_RST0 0xD0 /* RST0 marker code */ + #define JPEG_EOI 0xD9 /* EOI marker code */ + #define JPEG_APP0 0xE0 /* APP0 marker code */ + #define JPEG_COM 0xFE /* COM marker code */ + + + /* If we have a brain-damaged compiler that emits warnings (or worse, errors) + * for structure definitions that are never filled in, keep it quiet by + * supplying dummy definitions for the various substructures. + */ + + #ifdef INCOMPLETE_TYPES_BROKEN + #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */ + struct jvirt_sarray_control { long dummy; }; + struct jvirt_barray_control { long dummy; }; + struct jpeg_comp_master { long dummy; }; + struct jpeg_c_main_controller { long dummy; }; + struct jpeg_c_prep_controller { long dummy; }; + struct jpeg_c_coef_controller { long dummy; }; + struct jpeg_marker_writer { long dummy; }; + struct jpeg_color_converter { long dummy; }; + struct jpeg_downsampler { long dummy; }; + struct jpeg_forward_dct { long dummy; }; + struct jpeg_entropy_encoder { long dummy; }; + struct jpeg_decomp_master { long dummy; }; + struct jpeg_d_main_controller { long dummy; }; + struct jpeg_d_coef_controller { long dummy; }; + struct jpeg_d_post_controller { long dummy; }; + struct jpeg_input_controller { long dummy; }; + struct jpeg_marker_reader { long dummy; }; + struct jpeg_entropy_decoder { long dummy; }; + struct jpeg_inverse_dct { long dummy; }; + struct jpeg_upsampler { long dummy; }; + struct jpeg_color_deconverter { long dummy; }; + struct jpeg_color_quantizer { long dummy; }; + #endif /* JPEG_INTERNALS */ + #endif /* INCOMPLETE_TYPES_BROKEN */ + + + /* + * The JPEG library modules define JPEG_INTERNALS before including this file. + * The internal structure declarations are read only when that is true. + * Applications using the library should not include jpegint.h, but may wish + * to include jerror.h. + */ + + #ifdef JPEG_INTERNALS + #include "jpegint.h" /* fetch private declarations */ + #include "jerror.h" /* fetch error codes too */ + #endif + + #endif /* JPEGLIB_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jquant1.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jquant1.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jquant1.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,856 ---- + /* + * jquant1.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains 1-pass color quantization (color mapping) routines. + * These routines provide mapping to a fixed color map using equally spaced + * color values. Optional Floyd-Steinberg or ordered dithering is available. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + #ifdef QUANT_1PASS_SUPPORTED + + + /* + * The main purpose of 1-pass quantization is to provide a fast, if not very + * high quality, colormapped output capability. A 2-pass quantizer usually + * gives better visual quality; however, for quantized grayscale output this + * quantizer is perfectly adequate. Dithering is highly recommended with this + * quantizer, though you can turn it off if you really want to. + * + * In 1-pass quantization the colormap must be chosen in advance of seeing the + * image. We use a map consisting of all combinations of Ncolors[i] color + * values for the i'th component. The Ncolors[] values are chosen so that + * their product, the total number of colors, is no more than that requested. + * (In most cases, the product will be somewhat less.) + * + * Since the colormap is orthogonal, the representative value for each color + * component can be determined without considering the other components; + * then these indexes can be combined into a colormap index by a standard + * N-dimensional-array-subscript calculation. Most of the arithmetic involved + * can be precalculated and stored in the lookup table colorindex[]. + * colorindex[i][j] maps pixel value j in component i to the nearest + * representative value (grid plane) for that component; this index is + * multiplied by the array stride for component i, so that the + * index of the colormap entry closest to a given pixel value is just + * sum( colorindex[component-number][pixel-component-value] ) + * Aside from being fast, this scheme allows for variable spacing between + * representative values with no additional lookup cost. + * + * If gamma correction has been applied in color conversion, it might be wise + * to adjust the color grid spacing so that the representative colors are + * equidistant in linear space. At this writing, gamma correction is not + * implemented by jdcolor, so nothing is done here. + */ + + + /* Declarations for ordered dithering. + * + * We use a standard 16x16 ordered dither array. The basic concept of ordered + * dithering is described in many references, for instance Dale Schumacher's + * chapter II.2 of Graphics Gems II (James Arvo, ed. Academic Press, 1991). + * In place of Schumacher's comparisons against a "threshold" value, we add a + * "dither" value to the input pixel and then round the result to the nearest + * output value. The dither value is equivalent to (0.5 - threshold) times + * the distance between output values. For ordered dithering, we assume that + * the output colors are equally spaced; if not, results will probably be + * worse, since the dither may be too much or too little at a given point. + * + * The normal calculation would be to form pixel value + dither, range-limit + * this to 0..MAXJSAMPLE, and then index into the colorindex table as usual. + * We can skip the separate range-limiting step by extending the colorindex + * table in both directions. + */ + + #define ODITHER_SIZE 16 /* dimension of dither matrix */ + /* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */ + #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */ + #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */ + + typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE]; + typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE]; + + static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = { + /* Bayer's order-4 dither array. Generated by the code given in + * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I. + * The values in this array must range from 0 to ODITHER_CELLS-1. + */ + { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }, + { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 }, + { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 }, + { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 }, + { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 }, + { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 }, + { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 }, + { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 }, + { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 }, + { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 }, + { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 }, + { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 }, + { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 }, + { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 }, + { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 }, + { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 } + }; + + + /* Declarations for Floyd-Steinberg dithering. + * + * Errors are accumulated into the array fserrors[], at a resolution of + * 1/16th of a pixel count. The error at a given pixel is propagated + * to its not-yet-processed neighbors using the standard F-S fractions, + * ... (here) 7/16 + * 3/16 5/16 1/16 + * We work left-to-right on even rows, right-to-left on odd rows. + * + * We can get away with a single array (holding one row's worth of errors) + * by using it to store the current row's errors at pixel columns not yet + * processed, but the next row's errors at columns already processed. We + * need only a few extra variables to hold the errors immediately around the + * current column. (If we are lucky, those variables are in registers, but + * even if not, they're probably cheaper to access than array elements are.) + * + * The fserrors[] array is indexed [component#][position]. + * We provide (#columns + 2) entries per component; the extra entry at each + * end saves us from special-casing the first and last pixels. + * + * Note: on a wide image, we might not have enough room in a PC's near data + * segment to hold the error array; so it is allocated with alloc_large. + */ + + #if BITS_IN_JSAMPLE == 8 + typedef INT16 FSERROR; /* 16 bits should be enough */ + typedef int LOCFSERROR; /* use 'int' for calculation temps */ + #else + typedef INT32 FSERROR; /* may need more than 16 bits */ + typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */ + #endif + + typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */ + + + /* Private subobject */ + + #define MAX_Q_COMPS 4 /* max components I can handle */ + + typedef struct { + struct jpeg_color_quantizer pub; /* public fields */ + + /* Initially allocated colormap is saved here */ + JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */ + int sv_actual; /* number of entries in use */ + + JSAMPARRAY colorindex; /* Precomputed mapping for speed */ + /* colorindex[i][j] = index of color closest to pixel value j in component i, + * premultiplied as described above. Since colormap indexes must fit into + * JSAMPLEs, the entries of this array will too. + */ + boolean is_padded; /* is the colorindex padded for odither? */ + + int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */ + + /* Variables for ordered dithering */ + int row_index; /* cur row's vertical index in dither matrix */ + ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */ + + /* Variables for Floyd-Steinberg dithering */ + FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ + boolean on_odd_row; /* flag to remember which row we are on */ + } my_cquantizer; + + typedef my_cquantizer * my_cquantize_ptr; + + + /* + * Policy-making subroutines for create_colormap and create_colorindex. + * These routines determine the colormap to be used. The rest of the module + * only assumes that the colormap is orthogonal. + * + * * select_ncolors decides how to divvy up the available colors + * among the components. + * * output_value defines the set of representative values for a component. + * * largest_input_value defines the mapping from input values to + * representative values for a component. + * Note that the latter two routines may impose different policies for + * different components, though this is not currently done. + */ + + + LOCAL(int) + select_ncolors (j_decompress_ptr cinfo, int Ncolors[]) + /* Determine allocation of desired colors to components, */ + /* and fill in Ncolors[] array to indicate choice. */ + /* Return value is total number of colors (product of Ncolors[] values). */ + { + int nc = cinfo->out_color_components; /* number of color components */ + int max_colors = cinfo->desired_number_of_colors; + int total_colors, iroot, i, j; + boolean changed; + long temp; + static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE }; + + /* We can allocate at least the nc'th root of max_colors per component. */ + /* Compute floor(nc'th root of max_colors). */ + iroot = 1; + do { + iroot++; + temp = iroot; /* set temp = iroot ** nc */ + for (i = 1; i < nc; i++) + temp *= iroot; + } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */ + iroot--; /* now iroot = floor(root) */ + + /* Must have at least 2 color values per component */ + if (iroot < 2) + ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp); + + /* Initialize to iroot color values for each component */ + total_colors = 1; + for (i = 0; i < nc; i++) { + Ncolors[i] = iroot; + total_colors *= iroot; + } + /* We may be able to increment the count for one or more components without + * exceeding max_colors, though we know not all can be incremented. + * Sometimes, the first component can be incremented more than once! + * (Example: for 16 colors, we start at 2*2*2, go to 3*2*2, then 4*2*2.) + * In RGB colorspace, try to increment G first, then R, then B. + */ + do { + changed = FALSE; + for (i = 0; i < nc; i++) { + j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i); + /* calculate new total_colors if Ncolors[j] is incremented */ + temp = total_colors / Ncolors[j]; + temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */ + if (temp > (long) max_colors) + break; /* won't fit, done with this pass */ + Ncolors[j]++; /* OK, apply the increment */ + total_colors = (int) temp; + changed = TRUE; + } + } while (changed); + + return total_colors; + } + + + LOCAL(int) + output_value (j_decompress_ptr cinfo, int ci, int j, int maxj) + /* Return j'th output value, where j will range from 0 to maxj */ + /* The output values must fall in 0..MAXJSAMPLE in increasing order */ + { + /* We always provide values 0 and MAXJSAMPLE for each component; + * any additional values are equally spaced between these limits. + * (Forcing the upper and lower values to the limits ensures that + * dithering can't produce a color outside the selected gamut.) + */ + return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj); + } + + + LOCAL(int) + largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj) + /* Return largest input value that should map to j'th output value */ + /* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */ + { + /* Breakpoints are halfway between values returned by output_value */ + return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj)); + } + + + /* + * Create the colormap. + */ + + LOCAL(void) + create_colormap (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + JSAMPARRAY colormap; /* Created colormap */ + int total_colors; /* Number of distinct output colors */ + int i,j,k, nci, blksize, blkdist, ptr, val; + + /* Select number of colors for each component */ + total_colors = select_ncolors(cinfo, cquantize->Ncolors); + + /* Report selected color counts */ + if (cinfo->out_color_components == 3) + TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS, + total_colors, cquantize->Ncolors[0], + cquantize->Ncolors[1], cquantize->Ncolors[2]); + else + TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors); + + /* Allocate and fill in the colormap. */ + /* The colors are ordered in the map in standard row-major order, */ + /* i.e. rightmost (highest-indexed) color changes most rapidly. */ + + colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components); + + /* blksize is number of adjacent repeated entries for a component */ + /* blkdist is distance between groups of identical entries for a component */ + blkdist = total_colors; + + for (i = 0; i < cinfo->out_color_components; i++) { + /* fill in colormap entries for i'th color component */ + nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ + blksize = blkdist / nci; + for (j = 0; j < nci; j++) { + /* Compute j'th output value (out of nci) for component */ + val = output_value(cinfo, i, j, nci-1); + /* Fill in all colormap entries that have this value of this component */ + for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) { + /* fill in blksize entries beginning at ptr */ + for (k = 0; k < blksize; k++) + colormap[i][ptr+k] = (JSAMPLE) val; + } + } + blkdist = blksize; /* blksize of this color is blkdist of next */ + } + + /* Save the colormap in private storage, + * where it will survive color quantization mode changes. + */ + cquantize->sv_colormap = colormap; + cquantize->sv_actual = total_colors; + } + + + /* + * Create the color index table. + */ + + LOCAL(void) + create_colorindex (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + JSAMPROW indexptr; + int i,j,k, nci, blksize, val, pad; + + /* For ordered dither, we pad the color index tables by MAXJSAMPLE in + * each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE). + * This is not necessary in the other dithering modes. However, we + * flag whether it was done in case user changes dithering mode. + */ + if (cinfo->dither_mode == JDITHER_ORDERED) { + pad = MAXJSAMPLE*2; + cquantize->is_padded = TRUE; + } else { + pad = 0; + cquantize->is_padded = FALSE; + } + + cquantize->colorindex = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (MAXJSAMPLE+1 + pad), + (JDIMENSION) cinfo->out_color_components); + + /* blksize is number of adjacent repeated entries for a component */ + blksize = cquantize->sv_actual; + + for (i = 0; i < cinfo->out_color_components; i++) { + /* fill in colorindex entries for i'th color component */ + nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ + blksize = blksize / nci; + + /* adjust colorindex pointers to provide padding at negative indexes. */ + if (pad) + cquantize->colorindex[i] += MAXJSAMPLE; + + /* in loop, val = index of current output value, */ + /* and k = largest j that maps to current val */ + indexptr = cquantize->colorindex[i]; + val = 0; + k = largest_input_value(cinfo, i, 0, nci-1); + for (j = 0; j <= MAXJSAMPLE; j++) { + while (j > k) /* advance val if past boundary */ + k = largest_input_value(cinfo, i, ++val, nci-1); + /* premultiply so that no multiplication needed in main processing */ + indexptr[j] = (JSAMPLE) (val * blksize); + } + /* Pad at both ends if necessary */ + if (pad) + for (j = 1; j <= MAXJSAMPLE; j++) { + indexptr[-j] = indexptr[0]; + indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE]; + } + } + } + + + /* + * Create an ordered-dither array for a component having ncolors + * distinct output values. + */ + + LOCAL(ODITHER_MATRIX_PTR) + make_odither_array (j_decompress_ptr cinfo, int ncolors) + { + ODITHER_MATRIX_PTR odither; + int j,k; + INT32 num,den; + + odither = (ODITHER_MATRIX_PTR) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(ODITHER_MATRIX)); + /* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1). + * Hence the dither value for the matrix cell with fill order f + * (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1). + * On 16-bit-int machine, be careful to avoid overflow. + */ + den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1)); + for (j = 0; j < ODITHER_SIZE; j++) { + for (k = 0; k < ODITHER_SIZE; k++) { + num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k]))) + * MAXJSAMPLE; + /* Ensure round towards zero despite C's lack of consistency + * about rounding negative values in integer division... + */ + odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den); + } + } + return odither; + } + + + /* + * Create the ordered-dither tables. + * Components having the same number of representative colors may + * share a dither table. + */ + + LOCAL(void) + create_odither_tables (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + ODITHER_MATRIX_PTR odither; + int i, j, nci; + + for (i = 0; i < cinfo->out_color_components; i++) { + nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ + odither = NULL; /* search for matching prior component */ + for (j = 0; j < i; j++) { + if (nci == cquantize->Ncolors[j]) { + odither = cquantize->odither[j]; + break; + } + } + if (odither == NULL) /* need a new table? */ + odither = make_odither_array(cinfo, nci); + cquantize->odither[i] = odither; + } + } + + + /* + * Map some rows of pixels to the output colormapped representation. + */ + + METHODDEF(void) + color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) + /* General case, no dithering */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + JSAMPARRAY colorindex = cquantize->colorindex; + register int pixcode, ci; + register JSAMPROW ptrin, ptrout; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + register int nc = cinfo->out_color_components; + + for (row = 0; row < num_rows; row++) { + ptrin = input_buf[row]; + ptrout = output_buf[row]; + for (col = width; col > 0; col--) { + pixcode = 0; + for (ci = 0; ci < nc; ci++) { + pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]); + } + *ptrout++ = (JSAMPLE) pixcode; + } + } + } + + + METHODDEF(void) + color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) + /* Fast path for out_color_components==3, no dithering */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register int pixcode; + register JSAMPROW ptrin, ptrout; + JSAMPROW colorindex0 = cquantize->colorindex[0]; + JSAMPROW colorindex1 = cquantize->colorindex[1]; + JSAMPROW colorindex2 = cquantize->colorindex[2]; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + ptrin = input_buf[row]; + ptrout = output_buf[row]; + for (col = width; col > 0; col--) { + pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]); + pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]); + pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]); + *ptrout++ = (JSAMPLE) pixcode; + } + } + } + + + METHODDEF(void) + quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) + /* General case, with ordered dithering */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register JSAMPROW input_ptr; + register JSAMPROW output_ptr; + JSAMPROW colorindex_ci; + int * dither; /* points to active row of dither matrix */ + int row_index, col_index; /* current indexes into dither matrix */ + int nc = cinfo->out_color_components; + int ci; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + /* Initialize output values to 0 so can process components separately */ + jzero_far((void FAR *) output_buf[row], + (size_t) (width * SIZEOF(JSAMPLE))); + row_index = cquantize->row_index; + for (ci = 0; ci < nc; ci++) { + input_ptr = input_buf[row] + ci; + output_ptr = output_buf[row]; + colorindex_ci = cquantize->colorindex[ci]; + dither = cquantize->odither[ci][row_index]; + col_index = 0; + + for (col = width; col > 0; col--) { + /* Form pixel value + dither, range-limit to 0..MAXJSAMPLE, + * select output value, accumulate into output code for this pixel. + * Range-limiting need not be done explicitly, as we have extended + * the colorindex table to produce the right answers for out-of-range + * inputs. The maximum dither is +- MAXJSAMPLE; this sets the + * required amount of padding. + */ + *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]]; + input_ptr += nc; + output_ptr++; + col_index = (col_index + 1) & ODITHER_MASK; + } + } + /* Advance row index for next row */ + row_index = (row_index + 1) & ODITHER_MASK; + cquantize->row_index = row_index; + } + } + + + METHODDEF(void) + quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) + /* Fast path for out_color_components==3, with ordered dithering */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register int pixcode; + register JSAMPROW input_ptr; + register JSAMPROW output_ptr; + JSAMPROW colorindex0 = cquantize->colorindex[0]; + JSAMPROW colorindex1 = cquantize->colorindex[1]; + JSAMPROW colorindex2 = cquantize->colorindex[2]; + int * dither0; /* points to active row of dither matrix */ + int * dither1; + int * dither2; + int row_index, col_index; /* current indexes into dither matrix */ + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + row_index = cquantize->row_index; + input_ptr = input_buf[row]; + output_ptr = output_buf[row]; + dither0 = cquantize->odither[0][row_index]; + dither1 = cquantize->odither[1][row_index]; + dither2 = cquantize->odither[2][row_index]; + col_index = 0; + + for (col = width; col > 0; col--) { + pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) + + dither0[col_index]]); + pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) + + dither1[col_index]]); + pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) + + dither2[col_index]]); + *output_ptr++ = (JSAMPLE) pixcode; + col_index = (col_index + 1) & ODITHER_MASK; + } + row_index = (row_index + 1) & ODITHER_MASK; + cquantize->row_index = row_index; + } + } + + + METHODDEF(void) + quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) + /* General case, with Floyd-Steinberg dithering */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register LOCFSERROR cur; /* current error or pixel value */ + LOCFSERROR belowerr; /* error for pixel below cur */ + LOCFSERROR bpreverr; /* error for below/prev col */ + LOCFSERROR bnexterr; /* error for below/next col */ + LOCFSERROR delta; + register FSERRPTR errorptr; /* => fserrors[] at column before current */ + register JSAMPROW input_ptr; + register JSAMPROW output_ptr; + JSAMPROW colorindex_ci; + JSAMPROW colormap_ci; + int pixcode; + int nc = cinfo->out_color_components; + int dir; /* 1 for left-to-right, -1 for right-to-left */ + int dirnc; /* dir * nc */ + int ci; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + JSAMPLE *range_limit = cinfo->sample_range_limit; + SHIFT_TEMPS + + for (row = 0; row < num_rows; row++) { + /* Initialize output values to 0 so can process components separately */ + jzero_far((void FAR *) output_buf[row], + (size_t) (width * SIZEOF(JSAMPLE))); + for (ci = 0; ci < nc; ci++) { + input_ptr = input_buf[row] + ci; + output_ptr = output_buf[row]; + if (cquantize->on_odd_row) { + /* work right to left in this row */ + input_ptr += (width-1) * nc; /* so point to rightmost pixel */ + output_ptr += width-1; + dir = -1; + dirnc = -nc; + errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */ + } else { + /* work left to right in this row */ + dir = 1; + dirnc = nc; + errorptr = cquantize->fserrors[ci]; /* => entry before first column */ + } + colorindex_ci = cquantize->colorindex[ci]; + colormap_ci = cquantize->sv_colormap[ci]; + /* Preset error values: no error propagated to first pixel from left */ + cur = 0; + /* and no error propagated to row below yet */ + belowerr = bpreverr = 0; + + for (col = width; col > 0; col--) { + /* cur holds the error propagated from the previous pixel on the + * current line. Add the error propagated from the previous line + * to form the complete error correction term for this pixel, and + * round the error term (which is expressed * 16) to an integer. + * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct + * for either sign of the error value. + * Note: errorptr points to *previous* column's array entry. + */ + cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4); + /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. + * The maximum error is +- MAXJSAMPLE; this sets the required size + * of the range_limit array. + */ + cur += GETJSAMPLE(*input_ptr); + cur = GETJSAMPLE(range_limit[cur]); + /* Select output value, accumulate into output code for this pixel */ + pixcode = GETJSAMPLE(colorindex_ci[cur]); + *output_ptr += (JSAMPLE) pixcode; + /* Compute actual representation error at this pixel */ + /* Note: we can do this even though we don't have the final */ + /* pixel code, because the colormap is orthogonal. */ + cur -= GETJSAMPLE(colormap_ci[pixcode]); + /* Compute error fractions to be propagated to adjacent pixels. + * Add these into the running sums, and simultaneously shift the + * next-line error sums left by 1 column. + */ + bnexterr = cur; + delta = cur * 2; + cur += delta; /* form error * 3 */ + errorptr[0] = (FSERROR) (bpreverr + cur); + cur += delta; /* form error * 5 */ + bpreverr = belowerr + cur; + belowerr = bnexterr; + cur += delta; /* form error * 7 */ + /* At this point cur contains the 7/16 error value to be propagated + * to the next pixel on the current line, and all the errors for the + * next line have been shifted over. We are therefore ready to move on. + */ + input_ptr += dirnc; /* advance input ptr to next column */ + output_ptr += dir; /* advance output ptr to next column */ + errorptr += dir; /* advance errorptr to current column */ + } + /* Post-loop cleanup: we must unload the final error value into the + * final fserrors[] entry. Note we need not unload belowerr because + * it is for the dummy column before or after the actual array. + */ + errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */ + } + cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE); + } + } + + + /* + * Allocate workspace for Floyd-Steinberg errors. + */ + + LOCAL(void) + alloc_fs_workspace (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + size_t arraysize; + int i; + + arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); + for (i = 0; i < cinfo->out_color_components; i++) { + cquantize->fserrors[i] = (FSERRPTR) + (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); + } + } + + + /* + * Initialize for one-pass color quantization. + */ + + METHODDEF(void) + start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + size_t arraysize; + int i; + + /* Install my colormap. */ + cinfo->colormap = cquantize->sv_colormap; + cinfo->actual_number_of_colors = cquantize->sv_actual; + + /* Initialize for desired dithering mode. */ + switch (cinfo->dither_mode) { + case JDITHER_NONE: + if (cinfo->out_color_components == 3) + cquantize->pub.color_quantize = color_quantize3; + else + cquantize->pub.color_quantize = color_quantize; + break; + case JDITHER_ORDERED: + if (cinfo->out_color_components == 3) + cquantize->pub.color_quantize = quantize3_ord_dither; + else + cquantize->pub.color_quantize = quantize_ord_dither; + cquantize->row_index = 0; /* initialize state for ordered dither */ + /* If user changed to ordered dither from another mode, + * we must recreate the color index table with padding. + * This will cost extra space, but probably isn't very likely. + */ + if (! cquantize->is_padded) + create_colorindex(cinfo); + /* Create ordered-dither tables if we didn't already. */ + if (cquantize->odither[0] == NULL) + create_odither_tables(cinfo); + break; + case JDITHER_FS: + cquantize->pub.color_quantize = quantize_fs_dither; + cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */ + /* Allocate Floyd-Steinberg workspace if didn't already. */ + if (cquantize->fserrors[0] == NULL) + alloc_fs_workspace(cinfo); + /* Initialize the propagated errors to zero. */ + arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); + for (i = 0; i < cinfo->out_color_components; i++) + jzero_far((void FAR *) cquantize->fserrors[i], arraysize); + break; + default: + ERREXIT(cinfo, JERR_NOT_COMPILED); + break; + } + } + + + /* + * Finish up at the end of the pass. + */ + + METHODDEF(void) + finish_pass_1_quant (j_decompress_ptr cinfo) + { + /* no work in 1-pass case */ + } + + + /* + * Switch to a new external colormap between output passes. + * Shouldn't get to this module! + */ + + METHODDEF(void) + new_color_map_1_quant (j_decompress_ptr cinfo) + { + ERREXIT(cinfo, JERR_MODE_CHANGE); + } + + + /* + * Module initialization routine for 1-pass color quantization. + */ + + GLOBAL(void) + jinit_1pass_quantizer (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize; + + cquantize = (my_cquantize_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_cquantizer)); + cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; + cquantize->pub.start_pass = start_pass_1_quant; + cquantize->pub.finish_pass = finish_pass_1_quant; + cquantize->pub.new_color_map = new_color_map_1_quant; + cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */ + cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */ + + /* Make sure my internal arrays won't overflow */ + if (cinfo->out_color_components > MAX_Q_COMPS) + ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS); + /* Make sure colormap indexes can be represented by JSAMPLEs */ + if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1)) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1); + + /* Create the colormap and color index table. */ + create_colormap(cinfo); + create_colorindex(cinfo); + + /* Allocate Floyd-Steinberg workspace now if requested. + * We do this now since it is FAR storage and may affect the memory + * manager's space calculations. If the user changes to FS dither + * mode in a later pass, we will allocate the space then, and will + * possibly overrun the max_memory_to_use setting. + */ + if (cinfo->dither_mode == JDITHER_FS) + alloc_fs_workspace(cinfo); + } + + #endif /* QUANT_1PASS_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jquant2.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jquant2.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jquant2.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,1310 ---- + /* + * jquant2.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains 2-pass color quantization (color mapping) routines. + * These routines provide selection of a custom color map for an image, + * followed by mapping of the image to that color map, with optional + * Floyd-Steinberg dithering. + * It is also possible to use just the second pass to map to an arbitrary + * externally-given color map. + * + * Note: ordered dithering is not supported, since there isn't any fast + * way to compute intercolor distances; it's unclear that ordered dither's + * fundamental assumptions even hold with an irregularly spaced color map. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + #ifdef QUANT_2PASS_SUPPORTED + + + /* + * This module implements the well-known Heckbert paradigm for color + * quantization. Most of the ideas used here can be traced back to + * Heckbert's seminal paper + * Heckbert, Paul. "Color Image Quantization for Frame Buffer Display", + * Proc. SIGGRAPH '82, Computer Graphics v.16 #3 (July 1982), pp 297-304. + * + * In the first pass over the image, we accumulate a histogram showing the + * usage count of each possible color. To keep the histogram to a reasonable + * size, we reduce the precision of the input; typical practice is to retain + * 5 or 6 bits per color, so that 8 or 4 different input values are counted + * in the same histogram cell. + * + * Next, the color-selection step begins with a box representing the whole + * color space, and repeatedly splits the "largest" remaining box until we + * have as many boxes as desired colors. Then the mean color in each + * remaining box becomes one of the possible output colors. + * + * The second pass over the image maps each input pixel to the closest output + * color (optionally after applying a Floyd-Steinberg dithering correction). + * This mapping is logically trivial, but making it go fast enough requires + * considerable care. + * + * Heckbert-style quantizers vary a good deal in their policies for choosing + * the "largest" box and deciding where to cut it. The particular policies + * used here have proved out well in experimental comparisons, but better ones + * may yet be found. + * + * In earlier versions of the IJG code, this module quantized in YCbCr color + * space, processing the raw upsampled data without a color conversion step. + * This allowed the color conversion math to be done only once per colormap + * entry, not once per pixel. However, that optimization precluded other + * useful optimizations (such as merging color conversion with upsampling) + * and it also interfered with desired capabilities such as quantizing to an + * externally-supplied colormap. We have therefore abandoned that approach. + * The present code works in the post-conversion color space, typically RGB. + * + * To improve the visual quality of the results, we actually work in scaled + * RGB space, giving G distances more weight than R, and R in turn more than + * B. To do everything in integer math, we must use integer scale factors. + * The 2/3/1 scale factors used here correspond loosely to the relative + * weights of the colors in the NTSC grayscale equation. + * If you want to use this code to quantize a non-RGB color space, you'll + * probably need to change these scale factors. + */ + + #define R_SCALE 2 /* scale R distances by this much */ + #define G_SCALE 3 /* scale G distances by this much */ + #define B_SCALE 1 /* and B by this much */ + + /* Relabel R/G/B as components 0/1/2, respecting the RGB ordering defined + * in jmorecfg.h. As the code stands, it will do the right thing for R,G,B + * and B,G,R orders. If you define some other weird order in jmorecfg.h, + * you'll get compile errors until you extend this logic. In that case + * you'll probably want to tweak the histogram sizes too. + */ + + #if RGB_RED == 0 + #define C0_SCALE R_SCALE + #endif + #if RGB_BLUE == 0 + #define C0_SCALE B_SCALE + #endif + #if RGB_GREEN == 1 + #define C1_SCALE G_SCALE + #endif + #if RGB_RED == 2 + #define C2_SCALE R_SCALE + #endif + #if RGB_BLUE == 2 + #define C2_SCALE B_SCALE + #endif + + + /* + * First we have the histogram data structure and routines for creating it. + * + * The number of bits of precision can be adjusted by changing these symbols. + * We recommend keeping 6 bits for G and 5 each for R and B. + * If you have plenty of memory and cycles, 6 bits all around gives marginally + * better results; if you are short of memory, 5 bits all around will save + * some space but degrade the results. + * To maintain a fully accurate histogram, we'd need to allocate a "long" + * (preferably unsigned long) for each cell. In practice this is overkill; + * we can get by with 16 bits per cell. Few of the cell counts will overflow, + * and clamping those that do overflow to the maximum value will give close- + * enough results. This reduces the recommended histogram size from 256Kb + * to 128Kb, which is a useful savings on PC-class machines. + * (In the second pass the histogram space is re-used for pixel mapping data; + * in that capacity, each cell must be able to store zero to the number of + * desired colors. 16 bits/cell is plenty for that too.) + * Since the JPEG code is intended to run in small memory model on 80x86 + * machines, we can't just allocate the histogram in one chunk. Instead + * of a true 3-D array, we use a row of pointers to 2-D arrays. Each + * pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and + * each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries. Note that + * on 80x86 machines, the pointer row is in near memory but the actual + * arrays are in far memory (same arrangement as we use for image arrays). + */ + + #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */ + + /* These will do the right thing for either R,G,B or B,G,R color order, + * but you may not like the results for other color orders. + */ + #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */ + #define HIST_C1_BITS 6 /* bits of precision in G histogram */ + #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */ + + /* Number of elements along histogram axes. */ + #define HIST_C0_ELEMS (1<<HIST_C0_BITS) + #define HIST_C1_ELEMS (1<<HIST_C1_BITS) + #define HIST_C2_ELEMS (1<<HIST_C2_BITS) + + /* These are the amounts to shift an input value to get a histogram index. */ + #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS) + #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS) + #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS) + + + typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */ + + typedef histcell FAR * histptr; /* for pointers to histogram cells */ + + typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */ + typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */ + typedef hist2d * hist3d; /* type for top-level pointer */ + + + /* Declarations for Floyd-Steinberg dithering. + * + * Errors are accumulated into the array fserrors[], at a resolution of + * 1/16th of a pixel count. The error at a given pixel is propagated + * to its not-yet-processed neighbors using the standard F-S fractions, + * ... (here) 7/16 + * 3/16 5/16 1/16 + * We work left-to-right on even rows, right-to-left on odd rows. + * + * We can get away with a single array (holding one row's worth of errors) + * by using it to store the current row's errors at pixel columns not yet + * processed, but the next row's errors at columns already processed. We + * need only a few extra variables to hold the errors immediately around the + * current column. (If we are lucky, those variables are in registers, but + * even if not, they're probably cheaper to access than array elements are.) + * + * The fserrors[] array has (#columns + 2) entries; the extra entry at + * each end saves us from special-casing the first and last pixels. + * Each entry is three values long, one value for each color component. + * + * Note: on a wide image, we might not have enough room in a PC's near data + * segment to hold the error array; so it is allocated with alloc_large. + */ + + #if BITS_IN_JSAMPLE == 8 + typedef INT16 FSERROR; /* 16 bits should be enough */ + typedef int LOCFSERROR; /* use 'int' for calculation temps */ + #else + typedef INT32 FSERROR; /* may need more than 16 bits */ + typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */ + #endif + + typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */ + + + /* Private subobject */ + + typedef struct { + struct jpeg_color_quantizer pub; /* public fields */ + + /* Space for the eventually created colormap is stashed here */ + JSAMPARRAY sv_colormap; /* colormap allocated at init time */ + int desired; /* desired # of colors = size of colormap */ + + /* Variables for accumulating image statistics */ + hist3d histogram; /* pointer to the histogram */ + + boolean needs_zeroed; /* TRUE if next pass must zero histogram */ + + /* Variables for Floyd-Steinberg dithering */ + FSERRPTR fserrors; /* accumulated errors */ + boolean on_odd_row; /* flag to remember which row we are on */ + int * error_limiter; /* table for clamping the applied error */ + } my_cquantizer; + + typedef my_cquantizer * my_cquantize_ptr; + + + /* + * Prescan some rows of pixels. + * In this module the prescan simply updates the histogram, which has been + * initialized to zeroes by start_pass. + * An output_buf parameter is required by the method signature, but no data + * is actually output (in fact the buffer controller is probably passing a + * NULL pointer). + */ + + METHODDEF(void) + prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, + JSAMPARRAY output_buf, int num_rows) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + register JSAMPROW ptr; + register histptr histp; + register hist3d histogram = cquantize->histogram; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + ptr = input_buf[row]; + for (col = width; col > 0; col--) { + /* get pixel value and index into the histogram */ + histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT] + [GETJSAMPLE(ptr[1]) >> C1_SHIFT] + [GETJSAMPLE(ptr[2]) >> C2_SHIFT]; + /* increment, check for overflow and undo increment if so. */ + if (++(*histp) <= 0) + (*histp)--; + ptr += 3; + } + } + } + + + /* + * Next we have the really interesting routines: selection of a colormap + * given the completed histogram. + * These routines work with a list of "boxes", each representing a rectangular + * subset of the input color space (to histogram precision). + */ + + typedef struct { + /* The bounds of the box (inclusive); expressed as histogram indexes */ + int c0min, c0max; + int c1min, c1max; + int c2min, c2max; + /* The volume (actually 2-norm) of the box */ + INT32 volume; + /* The number of nonzero histogram cells within this box */ + long colorcount; + } box; + + typedef box * boxptr; + + + LOCAL(boxptr) + find_biggest_color_pop (boxptr boxlist, int numboxes) + /* Find the splittable box with the largest color population */ + /* Returns NULL if no splittable boxes remain */ + { + register boxptr boxp; + register int i; + register long maxc = 0; + boxptr which = NULL; + + for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) { + if (boxp->colorcount > maxc && boxp->volume > 0) { + which = boxp; + maxc = boxp->colorcount; + } + } + return which; + } + + + LOCAL(boxptr) + find_biggest_volume (boxptr boxlist, int numboxes) + /* Find the splittable box with the largest (scaled) volume */ + /* Returns NULL if no splittable boxes remain */ + { + register boxptr boxp; + register int i; + register INT32 maxv = 0; + boxptr which = NULL; + + for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) { + if (boxp->volume > maxv) { + which = boxp; + maxv = boxp->volume; + } + } + return which; + } + + + LOCAL(void) + update_box (j_decompress_ptr cinfo, boxptr boxp) + /* Shrink the min/max bounds of a box to enclose only nonzero elements, */ + /* and recompute its volume and population */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + histptr histp; + int c0,c1,c2; + int c0min,c0max,c1min,c1max,c2min,c2max; + INT32 dist0,dist1,dist2; + long ccount; + + c0min = boxp->c0min; c0max = boxp->c0max; + c1min = boxp->c1min; c1max = boxp->c1max; + c2min = boxp->c2min; c2max = boxp->c2max; + + if (c0max > c0min) + for (c0 = c0min; c0 <= c0max; c0++) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c0min = c0min = c0; + goto have_c0min; + } + } + have_c0min: + if (c0max > c0min) + for (c0 = c0max; c0 >= c0min; c0--) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c0max = c0max = c0; + goto have_c0max; + } + } + have_c0max: + if (c1max > c1min) + for (c1 = c1min; c1 <= c1max; c1++) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c1min = c1min = c1; + goto have_c1min; + } + } + have_c1min: + if (c1max > c1min) + for (c1 = c1max; c1 >= c1min; c1--) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) + if (*histp++ != 0) { + boxp->c1max = c1max = c1; + goto have_c1max; + } + } + have_c1max: + if (c2max > c2min) + for (c2 = c2min; c2 <= c2max; c2++) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1min][c2]; + for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) + if (*histp != 0) { + boxp->c2min = c2min = c2; + goto have_c2min; + } + } + have_c2min: + if (c2max > c2min) + for (c2 = c2max; c2 >= c2min; c2--) + for (c0 = c0min; c0 <= c0max; c0++) { + histp = & histogram[c0][c1min][c2]; + for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) + if (*histp != 0) { + boxp->c2max = c2max = c2; + goto have_c2max; + } + } + have_c2max: + + /* Update box volume. + * We use 2-norm rather than real volume here; this biases the method + * against making long narrow boxes, and it has the side benefit that + * a box is splittable iff norm > 0. + * Since the differences are expressed in histogram-cell units, + * we have to shift back to JSAMPLE units to get consistent distances; + * after which, we scale according to the selected distance scale factors. + */ + dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE; + dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE; + dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE; + boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2; + + /* Now scan remaining volume of box and compute population */ + ccount = 0; + for (c0 = c0min; c0 <= c0max; c0++) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++, histp++) + if (*histp != 0) { + ccount++; + } + } + boxp->colorcount = ccount; + } + + + LOCAL(int) + median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes, + int desired_colors) + /* Repeatedly select and split the largest box until we have enough boxes */ + { + int n,lb; + int c0,c1,c2,cmax; + register boxptr b1,b2; + + while (numboxes < desired_colors) { + /* Select box to split. + * Current algorithm: by population for first half, then by volume. + */ + if (numboxes*2 <= desired_colors) { + b1 = find_biggest_color_pop(boxlist, numboxes); + } else { + b1 = find_biggest_volume(boxlist, numboxes); + } + if (b1 == NULL) /* no splittable boxes left! */ + break; + b2 = &boxlist[numboxes]; /* where new box will go */ + /* Copy the color bounds to the new box. */ + b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max; + b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min; + /* Choose which axis to split the box on. + * Current algorithm: longest scaled axis. + * See notes in update_box about scaling distances. + */ + c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE; + c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE; + c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE; + /* We want to break any ties in favor of green, then red, blue last. + * This code does the right thing for R,G,B or B,G,R color orders only. + */ + #if RGB_RED == 0 + cmax = c1; n = 1; + if (c0 > cmax) { cmax = c0; n = 0; } + if (c2 > cmax) { n = 2; } + #else + cmax = c1; n = 1; + if (c2 > cmax) { cmax = c2; n = 2; } + if (c0 > cmax) { n = 0; } + #endif + /* Choose split point along selected axis, and update box bounds. + * Current algorithm: split at halfway point. + * (Since the box has been shrunk to minimum volume, + * any split will produce two nonempty subboxes.) + * Note that lb value is max for lower box, so must be < old max. + */ + switch (n) { + case 0: + lb = (b1->c0max + b1->c0min) / 2; + b1->c0max = lb; + b2->c0min = lb+1; + break; + case 1: + lb = (b1->c1max + b1->c1min) / 2; + b1->c1max = lb; + b2->c1min = lb+1; + break; + case 2: + lb = (b1->c2max + b1->c2min) / 2; + b1->c2max = lb; + b2->c2min = lb+1; + break; + } + /* Update stats for boxes */ + update_box(cinfo, b1); + update_box(cinfo, b2); + numboxes++; + } + return numboxes; + } + + + LOCAL(void) + compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor) + /* Compute representative color for a box, put it in colormap[icolor] */ + { + /* Current algorithm: mean weighted by pixels (not colors) */ + /* Note it is important to get the rounding correct! */ + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + histptr histp; + int c0,c1,c2; + int c0min,c0max,c1min,c1max,c2min,c2max; + long count; + long total = 0; + long c0total = 0; + long c1total = 0; + long c2total = 0; + + c0min = boxp->c0min; c0max = boxp->c0max; + c1min = boxp->c1min; c1max = boxp->c1max; + c2min = boxp->c2min; c2max = boxp->c2max; + + for (c0 = c0min; c0 <= c0max; c0++) + for (c1 = c1min; c1 <= c1max; c1++) { + histp = & histogram[c0][c1][c2min]; + for (c2 = c2min; c2 <= c2max; c2++) { + if ((count = *histp++) != 0) { + total += count; + c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count; + c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count; + c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count; + } + } + } + + cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total); + cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total); + cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total); + } + + + LOCAL(void) + select_colors (j_decompress_ptr cinfo, int desired_colors) + /* Master routine for color selection */ + { + boxptr boxlist; + int numboxes; + int i; + + /* Allocate workspace for box list */ + boxlist = (boxptr) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box)); + /* Initialize one box containing whole space */ + numboxes = 1; + boxlist[0].c0min = 0; + boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT; + boxlist[0].c1min = 0; + boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT; + boxlist[0].c2min = 0; + boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT; + /* Shrink it to actually-used volume and set its statistics */ + update_box(cinfo, & boxlist[0]); + /* Perform median-cut to produce final box list */ + numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors); + /* Compute the representative color for each box, fill colormap */ + for (i = 0; i < numboxes; i++) + compute_color(cinfo, & boxlist[i], i); + cinfo->actual_number_of_colors = numboxes; + TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes); + } + + + /* + * These routines are concerned with the time-critical task of mapping input + * colors to the nearest color in the selected colormap. + * + * We re-use the histogram space as an "inverse color map", essentially a + * cache for the results of nearest-color searches. All colors within a + * histogram cell will be mapped to the same colormap entry, namely the one + * closest to the cell's center. This may not be quite the closest entry to + * the actual input color, but it's almost as good. A zero in the cache + * indicates we haven't found the nearest color for that cell yet; the array + * is cleared to zeroes before starting the mapping pass. When we find the + * nearest color for a cell, its colormap index plus one is recorded in the + * cache for future use. The pass2 scanning routines call fill_inverse_cmap + * when they need to use an unfilled entry in the cache. + * + * Our method of efficiently finding nearest colors is based on the "locally + * sorted search" idea described by Heckbert and on the incremental distance + * calculation described by Spencer W. Thomas in chapter III.1 of Graphics + * Gems II (James Arvo, ed. Academic Press, 1991). Thomas points out that + * the distances from a given colormap entry to each cell of the histogram can + * be computed quickly using an incremental method: the differences between + * distances to adjacent cells themselves differ by a constant. This allows a + * fairly fast implementation of the "brute force" approach of computing the + * distance from every colormap entry to every histogram cell. Unfortunately, + * it needs a work array to hold the best-distance-so-far for each histogram + * cell (because the inner loop has to be over cells, not colormap entries). + * The work array elements have to be INT32s, so the work array would need + * 256Kb at our recommended precision. This is not feasible in DOS machines. + * + * To get around these problems, we apply Thomas' method to compute the + * nearest colors for only the cells within a small subbox of the histogram. + * The work array need be only as big as the subbox, so the memory usage + * problem is solved. Furthermore, we need not fill subboxes that are never + * referenced in pass2; many images use only part of the color gamut, so a + * fair amount of work is saved. An additional advantage of this + * approach is that we can apply Heckbert's locality criterion to quickly + * eliminate colormap entries that are far away from the subbox; typically + * three-fourths of the colormap entries are rejected by Heckbert's criterion, + * and we need not compute their distances to individual cells in the subbox. + * The speed of this approach is heavily influenced by the subbox size: too + * small means too much overhead, too big loses because Heckbert's criterion + * can't eliminate as many colormap entries. Empirically the best subbox + * size seems to be about 1/512th of the histogram (1/8th in each direction). + * + * Thomas' article also describes a refined method which is asymptotically + * faster than the brute-force method, but it is also far more complex and + * cannot efficiently be applied to small subboxes. It is therefore not + * useful for programs intended to be portable to DOS machines. On machines + * with plenty of memory, filling the whole histogram in one shot with Thomas' + * refined method might be faster than the present code --- but then again, + * it might not be any faster, and it's certainly more complicated. + */ + + + /* log2(histogram cells in update box) for each axis; this can be adjusted */ + #define BOX_C0_LOG (HIST_C0_BITS-3) + #define BOX_C1_LOG (HIST_C1_BITS-3) + #define BOX_C2_LOG (HIST_C2_BITS-3) + + #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */ + #define BOX_C1_ELEMS (1<<BOX_C1_LOG) + #define BOX_C2_ELEMS (1<<BOX_C2_LOG) + + #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG) + #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG) + #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG) + + + /* + * The next three routines implement inverse colormap filling. They could + * all be folded into one big routine, but splitting them up this way saves + * some stack space (the mindist[] and bestdist[] arrays need not coexist) + * and may allow some compilers to produce better code by registerizing more + * inner-loop variables. + */ + + LOCAL(int) + find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, + JSAMPLE colorlist[]) + /* Locate the colormap entries close enough to an update box to be candidates + * for the nearest entry to some cell(s) in the update box. The update box + * is specified by the center coordinates of its first cell. The number of + * candidate colormap entries is returned, and their colormap indexes are + * placed in colorlist[]. + * This routine uses Heckbert's "locally sorted search" criterion to select + * the colors that need further consideration. + */ + { + int numcolors = cinfo->actual_number_of_colors; + int maxc0, maxc1, maxc2; + int centerc0, centerc1, centerc2; + int i, x, ncolors; + INT32 minmaxdist, min_dist, max_dist, tdist; + INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */ + + /* Compute true coordinates of update box's upper corner and center. + * Actually we compute the coordinates of the center of the upper-corner + * histogram cell, which are the upper bounds of the volume we care about. + * Note that since ">>" rounds down, the "center" values may be closer to + * min than to max; hence comparisons to them must be "<=", not "<". + */ + maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT)); + centerc0 = (minc0 + maxc0) >> 1; + maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT)); + centerc1 = (minc1 + maxc1) >> 1; + maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT)); + centerc2 = (minc2 + maxc2) >> 1; + + /* For each color in colormap, find: + * 1. its minimum squared-distance to any point in the update box + * (zero if color is within update box); + * 2. its maximum squared-distance to any point in the update box. + * Both of these can be found by considering only the corners of the box. + * We save the minimum distance for each color in mindist[]; + * only the smallest maximum distance is of interest. + */ + minmaxdist = 0x7FFFFFFFL; + + for (i = 0; i < numcolors; i++) { + /* We compute the squared-c0-distance term, then add in the other two. */ + x = GETJSAMPLE(cinfo->colormap[0][i]); + if (x < minc0) { + tdist = (x - minc0) * C0_SCALE; + min_dist = tdist*tdist; + tdist = (x - maxc0) * C0_SCALE; + max_dist = tdist*tdist; + } else if (x > maxc0) { + tdist = (x - maxc0) * C0_SCALE; + min_dist = tdist*tdist; + tdist = (x - minc0) * C0_SCALE; + max_dist = tdist*tdist; + } else { + /* within cell range so no contribution to min_dist */ + min_dist = 0; + if (x <= centerc0) { + tdist = (x - maxc0) * C0_SCALE; + max_dist = tdist*tdist; + } else { + tdist = (x - minc0) * C0_SCALE; + max_dist = tdist*tdist; + } + } + + x = GETJSAMPLE(cinfo->colormap[1][i]); + if (x < minc1) { + tdist = (x - minc1) * C1_SCALE; + min_dist += tdist*tdist; + tdist = (x - maxc1) * C1_SCALE; + max_dist += tdist*tdist; + } else if (x > maxc1) { + tdist = (x - maxc1) * C1_SCALE; + min_dist += tdist*tdist; + tdist = (x - minc1) * C1_SCALE; + max_dist += tdist*tdist; + } else { + /* within cell range so no contribution to min_dist */ + if (x <= centerc1) { + tdist = (x - maxc1) * C1_SCALE; + max_dist += tdist*tdist; + } else { + tdist = (x - minc1) * C1_SCALE; + max_dist += tdist*tdist; + } + } + + x = GETJSAMPLE(cinfo->colormap[2][i]); + if (x < minc2) { + tdist = (x - minc2) * C2_SCALE; + min_dist += tdist*tdist; + tdist = (x - maxc2) * C2_SCALE; + max_dist += tdist*tdist; + } else if (x > maxc2) { + tdist = (x - maxc2) * C2_SCALE; + min_dist += tdist*tdist; + tdist = (x - minc2) * C2_SCALE; + max_dist += tdist*tdist; + } else { + /* within cell range so no contribution to min_dist */ + if (x <= centerc2) { + tdist = (x - maxc2) * C2_SCALE; + max_dist += tdist*tdist; + } else { + tdist = (x - minc2) * C2_SCALE; + max_dist += tdist*tdist; + } + } + + mindist[i] = min_dist; /* save away the results */ + if (max_dist < minmaxdist) + minmaxdist = max_dist; + } + + /* Now we know that no cell in the update box is more than minmaxdist + * away from some colormap entry. Therefore, only colors that are + * within minmaxdist of some part of the box need be considered. + */ + ncolors = 0; + for (i = 0; i < numcolors; i++) { + if (mindist[i] <= minmaxdist) + colorlist[ncolors++] = (JSAMPLE) i; + } + return ncolors; + } + + + LOCAL(void) + find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, + int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[]) + /* Find the closest colormap entry for each cell in the update box, + * given the list of candidate colors prepared by find_nearby_colors. + * Return the indexes of the closest entries in the bestcolor[] array. + * This routine uses Thomas' incremental distance calculation method to + * find the distance from a colormap entry to successive cells in the box. + */ + { + int ic0, ic1, ic2; + int i, icolor; + register INT32 * bptr; /* pointer into bestdist[] array */ + JSAMPLE * cptr; /* pointer into bestcolor[] array */ + INT32 dist0, dist1; /* initial distance values */ + register INT32 dist2; /* current distance in inner loop */ + INT32 xx0, xx1; /* distance increments */ + register INT32 xx2; + INT32 inc0, inc1, inc2; /* initial values for increments */ + /* This array holds the distance to the nearest-so-far color for each cell */ + INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; + + /* Initialize best-distance for each cell of the update box */ + bptr = bestdist; + for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--) + *bptr++ = 0x7FFFFFFFL; + + /* For each color selected by find_nearby_colors, + * compute its distance to the center of each cell in the box. + * If that's less than best-so-far, update best distance and color number. + */ + + /* Nominal steps between cell centers ("x" in Thomas article) */ + #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE) + #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE) + #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE) + + for (i = 0; i < numcolors; i++) { + icolor = GETJSAMPLE(colorlist[i]); + /* Compute (square of) distance from minc0/c1/c2 to this color */ + inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE; + dist0 = inc0*inc0; + inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE; + dist0 += inc1*inc1; + inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE; + dist0 += inc2*inc2; + /* Form the initial difference increments */ + inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0; + inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1; + inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2; + /* Now loop over all cells in box, updating distance per Thomas method */ + bptr = bestdist; + cptr = bestcolor; + xx0 = inc0; + for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) { + dist1 = dist0; + xx1 = inc1; + for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) { + dist2 = dist1; + xx2 = inc2; + for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) { + if (dist2 < *bptr) { + *bptr = dist2; + *cptr = (JSAMPLE) icolor; + } + dist2 += xx2; + xx2 += 2 * STEP_C2 * STEP_C2; + bptr++; + cptr++; + } + dist1 += xx1; + xx1 += 2 * STEP_C1 * STEP_C1; + } + dist0 += xx0; + xx0 += 2 * STEP_C0 * STEP_C0; + } + } + } + + + LOCAL(void) + fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2) + /* Fill the inverse-colormap entries in the update box that contains */ + /* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */ + /* we can fill as many others as we wish.) */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + int minc0, minc1, minc2; /* lower left corner of update box */ + int ic0, ic1, ic2; + register JSAMPLE * cptr; /* pointer into bestcolor[] array */ + register histptr cachep; /* pointer into main cache array */ + /* This array lists the candidate colormap indexes. */ + JSAMPLE colorlist[MAXNUMCOLORS]; + int numcolors; /* number of candidate colors */ + /* This array holds the actually closest colormap index for each cell. */ + JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; + + /* Convert cell coordinates to update box ID */ + c0 >>= BOX_C0_LOG; + c1 >>= BOX_C1_LOG; + c2 >>= BOX_C2_LOG; + + /* Compute true coordinates of update box's origin corner. + * Actually we compute the coordinates of the center of the corner + * histogram cell, which are the lower bounds of the volume we care about. + */ + minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1); + minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1); + minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1); + + /* Determine which colormap entries are close enough to be candidates + * for the nearest entry to some cell in the update box. + */ + numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist); + + /* Determine the actually nearest colors. */ + find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist, + bestcolor); + + /* Save the best color numbers (plus 1) in the main cache array */ + c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */ + c1 <<= BOX_C1_LOG; + c2 <<= BOX_C2_LOG; + cptr = bestcolor; + for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) { + for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) { + cachep = & histogram[c0+ic0][c1+ic1][c2]; + for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) { + *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1); + } + } + } + } + + + /* + * Map some rows of pixels to the output colormapped representation. + */ + + METHODDEF(void) + pass2_no_dither (j_decompress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) + /* This version performs no dithering */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + register JSAMPROW inptr, outptr; + register histptr cachep; + register int c0, c1, c2; + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + + for (row = 0; row < num_rows; row++) { + inptr = input_buf[row]; + outptr = output_buf[row]; + for (col = width; col > 0; col--) { + /* get pixel value and index into the cache */ + c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT; + c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT; + c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT; + cachep = & histogram[c0][c1][c2]; + /* If we have not seen this color before, find nearest colormap entry */ + /* and update the cache */ + if (*cachep == 0) + fill_inverse_cmap(cinfo, c0,c1,c2); + /* Now emit the colormap index for this cell */ + *outptr++ = (JSAMPLE) (*cachep - 1); + } + } + } + + + METHODDEF(void) + pass2_fs_dither (j_decompress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) + /* This version performs Floyd-Steinberg dithering */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */ + LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */ + LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */ + register FSERRPTR errorptr; /* => fserrors[] at column before current */ + JSAMPROW inptr; /* => current input pixel */ + JSAMPROW outptr; /* => current output pixel */ + histptr cachep; + int dir; /* +1 or -1 depending on direction */ + int dir3; /* 3*dir, for advancing inptr & errorptr */ + int row; + JDIMENSION col; + JDIMENSION width = cinfo->output_width; + JSAMPLE *range_limit = cinfo->sample_range_limit; + int *error_limit = cquantize->error_limiter; + JSAMPROW colormap0 = cinfo->colormap[0]; + JSAMPROW colormap1 = cinfo->colormap[1]; + JSAMPROW colormap2 = cinfo->colormap[2]; + SHIFT_TEMPS + + for (row = 0; row < num_rows; row++) { + inptr = input_buf[row]; + outptr = output_buf[row]; + if (cquantize->on_odd_row) { + /* work right to left in this row */ + inptr += (width-1) * 3; /* so point to rightmost pixel */ + outptr += width-1; + dir = -1; + dir3 = -3; + errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */ + cquantize->on_odd_row = FALSE; /* flip for next time */ + } else { + /* work left to right in this row */ + dir = 1; + dir3 = 3; + errorptr = cquantize->fserrors; /* => entry before first real column */ + cquantize->on_odd_row = TRUE; /* flip for next time */ + } + /* Preset error values: no error propagated to first pixel from left */ + cur0 = cur1 = cur2 = 0; + /* and no error propagated to row below yet */ + belowerr0 = belowerr1 = belowerr2 = 0; + bpreverr0 = bpreverr1 = bpreverr2 = 0; + + for (col = width; col > 0; col--) { + /* curN holds the error propagated from the previous pixel on the + * current line. Add the error propagated from the previous line + * to form the complete error correction term for this pixel, and + * round the error term (which is expressed * 16) to an integer. + * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct + * for either sign of the error value. + * Note: errorptr points to *previous* column's array entry. + */ + cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4); + cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4); + cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4); + /* Limit the error using transfer function set by init_error_limit. + * See comments with init_error_limit for rationale. + */ + cur0 = error_limit[cur0]; + cur1 = error_limit[cur1]; + cur2 = error_limit[cur2]; + /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. + * The maximum error is +- MAXJSAMPLE (or less with error limiting); + * this sets the required size of the range_limit array. + */ + cur0 += GETJSAMPLE(inptr[0]); + cur1 += GETJSAMPLE(inptr[1]); + cur2 += GETJSAMPLE(inptr[2]); + cur0 = GETJSAMPLE(range_limit[cur0]); + cur1 = GETJSAMPLE(range_limit[cur1]); + cur2 = GETJSAMPLE(range_limit[cur2]); + /* Index into the cache with adjusted pixel value */ + cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT]; + /* If we have not seen this color before, find nearest colormap */ + /* entry and update the cache */ + if (*cachep == 0) + fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT); + /* Now emit the colormap index for this cell */ + { register int pixcode = *cachep - 1; + *outptr = (JSAMPLE) pixcode; + /* Compute representation error for this pixel */ + cur0 -= GETJSAMPLE(colormap0[pixcode]); + cur1 -= GETJSAMPLE(colormap1[pixcode]); + cur2 -= GETJSAMPLE(colormap2[pixcode]); + } + /* Compute error fractions to be propagated to adjacent pixels. + * Add these into the running sums, and simultaneously shift the + * next-line error sums left by 1 column. + */ + { register LOCFSERROR bnexterr, delta; + + bnexterr = cur0; /* Process component 0 */ + delta = cur0 * 2; + cur0 += delta; /* form error * 3 */ + errorptr[0] = (FSERROR) (bpreverr0 + cur0); + cur0 += delta; /* form error * 5 */ + bpreverr0 = belowerr0 + cur0; + belowerr0 = bnexterr; + cur0 += delta; /* form error * 7 */ + bnexterr = cur1; /* Process component 1 */ + delta = cur1 * 2; + cur1 += delta; /* form error * 3 */ + errorptr[1] = (FSERROR) (bpreverr1 + cur1); + cur1 += delta; /* form error * 5 */ + bpreverr1 = belowerr1 + cur1; + belowerr1 = bnexterr; + cur1 += delta; /* form error * 7 */ + bnexterr = cur2; /* Process component 2 */ + delta = cur2 * 2; + cur2 += delta; /* form error * 3 */ + errorptr[2] = (FSERROR) (bpreverr2 + cur2); + cur2 += delta; /* form error * 5 */ + bpreverr2 = belowerr2 + cur2; + belowerr2 = bnexterr; + cur2 += delta; /* form error * 7 */ + } + /* At this point curN contains the 7/16 error value to be propagated + * to the next pixel on the current line, and all the errors for the + * next line have been shifted over. We are therefore ready to move on. + */ + inptr += dir3; /* Advance pixel pointers to next column */ + outptr += dir; + errorptr += dir3; /* advance errorptr to current column */ + } + /* Post-loop cleanup: we must unload the final error values into the + * final fserrors[] entry. Note we need not unload belowerrN because + * it is for the dummy column before or after the actual array. + */ + errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */ + errorptr[1] = (FSERROR) bpreverr1; + errorptr[2] = (FSERROR) bpreverr2; + } + } + + + /* + * Initialize the error-limiting transfer function (lookup table). + * The raw F-S error computation can potentially compute error values of up to + * +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be + * much less, otherwise obviously wrong pixels will be created. (Typical + * effects include weird fringes at color-area boundaries, isolated bright + * pixels in a dark area, etc.) The standard advice for avoiding this problem + * is to ensure that the "corners" of the color cube are allocated as output + * colors; then repeated errors in the same direction cannot cause cascading + * error buildup. However, that only prevents the error from getting + * completely out of hand; Aaron Giles reports that error limiting improves + * the results even with corner colors allocated. + * A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty + * well, but the smoother transfer function used below is even better. Thanks + * to Aaron Giles for this idea. + */ + + LOCAL(void) + init_error_limit (j_decompress_ptr cinfo) + /* Allocate and fill in the error_limiter table */ + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + int * table; + int in, out; + + table = (int *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int)); + table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */ + cquantize->error_limiter = table; + + #define STEPSIZE ((MAXJSAMPLE+1)/16) + /* Map errors 1:1 up to +- MAXJSAMPLE/16 */ + out = 0; + for (in = 0; in < STEPSIZE; in++, out++) { + table[in] = out; table[-in] = -out; + } + /* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */ + for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) { + table[in] = out; table[-in] = -out; + } + /* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */ + for (; in <= MAXJSAMPLE; in++) { + table[in] = out; table[-in] = -out; + } + #undef STEPSIZE + } + + + /* + * Finish up at the end of each pass. + */ + + METHODDEF(void) + finish_pass1 (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + + /* Select the representative colors and fill in cinfo->colormap */ + cinfo->colormap = cquantize->sv_colormap; + select_colors(cinfo, cquantize->desired); + /* Force next pass to zero the color index table */ + cquantize->needs_zeroed = TRUE; + } + + + METHODDEF(void) + finish_pass2 (j_decompress_ptr cinfo) + { + /* no work */ + } + + + /* + * Initialize for each processing pass. + */ + + METHODDEF(void) + start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + hist3d histogram = cquantize->histogram; + int i; + + /* Only F-S dithering or no dithering is supported. */ + /* If user asks for ordered dither, give him F-S. */ + if (cinfo->dither_mode != JDITHER_NONE) + cinfo->dither_mode = JDITHER_FS; + + if (is_pre_scan) { + /* Set up method pointers */ + cquantize->pub.color_quantize = prescan_quantize; + cquantize->pub.finish_pass = finish_pass1; + cquantize->needs_zeroed = TRUE; /* Always zero histogram */ + } else { + /* Set up method pointers */ + if (cinfo->dither_mode == JDITHER_FS) + cquantize->pub.color_quantize = pass2_fs_dither; + else + cquantize->pub.color_quantize = pass2_no_dither; + cquantize->pub.finish_pass = finish_pass2; + + /* Make sure color count is acceptable */ + i = cinfo->actual_number_of_colors; + if (i < 1) + ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1); + if (i > MAXNUMCOLORS) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); + + if (cinfo->dither_mode == JDITHER_FS) { + size_t arraysize = (size_t) ((cinfo->output_width + 2) * + (3 * SIZEOF(FSERROR))); + /* Allocate Floyd-Steinberg workspace if we didn't already. */ + if (cquantize->fserrors == NULL) + cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) + ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); + /* Initialize the propagated errors to zero. */ + jzero_far((void FAR *) cquantize->fserrors, arraysize); + /* Make the error-limit table if we didn't already. */ + if (cquantize->error_limiter == NULL) + init_error_limit(cinfo); + cquantize->on_odd_row = FALSE; + } + + } + /* Zero the histogram or inverse color map, if necessary */ + if (cquantize->needs_zeroed) { + for (i = 0; i < HIST_C0_ELEMS; i++) { + jzero_far((void FAR *) histogram[i], + HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell)); + } + cquantize->needs_zeroed = FALSE; + } + } + + + /* + * Switch to a new external colormap between output passes. + */ + + METHODDEF(void) + new_color_map_2_quant (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; + + /* Reset the inverse color map */ + cquantize->needs_zeroed = TRUE; + } + + + /* + * Module initialization routine for 2-pass color quantization. + */ + + GLOBAL(void) + jinit_2pass_quantizer (j_decompress_ptr cinfo) + { + my_cquantize_ptr cquantize; + int i; + + cquantize = (my_cquantize_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(my_cquantizer)); + cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; + cquantize->pub.start_pass = start_pass_2_quant; + cquantize->pub.new_color_map = new_color_map_2_quant; + cquantize->fserrors = NULL; /* flag optional arrays not allocated */ + cquantize->error_limiter = NULL; + + /* Make sure jdmaster didn't give me a case I can't handle */ + if (cinfo->out_color_components != 3) + ERREXIT(cinfo, JERR_NOTIMPL); + + /* Allocate the histogram/inverse colormap storage */ + cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d)); + for (i = 0; i < HIST_C0_ELEMS; i++) { + cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell)); + } + cquantize->needs_zeroed = TRUE; /* histogram is garbage now */ + + /* Allocate storage for the completed colormap, if required. + * We do this now since it is FAR storage and may affect + * the memory manager's space calculations. + */ + if (cinfo->enable_2pass_quant) { + /* Make sure color count is acceptable */ + int desired = cinfo->desired_number_of_colors; + /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */ + if (desired < 8) + ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8); + /* Make sure colormap indexes can be represented by JSAMPLEs */ + if (desired > MAXNUMCOLORS) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS); + cquantize->sv_colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3); + cquantize->desired = desired; + } else + cquantize->sv_colormap = NULL; + + /* Only F-S dithering or no dithering is supported. */ + /* If user asks for ordered dither, give him F-S. */ + if (cinfo->dither_mode != JDITHER_NONE) + cinfo->dither_mode = JDITHER_FS; + + /* Allocate Floyd-Steinberg workspace if necessary. + * This isn't really needed until pass 2, but again it is FAR storage. + * Although we will cope with a later change in dither_mode, + * we do not promise to honor max_memory_to_use if dither_mode changes. + */ + if (cinfo->dither_mode == JDITHER_FS) { + cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR)))); + /* Might as well create the error-limiting table too. */ + init_error_limit(cinfo); + } + } + + #endif /* QUANT_2PASS_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jutils.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jutils.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jutils.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,179 ---- + /* + * jutils.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains tables and miscellaneous utility routines needed + * for both compression and decompression. + * Note we prefix all global names with "j" to minimize conflicts with + * a surrounding application. + */ + + #define JPEG_INTERNALS + #include "jinclude.h" + #include "jpeglib.h" + + + /* + * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element + * of a DCT block read in natural order (left to right, top to bottom). + */ + + #if 0 /* This table is not actually needed in v6a */ + + const int jpeg_zigzag_order[DCTSIZE2] = { + 0, 1, 5, 6, 14, 15, 27, 28, + 2, 4, 7, 13, 16, 26, 29, 42, + 3, 8, 12, 17, 25, 30, 41, 43, + 9, 11, 18, 24, 31, 40, 44, 53, + 10, 19, 23, 32, 39, 45, 52, 54, + 20, 22, 33, 38, 46, 51, 55, 60, + 21, 34, 37, 47, 50, 56, 59, 61, + 35, 36, 48, 49, 57, 58, 62, 63 + }; + + #endif + + /* + * jpeg_natural_order[i] is the natural-order position of the i'th element + * of zigzag order. + * + * When reading corrupted data, the Huffman decoders could attempt + * to reference an entry beyond the end of this array (if the decoded + * zero run length reaches past the end of the block). To prevent + * wild stores without adding an inner-loop test, we put some extra + * "63"s after the real entries. This will cause the extra coefficient + * to be stored in location 63 of the block, not somewhere random. + * The worst case would be a run-length of 15, which means we need 16 + * fake entries. + */ + + const int jpeg_natural_order[DCTSIZE2+16] = { + 0, 1, 8, 16, 9, 2, 3, 10, + 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, + 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, + 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, + 53, 60, 61, 54, 47, 55, 62, 63, + 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ + 63, 63, 63, 63, 63, 63, 63, 63 + }; + + + /* + * Arithmetic utilities + */ + + GLOBAL(long) + jdiv_round_up (long a, long b) + /* Compute a/b rounded up to next integer, ie, ceil(a/b) */ + /* Assumes a >= 0, b > 0 */ + { + return (a + b - 1L) / b; + } + + + GLOBAL(long) + jround_up (long a, long b) + /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ + /* Assumes a >= 0, b > 0 */ + { + a += b - 1L; + return a - (a % b); + } + + + /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays + * and coefficient-block arrays. This won't work on 80x86 because the arrays + * are FAR and we're assuming a small-pointer memory model. However, some + * DOS compilers provide far-pointer versions of memcpy() and memset() even + * in the small-model libraries. These will be used if USE_FMEM is defined. + * Otherwise, the routines below do it the hard way. (The performance cost + * is not all that great, because these routines aren't very heavily used.) + */ + + #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ + #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) + #define FMEMZERO(target,size) MEMZERO(target,size) + #else /* 80x86 case, define if we can */ + #ifdef USE_FMEM + #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) + #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) + #endif + #endif + + + GLOBAL(void) + jcopy_sample_rows (JSAMPARRAY input_array, int source_row, + JSAMPARRAY output_array, int dest_row, + int num_rows, JDIMENSION num_cols) + /* Copy some rows of samples from one place to another. + * num_rows rows are copied from input_array[source_row++] + * to output_array[dest_row++]; these areas may overlap for duplication. + * The source and destination arrays must be at least as wide as num_cols. + */ + { + register JSAMPROW inptr, outptr; + #ifdef FMEMCOPY + register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE)); + #else + register JDIMENSION count; + #endif + register int row; + + input_array += source_row; + output_array += dest_row; + + for (row = num_rows; row > 0; row--) { + inptr = *input_array++; + outptr = *output_array++; + #ifdef FMEMCOPY + FMEMCOPY(outptr, inptr, count); + #else + for (count = num_cols; count > 0; count--) + *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ + #endif + } + } + + + GLOBAL(void) + jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, + JDIMENSION num_blocks) + /* Copy a row of coefficient blocks from one place to another. */ + { + #ifdef FMEMCOPY + FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); + #else + register JCOEFPTR inptr, outptr; + register long count; + + inptr = (JCOEFPTR) input_row; + outptr = (JCOEFPTR) output_row; + for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) { + *outptr++ = *inptr++; + } + #endif + } + + + GLOBAL(void) + jzero_far (void FAR * target, size_t bytestozero) + /* Zero out a chunk of FAR memory. */ + /* This might be sample-array data, block-array data, or alloc_large data. */ + { + #ifdef FMEMZERO + FMEMZERO(target, bytestozero); + #else + register char FAR * ptr = (char FAR *) target; + register size_t count; + + for (count = bytestozero; count > 0; count--) { + *ptr++ = 0; + } + #endif + } Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jversion.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jversion.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/jversion.h Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,14 ---- + /* + * jversion.h + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains software version identification. + */ + + + #define JVERSION "6a 7-Feb-96" + + #define JCOPYRIGHT "Copyright (C) 1996, Thomas G. Lane" Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/output_large_decode.ppm Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/rdcolmap.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/rdcolmap.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/rdcolmap.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,253 ---- + /* + * rdcolmap.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file implements djpeg's "-map file" switch. It reads a source image + * and constructs a colormap to be supplied to the JPEG decompressor. + * + * Currently, these file formats are supported for the map file: + * GIF: the contents of the GIF's global colormap are used. + * PPM (either text or raw flavor): the entire file is read and + * each unique pixel value is entered in the map. + * Note that reading a large PPM file will be horrendously slow. + * Typically, a PPM-format map file should contain just one pixel + * of each desired color. Such a file can be extracted from an + * ordinary image PPM file with ppmtomap(1). + * + * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not + * currently implemented. + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + + #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ + + /* Portions of this code are based on the PBMPLUS library, which is: + ** + ** Copyright (C) 1988 by Jef Poskanzer. + ** + ** Permission to use, copy, modify, and distribute this software and its + ** documentation for any purpose and without fee is hereby granted, provided + ** that the above copyright notice appear in all copies and that both that + ** copyright notice and this permission notice appear in supporting + ** documentation. This software is provided "as is" without express or + ** implied warranty. + */ + + + /* + * Add a (potentially) new color to the color map. + */ + + LOCAL(void) + add_map_entry (j_decompress_ptr cinfo, int R, int G, int B) + { + JSAMPROW colormap0 = cinfo->colormap[0]; + JSAMPROW colormap1 = cinfo->colormap[1]; + JSAMPROW colormap2 = cinfo->colormap[2]; + int ncolors = cinfo->actual_number_of_colors; + int index; + + /* Check for duplicate color. */ + for (index = 0; index < ncolors; index++) { + if (GETJSAMPLE(colormap0[index]) == R && + GETJSAMPLE(colormap1[index]) == G && + GETJSAMPLE(colormap2[index]) == B) + return; /* color is already in map */ + } + + /* Check for map overflow. */ + if (ncolors >= (MAXJSAMPLE+1)) + ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1)); + + /* OK, add color to map. */ + colormap0[ncolors] = (JSAMPLE) R; + colormap1[ncolors] = (JSAMPLE) G; + colormap2[ncolors] = (JSAMPLE) B; + cinfo->actual_number_of_colors++; + } + + + /* + * Extract color map from a GIF file. + */ + + LOCAL(void) + read_gif_map (j_decompress_ptr cinfo, FILE * infile) + { + int header[13]; + int i, colormaplen; + int R, G, B; + + /* Initial 'G' has already been read by read_color_map */ + /* Read the rest of the GIF header and logical screen descriptor */ + for (i = 1; i < 13; i++) { + if ((header[i] = getc(infile)) == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + } + + /* Verify GIF Header */ + if (header[1] != 'I' || header[2] != 'F') + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + /* There must be a global color map. */ + if ((header[10] & 0x80) == 0) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + /* OK, fetch it. */ + colormaplen = 2 << (header[10] & 0x07); + + for (i = 0; i < colormaplen; i++) { + R = getc(infile); + G = getc(infile); + B = getc(infile); + if (R == EOF || G == EOF || B == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + add_map_entry(cinfo, + R << (BITS_IN_JSAMPLE-8), + G << (BITS_IN_JSAMPLE-8), + B << (BITS_IN_JSAMPLE-8)); + } + } + + + /* Support routines for reading PPM */ + + + LOCAL(int) + pbm_getc (FILE * infile) + /* Read next char, skipping over any comments */ + /* A comment/newline sequence is returned as a newline */ + { + register int ch; + + ch = getc(infile); + if (ch == '#') { + do { + ch = getc(infile); + } while (ch != '\n' && ch != EOF); + } + return ch; + } + + + LOCAL(unsigned int) + read_pbm_integer (j_decompress_ptr cinfo, FILE * infile) + /* Read an unsigned decimal integer from the PPM file */ + /* Swallows one trailing character after the integer */ + /* Note that on a 16-bit-int machine, only values up to 64k can be read. */ + /* This should not be a problem in practice. */ + { + register int ch; + register unsigned int val; + + /* Skip any leading whitespace */ + do { + ch = pbm_getc(infile); + if (ch == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); + + if (ch < '0' || ch > '9') + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + val = ch - '0'; + while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { + val *= 10; + val += ch - '0'; + } + return val; + } + + + /* + * Extract color map from a PPM file. + */ + + LOCAL(void) + read_ppm_map (j_decompress_ptr cinfo, FILE * infile) + { + int c; + unsigned int w, h, maxval, row, col; + int R, G, B; + + /* Initial 'P' has already been read by read_color_map */ + c = getc(infile); /* save format discriminator for a sec */ + + /* while we fetch the remaining header info */ + w = read_pbm_integer(cinfo, infile); + h = read_pbm_integer(cinfo, infile); + maxval = read_pbm_integer(cinfo, infile); + + if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + /* For now, we don't support rescaling from an unusual maxval. */ + if (maxval != (unsigned int) MAXJSAMPLE) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + + switch (c) { + case '3': /* it's a text-format PPM file */ + for (row = 0; row < h; row++) { + for (col = 0; col < w; col++) { + R = read_pbm_integer(cinfo, infile); + G = read_pbm_integer(cinfo, infile); + B = read_pbm_integer(cinfo, infile); + add_map_entry(cinfo, R, G, B); + } + } + break; + + case '6': /* it's a raw-format PPM file */ + for (row = 0; row < h; row++) { + for (col = 0; col < w; col++) { + R = pbm_getc(infile); + G = pbm_getc(infile); + B = pbm_getc(infile); + if (R == EOF || G == EOF || B == EOF) + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + add_map_entry(cinfo, R, G, B); + } + } + break; + + default: + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + break; + } + } + + + /* + * Main entry point from djpeg.c. + * Input: opened input file (from file name argument on command line). + * Output: colormap and actual_number_of_colors fields are set in cinfo. + */ + + GLOBAL(void) + read_color_map (j_decompress_ptr cinfo, FILE * infile) + { + /* Allocate space for a color map of maximum supported size. */ + cinfo->colormap = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3); + cinfo->actual_number_of_colors = 0; /* initialize map to empty */ + + /* Read first byte to determine file format */ + switch (getc(infile)) { + case 'G': + read_gif_map(cinfo, infile); + break; + case 'P': + read_ppm_map(cinfo, infile); + break; + default: + ERREXIT(cinfo, JERR_BAD_CMAP_FILE); + break; + } + } + + #endif /* QUANT_2PASS_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrbmp.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrbmp.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrbmp.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,442 ---- + /* + * wrbmp.c + * + * Copyright (C) 1994-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in Microsoft "BMP" + * format (MS Windows 3.x and OS/2 1.x flavors). + * Either 8-bit colormapped or 24-bit full-color format can be written. + * No compression is supported. + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + * + * This code contributed by James Arthur Boucher. + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + + #ifdef BMP_SUPPORTED + + + /* + * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. + * This is not yet implemented. + */ + + #if BITS_IN_JSAMPLE != 8 + Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ + #endif + + /* + * Since BMP stores scanlines bottom-to-top, we have to invert the image + * from JPEG's top-to-bottom order. To do this, we save the outgoing data + * in a virtual array during put_pixel_row calls, then actually emit the + * BMP file during finish_output. The virtual array contains one JSAMPLE per + * pixel if the output is grayscale or colormapped, three if it is full color. + */ + + /* Private version of data destination object */ + + typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + boolean is_os2; /* saves the OS2 format request flag */ + + jvirt_sarray_ptr whole_image; /* needed to reverse row order */ + JDIMENSION data_width; /* JSAMPLEs per row */ + JDIMENSION row_width; /* physical width of one row in the BMP file */ + int pad_bytes; /* number of padding bytes needed per row */ + JDIMENSION cur_output_row; /* next row# to write to virtual array */ + } bmp_dest_struct; + + typedef bmp_dest_struct * bmp_dest_ptr; + + + /* Forward declarations */ + LOCAL(void) write_colormap + JPP((j_decompress_ptr cinfo, bmp_dest_ptr dest, + int map_colors, int map_entry_size)); + + + /* + * Write some pixel data. + * In this module rows_supplied will always be 1. + */ + + METHODDEF(void) + put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + /* This version is for writing 24-bit pixels */ + { + bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; + JSAMPARRAY image_ptr; + register JSAMPROW inptr, outptr; + register JDIMENSION col; + int pad; + + /* Access next row in virtual array */ + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->whole_image, + dest->cur_output_row, (JDIMENSION) 1, TRUE); + dest->cur_output_row++; + + /* Transfer data. Note destination values must be in BGR order + * (even though Microsoft's own documents say the opposite). + */ + inptr = dest->pub.buffer[0]; + outptr = image_ptr[0]; + for (col = cinfo->output_width; col > 0; col--) { + outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ + outptr[1] = *inptr++; + outptr[0] = *inptr++; + outptr += 3; + } + + /* Zero out the pad bytes. */ + pad = dest->pad_bytes; + while (--pad >= 0) + *outptr++ = 0; + } + + METHODDEF(void) + put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + /* This version is for grayscale OR quantized color output */ + { + bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; + JSAMPARRAY image_ptr; + register JSAMPROW inptr, outptr; + register JDIMENSION col; + int pad; + + /* Access next row in virtual array */ + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->whole_image, + dest->cur_output_row, (JDIMENSION) 1, TRUE); + dest->cur_output_row++; + + /* Transfer data. */ + inptr = dest->pub.buffer[0]; + outptr = image_ptr[0]; + for (col = cinfo->output_width; col > 0; col--) { + *outptr++ = *inptr++; /* can omit GETJSAMPLE() safely */ + } + + /* Zero out the pad bytes. */ + pad = dest->pad_bytes; + while (--pad >= 0) + *outptr++ = 0; + } + + + /* + * Startup: normally writes the file header. + * In this module we may as well postpone everything until finish_output. + */ + + METHODDEF(void) + start_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + /* no work here */ + } + + + /* + * Finish up at the end of the file. + * + * Here is where we really output the BMP file. + * + * First, routines to write the Windows and OS/2 variants of the file header. + */ + + LOCAL(void) + write_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) + /* Write a Windows-style BMP file header, including colormap if needed */ + { + char bmpfileheader[14]; + char bmpinfoheader[40]; + #define PUT_2B(array,offset,value) \ + (array[offset] = (char) ((value) & 0xFF), \ + array[offset+1] = (char) (((value) >> 8) & 0xFF)) + #define PUT_4B(array,offset,value) \ + (array[offset] = (char) ((value) & 0xFF), \ + array[offset+1] = (char) (((value) >> 8) & 0xFF), \ + array[offset+2] = (char) (((value) >> 16) & 0xFF), \ + array[offset+3] = (char) (((value) >> 24) & 0xFF)) + INT32 headersize, bfSize; + int bits_per_pixel, cmap_entries; + + /* Compute colormap size and total file size */ + if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) { + /* Colormapped RGB */ + bits_per_pixel = 8; + cmap_entries = 256; + } else { + /* Unquantized, full color RGB */ + bits_per_pixel = 24; + cmap_entries = 0; + } + } else { + /* Grayscale output. We need to fake a 256-entry colormap. */ + bits_per_pixel = 8; + cmap_entries = 256; + } + /* File size */ + headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */ + bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; + + /* Set unused fields of header to 0 */ + MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); + MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader)); + + /* Fill the file header */ + bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ + bmpfileheader[1] = 0x4D; + PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ + /* we leave bfReserved1 & bfReserved2 = 0 */ + PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ + + /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */ + PUT_2B(bmpinfoheader, 0, 40); /* biSize */ + PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */ + PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */ + PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */ + PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */ + /* we leave biCompression = 0, for none */ + /* we leave biSizeImage = 0; this is correct for uncompressed data */ + if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */ + PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */ + PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */ + } + PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */ + /* we leave biClrImportant = 0 */ + + if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) + ERREXIT(cinfo, JERR_FILE_WRITE); + if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40) + ERREXIT(cinfo, JERR_FILE_WRITE); + + if (cmap_entries > 0) + write_colormap(cinfo, dest, cmap_entries, 4); + } + + + LOCAL(void) + write_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) + /* Write an OS2-style BMP file header, including colormap if needed */ + { + char bmpfileheader[14]; + char bmpcoreheader[12]; + INT32 headersize, bfSize; + int bits_per_pixel, cmap_entries; + + /* Compute colormap size and total file size */ + if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) { + /* Colormapped RGB */ + bits_per_pixel = 8; + cmap_entries = 256; + } else { + /* Unquantized, full color RGB */ + bits_per_pixel = 24; + cmap_entries = 0; + } + } else { + /* Grayscale output. We need to fake a 256-entry colormap. */ + bits_per_pixel = 8; + cmap_entries = 256; + } + /* File size */ + headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */ + bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; + + /* Set unused fields of header to 0 */ + MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); + MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader)); + + /* Fill the file header */ + bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ + bmpfileheader[1] = 0x4D; + PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ + /* we leave bfReserved1 & bfReserved2 = 0 */ + PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ + + /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */ + PUT_2B(bmpcoreheader, 0, 12); /* bcSize */ + PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */ + PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */ + PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */ + PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */ + + if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) + ERREXIT(cinfo, JERR_FILE_WRITE); + if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12) + ERREXIT(cinfo, JERR_FILE_WRITE); + + if (cmap_entries > 0) + write_colormap(cinfo, dest, cmap_entries, 3); + } + + + /* + * Write the colormap. + * Windows uses BGR0 map entries; OS/2 uses BGR entries. + */ + + LOCAL(void) + write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest, + int map_colors, int map_entry_size) + { + JSAMPARRAY colormap = cinfo->colormap; + int num_colors = cinfo->actual_number_of_colors; + FILE * outfile = dest->pub.output_file; + int i; + + if (colormap != NULL) { + if (cinfo->out_color_components == 3) { + /* Normal case with RGB colormap */ + for (i = 0; i < num_colors; i++) { + putc(GETJSAMPLE(colormap[2][i]), outfile); + putc(GETJSAMPLE(colormap[1][i]), outfile); + putc(GETJSAMPLE(colormap[0][i]), outfile); + if (map_entry_size == 4) + putc(0, outfile); + } + } else { + /* Grayscale colormap (only happens with grayscale quantization) */ + for (i = 0; i < num_colors; i++) { + putc(GETJSAMPLE(colormap[0][i]), outfile); + putc(GETJSAMPLE(colormap[0][i]), outfile); + putc(GETJSAMPLE(colormap[0][i]), outfile); + if (map_entry_size == 4) + putc(0, outfile); + } + } + } else { + /* If no colormap, must be grayscale data. Generate a linear "map". */ + for (i = 0; i < 256; i++) { + putc(i, outfile); + putc(i, outfile); + putc(i, outfile); + if (map_entry_size == 4) + putc(0, outfile); + } + } + /* Pad colormap with zeros to ensure specified number of colormap entries */ + if (i > map_colors) + ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i); + for (; i < map_colors; i++) { + putc(0, outfile); + putc(0, outfile); + putc(0, outfile); + if (map_entry_size == 4) + putc(0, outfile); + } + } + + + METHODDEF(void) + finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; + register FILE * outfile = dest->pub.output_file; + JSAMPARRAY image_ptr; + register JSAMPROW data_ptr; + JDIMENSION row; + register JDIMENSION col; + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + + /* Write the header and colormap */ + if (dest->is_os2) + write_os2_header(cinfo, dest); + else + write_bmp_header(cinfo, dest); + + /* Write the file body from our virtual array */ + for (row = cinfo->output_height; row > 0; row--) { + if (progress != NULL) { + progress->pub.pass_counter = (long) (cinfo->output_height - row); + progress->pub.pass_limit = (long) cinfo->output_height; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } + image_ptr = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE); + data_ptr = image_ptr[0]; + for (col = dest->row_width; col > 0; col--) { + putc(GETJSAMPLE(*data_ptr), outfile); + data_ptr++; + } + } + if (progress != NULL) + progress->completed_extra_passes++; + + /* Make sure we wrote the output file OK */ + fflush(outfile); + if (ferror(outfile)) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + + + /* + * The module selection routine for BMP format output. + */ + + GLOBAL(djpeg_dest_ptr) + jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2) + { + bmp_dest_ptr dest; + JDIMENSION row_width; + + /* Create module interface object, fill in method pointers */ + dest = (bmp_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(bmp_dest_struct)); + dest->pub.start_output = start_output_bmp; + dest->pub.finish_output = finish_output_bmp; + dest->is_os2 = is_os2; + + if (cinfo->out_color_space == JCS_GRAYSCALE) { + dest->pub.put_pixel_rows = put_gray_rows; + } else if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) + dest->pub.put_pixel_rows = put_gray_rows; + else + dest->pub.put_pixel_rows = put_pixel_rows; + } else { + ERREXIT(cinfo, JERR_BMP_COLORSPACE); + } + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Determine width of rows in the BMP file (padded to 4-byte boundary). */ + row_width = cinfo->output_width * cinfo->output_components; + dest->data_width = row_width; + while ((row_width & 3) != 0) row_width++; + dest->row_width = row_width; + dest->pad_bytes = (int) (row_width - dest->data_width); + + /* Allocate space for inversion array, prepare for write pass */ + dest->whole_image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + row_width, cinfo->output_height, (JDIMENSION) 1); + dest->cur_output_row = 0; + if (cinfo->progress != NULL) { + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + progress->total_extra_passes++; /* count file input as separate pass */ + } + + /* Create decompressor output buffer. */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + + return (djpeg_dest_ptr) dest; + } + + #endif /* BMP_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrgif.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrgif.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrgif.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,505 ---- + /* + * wrgif.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + ************************************************************************** + * WARNING: You will need an LZW patent license from Unisys in order to * + * use this file legally in any commercial or shareware application. * + ************************************************************************** + * + * This file contains routines to write output images in GIF format. + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + */ + + /* + * This code is loosely based on ppmtogif from the PBMPLUS distribution + * of Feb. 1991. That file contains the following copyright notice: + * Based on GIFENCODE by David Rowley <mgardi at watdscu.waterloo.edu>. + * Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al. + * Copyright (C) 1989 by Jef Poskanzer. + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. This software is provided "as is" without express or + * implied warranty. + * + * We are also required to state that + * "The Graphics Interchange Format(c) is the Copyright property of + * CompuServe Incorporated. GIF(sm) is a Service Mark property of + * CompuServe Incorporated." + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + + #ifdef GIF_SUPPORTED + + + #define MAX_LZW_BITS 12 /* maximum LZW code size (4096 symbols) */ + + typedef INT16 code_int; /* must hold -1 .. 2**MAX_LZW_BITS */ + + #define LZW_TABLE_SIZE ((code_int) 1 << MAX_LZW_BITS) + + #define HSIZE 5003 /* hash table size for 80% occupancy */ + + typedef int hash_int; /* must hold -2*HSIZE..2*HSIZE */ + + #define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1) + + + /* + * The LZW hash table consists of two parallel arrays: + * hash_code[i] code of symbol in slot i, or 0 if empty slot + * hash_value[i] symbol's value; undefined if empty slot + * where slot values (i) range from 0 to HSIZE-1. The symbol value is + * its prefix symbol's code concatenated with its suffix character. + * + * Algorithm: use open addressing double hashing (no chaining) on the + * prefix code / suffix character combination. We do a variant of Knuth's + * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime + * secondary probe. + * + * The hash_value[] table is allocated from FAR heap space since it would + * use up rather a lot of the near data space in a PC. + */ + + typedef INT32 hash_entry; /* must hold (code_int<<8) | byte */ + + #define HASH_ENTRY(prefix,suffix) ((((hash_entry) (prefix)) << 8) | (suffix)) + + + /* Private version of data destination object */ + + typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + j_decompress_ptr cinfo; /* back link saves passing separate parm */ + + /* State for packing variable-width codes into a bitstream */ + int n_bits; /* current number of bits/code */ + code_int maxcode; /* maximum code, given n_bits */ + int init_bits; /* initial n_bits ... restored after clear */ + INT32 cur_accum; /* holds bits not yet output */ + int cur_bits; /* # of bits in cur_accum */ + + /* LZW string construction */ + code_int waiting_code; /* symbol not yet output; may be extendable */ + boolean first_byte; /* if TRUE, waiting_code is not valid */ + + /* State for LZW code assignment */ + code_int ClearCode; /* clear code (doesn't change) */ + code_int EOFCode; /* EOF code (ditto) */ + code_int free_code; /* first not-yet-used symbol code */ + + /* LZW hash table */ + code_int *hash_code; /* => hash table of symbol codes */ + hash_entry FAR *hash_value; /* => hash table of symbol values */ + + /* GIF data packet construction buffer */ + int bytesinpkt; /* # of bytes in current packet */ + char packetbuf[256]; /* workspace for accumulating packet */ + + } gif_dest_struct; + + typedef gif_dest_struct * gif_dest_ptr; + + + /* + * Routines to package compressed data bytes into GIF data blocks. + * A data block consists of a count byte (1..255) and that many data bytes. + */ + + LOCAL(void) + flush_packet (gif_dest_ptr dinfo) + /* flush any accumulated data */ + { + if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */ + dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++; + if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt) + != (size_t) dinfo->bytesinpkt) + ERREXIT(dinfo->cinfo, JERR_FILE_WRITE); + dinfo->bytesinpkt = 0; + } + } + + + /* Add a character to current packet; flush to disk if necessary */ + #define CHAR_OUT(dinfo,c) \ + { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \ + if ((dinfo)->bytesinpkt >= 255) \ + flush_packet(dinfo); \ + } + + + /* Routine to convert variable-width codes into a byte stream */ + + LOCAL(void) + output (gif_dest_ptr dinfo, code_int code) + /* Emit a code of n_bits bits */ + /* Uses cur_accum and cur_bits to reblock into 8-bit bytes */ + { + dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits; + dinfo->cur_bits += dinfo->n_bits; + + while (dinfo->cur_bits >= 8) { + CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); + dinfo->cur_accum >>= 8; + dinfo->cur_bits -= 8; + } + + /* + * If the next entry is going to be too big for the code size, + * then increase it, if possible. We do this here to ensure + * that it's done in sync with the decoder's codesize increases. + */ + if (dinfo->free_code > dinfo->maxcode) { + dinfo->n_bits++; + if (dinfo->n_bits == MAX_LZW_BITS) + dinfo->maxcode = LZW_TABLE_SIZE; /* free_code will never exceed this */ + else + dinfo->maxcode = MAXCODE(dinfo->n_bits); + } + } + + + /* The LZW algorithm proper */ + + + LOCAL(void) + clear_hash (gif_dest_ptr dinfo) + /* Fill the hash table with empty entries */ + { + /* It's sufficient to zero hash_code[] */ + MEMZERO(dinfo->hash_code, HSIZE * SIZEOF(code_int)); + } + + + LOCAL(void) + clear_block (gif_dest_ptr dinfo) + /* Reset compressor and issue a Clear code */ + { + clear_hash(dinfo); /* delete all the symbols */ + dinfo->free_code = dinfo->ClearCode + 2; + output(dinfo, dinfo->ClearCode); /* inform decoder */ + dinfo->n_bits = dinfo->init_bits; /* reset code size */ + dinfo->maxcode = MAXCODE(dinfo->n_bits); + } + + + LOCAL(void) + compress_init (gif_dest_ptr dinfo, int i_bits) + /* Initialize LZW compressor */ + { + /* init all the state variables */ + dinfo->n_bits = dinfo->init_bits = i_bits; + dinfo->maxcode = MAXCODE(dinfo->n_bits); + dinfo->ClearCode = ((code_int) 1 << (i_bits - 1)); + dinfo->EOFCode = dinfo->ClearCode + 1; + dinfo->free_code = dinfo->ClearCode + 2; + dinfo->first_byte = TRUE; /* no waiting symbol yet */ + /* init output buffering vars */ + dinfo->bytesinpkt = 0; + dinfo->cur_accum = 0; + dinfo->cur_bits = 0; + /* clear hash table */ + clear_hash(dinfo); + /* GIF specifies an initial Clear code */ + output(dinfo, dinfo->ClearCode); + } + + + LOCAL(void) + compress_byte (gif_dest_ptr dinfo, int c) + /* Accept and compress one 8-bit byte */ + { + register hash_int i; + register hash_int disp; + register hash_entry probe_value; + + if (dinfo->first_byte) { /* need to initialize waiting_code */ + dinfo->waiting_code = c; + dinfo->first_byte = FALSE; + return; + } + + /* Probe hash table to see if a symbol exists for + * waiting_code followed by c. + * If so, replace waiting_code by that symbol and return. + */ + i = ((hash_int) c << (MAX_LZW_BITS-8)) + dinfo->waiting_code; + /* i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE */ + if (i >= HSIZE) + i -= HSIZE; + + probe_value = HASH_ENTRY(dinfo->waiting_code, c); + + if (dinfo->hash_code[i] != 0) { /* is first probed slot empty? */ + if (dinfo->hash_value[i] == probe_value) { + dinfo->waiting_code = dinfo->hash_code[i]; + return; + } + if (i == 0) /* secondary hash (after G. Knott) */ + disp = 1; + else + disp = HSIZE - i; + for (;;) { + i -= disp; + if (i < 0) + i += HSIZE; + if (dinfo->hash_code[i] == 0) + break; /* hit empty slot */ + if (dinfo->hash_value[i] == probe_value) { + dinfo->waiting_code = dinfo->hash_code[i]; + return; + } + } + } + + /* here when hashtable[i] is an empty slot; desired symbol not in table */ + output(dinfo, dinfo->waiting_code); + if (dinfo->free_code < LZW_TABLE_SIZE) { + dinfo->hash_code[i] = dinfo->free_code++; /* add symbol to hashtable */ + dinfo->hash_value[i] = probe_value; + } else + clear_block(dinfo); + dinfo->waiting_code = c; + } + + + LOCAL(void) + compress_term (gif_dest_ptr dinfo) + /* Clean up at end */ + { + /* Flush out the buffered code */ + if (! dinfo->first_byte) + output(dinfo, dinfo->waiting_code); + /* Send an EOF code */ + output(dinfo, dinfo->EOFCode); + /* Flush the bit-packing buffer */ + if (dinfo->cur_bits > 0) { + CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); + } + /* Flush the packet buffer */ + flush_packet(dinfo); + } + + + /* GIF header construction */ + + + LOCAL(void) + put_word (gif_dest_ptr dinfo, unsigned int w) + /* Emit a 16-bit word, LSB first */ + { + putc(w & 0xFF, dinfo->pub.output_file); + putc((w >> 8) & 0xFF, dinfo->pub.output_file); + } + + + LOCAL(void) + put_3bytes (gif_dest_ptr dinfo, int val) + /* Emit 3 copies of same byte value --- handy subr for colormap construction */ + { + putc(val, dinfo->pub.output_file); + putc(val, dinfo->pub.output_file); + putc(val, dinfo->pub.output_file); + } + + + LOCAL(void) + emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap) + /* Output the GIF file header, including color map */ + /* If colormap==NULL, synthesize a gray-scale colormap */ + { + int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte; + int cshift = dinfo->cinfo->data_precision - 8; + int i; + + if (num_colors > 256) + ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors); + /* Compute bits/pixel and related values */ + BitsPerPixel = 1; + while (num_colors > (1 << BitsPerPixel)) + BitsPerPixel++; + ColorMapSize = 1 << BitsPerPixel; + if (BitsPerPixel <= 1) + InitCodeSize = 2; + else + InitCodeSize = BitsPerPixel; + /* + * Write the GIF header. + * Note that we generate a plain GIF87 header for maximum compatibility. + */ + putc('G', dinfo->pub.output_file); + putc('I', dinfo->pub.output_file); + putc('F', dinfo->pub.output_file); + putc('8', dinfo->pub.output_file); + putc('7', dinfo->pub.output_file); + putc('a', dinfo->pub.output_file); + /* Write the Logical Screen Descriptor */ + put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); + put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); + FlagByte = 0x80; /* Yes, there is a global color table */ + FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */ + FlagByte |= (BitsPerPixel-1); /* size of global color table */ + putc(FlagByte, dinfo->pub.output_file); + putc(0, dinfo->pub.output_file); /* Background color index */ + putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */ + /* Write the Global Color Map */ + /* If the color map is more than 8 bits precision, */ + /* we reduce it to 8 bits by shifting */ + for (i=0; i < ColorMapSize; i++) { + if (i < num_colors) { + if (colormap != NULL) { + if (dinfo->cinfo->out_color_space == JCS_RGB) { + /* Normal case: RGB color map */ + putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file); + putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file); + putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file); + } else { + /* Grayscale "color map": possible if quantizing grayscale image */ + put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift); + } + } else { + /* Create a gray-scale map of num_colors values, range 0..255 */ + put_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1)); + } + } else { + /* fill out the map to a power of 2 */ + put_3bytes(dinfo, 0); + } + } + /* Write image separator and Image Descriptor */ + putc(',', dinfo->pub.output_file); /* separator */ + put_word(dinfo, 0); /* left/top offset */ + put_word(dinfo, 0); + put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */ + put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); + /* flag byte: not interlaced, no local color map */ + putc(0x00, dinfo->pub.output_file); + /* Write Initial Code Size byte */ + putc(InitCodeSize, dinfo->pub.output_file); + + /* Initialize for LZW compression of image data */ + compress_init(dinfo, InitCodeSize+1); + } + + + /* + * Startup: write the file header. + */ + + METHODDEF(void) + start_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + gif_dest_ptr dest = (gif_dest_ptr) dinfo; + + if (cinfo->quantize_colors) + emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap); + else + emit_header(dest, 256, (JSAMPARRAY) NULL); + } + + + /* + * Write some pixel data. + * In this module rows_supplied will always be 1. + */ + + METHODDEF(void) + put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + { + gif_dest_ptr dest = (gif_dest_ptr) dinfo; + register JSAMPROW ptr; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + for (col = cinfo->output_width; col > 0; col--) { + compress_byte(dest, GETJSAMPLE(*ptr++)); + } + } + + + /* + * Finish up at the end of the file. + */ + + METHODDEF(void) + finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + gif_dest_ptr dest = (gif_dest_ptr) dinfo; + + /* Flush LZW mechanism */ + compress_term(dest); + /* Write a zero-length data block to end the series */ + putc(0, dest->pub.output_file); + /* Write the GIF terminator mark */ + putc(';', dest->pub.output_file); + /* Make sure we wrote the output file OK */ + fflush(dest->pub.output_file); + if (ferror(dest->pub.output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + + + /* + * The module selection routine for GIF format output. + */ + + GLOBAL(djpeg_dest_ptr) + jinit_write_gif (j_decompress_ptr cinfo) + { + gif_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (gif_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(gif_dest_struct)); + dest->cinfo = cinfo; /* make back link for subroutines */ + dest->pub.start_output = start_output_gif; + dest->pub.put_pixel_rows = put_pixel_rows; + dest->pub.finish_output = finish_output_gif; + + if (cinfo->out_color_space != JCS_GRAYSCALE && + cinfo->out_color_space != JCS_RGB) + ERREXIT(cinfo, JERR_GIF_COLORSPACE); + + /* Force quantization if color or if > 8 bits input */ + if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) { + /* Force quantization to at most 256 colors */ + cinfo->quantize_colors = TRUE; + if (cinfo->desired_number_of_colors > 256) + cinfo->desired_number_of_colors = 256; + } + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + if (cinfo->output_components != 1) /* safety check: just one component? */ + ERREXIT(cinfo, JERR_GIF_BUG); + + /* Create decompressor output buffer. */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + + /* Allocate space for hash table */ + dest->hash_code = (code_int *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + HSIZE * SIZEOF(code_int)); + dest->hash_value = (hash_entry FAR *) + (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, + HSIZE * SIZEOF(hash_entry)); + + return (djpeg_dest_ptr) dest; + } + + #endif /* GIF_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrppm.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrppm.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrppm.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,268 ---- + /* + * wrppm.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in PPM/PGM format. + * The extended 2-byte-per-sample raw PPM/PGM formats are supported. + * The PBMPLUS library is NOT required to compile this software + * (but it is highly useful as a set of PPM image manipulation programs). + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + + #ifdef PPM_SUPPORTED + + + /* + * For 12-bit JPEG data, we either downscale the values to 8 bits + * (to write standard byte-per-sample PPM/PGM files), or output + * nonstandard word-per-sample PPM/PGM files. Downscaling is done + * if PPM_NORAWWORD is defined (this can be done in the Makefile + * or in jconfig.h). + * (When the core library supports data precision reduction, a cleaner + * implementation will be to ask for that instead.) + */ + + #if BITS_IN_JSAMPLE == 8 + #define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) (v) + #define BYTESPERSAMPLE 1 + #define PPM_MAXVAL 255 + #else + #ifdef PPM_NORAWWORD + #define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8)) + #define BYTESPERSAMPLE 1 + #define PPM_MAXVAL 255 + #else + /* The word-per-sample format always puts the LSB first. */ + #define PUTPPMSAMPLE(ptr,v) \ + { register int val_ = v; \ + *ptr++ = (char) (val_ & 0xFF); \ + *ptr++ = (char) ((val_ >> 8) & 0xFF); \ + } + #define BYTESPERSAMPLE 2 + #define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1) + #endif + #endif + + + /* + * When JSAMPLE is the same size as char, we can just fwrite() the + * decompressed data to the PPM or PGM file. On PCs, in order to make this + * work the output buffer must be allocated in near data space, because we are + * assuming small-data memory model wherein fwrite() can't reach far memory. + * If you need to process very wide images on a PC, you might have to compile + * in large-memory model, or else replace fwrite() with a putc() loop --- + * which will be much slower. + */ + + + /* Private version of data destination object */ + + typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + /* Usually these two pointers point to the same place: */ + char *iobuffer; /* fwrite's I/O buffer */ + JSAMPROW pixrow; /* decompressor output buffer */ + size_t buffer_width; /* width of I/O buffer */ + JDIMENSION samples_per_row; /* JSAMPLEs per output row */ + } ppm_dest_struct; + + typedef ppm_dest_struct * ppm_dest_ptr; + + + /* + * Write some pixel data. + * In this module rows_supplied will always be 1. + * + * put_pixel_rows handles the "normal" 8-bit case where the decompressor + * output buffer is physically the same as the fwrite buffer. + */ + + METHODDEF(void) + put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + { + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + } + + + /* + * This code is used when we have to copy the data and apply a pixel + * format translation. Typically this only happens in 12-bit mode. + */ + + METHODDEF(void) + copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + { + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + register char * bufferptr; + register JSAMPROW ptr; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + bufferptr = dest->iobuffer; + for (col = dest->samples_per_row; col > 0; col--) { + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++)); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + } + + + /* + * Write some pixel data when color quantization is in effect. + * We have to demap the color index values to straight data. + */ + + METHODDEF(void) + put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + { + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + register char * bufferptr; + register int pixval; + register JSAMPROW ptr; + register JSAMPROW color_map0 = cinfo->colormap[0]; + register JSAMPROW color_map1 = cinfo->colormap[1]; + register JSAMPROW color_map2 = cinfo->colormap[2]; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + bufferptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + pixval = GETJSAMPLE(*ptr++); + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval])); + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval])); + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval])); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + } + + + METHODDEF(void) + put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + { + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + register char * bufferptr; + register JSAMPROW ptr; + register JSAMPROW color_map = cinfo->colormap[0]; + register JDIMENSION col; + + ptr = dest->pub.buffer[0]; + bufferptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)])); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + } + + + /* + * Startup: write the file header. + */ + + METHODDEF(void) + start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; + + /* Emit file header */ + switch (cinfo->out_color_space) { + case JCS_GRAYSCALE: + /* emit header for raw PGM format */ + fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n", + (long) cinfo->output_width, (long) cinfo->output_height, + PPM_MAXVAL); + break; + case JCS_RGB: + /* emit header for raw PPM format */ + fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n", + (long) cinfo->output_width, (long) cinfo->output_height, + PPM_MAXVAL); + break; + default: + ERREXIT(cinfo, JERR_PPM_COLORSPACE); + } + } + + + /* + * Finish up at the end of the file. + */ + + METHODDEF(void) + finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + /* Make sure we wrote the output file OK */ + fflush(dinfo->output_file); + if (ferror(dinfo->output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + + + /* + * The module selection routine for PPM format output. + */ + + GLOBAL(djpeg_dest_ptr) + jinit_write_ppm (j_decompress_ptr cinfo) + { + ppm_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (ppm_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(ppm_dest_struct)); + dest->pub.start_output = start_output_ppm; + dest->pub.finish_output = finish_output_ppm; + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Create physical I/O buffer. Note we make this near on a PC. */ + dest->samples_per_row = cinfo->output_width * cinfo->out_color_components; + dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char)); + dest->iobuffer = (char *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width); + + if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 || + SIZEOF(JSAMPLE) != SIZEOF(char)) { + /* When quantizing, we need an output buffer for colormap indexes + * that's separate from the physical I/O buffer. We also need a + * separate buffer if pixel format translation must take place. + */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->output_width * cinfo->output_components, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + if (! cinfo->quantize_colors) + dest->pub.put_pixel_rows = copy_pixel_rows; + else if (cinfo->out_color_space == JCS_GRAYSCALE) + dest->pub.put_pixel_rows = put_demapped_gray; + else + dest->pub.put_pixel_rows = put_demapped_rgb; + } else { + /* We will fwrite() directly from decompressor output buffer. */ + /* Synthesize a JSAMPARRAY pointer structure */ + /* Cast here implies near->far pointer conversion on PCs */ + dest->pixrow = (JSAMPROW) dest->iobuffer; + dest->pub.buffer = & dest->pixrow; + dest->pub.buffer_height = 1; + dest->pub.put_pixel_rows = put_pixel_rows; + } + + return (djpeg_dest_ptr) dest; + } + + #endif /* PPM_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrrle.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrrle.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrrle.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,305 ---- + /* + * wrrle.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in RLE format. + * The Utah Raster Toolkit library is required (version 3.1 or later). + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + * + * Based on code contributed by Mike Lijewski, + * with updates from Robert Hutchinson. + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + + #ifdef RLE_SUPPORTED + + /* rle.h is provided by the Utah Raster Toolkit. */ + + #include <rle.h> + + /* + * We assume that JSAMPLE has the same representation as rle_pixel, + * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. + */ + + #if BITS_IN_JSAMPLE != 8 + Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ + #endif + + + /* + * Since RLE stores scanlines bottom-to-top, we have to invert the image + * from JPEG's top-to-bottom order. To do this, we save the outgoing data + * in a virtual array during put_pixel_row calls, then actually emit the + * RLE file during finish_output. + */ + + + /* + * For now, if we emit an RLE color map then it is always 256 entries long, + * though not all of the entries need be used. + */ + + #define CMAPBITS 8 + #define CMAPLENGTH (1<<(CMAPBITS)) + + typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + jvirt_sarray_ptr image; /* virtual array to store the output image */ + rle_map *colormap; /* RLE-style color map, or NULL if none */ + rle_pixel **rle_row; /* To pass rows to rle_putrow() */ + + } rle_dest_struct; + + typedef rle_dest_struct * rle_dest_ptr; + + /* Forward declarations */ + METHODDEF(void) rle_put_pixel_rows + JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied)); + + + /* + * Write the file header. + * + * In this module it's easier to wait till finish_output to write anything. + */ + + METHODDEF(void) + start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + rle_dest_ptr dest = (rle_dest_ptr) dinfo; + size_t cmapsize; + int i, ci; + #ifdef PROGRESS_REPORT + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + #endif + + /* + * Make sure the image can be stored in RLE format. + * + * - RLE stores image dimensions as *signed* 16 bit integers. JPEG + * uses unsigned, so we have to check the width. + * + * - Colorspace is expected to be grayscale or RGB. + * + * - The number of channels (components) is expected to be 1 (grayscale/ + * pseudocolor) or 3 (truecolor/directcolor). + * (could be 2 or 4 if using an alpha channel, but we aren't) + */ + + if (cinfo->output_width > 32767 || cinfo->output_height > 32767) + ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, + cinfo->output_height); + + if (cinfo->out_color_space != JCS_GRAYSCALE && + cinfo->out_color_space != JCS_RGB) + ERREXIT(cinfo, JERR_RLE_COLORSPACE); + + if (cinfo->output_components != 1 && cinfo->output_components != 3) + ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components); + + /* Convert colormap, if any, to RLE format. */ + + dest->colormap = NULL; + + if (cinfo->quantize_colors) { + /* Allocate storage for RLE-style cmap, zero any extra entries */ + cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map); + dest->colormap = (rle_map *) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize); + MEMZERO(dest->colormap, cmapsize); + + /* Save away data in RLE format --- note 8-bit left shift! */ + /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */ + for (ci = 0; ci < cinfo->out_color_components; ci++) { + for (i = 0; i < cinfo->actual_number_of_colors; i++) { + dest->colormap[ci * CMAPLENGTH + i] = + GETJSAMPLE(cinfo->colormap[ci][i]) << 8; + } + } + } + + /* Set the output buffer to the first row */ + dest->pub.buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE); + dest->pub.buffer_height = 1; + + dest->pub.put_pixel_rows = rle_put_pixel_rows; + + #ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->total_extra_passes++; /* count file writing as separate pass */ + } + #endif + } + + + /* + * Write some pixel data. + * + * This routine just saves the data away in a virtual array. + */ + + METHODDEF(void) + rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + { + rle_dest_ptr dest = (rle_dest_ptr) dinfo; + + if (cinfo->output_scanline < cinfo->output_height) { + dest->pub.buffer = (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, + cinfo->output_scanline, (JDIMENSION) 1, TRUE); + } + } + + /* + * Finish up at the end of the file. + * + * Here is where we really output the RLE file. + */ + + METHODDEF(void) + finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + rle_dest_ptr dest = (rle_dest_ptr) dinfo; + rle_hdr header; /* Output file information */ + rle_pixel **rle_row, *red, *green, *blue; + JSAMPROW output_row; + char cmapcomment[80]; + int row, col; + int ci; + #ifdef PROGRESS_REPORT + cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; + #endif + + /* Initialize the header info */ + header = *rle_hdr_init(NULL); + header.rle_file = dest->pub.output_file; + header.xmin = 0; + header.xmax = cinfo->output_width - 1; + header.ymin = 0; + header.ymax = cinfo->output_height - 1; + header.alpha = 0; + header.ncolors = cinfo->output_components; + for (ci = 0; ci < cinfo->output_components; ci++) { + RLE_SET_BIT(header, ci); + } + if (cinfo->quantize_colors) { + header.ncmap = cinfo->out_color_components; + header.cmaplen = CMAPBITS; + header.cmap = dest->colormap; + /* Add a comment to the output image with the true colormap length. */ + sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors); + rle_putcom(cmapcomment, &header); + } + + /* Emit the RLE header and color map (if any) */ + rle_put_setup(&header); + + /* Now output the RLE data from our virtual array. + * We assume here that (a) rle_pixel is represented the same as JSAMPLE, + * and (b) we are not on a machine where FAR pointers differ from regular. + */ + + #ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_limit = cinfo->output_height; + progress->pub.pass_counter = 0; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } + #endif + + if (cinfo->output_components == 1) { + for (row = cinfo->output_height-1; row >= 0; row--) { + rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, + (JDIMENSION) row, (JDIMENSION) 1, FALSE); + rle_putrow(rle_row, (int) cinfo->output_width, &header); + #ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_counter++; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } + #endif + } + } else { + for (row = cinfo->output_height-1; row >= 0; row--) { + rle_row = (rle_pixel **) dest->rle_row; + output_row = * (*cinfo->mem->access_virt_sarray) + ((j_common_ptr) cinfo, dest->image, + (JDIMENSION) row, (JDIMENSION) 1, FALSE); + red = rle_row[0]; + green = rle_row[1]; + blue = rle_row[2]; + for (col = cinfo->output_width; col > 0; col--) { + *red++ = GETJSAMPLE(*output_row++); + *green++ = GETJSAMPLE(*output_row++); + *blue++ = GETJSAMPLE(*output_row++); + } + rle_putrow(rle_row, (int) cinfo->output_width, &header); + #ifdef PROGRESS_REPORT + if (progress != NULL) { + progress->pub.pass_counter++; + (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); + } + #endif + } + } + + #ifdef PROGRESS_REPORT + if (progress != NULL) + progress->completed_extra_passes++; + #endif + + /* Emit file trailer */ + rle_puteof(&header); + fflush(dest->pub.output_file); + if (ferror(dest->pub.output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + + + /* + * The module selection routine for RLE format output. + */ + + GLOBAL(djpeg_dest_ptr) + jinit_write_rle (j_decompress_ptr cinfo) + { + rle_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (rle_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(rle_dest_struct)); + dest->pub.start_output = start_output_rle; + dest->pub.finish_output = finish_output_rle; + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Allocate a work array for output to the RLE library. */ + dest->rle_row = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, + cinfo->output_width, (JDIMENSION) cinfo->output_components); + + /* Allocate a virtual array to hold the image. */ + dest->image = (*cinfo->mem->request_virt_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, + (JDIMENSION) (cinfo->output_width * cinfo->output_components), + cinfo->output_height, (JDIMENSION) 1); + + return (djpeg_dest_ptr) dest; + } + + #endif /* RLE_SUPPORTED */ Index: llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrtarga.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrtarga.c:1.1 *** /dev/null Tue Jan 9 17:45:04 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/consumer-jpeg/wrtarga.c Tue Jan 9 17:44:34 2007 *************** *** 0 **** --- 1,253 ---- + /* + * wrtarga.c + * + * Copyright (C) 1991-1996, Thomas G. Lane. + * This file is part of the Independent JPEG Group's software. + * For conditions of distribution and use, see the accompanying README file. + * + * This file contains routines to write output images in Targa format. + * + * These routines may need modification for non-Unix environments or + * specialized applications. As they stand, they assume output to + * an ordinary stdio stream. + * + * Based on code contributed by Lee Daniel Crocker. + */ + + #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ + + #ifdef TARGA_SUPPORTED + + + /* + * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. + * This is not yet implemented. + */ + + #if BITS_IN_JSAMPLE != 8 + Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ + #endif + + /* + * The output buffer needs to be writable by fwrite(). On PCs, we must + * allocate the buffer in near data space, because we are assuming small-data + * memory model, wherein fwrite() can't reach far memory. If you need to + * process very wide images on a PC, you might have to compile in large-memory + * model, or else replace fwrite() with a putc() loop --- which will be much + * slower. + */ + + + /* Private version of data destination object */ + + typedef struct { + struct djpeg_dest_struct pub; /* public fields */ + + char *iobuffer; /* physical I/O buffer */ + JDIMENSION buffer_width; /* width of one row */ + } tga_dest_struct; + + typedef tga_dest_struct * tga_dest_ptr; + + + LOCAL(void) + write_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors) + /* Create and write a Targa header */ + { + char targaheader[18]; + + /* Set unused fields of header to 0 */ + MEMZERO(targaheader, SIZEOF(targaheader)); + + if (num_colors > 0) { + targaheader[1] = 1; /* color map type 1 */ + targaheader[5] = (char) (num_colors & 0xFF); + targaheader[6] = (char) (num_colors >> 8); + targaheader[7] = 24; /* 24 bits per cmap entry */ + } + + targaheader[12] = (char) (cinfo->output_width & 0xFF); + targaheader[13] = (char) (cinfo->output_width >> 8); + targaheader[14] = (char) (cinfo->output_height & 0xFF); + targaheader[15] = (char) (cinfo->output_height >> 8); + targaheader[17] = 0x20; /* Top-down, non-interlaced */ + + if (cinfo->out_color_space == JCS_GRAYSCALE) { + targaheader[2] = 3; /* image type = uncompressed gray-scale */ + targaheader[16] = 8; /* bits per pixel */ + } else { /* must be RGB */ + if (num_colors > 0) { + targaheader[2] = 1; /* image type = colormapped RGB */ + targaheader[16] = 8; + } else { + targaheader[2] = 2; /* image type = uncompressed RGB */ + targaheader[16] = 24; + } + } + + if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + + + /* + * Write some pixel data. + * In this module rows_supplied will always be 1. + */ + + METHODDEF(void) + put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + /* used for unquantized full-color output */ + { + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + register JSAMPROW inptr; + register char * outptr; + register JDIMENSION col; + + inptr = dest->pub.buffer[0]; + outptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */ + outptr[1] = (char) GETJSAMPLE(inptr[1]); + outptr[2] = (char) GETJSAMPLE(inptr[0]); + inptr += 3, outptr += 3; + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + } + + METHODDEF(void) + put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + /* used for grayscale OR quantized color output */ + { + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + register JSAMPROW inptr; + register char * outptr; + register JDIMENSION col; + + inptr = dest->pub.buffer[0]; + outptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + *outptr++ = (char) GETJSAMPLE(*inptr++); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + } + + + /* + * Write some demapped pixel data when color quantization is in effect. + * For Targa, this is only applied to grayscale data. + */ + + METHODDEF(void) + put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, + JDIMENSION rows_supplied) + { + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + register JSAMPROW inptr; + register char * outptr; + register JSAMPROW color_map0 = cinfo->colormap[0]; + register JDIMENSION col; + + inptr = dest->pub.buffer[0]; + outptr = dest->iobuffer; + for (col = cinfo->output_width; col > 0; col--) { + *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]); + } + (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); + } + + + /* + * Startup: write the file header. + */ + + METHODDEF(void) + start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + tga_dest_ptr dest = (tga_dest_ptr) dinfo; + int num_colors, i; + FILE *outfile; + + if (cinfo->out_color_space == JCS_GRAYSCALE) { + /* Targa doesn't have a mapped grayscale format, so we will */ + /* demap quantized gray output. Never emit a colormap. */ + write_header(cinfo, dinfo, 0); + if (cinfo->quantize_colors) + dest->pub.put_pixel_rows = put_demapped_gray; + else + dest->pub.put_pixel_rows = put_gray_rows; + } else if (cinfo->out_color_space == JCS_RGB) { + if (cinfo->quantize_colors) { + /* We only support 8-bit colormap indexes, so only 256 colors */ + num_colors = cinfo->actual_number_of_colors; + if (num_colors > 256) + ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors); + write_header(cinfo, dinfo, num_colors); + /* Write the colormap. Note Targa uses BGR byte order */ + outfile = dest->pub.output_file; + for (i = 0; i < num_colors; i++) { + putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile); + putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile); + putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile); + } + dest->pub.put_pixel_rows = put_gray_rows; + } else { + write_header(cinfo, dinfo, 0); + dest->pub.put_pixel_rows = put_pixel_rows; + } + } else { + ERREXIT(cinfo, JERR_TGA_COLORSPACE); + } + } + + + /* + * Finish up at the end of the file. + */ + + METHODDEF(void) + finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) + { + /* Make sure we wrote the output file OK */ + fflush(dinfo->output_file); + if (ferror(dinfo->output_file)) + ERREXIT(cinfo, JERR_FILE_WRITE); + } + + + /* + * The module selection routine for Targa format output. + */ + + GLOBAL(djpeg_dest_ptr) + jinit_write_targa (j_decompress_ptr cinfo) + { + tga_dest_ptr dest; + + /* Create module interface object, fill in method pointers */ + dest = (tga_dest_ptr) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + SIZEOF(tga_dest_struct)); + dest->pub.start_output = start_output_tga; + dest->pub.finish_output = finish_output_tga; + + /* Calculate output image dimensions so we can allocate space */ + jpeg_calc_output_dimensions(cinfo); + + /* Create I/O buffer. Note we make this near on a PC. */ + dest->buffer_width = cinfo->output_width * cinfo->output_components; + dest->iobuffer = (char *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, + (size_t) (dest->buffer_width * SIZEOF(char))); + + /* Create decompressor output buffer. */ + dest->pub.buffer = (*cinfo->mem->alloc_sarray) + ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1); + dest->pub.buffer_height = 1; + + return (djpeg_dest_ptr) dest; + } + + #endif /* TARGA_SUPPORTED */ From sabre at nondot.org Tue Jan 9 17:45:03 2007 From: sabre at nondot.org (Chris Lattner) Date: Tue, 9 Jan 2007 17:45:03 -0600 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/COPYRIGHT INSTALL LICENSE Makefile README add.c code.c config.h debug.c decode.c gsm.h gsm_create.c gsm_decode.c gsm_destroy.c gsm_encode.c gsm_explode.c gsm_implode.c gsm_option.c gsm_print.c large.au.run.gsm long_term.c lpc.c preprocess.c private.h proto.h rpe.c short_term.c table.c toast.c toast.h toast_alaw.c toast_audio.c toast_lin.c toast_ulaw.c unproto.h Message-ID: <200701092345.l09Nj31f029039@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm: COPYRIGHT added (r1.1) INSTALL added (r1.1) LICENSE added (r1.1) Makefile added (r1.1) README added (r1.1) add.c added (r1.1) code.c added (r1.1) config.h added (r1.1) debug.c added (r1.1) decode.c added (r1.1) gsm.h added (r1.1) gsm_create.c added (r1.1) gsm_decode.c added (r1.1) gsm_destroy.c added (r1.1) gsm_encode.c added (r1.1) gsm_explode.c added (r1.1) gsm_implode.c added (r1.1) gsm_option.c added (r1.1) gsm_print.c added (r1.1) large.au.run.gsm added (r1.1) long_term.c added (r1.1) lpc.c added (r1.1) preprocess.c added (r1.1) private.h added (r1.1) proto.h added (r1.1) rpe.c added (r1.1) short_term.c added (r1.1) table.c added (r1.1) toast.c added (r1.1) toast.h added (r1.1) toast_alaw.c added (r1.1) toast_audio.c added (r1.1) toast_lin.c added (r1.1) toast_ulaw.c added (r1.1) unproto.h added (r1.1) --- Log message: Readd mibench --- Diffs of the changes: (+6199 -0) COPYRIGHT | 16 + INSTALL | 92 ++++++ LICENSE | 16 + Makefile | 7 README | 37 ++ add.c | 235 ++++++++++++++++ code.c | 99 ++++++ config.h | 34 ++ debug.c | 76 +++++ decode.c | 63 ++++ gsm.h | 68 ++++ gsm_create.c | 55 +++ gsm_decode.c | 125 ++++++++ gsm_destroy.c | 26 + gsm_encode.c | 207 ++++++++++++++ gsm_explode.c | 197 +++++++++++++ gsm_implode.c | 280 +++++++++++++++++++ gsm_option.c | 38 ++ gsm_print.c | 167 +++++++++++ large.au.run.gsm | 0 long_term.c | 603 ++++++++++++++++++++++++++++++++++++++++++ lpc.c | 341 +++++++++++++++++++++++ preprocess.c | 113 +++++++ private.h | 263 ++++++++++++++++++ proto.h | 65 ++++ rpe.c | 488 ++++++++++++++++++++++++++++++++++ short_term.c | 429 +++++++++++++++++++++++++++++ table.c | 63 ++++ toast.c | 787 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ toast.h | 105 +++++++ toast_alaw.c | 333 +++++++++++++++++++++++ toast_audio.c | 103 +++++++ toast_lin.c | 24 + toast_ulaw.c | 621 +++++++++++++++++++++++++++++++++++++++++++ unproto.h | 23 + 35 files changed, 6199 insertions(+) Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/COPYRIGHT diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/COPYRIGHT:1.1 *** /dev/null Tue Jan 9 17:44:45 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/COPYRIGHT Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,16 ---- + Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann, + Technische Universitaet Berlin + + Any use of this software is permitted provided that this notice is not + removed and that neither the authors nor the Technische Universitaet Berlin + are deemed to have made any representations as to the suitability of this + software for any purpose nor are held responsible for any defects of + this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + + As a matter of courtesy, the authors request to be informed about uses + this software has found, about bugs in this software, and about any + improvements that may be of general interest. + + Berlin, 28.11.1994 + Jutta Degener + Carsten Bormann Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/INSTALL diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/INSTALL:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/INSTALL Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,92 ---- + + /* + * Copyright 1992, 1993, 1994, by Jutta Degener and Carsten Bormann, + * Technische Universitaet Berlin. See the accompanying file "COPYRIGHT" + * for details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + How to get started: + + Edit the Makefile. + + You should configure a few machine-dependencies and what + compiler you want to use. + + The code works both with ANSI and K&R-C. Use + -DNeedFunctionPrototypes to compile with, or + -UNeedFunctionPrototypes to compile without, function + prototypes in the header files. + + Make addtst + + The "add" program that will be compiled and run checks whether + the basic math functions of the gsm library work with your + compiler. If it prints anything to stderr, complain (to us). + + Edit inc/config.h. + + Make + + Local versions of the gsm library and the "compress"-like filters + toast, untoast and tcat will be generated. + + If the compilation aborts because of a missing function, + declaration, or header file, see if there's something in + inc/config.h to work around it. If not, complain. + + Try it + + Grab an audio file from somewhere (raw u-law or Sun .au is fine, + linear 16-bit in host byte order will do), copy it, toast it, + untoast it, and listen to the result. + + If it doesn't sound anything like the original, read the manual. + If it still doesn't sound anything like the original, complain. + + + Installation + + You can install the gsm library interface, or the toast binaries, + or both. + + Edit the Makefile + + Fill in the directories where you want to install the + library, header files, manual pages, and binaries. + + Turn off the installation of one half of the distribution + (i.e., gsm library or toast binaries) by not setting the + corresponding directory root Makefile macro. + + + make install + + will install the programs "toast" with two links named + "tcat" and "untoast", and the gsm library "libgsm.a" with + a "gsm.h" header file, and their respective manual pages. + + + Optimizing + + This code was developed on a machine without an integer + multiplication instruction, where we obtained the fastest result by + replacing some of the integer multiplications with floating point + multiplications. + + Another possibility is the use of a lookup table; you can turn on + this feature by replacing -DUSE_FLOAT_MUL by -DUSE_TABLE_MUL. + + If your machine does multiply integers fast, define neither. + + + + Bug Reports + + Please direct bug reports to jutta at cs.tu-berlin.de and + cabo at cs.tu-berlin.de . + + + Good luck, + + Jutta Degener, + Carsten Bormann Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/LICENSE diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/LICENSE:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/LICENSE Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,16 ---- + Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann, + Technische Universitaet Berlin + + Any use of this software is permitted provided that this notice is not + removed and that neither the authors nor the Technische Universitaet Berlin + are deemed to have made any representations as to the suitability of this + software for any purpose nor are held responsible for any defects of + this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + + As a matter of courtesy, the authors request to be informed about uses + this software has found, about bugs in this software, and about any + improvements that may be of general interest. + + Berlin, 28.11.1994 + Jutta Degener + Carsten Bormann Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/Makefile Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,7 ---- + LEVEL = ../../../.. + + PROG = telecomm-gsm + CPPFLAGS = -DSTUPID_COMPILER -DNeedFunctionPrototypes=1 -DSASR + LDFLAGS = -lm + RUN_OPTIONS = -fps -c large.au.run.gsm + include $(LEVEL)/MultiSource/Makefile.multisrc Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/README diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/README:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/README Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,37 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + GSM 06.10 13 kbit/s RPE/LTP speech compression available + -------------------------------------------------------- + + The Communications and Operating Systems Research Group (KBS) at the + Technische Universitaet Berlin is currently working on a set of + UNIX-based tools for computer-mediated telecooperation that will be + made freely available. + + As part of this effort we are publishing an implementation of the + European GSM 06.10 provisional standard for full-rate speech + transcoding, prI-ETS 300 036, which uses RPE/LTP (residual pulse + excitation/long term prediction) coding at 13 kbit/s. + + GSM 06.10 compresses frames of 160 13-bit samples (8 kHz sampling + rate, i.e. a frame rate of 50 Hz) into 260 bits; for compatibility + with typical UNIX applications, our implementation turns frames of 160 + 16-bit linear samples into 33-byte frames (1650 Bytes/s). + The quality of the algorithm is good enough for reliable speaker + recognition; even music often survives transcoding in recognizable + form (given the bandwidth limitations of 8 kHz sampling rate). + + The interfaces offered are a front end modelled after compress(1), and + a library API. Compression and decompression run faster than realtime + on most SPARCstations. The implementation has been verified against the + ETSI standard test patterns. + + Jutta Degener (jutta at cs.tu-berlin.de) + Carsten Bormann (cabo at cs.tu-berlin.de) + + Communications and Operating Systems Research Group, TU Berlin + Fax: +49.30.31425156, Phone: +49.30.31424315 Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/add.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/add.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/add.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,235 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/add.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + /* + * See private.h for the more commonly used macro versions. + */ + + #include <stdio.h> + #include <assert.h> + + #include "private.h" + #include "gsm.h" + #include "proto.h" + + #define saturate(x) \ + ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x)) + + word gsm_add P2((a,b), word a, word b) + { + longword sum = (longword)a + (longword)b; + return saturate(sum); + } + + word gsm_sub P2((a,b), word a, word b) + { + longword diff = (longword)a - (longword)b; + return saturate(diff); + } + + word gsm_mult P2((a,b), word a, word b) + { + if (a == MIN_WORD && b == MIN_WORD) return MAX_WORD; + else return SASR( (longword)a * (longword)b, 15 ); + } + + word gsm_mult_r P2((a,b), word a, word b) + { + if (b == MIN_WORD && a == MIN_WORD) return MAX_WORD; + else { + longword prod = (longword)a * (longword)b + 16384; + prod >>= 15; + return prod & 0xFFFF; + } + } + + word gsm_abs P1((a), word a) + { + return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a; + } + + longword gsm_L_mult P2((a,b),word a, word b) + { + assert( a != MIN_WORD || b != MIN_WORD ); + return ((longword)a * (longword)b) << 1; + } + + longword gsm_L_add P2((a,b), longword a, longword b) + { + if (a < 0) { + if (b >= 0) return a + b; + else { + ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1); + return A >= MAX_LONGWORD ? MIN_LONGWORD :-(longword)A-2; + } + } + else if (b <= 0) return a + b; + else { + ulongword A = (ulongword)a + (ulongword)b; + return A > MAX_LONGWORD ? MAX_LONGWORD : A; + } + } + + longword gsm_L_sub P2((a,b), longword a, longword b) + { + if (a >= 0) { + if (b >= 0) return a - b; + else { + /* a>=0, b<0 */ + + ulongword A = (ulongword)a + -(b + 1); + return A >= MAX_LONGWORD ? MAX_LONGWORD : (A + 1); + } + } + else if (b <= 0) return a - b; + else { + /* a<0, b>0 */ + + ulongword A = (ulongword)-(a + 1) + b; + return A >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)A - 1; + } + } + + static unsigned char bitoff[ 256 ] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + word gsm_norm P1((a), longword a ) + /* + * the number of left shifts needed to normalize the 32 bit + * variable L_var1 for positive values on the interval + * + * with minimum of + * minimum of 1073741824 (01000000000000000000000000000000) and + * maximum of 2147483647 (01111111111111111111111111111111) + * + * + * and for negative values on the interval with + * minimum of -2147483648 (-10000000000000000000000000000000) and + * maximum of -1073741824 ( -1000000000000000000000000000000). + * + * in order to normalize the result, the following + * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 ); + * + * (That's 'ffs', only from the left, not the right..) + */ + { + assert(a != 0); + + if (a < 0) { + if (a <= -1073741824) return 0; + a = ~a; + } + + return a & 0xffff0000 + ? ( a & 0xff000000 + ? -1 + bitoff[ 0xFF & (a >> 24) ] + : 7 + bitoff[ 0xFF & (a >> 16) ] ) + : ( a & 0xff00 + ? 15 + bitoff[ 0xFF & (a >> 8) ] + : 23 + bitoff[ 0xFF & a ] ); + } + + longword gsm_L_asl P2((a,n), longword a, int n) + { + if (n >= 32) return 0; + if (n <= -32) return -(a < 0); + if (n < 0) return gsm_L_asr(a, -n); + return a << n; + } + + word gsm_asl P2((a,n), word a, int n) + { + if (n >= 16) return 0; + if (n <= -16) return -(a < 0); + if (n < 0) return gsm_asr(a, -n); + return a << n; + } + + longword gsm_L_asr P2((a,n), longword a, int n) + { + if (n >= 32) return -(a < 0); + if (n <= -32) return 0; + if (n < 0) return a << -n; + + # ifdef SASR + return a >> n; + # else + if (a >= 0) return a >> n; + else return -(longword)( -(ulongword)a >> n ); + # endif + } + + word gsm_asr P2((a,n), word a, int n) + { + if (n >= 16) return -(a < 0); + if (n <= -16) return 0; + if (n < 0) return a << -n; + + # ifdef SASR + return a >> n; + # else + if (a >= 0) return a >> n; + else return -(word)( -(uword)a >> n ); + # endif + } + + /* + * (From p. 46, end of section 4.2.5) + * + * NOTE: The following lines gives [sic] one correct implementation + * of the div(num, denum) arithmetic operation. Compute div + * which is the integer division of num by denum: with denum + * >= num > 0 + */ + + word gsm_div P2((num,denum), word num, word denum) + { + longword L_num = num; + longword L_denum = denum; + word div = 0; + int k = 15; + + /* The parameter num sometimes becomes zero. + * Although this is explicitly guarded against in 4.2.5, + * we assume that the result should then be zero as well. + */ + + /* assert(num != 0); */ + + assert(num >= 0 && denum >= num); + if (num == 0) + return 0; + + while (k--) { + div <<= 1; + L_num <<= 1; + + if (L_num >= L_denum) { + L_num -= L_denum; + div++; + } + } + + return div; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/code.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/code.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/code.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,99 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/code.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "config.h" + + + #ifdef HAS_STDLIB_H + #include <stdlib.h> + #else + # include "proto.h" + extern char * memcpy P((char *, char *, int)); + #endif + + #include "private.h" + #include "gsm.h" + #include "proto.h" + + /* + * 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER + */ + + void Gsm_Coder P8((S,s,LARc,Nc,bc,Mc,xmaxc,xMc), + + struct gsm_state * S, + + word * s, /* [0..159] samples IN */ + + /* + * The RPE-LTD coder works on a frame by frame basis. The length of + * the frame is equal to 160 samples. Some computations are done + * once per frame to produce at the output of the coder the + * LARc[1..8] parameters which are the coded LAR coefficients and + * also to realize the inverse filtering operation for the entire + * frame (160 samples of signal d[0..159]). These parts produce at + * the output of the coder: + */ + + word * LARc, /* [0..7] LAR coefficients OUT */ + + /* + * Procedure 4.2.11 to 4.2.18 are to be executed four times per + * frame. That means once for each sub-segment RPE-LTP analysis of + * 40 samples. These parts produce at the output of the coder: + */ + + word * Nc, /* [0..3] LTP lag OUT */ + word * bc, /* [0..3] coded LTP gain OUT */ + word * Mc, /* [0..3] RPE grid selection OUT */ + word * xmaxc,/* [0..3] Coded maximum amplitude OUT */ + word * xMc /* [13*4] normalized RPE samples OUT */ + ) + { + int k; + word * dp = S->dp0 + 120; /* [ -120...-1 ] */ + word * dpp = dp; /* [ 0...39 ] */ + + static word e [50] = {0}; + + word so[160]; + + Gsm_Preprocess (S, s, so); + Gsm_LPC_Analysis (S, so, LARc); + Gsm_Short_Term_Analysis_Filter (S, LARc, so); + + for (k = 0; k <= 3; k++, xMc += 13) { + + Gsm_Long_Term_Predictor ( S, + so+k*40, /* d [0..39] IN */ + dp, /* dp [-120..-1] IN */ + e + 5, /* e [0..39] OUT */ + dpp, /* dpp [0..39] OUT */ + Nc++, + bc++); + + Gsm_RPE_Encoding ( S, + e + 5, /* e ][0..39][ IN/OUT */ + xmaxc++, Mc++, xMc ); + /* + * Gsm_Update_of_reconstructed_short_time_residual_signal + * ( dpp, e + 5, dp ); + */ + + { register int i; + register longword ltmp; + for (i = 0; i <= 39; i++) + dp[ i ] = GSM_ADD( e[5 + i], dpp[i] ); + } + dp += 40; + dpp += 40; + + } + (void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160), + 120 * sizeof(*S->dp0) ); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/config.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/config.h:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/config.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,34 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /*$Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/config.h,v 1.1 2007/01/09 23:44:35 lattner Exp $*/ + + #ifndef CONFIG_H + #define CONFIG_H + + /*efine SIGHANDLER_T int /* signal handlers are void */ + /*efine HAS_SYSV_SIGNAL 1 /* sigs not blocked/reset? */ + + #define HAS_STDLIB_H 1 /* /usr/include/stdlib.h */ + /*efine HAS_LIMITS_H 1 /* /usr/include/limits.h */ + #define HAS_FCNTL_H 1 /* /usr/include/fcntl.h */ + /*efine HAS_ERRNO_DECL 1 /* errno.h declares errno */ + + #define HAS_FSTAT 1 /* fstat syscall */ + #define HAS_FCHMOD 1 /* fchmod syscall */ + #define HAS_FCHOWN 1 /* fchown syscall */ + + #define HAS_STRING_H 1 /* /usr/include/string.h */ + /*efine HAS_STRINGS_H 1 /* /usr/include/strings.h */ + + #define HAS_UNISTD_H 1 /* /usr/include/unistd.h */ + #define HAS_UTIME 1 /* POSIX utime(path, times) */ + /*efine HAS_UTIMES 1 /* use utimes() syscall instead */ + #define HAS_UTIME_H 1 /* UTIME header file */ + /*efine HAS_UTIMBUF 1 /* struct utimbuf */ + /*efine HAS_UTIMEUSEC 1 /* microseconds in utimbuf? */ + + #endif /* CONFIG_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/debug.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/debug.c:1.1 *** /dev/null Tue Jan 9 17:45:02 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/debug.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,76 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/debug.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "private.h" + + #ifndef NDEBUG + + /* If NDEBUG _is_ defined and no debugging should be performed, + * calls to functions in this module are #defined to nothing + * in private.h. + */ + + #include <stdio.h> + #include "proto.h" + + void gsm_debug_words P4( (name, from, to, ptr), + char * name, + int from, + int to, + word * ptr) + { + int nprinted = 0; + + fprintf( stderr, "%s [%d .. %d]: ", name, from, to ); + while (from <= to) { + fprintf(stderr, "%d ", ptr[ from ] ); + from++; + if (nprinted++ >= 7) { + nprinted = 0; + if (from < to) putc('\n', stderr); + } + } + putc('\n', stderr); + } + + void gsm_debug_longwords P4( (name, from, to, ptr), + char * name, + int from, + int to, + longword * ptr) + { + int nprinted = 0; + + fprintf( stderr, "%s [%d .. %d]: ", name, from, to ); + while (from <= to) { + + fprintf(stderr, "%d ", ptr[ from ] ); + from++; + if (nprinted++ >= 7) { + nprinted = 0; + if (from < to) putc('\n', stderr); + } + } + putc('\n', stderr); + } + + void gsm_debug_longword P2( (name, value), + char * name, + longword value ) + { + fprintf(stderr, "%s: %d\n", name, (long)value ); + } + + void gsm_debug_word P2( (name, value), + char * name, + word value ) + { + fprintf(stderr, "%s: %d\n", name, (long)value); + } + + #endif Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/decode.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/decode.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/decode.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,63 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/decode.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include <stdio.h> + + #include "private.h" + #include "gsm.h" + #include "proto.h" + + /* + * 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER + */ + + static void Postprocessing P2((S,s), + struct gsm_state * S, + register word * s) + { + register int k; + register word msr = S->msr; + register longword ltmp; /* for GSM_ADD */ + register word tmp; + + for (k = 160; k--; s++) { + tmp = GSM_MULT_R( msr, 28180 ); + msr = GSM_ADD(*s, tmp); /* Deemphasis */ + *s = GSM_ADD(msr, msr) & 0xFFF8; /* Truncation & Upscaling */ + } + S->msr = msr; + } + + void Gsm_Decoder P8((S,LARcr, Ncr,bcr,Mcr,xmaxcr,xMcr,s), + struct gsm_state * S, + + word * LARcr, /* [0..7] IN */ + + word * Ncr, /* [0..3] IN */ + word * bcr, /* [0..3] IN */ + word * Mcr, /* [0..3] IN */ + word * xmaxcr, /* [0..3] IN */ + word * xMcr, /* [0..13*4] IN */ + + word * s) /* [0..159] OUT */ + { + int j, k; + word erp[40], wt[160]; + word * drp = S->dp0 + 120; + + for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) { + + Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp ); + Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp ); + + for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ]; + } + + Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s ); + Postprocessing(S, s); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,68 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /*$Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm.h,v 1.1 2007/01/09 23:44:35 lattner Exp $*/ + + #ifndef GSM_H + #define GSM_H + + #ifdef __cplusplus + # define NeedFunctionPrototypes 1 + #endif + + #if __STDC__ + # define NeedFunctionPrototypes 1 + #endif + + #ifdef _NO_PROTO + # undef NeedFunctionPrototypes + #endif + + #undef GSM_P /* gnu stdio.h actually defines this... */ + + #if NeedFunctionPrototypes + # define GSM_P( protos ) protos + #else + # define GSM_P( protos ) ( /* protos */ ) + #endif + + #ifdef NeedFunctionPrototypes + # include <stdio.h> /* for FILE * */ + #endif + + /* + * Interface + */ + + typedef struct gsm_state * gsm; + typedef short gsm_signal; /* signed 16 bit */ + typedef unsigned char gsm_byte; + typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */ + + #define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */ + + #define GSM_PATCHLEVEL 6 + #define GSM_MINOR 0 + #define GSM_MAJOR 1 + + #define GSM_OPT_VERBOSE 1 + #define GSM_OPT_FAST 2 + + extern gsm gsm_create GSM_P((void)); + extern void gsm_destroy GSM_P((gsm)); + + extern int gsm_print GSM_P((FILE *, gsm, gsm_byte *)); + extern int gsm_option GSM_P((gsm, int, int *)); + + extern void gsm_encode GSM_P((gsm, gsm_signal *, gsm_byte *)); + extern int gsm_decode GSM_P((gsm, gsm_byte *, gsm_signal *)); + + extern int gsm_explode GSM_P((gsm, gsm_byte *, gsm_signal *)); + extern void gsm_implode GSM_P((gsm, gsm_signal *, gsm_byte *)); + + #undef GSM_P + + #endif /* GSM_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_create.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_create.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_create.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,55 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + static char ident[] = "$Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_create.c,v 1.1 2007/01/09 23:44:35 lattner Exp $"; + + #include "config.h" + + #ifdef HAS_STRING_H + #include <string.h> + #else + # include "proto.h" + extern char * memset P((char *, int, int)); + #endif + + #ifdef HAS_STDLIB_H + # include <stdlib.h> + #else + # ifdef HAS_MALLOC_H + # include <malloc.h> + # else + extern char * malloc(); + # endif + #endif + + #include <stdio.h> + + #include "gsm.h" + #include "private.h" + #include "proto.h" + + gsm gsm_create P0() + { + gsm r; + + #ifdef USE_TABLE_MUL + + static int mul_init = 0; + if (!mul_init) { + mul_init = 1; + init_umul_table(); + } + + #endif + + r = (gsm)malloc(sizeof(struct gsm_state)); + if (!r) return r; + + memset((char *)r, 0, sizeof(*r)); + r->nrp = 40; + + return r; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_decode.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_decode.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_decode.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,125 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_decode.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + int gsm_decode P3((s, c, target), gsm s, gsm_byte * c, gsm_signal * target) + { + word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4]; + + /* GSM_MAGIC = (*c >> 4) & 0xF; */ + + if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1; + + LARc[0] = (*c++ & 0xF) << 2; /* 1 */ + LARc[0] |= (*c >> 6) & 0x3; + LARc[1] = *c++ & 0x3F; + LARc[2] = (*c >> 3) & 0x1F; + LARc[3] = (*c++ & 0x7) << 2; + LARc[3] |= (*c >> 6) & 0x3; + LARc[4] = (*c >> 2) & 0xF; + LARc[5] = (*c++ & 0x3) << 2; + LARc[5] |= (*c >> 6) & 0x3; + LARc[6] = (*c >> 3) & 0x7; + LARc[7] = *c++ & 0x7; + Nc[0] = (*c >> 1) & 0x7F; + bc[0] = (*c++ & 0x1) << 1; + bc[0] |= (*c >> 7) & 0x1; + Mc[0] = (*c >> 5) & 0x3; + xmaxc[0] = (*c++ & 0x1F) << 1; + xmaxc[0] |= (*c >> 7) & 0x1; + xmc[0] = (*c >> 4) & 0x7; + xmc[1] = (*c >> 1) & 0x7; + xmc[2] = (*c++ & 0x1) << 2; + xmc[2] |= (*c >> 6) & 0x3; + xmc[3] = (*c >> 3) & 0x7; + xmc[4] = *c++ & 0x7; + xmc[5] = (*c >> 5) & 0x7; + xmc[6] = (*c >> 2) & 0x7; + xmc[7] = (*c++ & 0x3) << 1; /* 10 */ + xmc[7] |= (*c >> 7) & 0x1; + xmc[8] = (*c >> 4) & 0x7; + xmc[9] = (*c >> 1) & 0x7; + xmc[10] = (*c++ & 0x1) << 2; + xmc[10] |= (*c >> 6) & 0x3; + xmc[11] = (*c >> 3) & 0x7; + xmc[12] = *c++ & 0x7; + Nc[1] = (*c >> 1) & 0x7F; + bc[1] = (*c++ & 0x1) << 1; + bc[1] |= (*c >> 7) & 0x1; + Mc[1] = (*c >> 5) & 0x3; + xmaxc[1] = (*c++ & 0x1F) << 1; + xmaxc[1] |= (*c >> 7) & 0x1; + xmc[13] = (*c >> 4) & 0x7; + xmc[14] = (*c >> 1) & 0x7; + xmc[15] = (*c++ & 0x1) << 2; + xmc[15] |= (*c >> 6) & 0x3; + xmc[16] = (*c >> 3) & 0x7; + xmc[17] = *c++ & 0x7; + xmc[18] = (*c >> 5) & 0x7; + xmc[19] = (*c >> 2) & 0x7; + xmc[20] = (*c++ & 0x3) << 1; + xmc[20] |= (*c >> 7) & 0x1; + xmc[21] = (*c >> 4) & 0x7; + xmc[22] = (*c >> 1) & 0x7; + xmc[23] = (*c++ & 0x1) << 2; + xmc[23] |= (*c >> 6) & 0x3; + xmc[24] = (*c >> 3) & 0x7; + xmc[25] = *c++ & 0x7; + Nc[2] = (*c >> 1) & 0x7F; + bc[2] = (*c++ & 0x1) << 1; /* 20 */ + bc[2] |= (*c >> 7) & 0x1; + Mc[2] = (*c >> 5) & 0x3; + xmaxc[2] = (*c++ & 0x1F) << 1; + xmaxc[2] |= (*c >> 7) & 0x1; + xmc[26] = (*c >> 4) & 0x7; + xmc[27] = (*c >> 1) & 0x7; + xmc[28] = (*c++ & 0x1) << 2; + xmc[28] |= (*c >> 6) & 0x3; + xmc[29] = (*c >> 3) & 0x7; + xmc[30] = *c++ & 0x7; + xmc[31] = (*c >> 5) & 0x7; + xmc[32] = (*c >> 2) & 0x7; + xmc[33] = (*c++ & 0x3) << 1; + xmc[33] |= (*c >> 7) & 0x1; + xmc[34] = (*c >> 4) & 0x7; + xmc[35] = (*c >> 1) & 0x7; + xmc[36] = (*c++ & 0x1) << 2; + xmc[36] |= (*c >> 6) & 0x3; + xmc[37] = (*c >> 3) & 0x7; + xmc[38] = *c++ & 0x7; + Nc[3] = (*c >> 1) & 0x7F; + bc[3] = (*c++ & 0x1) << 1; + bc[3] |= (*c >> 7) & 0x1; + Mc[3] = (*c >> 5) & 0x3; + xmaxc[3] = (*c++ & 0x1F) << 1; + xmaxc[3] |= (*c >> 7) & 0x1; + xmc[39] = (*c >> 4) & 0x7; + xmc[40] = (*c >> 1) & 0x7; + xmc[41] = (*c++ & 0x1) << 2; + xmc[41] |= (*c >> 6) & 0x3; + xmc[42] = (*c >> 3) & 0x7; + xmc[43] = *c++ & 0x7; /* 30 */ + xmc[44] = (*c >> 5) & 0x7; + xmc[45] = (*c >> 2) & 0x7; + xmc[46] = (*c++ & 0x3) << 1; + xmc[46] |= (*c >> 7) & 0x1; + xmc[47] = (*c >> 4) & 0x7; + xmc[48] = (*c >> 1) & 0x7; + xmc[49] = (*c++ & 0x1) << 2; + xmc[49] |= (*c >> 6) & 0x3; + xmc[50] = (*c >> 3) & 0x7; + xmc[51] = *c & 0x7; /* 33 */ + + Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target); + + return 0; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_destroy.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_destroy.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_destroy.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,26 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_destroy.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "gsm.h" + #include "config.h" + #include "proto.h" + + #ifdef HAS_STDLIB_H + # include <stdlib.h> + #else + # ifdef HAS_MALLOC_H + # include <malloc.h> + # else + extern void free(); + # endif + #endif + + void gsm_destroy P1((S), gsm S) + { + if (S) free((char *)S); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_encode.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_encode.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_encode.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,207 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_encode.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "private.h" + #include "gsm.h" + #include "proto.h" + + void gsm_encode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c) + { + word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4]; + + Gsm_Coder(s, source, LARc, Nc, bc, Mc, xmaxc, xmc); + + + /* variable size + + GSM_MAGIC 4 + + LARc[0] 6 + LARc[1] 6 + LARc[2] 5 + LARc[3] 5 + LARc[4] 4 + LARc[5] 4 + LARc[6] 3 + LARc[7] 3 + + Nc[0] 7 + bc[0] 2 + Mc[0] 2 + xmaxc[0] 6 + xmc[0] 3 + xmc[1] 3 + xmc[2] 3 + xmc[3] 3 + xmc[4] 3 + xmc[5] 3 + xmc[6] 3 + xmc[7] 3 + xmc[8] 3 + xmc[9] 3 + xmc[10] 3 + xmc[11] 3 + xmc[12] 3 + + Nc[1] 7 + bc[1] 2 + Mc[1] 2 + xmaxc[1] 6 + xmc[13] 3 + xmc[14] 3 + xmc[15] 3 + xmc[16] 3 + xmc[17] 3 + xmc[18] 3 + xmc[19] 3 + xmc[20] 3 + xmc[21] 3 + xmc[22] 3 + xmc[23] 3 + xmc[24] 3 + xmc[25] 3 + + Nc[2] 7 + bc[2] 2 + Mc[2] 2 + xmaxc[2] 6 + xmc[26] 3 + xmc[27] 3 + xmc[28] 3 + xmc[29] 3 + xmc[30] 3 + xmc[31] 3 + xmc[32] 3 + xmc[33] 3 + xmc[34] 3 + xmc[35] 3 + xmc[36] 3 + xmc[37] 3 + xmc[38] 3 + + Nc[3] 7 + bc[3] 2 + Mc[3] 2 + xmaxc[3] 6 + xmc[39] 3 + xmc[40] 3 + xmc[41] 3 + xmc[42] 3 + xmc[43] 3 + xmc[44] 3 + xmc[45] 3 + xmc[46] 3 + xmc[47] 3 + xmc[48] 3 + xmc[49] 3 + xmc[50] 3 + xmc[51] 3 + */ + + + *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */ + | ((LARc[0] >> 2) & 0xF); + *c++ = ((LARc[0] & 0x3) << 6) + | (LARc[1] & 0x3F); + *c++ = ((LARc[2] & 0x1F) << 3) + | ((LARc[3] >> 2) & 0x7); + *c++ = ((LARc[3] & 0x3) << 6) + | ((LARc[4] & 0xF) << 2) + | ((LARc[5] >> 2) & 0x3); + *c++ = ((LARc[5] & 0x3) << 6) + | ((LARc[6] & 0x7) << 3) + | (LARc[7] & 0x7); + *c++ = ((Nc[0] & 0x7F) << 1) + | ((bc[0] >> 1) & 0x1); + *c++ = ((bc[0] & 0x1) << 7) + | ((Mc[0] & 0x3) << 5) + | ((xmaxc[0] >> 1) & 0x1F); + *c++ = ((xmaxc[0] & 0x1) << 7) + | ((xmc[0] & 0x7) << 4) + | ((xmc[1] & 0x7) << 1) + | ((xmc[2] >> 2) & 0x1); + *c++ = ((xmc[2] & 0x3) << 6) + | ((xmc[3] & 0x7) << 3) + | (xmc[4] & 0x7); + *c++ = ((xmc[5] & 0x7) << 5) /* 10 */ + | ((xmc[6] & 0x7) << 2) + | ((xmc[7] >> 1) & 0x3); + *c++ = ((xmc[7] & 0x1) << 7) + | ((xmc[8] & 0x7) << 4) + | ((xmc[9] & 0x7) << 1) + | ((xmc[10] >> 2) & 0x1); + *c++ = ((xmc[10] & 0x3) << 6) + | ((xmc[11] & 0x7) << 3) + | (xmc[12] & 0x7); + *c++ = ((Nc[1] & 0x7F) << 1) + | ((bc[1] >> 1) & 0x1); + *c++ = ((bc[1] & 0x1) << 7) + | ((Mc[1] & 0x3) << 5) + | ((xmaxc[1] >> 1) & 0x1F); + *c++ = ((xmaxc[1] & 0x1) << 7) + | ((xmc[13] & 0x7) << 4) + | ((xmc[14] & 0x7) << 1) + | ((xmc[15] >> 2) & 0x1); + *c++ = ((xmc[15] & 0x3) << 6) + | ((xmc[16] & 0x7) << 3) + | (xmc[17] & 0x7); + *c++ = ((xmc[18] & 0x7) << 5) + | ((xmc[19] & 0x7) << 2) + | ((xmc[20] >> 1) & 0x3); + *c++ = ((xmc[20] & 0x1) << 7) + | ((xmc[21] & 0x7) << 4) + | ((xmc[22] & 0x7) << 1) + | ((xmc[23] >> 2) & 0x1); + *c++ = ((xmc[23] & 0x3) << 6) + | ((xmc[24] & 0x7) << 3) + | (xmc[25] & 0x7); + *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */ + | ((bc[2] >> 1) & 0x1); + *c++ = ((bc[2] & 0x1) << 7) + | ((Mc[2] & 0x3) << 5) + | ((xmaxc[2] >> 1) & 0x1F); + *c++ = ((xmaxc[2] & 0x1) << 7) + | ((xmc[26] & 0x7) << 4) + | ((xmc[27] & 0x7) << 1) + | ((xmc[28] >> 2) & 0x1); + *c++ = ((xmc[28] & 0x3) << 6) + | ((xmc[29] & 0x7) << 3) + | (xmc[30] & 0x7); + *c++ = ((xmc[31] & 0x7) << 5) + | ((xmc[32] & 0x7) << 2) + | ((xmc[33] >> 1) & 0x3); + *c++ = ((xmc[33] & 0x1) << 7) + | ((xmc[34] & 0x7) << 4) + | ((xmc[35] & 0x7) << 1) + | ((xmc[36] >> 2) & 0x1); + *c++ = ((xmc[36] & 0x3) << 6) + | ((xmc[37] & 0x7) << 3) + | (xmc[38] & 0x7); + *c++ = ((Nc[3] & 0x7F) << 1) + | ((bc[3] >> 1) & 0x1); + *c++ = ((bc[3] & 0x1) << 7) + | ((Mc[3] & 0x3) << 5) + | ((xmaxc[3] >> 1) & 0x1F); + *c++ = ((xmaxc[3] & 0x1) << 7) + | ((xmc[39] & 0x7) << 4) + | ((xmc[40] & 0x7) << 1) + | ((xmc[41] >> 2) & 0x1); + *c++ = ((xmc[41] & 0x3) << 6) /* 30 */ + | ((xmc[42] & 0x7) << 3) + | (xmc[43] & 0x7); + *c++ = ((xmc[44] & 0x7) << 5) + | ((xmc[45] & 0x7) << 2) + | ((xmc[46] >> 1) & 0x3); + *c++ = ((xmc[46] & 0x1) << 7) + | ((xmc[47] & 0x7) << 4) + | ((xmc[48] & 0x7) << 1) + | ((xmc[49] >> 2) & 0x1); + *c++ = ((xmc[49] & 0x3) << 6) + | ((xmc[50] & 0x7) << 3) + | (xmc[51] & 0x7); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_explode.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_explode.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_explode.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,197 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_explode.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "private.h" + #include "gsm.h" + #include "proto.h" + + int gsm_explode P3((s, c, target), gsm s, gsm_byte * c, gsm_signal * target) + { + /* GSM_MAGIC = (*c >> 4) & 0xF; */ + + if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1; + + #define LARc target + + LARc[0] = (*c++ & 0xF) << 2; /* 1 */ + LARc[0] |= (*c >> 6) & 0x3; + LARc[1] = *c++ & 0x3F; + LARc[2] = (*c >> 3) & 0x1F; + LARc[3] = (*c++ & 0x7) << 2; + LARc[3] |= (*c >> 6) & 0x3; + LARc[4] = (*c >> 2) & 0xF; + LARc[5] = (*c++ & 0x3) << 2; + LARc[5] |= (*c >> 6) & 0x3; + LARc[6] = (*c >> 3) & 0x7; + LARc[7] = *c++ & 0x7; + + #define Nc (target + 8) + + Nc[0] = (*c >> 1) & 0x7F; + + #define bc (target + 9) + + bc[0] = (*c++ & 0x1) << 1; + bc[0] |= (*c >> 7) & 0x1; + + #define Mc (target + 10) + + Mc[0] = (*c >> 5) & 0x3; + + #define xmaxc (target + 11) + + xmaxc[0] = (*c++ & 0x1F) << 1; + xmaxc[0] |= (*c >> 7) & 0x1; + + #define xmc (target + 12) + + xmc[0] = (*c >> 4) & 0x7; + xmc[1] = (*c >> 1) & 0x7; + xmc[2] = (*c++ & 0x1) << 2; + xmc[2] |= (*c >> 6) & 0x3; + xmc[3] = (*c >> 3) & 0x7; + xmc[4] = *c++ & 0x7; + xmc[5] = (*c >> 5) & 0x7; + xmc[6] = (*c >> 2) & 0x7; + xmc[7] = (*c++ & 0x3) << 1; /* 10 */ + xmc[7] |= (*c >> 7) & 0x1; + xmc[8] = (*c >> 4) & 0x7; + xmc[9] = (*c >> 1) & 0x7; + xmc[10] = (*c++ & 0x1) << 2; + xmc[10] |= (*c >> 6) & 0x3; + xmc[11] = (*c >> 3) & 0x7; + xmc[12] = *c++ & 0x7; + + #undef Nc + #define Nc (target + 25 - 1) + + Nc[1] = (*c >> 1) & 0x7F; + + #undef bc + #define bc (target + 26 - 1) + + bc[1] = (*c++ & 0x1) << 1; + bc[1] |= (*c >> 7) & 0x1; + + #undef Mc + #define Mc (target + 27 - 1) + + Mc[1] = (*c >> 5) & 0x3; + + #undef xmaxc + #define xmaxc (target + 28 - 1) + + xmaxc[1] = (*c++ & 0x1F) << 1; + xmaxc[1] |= (*c >> 7) & 0x1; + + #undef xmc + #define xmc (target + 29 - 13) + + xmc[13] = (*c >> 4) & 0x7; + xmc[14] = (*c >> 1) & 0x7; + xmc[15] = (*c++ & 0x1) << 2; + xmc[15] |= (*c >> 6) & 0x3; + xmc[16] = (*c >> 3) & 0x7; + xmc[17] = *c++ & 0x7; + xmc[18] = (*c >> 5) & 0x7; + xmc[19] = (*c >> 2) & 0x7; + xmc[20] = (*c++ & 0x3) << 1; + xmc[20] |= (*c >> 7) & 0x1; + xmc[21] = (*c >> 4) & 0x7; + xmc[22] = (*c >> 1) & 0x7; + xmc[23] = (*c++ & 0x1) << 2; + xmc[23] |= (*c >> 6) & 0x3; + xmc[24] = (*c >> 3) & 0x7; + xmc[25] = *c++ & 0x7; + + #undef Nc + #define Nc (target + 42 - 2) + + Nc[2] = (*c >> 1) & 0x7F; + + #undef bc + #define bc (target + 43 - 2) + + bc[2] = (*c++ & 0x1) << 1; /* 20 */ + bc[2] |= (*c >> 7) & 0x1; + + #undef Mc + #define Mc (target + 44 - 2) + + Mc[2] = (*c >> 5) & 0x3; + + #undef xmaxc + #define xmaxc (target + 45 - 2) + + xmaxc[2] = (*c++ & 0x1F) << 1; + xmaxc[2] |= (*c >> 7) & 0x1; + + #undef xmc + #define xmc (target + 46 - 26) + + xmc[26] = (*c >> 4) & 0x7; + xmc[27] = (*c >> 1) & 0x7; + xmc[28] = (*c++ & 0x1) << 2; + xmc[28] |= (*c >> 6) & 0x3; + xmc[29] = (*c >> 3) & 0x7; + xmc[30] = *c++ & 0x7; + xmc[31] = (*c >> 5) & 0x7; + xmc[32] = (*c >> 2) & 0x7; + xmc[33] = (*c++ & 0x3) << 1; + xmc[33] |= (*c >> 7) & 0x1; + xmc[34] = (*c >> 4) & 0x7; + xmc[35] = (*c >> 1) & 0x7; + xmc[36] = (*c++ & 0x1) << 2; + xmc[36] |= (*c >> 6) & 0x3; + xmc[37] = (*c >> 3) & 0x7; + xmc[38] = *c++ & 0x7; + + #undef Nc + #define Nc (target + 59 - 3) + + Nc[3] = (*c >> 1) & 0x7F; + + #undef bc + #define bc (target + 60 - 3) + + bc[3] = (*c++ & 0x1) << 1; + bc[3] |= (*c >> 7) & 0x1; + + #undef Mc + #define Mc (target + 61 - 3) + + Mc[3] = (*c >> 5) & 0x3; + + #undef xmaxc + #define xmaxc (target + 62 - 3) + + xmaxc[3] = (*c++ & 0x1F) << 1; + xmaxc[3] |= (*c >> 7) & 0x1; + + #undef xmc + #define xmc (target + 63 - 39) + + xmc[39] = (*c >> 4) & 0x7; + xmc[40] = (*c >> 1) & 0x7; + xmc[41] = (*c++ & 0x1) << 2; + xmc[41] |= (*c >> 6) & 0x3; + xmc[42] = (*c >> 3) & 0x7; + xmc[43] = *c++ & 0x7; /* 30 */ + xmc[44] = (*c >> 5) & 0x7; + xmc[45] = (*c >> 2) & 0x7; + xmc[46] = (*c++ & 0x3) << 1; + xmc[46] |= (*c >> 7) & 0x1; + xmc[47] = (*c >> 4) & 0x7; + xmc[48] = (*c >> 1) & 0x7; + xmc[49] = (*c++ & 0x1) << 2; + xmc[49] |= (*c >> 6) & 0x3; + xmc[50] = (*c >> 3) & 0x7; + xmc[51] = *c & 0x7; /* 33 */ + + return 0; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_implode.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_implode.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_implode.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,280 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_implode.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + void gsm_implode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c) + { + /* variable size index + + GSM_MAGIC 4 - + + LARc[0] 6 0 + LARc[1] 6 1 + LARc[2] 5 2 + LARc[3] 5 3 + LARc[4] 4 4 + LARc[5] 4 5 + LARc[6] 3 6 + LARc[7] 3 7 + + Nc[0] 7 8 + bc[0] 2 9 + Mc[0] 2 10 + xmaxc[0] 6 11 + xmc[0] 3 12 + xmc[1] 3 13 + xmc[2] 3 14 + xmc[3] 3 15 + xmc[4] 3 16 + xmc[5] 3 17 + xmc[6] 3 18 + xmc[7] 3 19 + xmc[8] 3 20 + xmc[9] 3 21 + xmc[10] 3 22 + xmc[11] 3 23 + xmc[12] 3 24 + + Nc[1] 7 25 + bc[1] 2 26 + Mc[1] 2 27 + xmaxc[1] 6 28 + xmc[13] 3 29 + xmc[14] 3 30 + xmc[15] 3 31 + xmc[16] 3 32 + xmc[17] 3 33 + xmc[18] 3 34 + xmc[19] 3 35 + xmc[20] 3 36 + xmc[21] 3 37 + xmc[22] 3 38 + xmc[23] 3 39 + xmc[24] 3 40 + xmc[25] 3 41 + + Nc[2] 7 42 + bc[2] 2 43 + Mc[2] 2 44 + xmaxc[2] 6 45 + xmc[26] 3 46 + xmc[27] 3 47 + xmc[28] 3 48 + xmc[29] 3 49 + xmc[30] 3 50 + xmc[31] 3 51 + xmc[32] 3 52 + xmc[33] 3 53 + xmc[34] 3 54 + xmc[35] 3 55 + xmc[36] 3 56 + xmc[37] 3 57 + xmc[38] 3 58 + + Nc[3] 7 59 + bc[3] 2 60 + Mc[3] 2 61 + xmaxc[3] 6 62 + xmc[39] 3 63 + xmc[40] 3 64 + xmc[41] 3 65 + xmc[42] 3 66 + xmc[43] 3 67 + xmc[44] 3 68 + xmc[45] 3 69 + xmc[46] 3 70 + xmc[47] 3 71 + xmc[48] 3 72 + xmc[49] 3 73 + xmc[50] 3 74 + xmc[51] 3 75 + */ + + + #define LARc source + + *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */ + | ((LARc[0] >> 2) & 0xF); + *c++ = ((LARc[0] & 0x3) << 6) + | (LARc[1] & 0x3F); + *c++ = ((LARc[2] & 0x1F) << 3) + | ((LARc[3] >> 2) & 0x7); + *c++ = ((LARc[3] & 0x3) << 6) + | ((LARc[4] & 0xF) << 2) + | ((LARc[5] >> 2) & 0x3); + *c++ = ((LARc[5] & 0x3) << 6) + | ((LARc[6] & 0x7) << 3) + | (LARc[7] & 0x7); + + #define Nc (source + 8) + + *c++ = ((Nc[0] & 0x7F) << 1) + + #define bc (source + 9) + + | ((bc[0] >> 1) & 0x1); + *c++ = ((bc[0] & 0x1) << 7) + + #define Mc (source + 10) + + | ((Mc[0] & 0x3) << 5) + + #define xmaxc (source + 11) + + | ((xmaxc[0] >> 1) & 0x1F); + *c++ = ((xmaxc[0] & 0x1) << 7) + + #define xmc (source + 12) + + | ((xmc[0] & 0x7) << 4) + | ((xmc[1] & 0x7) << 1) + | ((xmc[2] >> 2) & 0x1); + *c++ = ((xmc[2] & 0x3) << 6) + | ((xmc[3] & 0x7) << 3) + | (xmc[4] & 0x7); + *c++ = ((xmc[5] & 0x7) << 5) /* 10 */ + | ((xmc[6] & 0x7) << 2) + | ((xmc[7] >> 1) & 0x3); + *c++ = ((xmc[7] & 0x1) << 7) + | ((xmc[8] & 0x7) << 4) + | ((xmc[9] & 0x7) << 1) + | ((xmc[10] >> 2) & 0x1); + *c++ = ((xmc[10] & 0x3) << 6) + | ((xmc[11] & 0x7) << 3) + | (xmc[12] & 0x7); + + #undef Nc + #define Nc (source + 25 - 1) + + *c++ = ((Nc[1] & 0x7F) << 1) + + #undef bc + #define bc (source + 26 - 1) + + | ((bc[1] >> 1) & 0x1); + *c++ = ((bc[1] & 0x1) << 7) + + #undef Mc + #define Mc (source + 27 - 1) + + | ((Mc[1] & 0x3) << 5) + + #undef xmaxc + #define xmaxc (source + 28 - 1) + + | ((xmaxc[1] >> 1) & 0x1F); + *c++ = ((xmaxc[1] & 0x1) << 7) + + #undef xmc + #define xmc (source + 29 - 13) + + | ((xmc[13] & 0x7) << 4) + | ((xmc[14] & 0x7) << 1) + | ((xmc[15] >> 2) & 0x1); + *c++ = ((xmc[15] & 0x3) << 6) + | ((xmc[16] & 0x7) << 3) + | (xmc[17] & 0x7); + *c++ = ((xmc[18] & 0x7) << 5) + | ((xmc[19] & 0x7) << 2) + | ((xmc[20] >> 1) & 0x3); + *c++ = ((xmc[20] & 0x1) << 7) + | ((xmc[21] & 0x7) << 4) + | ((xmc[22] & 0x7) << 1) + | ((xmc[23] >> 2) & 0x1); + *c++ = ((xmc[23] & 0x3) << 6) + | ((xmc[24] & 0x7) << 3) + | (xmc[25] & 0x7); + + #undef Nc + #define Nc (source + 42 - 2) + + *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */ + + #undef bc + #define bc (source + 43 - 2) + + | ((bc[2] >> 1) & 0x1); + *c++ = ((bc[2] & 0x1) << 7) + + #undef Mc + #define Mc (source + 44 - 2) + + | ((Mc[2] & 0x3) << 5) + + #undef xmaxc + #define xmaxc (source + 45 - 2) + + | ((xmaxc[2] >> 1) & 0x1F); + *c++ = ((xmaxc[2] & 0x1) << 7) + + #undef xmc + #define xmc (source + 46 - 26) + + | ((xmc[26] & 0x7) << 4) + | ((xmc[27] & 0x7) << 1) + | ((xmc[28] >> 2) & 0x1); + *c++ = ((xmc[28] & 0x3) << 6) + | ((xmc[29] & 0x7) << 3) + | (xmc[30] & 0x7); + *c++ = ((xmc[31] & 0x7) << 5) + | ((xmc[32] & 0x7) << 2) + | ((xmc[33] >> 1) & 0x3); + *c++ = ((xmc[33] & 0x1) << 7) + | ((xmc[34] & 0x7) << 4) + | ((xmc[35] & 0x7) << 1) + | ((xmc[36] >> 2) & 0x1); + *c++ = ((xmc[36] & 0x3) << 6) + | ((xmc[37] & 0x7) << 3) + | (xmc[38] & 0x7); + + #undef Nc + #define Nc (source + 59 - 3) + + *c++ = ((Nc[3] & 0x7F) << 1) + + #undef bc + #define bc (source + 60 - 3) + + | ((bc[3] >> 1) & 0x1); + *c++ = ((bc[3] & 0x1) << 7) + + #undef Mc + #define Mc (source + 61 - 3) + + | ((Mc[3] & 0x3) << 5) + + #undef xmaxc + #define xmaxc (source + 62 - 3) + + | ((xmaxc[3] >> 1) & 0x1F); + *c++ = ((xmaxc[3] & 0x1) << 7) + + #undef xmc + #define xmc (source + 63 - 39) + + | ((xmc[39] & 0x7) << 4) + | ((xmc[40] & 0x7) << 1) + | ((xmc[41] >> 2) & 0x1); + *c++ = ((xmc[41] & 0x3) << 6) /* 30 */ + | ((xmc[42] & 0x7) << 3) + | (xmc[43] & 0x7); + *c++ = ((xmc[44] & 0x7) << 5) + | ((xmc[45] & 0x7) << 2) + | ((xmc[46] >> 1) & 0x3); + *c++ = ((xmc[46] & 0x1) << 7) + | ((xmc[47] & 0x7) << 4) + | ((xmc[48] & 0x7) << 1) + | ((xmc[49] >> 2) & 0x1); + *c++ = ((xmc[49] & 0x3) << 6) + | ((xmc[50] & 0x7) << 3) + | (xmc[51] & 0x7); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_option.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_option.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_option.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,38 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_option.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + int gsm_option P3((r, opt, val), gsm r, int opt, int * val) + { + int result = -1; + + switch (opt) { + case GSM_OPT_VERBOSE: + #ifndef NDEBUG + result = r->verbose; + if (val) r->verbose = *val; + #endif + break; + + case GSM_OPT_FAST: + + #if defined(FAST) && defined(USE_FLOAT_MUL) + result = r->fast; + if (val) r->fast = !!*val; + #endif + break; + + default: + break; + } + return result; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_print.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_print.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_print.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,167 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/gsm_print.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include <stdio.h> + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + int gsm_print P3((f, s, c), FILE * f, gsm s, gsm_byte * c) + { + word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4]; + + /* GSM_MAGIC = (*c >> 4) & 0xF; */ + + if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1; + + LARc[0] = (*c++ & 0xF) << 2; /* 1 */ + LARc[0] |= (*c >> 6) & 0x3; + LARc[1] = *c++ & 0x3F; + LARc[2] = (*c >> 3) & 0x1F; + LARc[3] = (*c++ & 0x7) << 2; + LARc[3] |= (*c >> 6) & 0x3; + LARc[4] = (*c >> 2) & 0xF; + LARc[5] = (*c++ & 0x3) << 2; + LARc[5] |= (*c >> 6) & 0x3; + LARc[6] = (*c >> 3) & 0x7; + LARc[7] = *c++ & 0x7; + + + Nc[0] = (*c >> 1) & 0x7F; + bc[0] = (*c++ & 0x1) << 1; + bc[0] |= (*c >> 7) & 0x1; + Mc[0] = (*c >> 5) & 0x3; + xmaxc[0] = (*c++ & 0x1F) << 1; + xmaxc[0] |= (*c >> 7) & 0x1; + xmc[0] = (*c >> 4) & 0x7; + xmc[1] = (*c >> 1) & 0x7; + xmc[2] = (*c++ & 0x1) << 2; + xmc[2] |= (*c >> 6) & 0x3; + xmc[3] = (*c >> 3) & 0x7; + xmc[4] = *c++ & 0x7; + xmc[5] = (*c >> 5) & 0x7; + xmc[6] = (*c >> 2) & 0x7; + xmc[7] = (*c++ & 0x3) << 1; /* 10 */ + xmc[7] |= (*c >> 7) & 0x1; + xmc[8] = (*c >> 4) & 0x7; + xmc[9] = (*c >> 1) & 0x7; + xmc[10] = (*c++ & 0x1) << 2; + xmc[10] |= (*c >> 6) & 0x3; + xmc[11] = (*c >> 3) & 0x7; + xmc[12] = *c++ & 0x7; + + Nc[1] = (*c >> 1) & 0x7F; + bc[1] = (*c++ & 0x1) << 1; + bc[1] |= (*c >> 7) & 0x1; + Mc[1] = (*c >> 5) & 0x3; + xmaxc[1] = (*c++ & 0x1F) << 1; + xmaxc[1] |= (*c >> 7) & 0x1; + xmc[13] = (*c >> 4) & 0x7; + xmc[14] = (*c >> 1) & 0x7; + xmc[15] = (*c++ & 0x1) << 2; + xmc[15] |= (*c >> 6) & 0x3; + xmc[16] = (*c >> 3) & 0x7; + xmc[17] = *c++ & 0x7; + xmc[18] = (*c >> 5) & 0x7; + xmc[19] = (*c >> 2) & 0x7; + xmc[20] = (*c++ & 0x3) << 1; + xmc[20] |= (*c >> 7) & 0x1; + xmc[21] = (*c >> 4) & 0x7; + xmc[22] = (*c >> 1) & 0x7; + xmc[23] = (*c++ & 0x1) << 2; + xmc[23] |= (*c >> 6) & 0x3; + xmc[24] = (*c >> 3) & 0x7; + xmc[25] = *c++ & 0x7; + + + Nc[2] = (*c >> 1) & 0x7F; + bc[2] = (*c++ & 0x1) << 1; /* 20 */ + bc[2] |= (*c >> 7) & 0x1; + Mc[2] = (*c >> 5) & 0x3; + xmaxc[2] = (*c++ & 0x1F) << 1; + xmaxc[2] |= (*c >> 7) & 0x1; + xmc[26] = (*c >> 4) & 0x7; + xmc[27] = (*c >> 1) & 0x7; + xmc[28] = (*c++ & 0x1) << 2; + xmc[28] |= (*c >> 6) & 0x3; + xmc[29] = (*c >> 3) & 0x7; + xmc[30] = *c++ & 0x7; + xmc[31] = (*c >> 5) & 0x7; + xmc[32] = (*c >> 2) & 0x7; + xmc[33] = (*c++ & 0x3) << 1; + xmc[33] |= (*c >> 7) & 0x1; + xmc[34] = (*c >> 4) & 0x7; + xmc[35] = (*c >> 1) & 0x7; + xmc[36] = (*c++ & 0x1) << 2; + xmc[36] |= (*c >> 6) & 0x3; + xmc[37] = (*c >> 3) & 0x7; + xmc[38] = *c++ & 0x7; + + Nc[3] = (*c >> 1) & 0x7F; + bc[3] = (*c++ & 0x1) << 1; + bc[3] |= (*c >> 7) & 0x1; + Mc[3] = (*c >> 5) & 0x3; + xmaxc[3] = (*c++ & 0x1F) << 1; + xmaxc[3] |= (*c >> 7) & 0x1; + + xmc[39] = (*c >> 4) & 0x7; + xmc[40] = (*c >> 1) & 0x7; + xmc[41] = (*c++ & 0x1) << 2; + xmc[41] |= (*c >> 6) & 0x3; + xmc[42] = (*c >> 3) & 0x7; + xmc[43] = *c++ & 0x7; /* 30 */ + xmc[44] = (*c >> 5) & 0x7; + xmc[45] = (*c >> 2) & 0x7; + xmc[46] = (*c++ & 0x3) << 1; + xmc[46] |= (*c >> 7) & 0x1; + xmc[47] = (*c >> 4) & 0x7; + xmc[48] = (*c >> 1) & 0x7; + xmc[49] = (*c++ & 0x1) << 2; + xmc[49] |= (*c >> 6) & 0x3; + xmc[50] = (*c >> 3) & 0x7; + xmc[51] = *c & 0x7; /* 33 */ + + fprintf(f, + "LARc:\t%2.2d %2.2d %2.2d %2.2d %2.2d %2.2d %2.2d %2.2d\n", + LARc[0],LARc[1],LARc[2],LARc[3],LARc[4],LARc[5],LARc[6],LARc[7]); + + fprintf(f, "#1: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[0], bc[0], Mc[0], xmaxc[0]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[0],xmc[1],xmc[2],xmc[3],xmc[4],xmc[5],xmc[6], + xmc[7],xmc[8],xmc[9],xmc[10],xmc[11],xmc[12] ); + + fprintf(f, "#2: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[1], bc[1], Mc[1], xmaxc[1]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[13+0],xmc[13+1],xmc[13+2],xmc[13+3],xmc[13+4],xmc[13+5], + xmc[13+6], xmc[13+7],xmc[13+8],xmc[13+9],xmc[13+10],xmc[13+11], + xmc[13+12] ); + + fprintf(f, "#3: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[2], bc[2], Mc[2], xmaxc[2]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[26+0],xmc[26+1],xmc[26+2],xmc[26+3],xmc[26+4],xmc[26+5], + xmc[26+6], xmc[26+7],xmc[26+8],xmc[26+9],xmc[26+10],xmc[26+11], + xmc[26+12] ); + + fprintf(f, "#4: Nc %4.4d bc %d Mc %d xmaxc %d\n", + Nc[3], bc[3], Mc[3], xmaxc[3]); + fprintf(f, + "\t%.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d %.2d\n", + xmc[39+0],xmc[39+1],xmc[39+2],xmc[39+3],xmc[39+4],xmc[39+5], + xmc[39+6], xmc[39+7],xmc[39+8],xmc[39+9],xmc[39+10],xmc[39+11], + xmc[39+12] ); + + return 0; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/large.au.run.gsm Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/long_term.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/long_term.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/long_term.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,603 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/long_term.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include <stdio.h> + #include <assert.h> + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + + #ifdef USE_TABLE_MUL + + unsigned int umul_table[ 513 ][ 256 ]; + + init_umul_table() + { + int i, j; + int n; + unsigned int * p = &umul_table[0][0]; + + for (i = 0; i < 513; i++) { + n = 0; + for (j = 0; j < 256; j++) { + *p++ = n; + n += i; + } + } + } + + # define umul(x9, x15) \ + ((int)(umul_table[x9][x15 & 0x0FF] + (umul_table[x9][ x15 >> 8 ] << 8))) + + # define table_mul(a, b) \ + ( (a < 0) ? ((b < 0) ? umul(-a, -b) : -umul(-a, b)) \ + : ((b < 0) ? -umul(a, -b) : umul(a, b))) + + #endif /* USE_TABLE_MUL */ + + + + /* + * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION + */ + + + /* + * This procedure computes the LTP gain (bc) and the LTP lag (Nc) + * for the long term analysis filter. This is done by calculating a + * maximum of the cross-correlation function between the current + * sub-segment short term residual signal d[0..39] (output of + * the short term analysis filter; for simplification the index + * of this array begins at 0 and ends at 39 for each sub-segment of the + * RPE-LTP analysis) and the previous reconstructed short term + * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be + * performed to avoid overflow. + */ + + /* This procedure exists in four versions. First, the two integer + * versions with or without table-multiplication (as one function); + * then, the two floating point versions (as another function), with + * or without scaling. + */ + + #ifndef USE_FLOAT_MUL + + static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out), + register word * d, /* [0..39] IN */ + register word * dp, /* [-120..-1] IN */ + word * bc_out, /* OUT */ + word * Nc_out /* OUT */ + ) + { + register int k, lambda; + word Nc, bc; + word wt[40]; + + longword L_max, L_power; + word R, S, dmax, scal; + register word temp; + + /* Search of the optimum scaling of d[0..39]. + */ + dmax = 0; + + for (k = 0; k <= 39; k++) { + temp = d[k]; + temp = GSM_ABS( temp ); + if (temp > dmax) dmax = temp; + } + + temp = 0; + if (dmax == 0) scal = 0; + else { + assert(dmax > 0); + temp = gsm_norm( (longword)dmax << 16 ); + } + + if (temp > 6) scal = 0; + else scal = 6 - temp; + + assert(scal >= 0); + + /* Initialization of a working array wt + */ + + for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal ); + + /* Search for the maximum cross-correlation and coding of the LTP lag + */ + L_max = 0; + Nc = 40; /* index for the maximum cross-correlation */ + + for (lambda = 40; lambda <= 120; lambda++) { + + # undef STEP + # ifdef USE_TABLE_MUL + # define STEP(k) (table_mul(wt[k], dp[k - lambda])) + # else + # define STEP(k) (wt[k] * dp[k - lambda]) + # endif + + register longword L_result; + + L_result = STEP(0) ; L_result += STEP(1) ; + L_result += STEP(2) ; L_result += STEP(3) ; + L_result += STEP(4) ; L_result += STEP(5) ; + L_result += STEP(6) ; L_result += STEP(7) ; + L_result += STEP(8) ; L_result += STEP(9) ; + L_result += STEP(10) ; L_result += STEP(11) ; + L_result += STEP(12) ; L_result += STEP(13) ; + L_result += STEP(14) ; L_result += STEP(15) ; + L_result += STEP(16) ; L_result += STEP(17) ; + L_result += STEP(18) ; L_result += STEP(19) ; + L_result += STEP(20) ; L_result += STEP(21) ; + L_result += STEP(22) ; L_result += STEP(23) ; + L_result += STEP(24) ; L_result += STEP(25) ; + L_result += STEP(26) ; L_result += STEP(27) ; + L_result += STEP(28) ; L_result += STEP(29) ; + L_result += STEP(30) ; L_result += STEP(31) ; + L_result += STEP(32) ; L_result += STEP(33) ; + L_result += STEP(34) ; L_result += STEP(35) ; + L_result += STEP(36) ; L_result += STEP(37) ; + L_result += STEP(38) ; L_result += STEP(39) ; + + if (L_result > L_max) { + + Nc = lambda; + L_max = L_result; + } + } + + *Nc_out = Nc; + + L_max <<= 1; + + /* Rescaling of L_max + */ + assert(scal <= 100 && scal >= -100); + L_max = L_max >> (6 - scal); /* sub(6, scal) */ + + assert( Nc <= 120 && Nc >= 40); + + /* Compute the power of the reconstructed short term residual + * signal dp[..] + */ + L_power = 0; + for (k = 0; k <= 39; k++) { + + register longword L_temp; + + L_temp = SASR( dp[k - Nc], 3 ); + L_power += L_temp * L_temp; + } + L_power <<= 1; /* from L_MULT */ + + /* Normalization of L_max and L_power + */ + + if (L_max <= 0) { + *bc_out = 0; + return; + } + if (L_max >= L_power) { + *bc_out = 3; + return; + } + + temp = gsm_norm( L_power ); + + R = SASR( L_max << temp, 16 ); + S = SASR( L_power << temp, 16 ); + + /* Coding of the LTP gain + */ + + /* Table 4.3a must be used to obtain the level DLB[i] for the + * quantization of the LTP gain b to get the coded version bc. + */ + for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break; + *bc_out = bc; + } + + #else /* USE_FLOAT_MUL */ + + static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out), + register word * d, /* [0..39] IN */ + register word * dp, /* [-120..-1] IN */ + word * bc_out, /* OUT */ + word * Nc_out /* OUT */ + ) + { + register int k, lambda; + word Nc, bc; + + float wt_float[40]; + float dp_float_base[120], * dp_float = dp_float_base + 120; + + longword L_max, L_power; + word R, S, dmax, scal; + register word temp; + + /* Search of the optimum scaling of d[0..39]. + */ + dmax = 0; + + for (k = 0; k <= 39; k++) { + temp = d[k]; + temp = GSM_ABS( temp ); + if (temp > dmax) dmax = temp; + } + + temp = 0; + if (dmax == 0) scal = 0; + else { + assert(dmax > 0); + temp = gsm_norm( (longword)dmax << 16 ); + } + + if (temp > 6) scal = 0; + else scal = 6 - temp; + + assert(scal >= 0); + + /* Initialization of a working array wt + */ + + for (k = 0; k < 40; k++) wt_float[k] = SASR( d[k], scal ); + for (k = -120; k < 0; k++) dp_float[k] = dp[k]; + + /* Search for the maximum cross-correlation and coding of the LTP lag + */ + L_max = 0; + Nc = 40; /* index for the maximum cross-correlation */ + + for (lambda = 40; lambda <= 120; lambda += 9) { + + /* Calculate L_result for l = lambda .. lambda + 9. + */ + register float *lp = dp_float - lambda; + + register float W; + register float a = lp[-8], b = lp[-7], c = lp[-6], + d = lp[-5], e = lp[-4], f = lp[-3], + g = lp[-2], h = lp[-1]; + register float E; + register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0, + S5 = 0, S6 = 0, S7 = 0, S8 = 0; + + # undef STEP + # define STEP(K, a, b, c, d, e, f, g, h) \ + W = wt_float[K]; \ + E = W * a; S8 += E; \ + E = W * b; S7 += E; \ + E = W * c; S6 += E; \ + E = W * d; S5 += E; \ + E = W * e; S4 += E; \ + E = W * f; S3 += E; \ + E = W * g; S2 += E; \ + E = W * h; S1 += E; \ + a = lp[K]; \ + E = W * a; S0 += E + + # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h) + # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a) + # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b) + # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c) + # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d) + # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e) + # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f) + # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g) + + STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3); + STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7); + + STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11); + STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15); + + STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19); + STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23); + + STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27); + STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31); + + STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35); + STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39); + + if (S0 > L_max) { L_max = S0; Nc = lambda; } + if (S1 > L_max) { L_max = S1; Nc = lambda + 1; } + if (S2 > L_max) { L_max = S2; Nc = lambda + 2; } + if (S3 > L_max) { L_max = S3; Nc = lambda + 3; } + if (S4 > L_max) { L_max = S4; Nc = lambda + 4; } + if (S5 > L_max) { L_max = S5; Nc = lambda + 5; } + if (S6 > L_max) { L_max = S6; Nc = lambda + 6; } + if (S7 > L_max) { L_max = S7; Nc = lambda + 7; } + if (S8 > L_max) { L_max = S8; Nc = lambda + 8; } + } + *Nc_out = Nc; + + L_max <<= 1; + + /* Rescaling of L_max + */ + assert(scal <= 100 && scal >= -100); + L_max = L_max >> (6 - scal); /* sub(6, scal) */ + + assert( Nc <= 120 && Nc >= 40); + + /* Compute the power of the reconstructed short term residual + * signal dp[..] + */ + L_power = 0; + for (k = 0; k <= 39; k++) { + + register longword L_temp; + + L_temp = SASR( dp[k - Nc], 3 ); + L_power += L_temp * L_temp; + } + L_power <<= 1; /* from L_MULT */ + + /* Normalization of L_max and L_power + */ + + if (L_max <= 0) { + *bc_out = 0; + return; + } + if (L_max >= L_power) { + *bc_out = 3; + return; + } + + temp = gsm_norm( L_power ); + + R = SASR( L_max << temp, 16 ); + S = SASR( L_power << temp, 16 ); + + /* Coding of the LTP gain + */ + + /* Table 4.3a must be used to obtain the level DLB[i] for the + * quantization of the LTP gain b to get the coded version bc. + */ + for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break; + *bc_out = bc; + } + + #ifdef FAST + + static void Fast_Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out), + register word * d, /* [0..39] IN */ + register word * dp, /* [-120..-1] IN */ + word * bc_out, /* OUT */ + word * Nc_out /* OUT */ + ) + { + register int k, lambda; + word Nc, bc; + + float wt_float[40]; + float dp_float_base[120], * dp_float = dp_float_base + 120; + + register float L_max, L_power; + + for (k = 0; k < 40; ++k) wt_float[k] = (float)d[k]; + for (k = -120; k <= 0; ++k) dp_float[k] = (float)dp[k]; + + /* Search for the maximum cross-correlation and coding of the LTP lag + */ + L_max = 0; + Nc = 40; /* index for the maximum cross-correlation */ + + for (lambda = 40; lambda <= 120; lambda += 9) { + + /* Calculate L_result for l = lambda .. lambda + 9. + */ + register float *lp = dp_float - lambda; + + register float W; + register float a = lp[-8], b = lp[-7], c = lp[-6], + d = lp[-5], e = lp[-4], f = lp[-3], + g = lp[-2], h = lp[-1]; + register float E; + register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0, + S5 = 0, S6 = 0, S7 = 0, S8 = 0; + + # undef STEP + # define STEP(K, a, b, c, d, e, f, g, h) \ + W = wt_float[K]; \ + E = W * a; S8 += E; \ + E = W * b; S7 += E; \ + E = W * c; S6 += E; \ + E = W * d; S5 += E; \ + E = W * e; S4 += E; \ + E = W * f; S3 += E; \ + E = W * g; S2 += E; \ + E = W * h; S1 += E; \ + a = lp[K]; \ + E = W * a; S0 += E + + # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h) + # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a) + # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b) + # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c) + # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d) + # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e) + # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f) + # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g) + + STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3); + STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7); + + STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11); + STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15); + + STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19); + STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23); + + STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27); + STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31); + + STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35); + STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39); + + if (S0 > L_max) { L_max = S0; Nc = lambda; } + if (S1 > L_max) { L_max = S1; Nc = lambda + 1; } + if (S2 > L_max) { L_max = S2; Nc = lambda + 2; } + if (S3 > L_max) { L_max = S3; Nc = lambda + 3; } + if (S4 > L_max) { L_max = S4; Nc = lambda + 4; } + if (S5 > L_max) { L_max = S5; Nc = lambda + 5; } + if (S6 > L_max) { L_max = S6; Nc = lambda + 6; } + if (S7 > L_max) { L_max = S7; Nc = lambda + 7; } + if (S8 > L_max) { L_max = S8; Nc = lambda + 8; } + } + *Nc_out = Nc; + + if (L_max <= 0.) { + *bc_out = 0; + return; + } + + /* Compute the power of the reconstructed short term residual + * signal dp[..] + */ + dp_float -= Nc; + L_power = 0; + for (k = 0; k < 40; ++k) { + register float f = dp_float[k]; + L_power += f * f; + } + + if (L_max >= L_power) { + *bc_out = 3; + return; + } + + /* Coding of the LTP gain + * Table 4.3a must be used to obtain the level DLB[i] for the + * quantization of the LTP gain b to get the coded version bc. + */ + lambda = L_max / L_power * 32768.; + for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break; + *bc_out = bc; + } + + #endif /* FAST */ + #endif /* USE_FLOAT_MUL */ + + + /* 4.2.12 */ + + static void Long_term_analysis_filtering P6((bc,Nc,dp,d,dpp,e), + word bc, /* IN */ + word Nc, /* IN */ + register word * dp, /* previous d [-120..-1] IN */ + register word * d, /* d [0..39] IN */ + register word * dpp, /* estimate [0..39] OUT */ + register word * e /* long term res. signal [0..39] OUT */ + ) + /* + * In this part, we have to decode the bc parameter to compute + * the samples of the estimate dpp[0..39]. The decoding of bc needs the + * use of table 4.3b. The long term residual signal e[0..39] + * is then calculated to be fed to the RPE encoding section. + */ + { + register int k; + register longword ltmp; + + # undef STEP + # define STEP(BP) \ + for (k = 0; k <= 39; k++) { \ + dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \ + e[k] = GSM_SUB( d[k], dpp[k] ); \ + } + + switch (bc) { + case 0: STEP( 3277 ); break; + case 1: STEP( 11469 ); break; + case 2: STEP( 21299 ); break; + case 3: STEP( 32767 ); break; + } + } + + void Gsm_Long_Term_Predictor P7((S,d,dp,e,dpp,Nc,bc), /* 4x for 160 samples */ + + struct gsm_state * S, + + word * d, /* [0..39] residual signal IN */ + word * dp, /* [-120..-1] d' IN */ + + word * e, /* [0..39] OUT */ + word * dpp, /* [0..39] OUT */ + word * Nc, /* correlation lag OUT */ + word * bc /* gain factor OUT */ + ) + { + assert( d ); assert( dp ); assert( e ); + assert( dpp); assert( Nc ); assert( bc ); + + #if defined(FAST) && defined(USE_FLOAT_MUL) + if (S->fast) + Fast_Calculation_of_the_LTP_parameters( d, dp, bc, Nc ); + else + #endif + Calculation_of_the_LTP_parameters( d, dp, bc, Nc ); + + Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e ); + } + + /* 4.3.2 */ + void Gsm_Long_Term_Synthesis_Filtering P5((S,Ncr,bcr,erp,drp), + struct gsm_state * S, + + word Ncr, + word bcr, + register word * erp, /* [0..39] IN */ + register word * drp /* [-120..-1] IN, [0..40] OUT */ + ) + /* + * This procedure uses the bcr and Ncr parameter to realize the + * long term synthesis filtering. The decoding of bcr needs + * table 4.3b. + */ + { + register longword ltmp; /* for ADD */ + register int k; + word brp, drpp, Nr; + + /* Check the limits of Nr. + */ + Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr; + S->nrp = Nr; + assert(Nr >= 40 && Nr <= 120); + + /* Decoding of the LTP gain bcr + */ + brp = gsm_QLB[ bcr ]; + + /* Computation of the reconstructed short term residual + * signal drp[0..39] + */ + assert(brp != MIN_WORD); + + for (k = 0; k <= 39; k++) { + drpp = GSM_MULT_R( brp, drp[ k - Nr ] ); + drp[k] = GSM_ADD( erp[k], drpp ); + } + + /* + * Update of the reconstructed short term residual signal + * drp[ -1..-120 ] + */ + + for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ]; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/lpc.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/lpc.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/lpc.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,341 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/lpc.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include <stdio.h> + #include <assert.h> + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + #undef P + + /* + * 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION + */ + + /* 4.2.4 */ + + + static void Autocorrelation P2((s, L_ACF), + word * s, /* [0..159] IN/OUT */ + longword * L_ACF) /* [0..8] OUT */ + /* + * The goal is to compute the array L_ACF[k]. The signal s[i] must + * be scaled in order to avoid an overflow situation. + */ + { + register int k, i; + + word temp, smax, scalauto; + + #ifdef USE_FLOAT_MUL + float float_s[160]; + #endif + + /* Dynamic scaling of the array s[0..159] + */ + + /* Search for the maximum. + */ + smax = 0; + for (k = 0; k <= 159; k++) { + temp = GSM_ABS( s[k] ); + if (temp > smax) smax = temp; + } + + /* Computation of the scaling factor. + */ + if (smax == 0) scalauto = 0; + else { + assert(smax > 0); + scalauto = 4 - gsm_norm( (longword)smax << 16 );/* sub(4,..) */ + } + + /* Scaling of the array s[0...159] + */ + + if (scalauto > 0) { + + # ifdef USE_FLOAT_MUL + # define SCALE(n) \ + case n: for (k = 0; k <= 159; k++) \ + float_s[k] = (float) \ + (s[k] = GSM_MULT_R(s[k], 16384 >> (n-1)));\ + break; + # else + # define SCALE(n) \ + case n: for (k = 0; k <= 159; k++) \ + s[k] = GSM_MULT_R( s[k], 16384 >> (n-1) );\ + break; + # endif /* USE_FLOAT_MUL */ + + switch (scalauto) { + SCALE(1) + SCALE(2) + SCALE(3) + SCALE(4) + } + # undef SCALE + } + # ifdef USE_FLOAT_MUL + else for (k = 0; k <= 159; k++) float_s[k] = (float) s[k]; + # endif + + /* Compute the L_ACF[..]. + */ + { + # ifdef USE_FLOAT_MUL + register float * sp = float_s; + register float sl = *sp; + + # define STEP(k) L_ACF[k] += (longword)(sl * sp[ -(k) ]); + # else + word * sp = s; + word sl = *sp; + + # define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]); + # endif + + # define NEXTI sl = *++sp + + + for (k = 9; k--; L_ACF[k] = 0) ; + + STEP (0); + NEXTI; + STEP(0); STEP(1); + NEXTI; + STEP(0); STEP(1); STEP(2); + NEXTI; + STEP(0); STEP(1); STEP(2); STEP(3); + NEXTI; + STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); + NEXTI; + STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); + NEXTI; + STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6); + NEXTI; + STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6); STEP(7); + + for (i = 8; i <= 159; i++) { + + NEXTI; + + STEP(0); + STEP(1); STEP(2); STEP(3); STEP(4); + STEP(5); STEP(6); STEP(7); STEP(8); + } + + for (k = 9; k--; L_ACF[k] <<= 1) ; + + } + /* Rescaling of the array s[0..159] + */ + if (scalauto > 0) { + assert(scalauto <= 4); + for (k = 160; k--; *s++ <<= scalauto) ; + } + } + + #if defined(USE_FLOAT_MUL) && defined(FAST) + + static void Fast_Autocorrelation P2((s, L_ACF), + word * s, /* [0..159] IN/OUT */ + longword * L_ACF) /* [0..8] OUT */ + { + register int k, i; + float f_L_ACF[9]; + float scale; + + float s_f[160]; + register float *sf = s_f; + + for (i = 0; i < 160; ++i) sf[i] = s[i]; + for (k = 0; k <= 8; k++) { + register float L_temp2 = 0; + register float *sfl = sf - k; + for (i = k; i < 160; ++i) L_temp2 += sf[i] * sfl[i]; + f_L_ACF[k] = L_temp2; + } + scale = MAX_LONGWORD / f_L_ACF[0]; + + for (k = 0; k <= 8; k++) { + L_ACF[k] = f_L_ACF[k] * scale; + } + } + #endif /* defined (USE_FLOAT_MUL) && defined (FAST) */ + + /* 4.2.5 */ + + static void Reflection_coefficients P2( (L_ACF, r), + longword * L_ACF, /* 0...8 IN */ + register word * r /* 0...7 OUT */ + ) + { + register int i, m, n; + register word temp; + register longword ltmp; + word ACF[9]; /* 0..8 */ + word P[ 9]; /* 0..8 */ + word K[ 9]; /* 2..8 */ + + /* Schur recursion with 16 bits arithmetic. + */ + + if (L_ACF[0] == 0) { + for (i = 8; i--; *r++ = 0) ; + return; + } + + assert( L_ACF[0] != 0 ); + temp = gsm_norm( L_ACF[0] ); + + assert(temp >= 0 && temp < 32); + + /* ? overflow ? */ + for (i = 0; i <= 8; i++) ACF[i] = SASR( L_ACF[i] << temp, 16 ); + + /* Initialize array P[..] and K[..] for the recursion. + */ + + for (i = 1; i <= 7; i++) K[ i ] = ACF[ i ]; + for (i = 0; i <= 8; i++) P[ i ] = ACF[ i ]; + + /* Compute reflection coefficients + */ + for (n = 1; n <= 8; n++, r++) { + + temp = P[1]; + temp = GSM_ABS(temp); + if (P[0] < temp) { + for (i = n; i <= 8; i++) *r++ = 0; + return; + } + + *r = gsm_div( temp, P[0] ); + + assert(*r >= 0); + if (P[1] > 0) *r = -*r; /* r[n] = sub(0, r[n]) */ + assert (*r != MIN_WORD); + if (n == 8) return; + + /* Schur recursion + */ + temp = GSM_MULT_R( P[1], *r ); + P[0] = GSM_ADD( P[0], temp ); + + for (m = 1; m <= 8 - n; m++) { + temp = GSM_MULT_R( K[ m ], *r ); + P[m] = GSM_ADD( P[ m+1 ], temp ); + + temp = GSM_MULT_R( P[ m+1 ], *r ); + K[m] = GSM_ADD( K[ m ], temp ); + } + } + } + + /* 4.2.6 */ + + static void Transformation_to_Log_Area_Ratios P1((r), + register word * r /* 0..7 IN/OUT */ + ) + /* + * The following scaling for r[..] and LAR[..] has been used: + * + * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1. + * LAR[..] = integer( real_LAR[..] * 16384 ); + * with -1.625 <= real_LAR <= 1.625 + */ + { + register word temp; + register int i; + + + /* Computation of the LAR[0..7] from the r[0..7] + */ + for (i = 1; i <= 8; i++, r++) { + + temp = *r; + temp = GSM_ABS(temp); + assert(temp >= 0); + + if (temp < 22118) { + temp >>= 1; + } else if (temp < 31130) { + assert( temp >= 11059 ); + temp -= 11059; + } else { + assert( temp >= 26112 ); + temp -= 26112; + temp <<= 2; + } + + *r = *r < 0 ? -temp : temp; + assert( *r != MIN_WORD ); + } + } + + /* 4.2.7 */ + + static void Quantization_and_coding P1((LAR), + register word * LAR /* [0..7] IN/OUT */ + ) + { + register word temp; + longword ltmp; + + + /* This procedure needs four tables; the following equations + * give the optimum scaling for the constants: + * + * A[0..7] = integer( real_A[0..7] * 1024 ) + * B[0..7] = integer( real_B[0..7] * 512 ) + * MAC[0..7] = maximum of the LARc[0..7] + * MIC[0..7] = minimum of the LARc[0..7] + */ + + # undef STEP + # define STEP( A, B, MAC, MIC ) \ + temp = GSM_MULT( A, *LAR ); \ + temp = GSM_ADD( temp, B ); \ + temp = GSM_ADD( temp, 256 ); \ + temp = SASR( temp, 9 ); \ + *LAR = temp>MAC ? MAC - MIC : (temp<MIC ? 0 : temp - MIC); \ + LAR++; + + STEP( 20480, 0, 31, -32 ); + STEP( 20480, 0, 31, -32 ); + STEP( 20480, 2048, 15, -16 ); + STEP( 20480, -2560, 15, -16 ); + + STEP( 13964, 94, 7, -8 ); + STEP( 15360, -1792, 7, -8 ); + STEP( 8534, -341, 3, -4 ); + STEP( 9036, -1144, 3, -4 ); + + # undef STEP + } + + void Gsm_LPC_Analysis P3((S, s,LARc), + struct gsm_state *S, + word * s, /* 0..159 signals IN/OUT */ + word * LARc) /* 0..7 LARc's OUT */ + { + longword L_ACF[9]; + + #if defined(USE_FLOAT_MUL) && defined(FAST) + if (S->fast) Fast_Autocorrelation (s, L_ACF ); + else + #endif + Autocorrelation (s, L_ACF ); + Reflection_coefficients (L_ACF, LARc ); + Transformation_to_Log_Area_Ratios (LARc); + Quantization_and_coding (LARc); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/preprocess.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/preprocess.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/preprocess.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,113 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/preprocess.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include <stdio.h> + #include <assert.h> + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION + * + * After A-law to linear conversion (or directly from the + * Ato D converter) the following scaling is assumed for + * input to the RPE-LTP algorithm: + * + * in: 0.1.....................12 + * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.* + * + * Where S is the sign bit, v a valid bit, and * a "don't care" bit. + * The original signal is called sop[..] + * + * out: 0.1................... 12 + * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0 + */ + + + void Gsm_Preprocess P3((S, s, so), + struct gsm_state * S, + word * s, + word * so ) /* [0..159] IN/OUT */ + { + + word z1 = S->z1; + longword L_z2 = S->L_z2; + word mp = S->mp; + + word s1; + longword L_s2; + + longword L_temp; + + word msp, lsp; + word SO; + + longword ltmp; /* for ADD */ + ulongword utmp; /* for L_ADD */ + + register int k = 160; + + while (k--) { + + /* 4.2.1 Downscaling of the input signal + */ + SO = SASR( *s, 3 ) << 2; + s++; + + assert (SO >= -0x4000); /* downscaled by */ + assert (SO <= 0x3FFC); /* previous routine. */ + + + /* 4.2.2 Offset compensation + * + * This part implements a high-pass filter and requires extended + * arithmetic precision for the recursive part of this filter. + * The input of this procedure is the array so[0...159] and the + * output the array sof[ 0...159 ]. + */ + /* Compute the non-recursive part + */ + + s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */ + z1 = SO; + + assert(s1 != MIN_WORD); + + /* Compute the recursive part + */ + L_s2 = s1; + L_s2 <<= 15; + + /* Execution of a 31 bv 16 bits multiplication + */ + + msp = SASR( L_z2, 15 ); + lsp = L_z2-((longword)msp<<15); /* gsm_L_sub(L_z2,(msp<<15)); */ + + L_s2 += GSM_MULT_R( lsp, 32735 ); + L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/ + L_z2 = GSM_L_ADD( L_temp, L_s2 ); + + /* Compute sof[k] with rounding + */ + L_temp = GSM_L_ADD( L_z2, 16384 ); + + /* 4.2.3 Preemphasis + */ + + msp = GSM_MULT_R( mp, -28180 ); + mp = SASR( L_temp, 15 ); + *so++ = GSM_ADD( mp, msp ); + } + + S->z1 = z1; + S->L_z2 = L_z2; + S->mp = mp; + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/private.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/private.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/private.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,263 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /*$Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/private.h,v 1.1 2007/01/09 23:44:35 lattner Exp $*/ + + #ifndef PRIVATE_H + #define PRIVATE_H + + typedef short word; /* 16 bit signed int */ + typedef long longword; /* 32 bit signed int */ + + typedef unsigned short uword; /* unsigned word */ + typedef unsigned long ulongword; /* unsigned longword */ + + struct gsm_state { + + word dp0[ 280 ]; + + word z1; /* preprocessing.c, Offset_com. */ + longword L_z2; /* Offset_com. */ + int mp; /* Preemphasis */ + + word u[8]; /* short_term_aly_filter.c */ + word LARpp[2][8]; /* */ + word j; /* */ + + word nrp; /* 40 */ /* long_term.c, synthesis */ + word v[9]; /* short_term.c, synthesis */ + word msr; /* decoder.c, Postprocessing */ + + char verbose; /* only used if !NDEBUG */ + char fast; /* only used if FAST */ + + }; + + + #define MIN_WORD ((-32767)-1) + #define MAX_WORD ( 32767) + + #define MIN_LONGWORD ((-2147483647)-1) + #define MAX_LONGWORD ( 2147483647) + + #ifdef SASR /* >> is a signed arithmetic shift right */ + #undef SASR + #define SASR(x, by) ((x) >> (by)) + #endif /* SASR */ + + + #include "proto.h" + + /* + * Prototypes from add.c + */ + extern word gsm_mult P((word a, word b)); + extern longword gsm_L_mult P((word a, word b)); + extern word gsm_mult_r P((word a, word b)); + + extern word gsm_div P((word num, word denum)); + + extern word gsm_add P(( word a, word b )); + extern longword gsm_L_add P(( longword a, longword b )); + + extern word gsm_sub P((word a, word b)); + extern longword gsm_L_sub P((longword a, longword b)); + + extern word gsm_abs P((word a)); + + extern word gsm_norm P(( longword a )); + + extern longword gsm_L_asl P((longword a, int n)); + extern word gsm_asl P((word a, int n)); + + extern longword gsm_L_asr P((longword a, int n)); + extern word gsm_asr P((word a, int n)); + + /* + * Inlined functions from add.h + */ + + /* + * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \ + * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15)) + */ + #define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \ + (SASR( ((longword)(a) * (longword)(b) + 16384), 15 )) + + # define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \ + (SASR( ((longword)(a) * (longword)(b)), 15 )) + + # define GSM_L_MULT(a, b) /* word a, word b */ \ + (((longword)(a) * (longword)(b)) << 1) + + # define GSM_L_ADD(a, b) \ + ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \ + : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \ + >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \ + : ((b) <= 0 ? (a) + (b) \ + : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \ + ? MAX_LONGWORD : utmp)) + + /* + * # define GSM_ADD(a, b) \ + * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \ + * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) + */ + /* Nonportable, but faster: */ + + #define GSM_ADD(a, b) \ + ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \ + MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp) + + # define GSM_SUB(a, b) \ + ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \ + ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) + + # define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a)) + + /* Use these if necessary: + + # define GSM_MULT_R(a, b) gsm_mult_r(a, b) + # define GSM_MULT(a, b) gsm_mult(a, b) + # define GSM_L_MULT(a, b) gsm_L_mult(a, b) + + # define GSM_L_ADD(a, b) gsm_L_add(a, b) + # define GSM_ADD(a, b) gsm_add(a, b) + # define GSM_SUB(a, b) gsm_sub(a, b) + + # define GSM_ABS(a) gsm_abs(a) + + */ + + /* + * More prototypes from implementations.. + */ + extern void Gsm_Coder P(( + struct gsm_state * S, + word * s, /* [0..159] samples IN */ + word * LARc, /* [0..7] LAR coefficients OUT */ + word * Nc, /* [0..3] LTP lag OUT */ + word * bc, /* [0..3] coded LTP gain OUT */ + word * Mc, /* [0..3] RPE grid selection OUT */ + word * xmaxc,/* [0..3] Coded maximum amplitude OUT */ + word * xMc /* [13*4] normalized RPE samples OUT */)); + + extern void Gsm_Long_Term_Predictor P(( /* 4x for 160 samples */ + struct gsm_state * S, + word * d, /* [0..39] residual signal IN */ + word * dp, /* [-120..-1] d' IN */ + word * e, /* [0..40] OUT */ + word * dpp, /* [0..40] OUT */ + word * Nc, /* correlation lag OUT */ + word * bc /* gain factor OUT */)); + + extern void Gsm_LPC_Analysis P(( + struct gsm_state * S, + word * s, /* 0..159 signals IN/OUT */ + word * LARc)); /* 0..7 LARc's OUT */ + + extern void Gsm_Preprocess P(( + struct gsm_state * S, + word * s, word * so)); + + extern void Gsm_Encoding P(( + struct gsm_state * S, + word * e, + word * ep, + word * xmaxc, + word * Mc, + word * xMc)); + + extern void Gsm_Short_Term_Analysis_Filter P(( + struct gsm_state * S, + word * LARc, /* coded log area ratio [0..7] IN */ + word * d /* st res. signal [0..159] IN/OUT */)); + + extern void Gsm_Decoder P(( + struct gsm_state * S, + word * LARcr, /* [0..7] IN */ + word * Ncr, /* [0..3] IN */ + word * bcr, /* [0..3] IN */ + word * Mcr, /* [0..3] IN */ + word * xmaxcr, /* [0..3] IN */ + word * xMcr, /* [0..13*4] IN */ + word * s)); /* [0..159] OUT */ + + extern void Gsm_Decoding P(( + struct gsm_state * S, + word xmaxcr, + word Mcr, + word * xMcr, /* [0..12] IN */ + word * erp)); /* [0..39] OUT */ + + extern void Gsm_Long_Term_Synthesis_Filtering P(( + struct gsm_state* S, + word Ncr, + word bcr, + word * erp, /* [0..39] IN */ + word * drp)); /* [-120..-1] IN, [0..40] OUT */ + + void Gsm_RPE_Decoding P(( + struct gsm_state *S, + word xmaxcr, + word Mcr, + word * xMcr, /* [0..12], 3 bits IN */ + word * erp)); /* [0..39] OUT */ + + void Gsm_RPE_Encoding P(( + struct gsm_state * S, + word * e, /* -5..-1][0..39][40..44 IN/OUT */ + word * xmaxc, /* OUT */ + word * Mc, /* OUT */ + word * xMc)); /* [0..12] OUT */ + + extern void Gsm_Short_Term_Synthesis_Filter P(( + struct gsm_state * S, + word * LARcr, /* log area ratios [0..7] IN */ + word * drp, /* received d [0...39] IN */ + word * s)); /* signal s [0..159] OUT */ + + extern void Gsm_Update_of_reconstructed_short_time_residual_signal P(( + word * dpp, /* [0...39] IN */ + word * ep, /* [0...39] IN */ + word * dp)); /* [-120...-1] IN/OUT */ + + /* + * Tables from table.c + */ + #ifndef GSM_TABLE_C + + extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8]; + extern word gsm_INVA[8]; + extern word gsm_DLB[4], gsm_QLB[4]; + extern word gsm_H[11]; + extern word gsm_NRFAC[8]; + extern word gsm_FAC[8]; + + #endif /* GSM_TABLE_C */ + + /* + * Debugging + */ + #ifdef NDEBUG + + # define gsm_debug_words(a, b, c, d) /* nil */ + # define gsm_debug_longwords(a, b, c, d) /* nil */ + # define gsm_debug_word(a, b) /* nil */ + # define gsm_debug_longword(a, b) /* nil */ + + #else /* !NDEBUG => DEBUG */ + + extern void gsm_debug_words P((char * name, int, int, word *)); + extern void gsm_debug_longwords P((char * name, int, int, longword *)); + extern void gsm_debug_longword P((char * name, longword)); + extern void gsm_debug_word P((char * name, word)); + + #endif /* !NDEBUG */ + + #include "unproto.h" + + #endif /* PRIVATE_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/proto.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/proto.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/proto.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,65 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /*$Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/proto.h,v 1.1 2007/01/09 23:44:35 lattner Exp $*/ + + #ifndef PROTO_H + #define PROTO_H + + #if __cplusplus + # define NeedFunctionPrototypes 1 + #endif + + #if __STDC__ + # define NeedFunctionPrototypes 1 + #endif + + #ifdef _NO_PROTO + # undef NeedFunctionPrototypes + #endif + + #undef P /* gnu stdio.h actually defines this... */ + #undef P0 + #undef P1 + #undef P2 + #undef P3 + #undef P4 + #undef P5 + #undef P6 + #undef P7 + #undef P8 + + #if NeedFunctionPrototypes + + # define P( protos ) protos + + # define P0() (void) + # define P1(x, a) (a) + # define P2(x, a, b) (a, b) + # define P3(x, a, b, c) (a, b, c) + # define P4(x, a, b, c, d) (a, b, c, d) + # define P5(x, a, b, c, d, e) (a, b, c, d, e) + # define P6(x, a, b, c, d, e, f) (a, b, c, d, e, f) + # define P7(x, a, b, c, d, e, f, g) (a, b, c, d, e, f, g) + # define P8(x, a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h) + + #else /* !NeedFunctionPrototypes */ + + # define P( protos ) ( /* protos */ ) + + # define P0() () + # define P1(x, a) x a; + # define P2(x, a, b) x a; b; + # define P3(x, a, b, c) x a; b; c; + # define P4(x, a, b, c, d) x a; b; c; d; + # define P5(x, a, b, c, d, e) x a; b; c; d; e; + # define P6(x, a, b, c, d, e, f) x a; b; c; d; e; f; + # define P7(x, a, b, c, d, e, f, g) x a; b; c; d; e; f; g; + # define P8(x, a, b, c, d, e, f, g, h) x a; b; c; d; e; f; g; h; + + #endif /* !NeedFunctionPrototypes */ + + #endif /* PROTO_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/rpe.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/rpe.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/rpe.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,488 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/rpe.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include <stdio.h> + #include <assert.h> + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + /* 4.2.13 .. 4.2.17 RPE ENCODING SECTION + */ + + /* 4.2.13 */ + + static void Weighting_filter P2((e, x), + register word * e, /* signal [-5..0.39.44] IN */ + word * x /* signal [0..39] OUT */ + ) + /* + * The coefficients of the weighting filter are stored in a table + * (see table 4.4). The following scaling is used: + * + * H[0..10] = integer( real_H[ 0..10] * 8192 ); + */ + { + /* word wt[ 50 ]; */ + + register longword L_result; + register int k /* , i */ ; + + /* Initialization of a temporary working array wt[0...49] + */ + + /* for (k = 0; k <= 4; k++) wt[k] = 0; + * for (k = 5; k <= 44; k++) wt[k] = *e++; + * for (k = 45; k <= 49; k++) wt[k] = 0; + * + * (e[-5..-1] and e[40..44] are allocated by the caller, + * are initially zero and are not written anywhere.) + */ + e -= 5; + + /* Compute the signal x[0..39] + */ + for (k = 0; k <= 39; k++) { + + L_result = 8192 >> 1; + + /* for (i = 0; i <= 10; i++) { + * L_temp = GSM_L_MULT( wt[k+i], gsm_H[i] ); + * L_result = GSM_L_ADD( L_result, L_temp ); + * } + */ + + #undef STEP + #define STEP( i, H ) (e[ k + i ] * (longword)H) + + /* Every one of these multiplications is done twice -- + * but I don't see an elegant way to optimize this. + * Do you? + */ + + #ifdef STUPID_COMPILER + L_result += STEP( 0, -134 ) ; + L_result += STEP( 1, -374 ) ; + /* + STEP( 2, 0 ) */ + L_result += STEP( 3, 2054 ) ; + L_result += STEP( 4, 5741 ) ; + L_result += STEP( 5, 8192 ) ; + L_result += STEP( 6, 5741 ) ; + L_result += STEP( 7, 2054 ) ; + /* + STEP( 8, 0 ) */ + L_result += STEP( 9, -374 ) ; + L_result += STEP( 10, -134 ) ; + #else + L_result += + STEP( 0, -134 ) + + STEP( 1, -374 ) + /* + STEP( 2, 0 ) */ + + STEP( 3, 2054 ) + + STEP( 4, 5741 ) + + STEP( 5, 8192 ) + + STEP( 6, 5741 ) + + STEP( 7, 2054 ) + /* + STEP( 8, 0 ) */ + + STEP( 9, -374 ) + + STEP(10, -134 ) + ; + #endif + + /* L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x2) *) + * L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x4) *) + * + * x[k] = SASR( L_result, 16 ); + */ + + /* 2 adds vs. >>16 => 14, minus one shift to compensate for + * those we lost when replacing L_MULT by '*'. + */ + + L_result = SASR( L_result, 13 ); + x[k] = ( L_result < MIN_WORD ? MIN_WORD + : (L_result > MAX_WORD ? MAX_WORD : L_result )); + } + } + + /* 4.2.14 */ + + static void RPE_grid_selection P3((x,xM,Mc_out), + word * x, /* [0..39] IN */ + word * xM, /* [0..12] OUT */ + word * Mc_out /* OUT */ + ) + /* + * The signal x[0..39] is used to select the RPE grid which is + * represented by Mc. + */ + { + /* register word temp1; */ + register int /* m, */ i; + register longword L_result, L_temp; + longword EM; /* xxx should be L_EM? */ + word Mc; + + longword L_common_0_3; + + EM = 0; + Mc = 0; + + /* for (m = 0; m <= 3; m++) { + * L_result = 0; + * + * + * for (i = 0; i <= 12; i++) { + * + * temp1 = SASR( x[m + 3*i], 2 ); + * + * assert(temp1 != MIN_WORD); + * + * L_temp = GSM_L_MULT( temp1, temp1 ); + * L_result = GSM_L_ADD( L_temp, L_result ); + * } + * + * if (L_result > EM) { + * Mc = m; + * EM = L_result; + * } + * } + */ + + #undef STEP + #define STEP( m, i ) L_temp = SASR( x[m + 3 * i], 2 ); \ + L_result += L_temp * L_temp; + + /* common part of 0 and 3 */ + + L_result = 0; + STEP( 0, 1 ); STEP( 0, 2 ); STEP( 0, 3 ); STEP( 0, 4 ); + STEP( 0, 5 ); STEP( 0, 6 ); STEP( 0, 7 ); STEP( 0, 8 ); + STEP( 0, 9 ); STEP( 0, 10); STEP( 0, 11); STEP( 0, 12); + L_common_0_3 = L_result; + + /* i = 0 */ + + STEP( 0, 0 ); + L_result <<= 1; /* implicit in L_MULT */ + EM = L_result; + + /* i = 1 */ + + L_result = 0; + STEP( 1, 0 ); + STEP( 1, 1 ); STEP( 1, 2 ); STEP( 1, 3 ); STEP( 1, 4 ); + STEP( 1, 5 ); STEP( 1, 6 ); STEP( 1, 7 ); STEP( 1, 8 ); + STEP( 1, 9 ); STEP( 1, 10); STEP( 1, 11); STEP( 1, 12); + L_result <<= 1; + if (L_result > EM) { + Mc = 1; + EM = L_result; + } + + /* i = 2 */ + + L_result = 0; + STEP( 2, 0 ); + STEP( 2, 1 ); STEP( 2, 2 ); STEP( 2, 3 ); STEP( 2, 4 ); + STEP( 2, 5 ); STEP( 2, 6 ); STEP( 2, 7 ); STEP( 2, 8 ); + STEP( 2, 9 ); STEP( 2, 10); STEP( 2, 11); STEP( 2, 12); + L_result <<= 1; + if (L_result > EM) { + Mc = 2; + EM = L_result; + } + + /* i = 3 */ + + L_result = L_common_0_3; + STEP( 3, 12 ); + L_result <<= 1; + if (L_result > EM) { + Mc = 3; + EM = L_result; + } + + /**/ + + /* Down-sampling by a factor 3 to get the selected xM[0..12] + * RPE sequence. + */ + for (i = 0; i <= 12; i ++) xM[i] = x[Mc + 3*i]; + *Mc_out = Mc; + } + + /* 4.12.15 */ + + static void APCM_quantization_xmaxc_to_exp_mant P3((xmaxc,exp_out,mant_out), + word xmaxc, /* IN */ + word * exp_out, /* OUT */ + word * mant_out ) /* OUT */ + { + word exp, mant; + + /* Compute exponent and mantissa of the decoded version of xmaxc + */ + + exp = 0; + if (xmaxc > 15) exp = SASR(xmaxc, 3) - 1; + mant = xmaxc - (exp << 3); + + if (mant == 0) { + exp = -4; + mant = 7; + } + else { + while (mant <= 7) { + mant = mant << 1 | 1; + exp--; + } + mant -= 8; + } + + assert( exp >= -4 && exp <= 6 ); + assert( mant >= 0 && mant <= 7 ); + + *exp_out = exp; + *mant_out = mant; + } + + static void APCM_quantization P5((xM,xMc,mant_out,exp_out,xmaxc_out), + word * xM, /* [0..12] IN */ + + word * xMc, /* [0..12] OUT */ + word * mant_out, /* OUT */ + word * exp_out, /* OUT */ + word * xmaxc_out /* OUT */ + ) + { + int i, itest; + + word xmax, xmaxc, temp, temp1, temp2; + word exp, mant; + + + /* Find the maximum absolute value xmax of xM[0..12]. + */ + + xmax = 0; + for (i = 0; i <= 12; i++) { + temp = xM[i]; + temp = GSM_ABS(temp); + if (temp > xmax) xmax = temp; + } + + /* Qantizing and coding of xmax to get xmaxc. + */ + + exp = 0; + temp = SASR( xmax, 9 ); + itest = 0; + + for (i = 0; i <= 5; i++) { + + itest |= (temp <= 0); + temp = SASR( temp, 1 ); + + assert(exp <= 5); + if (itest == 0) exp++; /* exp = add (exp, 1) */ + } + + assert(exp <= 6 && exp >= 0); + temp = exp + 5; + + assert(temp <= 11 && temp >= 0); + xmaxc = gsm_add( SASR(xmax, temp), exp << 3 ); + + /* Quantizing and coding of the xM[0..12] RPE sequence + * to get the xMc[0..12] + */ + + APCM_quantization_xmaxc_to_exp_mant( xmaxc, &exp, &mant ); + + /* This computation uses the fact that the decoded version of xmaxc + * can be calculated by using the exponent and the mantissa part of + * xmaxc (logarithmic table). + * So, this method avoids any division and uses only a scaling + * of the RPE samples by a function of the exponent. A direct + * multiplication by the inverse of the mantissa (NRFAC[0..7] + * found in table 4.5) gives the 3 bit coded version xMc[0..12] + * of the RPE samples. + */ + + + /* Direct computation of xMc[0..12] using table 4.5 + */ + + assert( exp <= 4096 && exp >= -4096); + assert( mant >= 0 && mant <= 7 ); + + temp1 = 6 - exp; /* normalization by the exponent */ + temp2 = gsm_NRFAC[ mant ]; /* inverse mantissa */ + + for (i = 0; i <= 12; i++) { + + assert(temp1 >= 0 && temp1 < 16); + + temp = xM[i] << temp1; + temp = GSM_MULT( temp, temp2 ); + temp = SASR(temp, 12); + xMc[i] = temp + 4; /* see note below */ + } + + /* NOTE: This equation is used to make all the xMc[i] positive. + */ + + *mant_out = mant; + *exp_out = exp; + *xmaxc_out = xmaxc; + } + + /* 4.2.16 */ + + static void APCM_inverse_quantization P4((xMc,mant,exp,xMp), + register word * xMc, /* [0..12] IN */ + word mant, + word exp, + register word * xMp) /* [0..12] OUT */ + /* + * This part is for decoding the RPE sequence of coded xMc[0..12] + * samples to obtain the xMp[0..12] array. Table 4.6 is used to get + * the mantissa of xmaxc (FAC[0..7]). + */ + { + int i; + word temp, temp1, temp2, temp3; + longword ltmp; + + assert( mant >= 0 && mant <= 7 ); + + temp1 = gsm_FAC[ mant ]; /* see 4.2-15 for mant */ + temp2 = gsm_sub( 6, exp ); /* see 4.2-15 for exp */ + temp3 = gsm_asl( 1, gsm_sub( temp2, 1 )); + + for (i = 13; i--;) { + + assert( *xMc <= 7 && *xMc >= 0 ); /* 3 bit unsigned */ + + /* temp = gsm_sub( *xMc++ << 1, 7 ); */ + temp = (*xMc++ << 1) - 7; /* restore sign */ + assert( temp <= 7 && temp >= -7 ); /* 4 bit signed */ + + temp <<= 12; /* 16 bit signed */ + temp = GSM_MULT_R( temp1, temp ); + temp = GSM_ADD( temp, temp3 ); + *xMp++ = gsm_asr( temp, temp2 ); + } + } + + /* 4.2.17 */ + + static void RPE_grid_positioning P3((Mc,xMp,ep), + word Mc, /* grid position IN */ + register word * xMp, /* [0..12] IN */ + register word * ep /* [0..39] OUT */ + ) + /* + * This procedure computes the reconstructed long term residual signal + * ep[0..39] for the LTP analysis filter. The inputs are the Mc + * which is the grid position selection and the xMp[0..12] decoded + * RPE samples which are upsampled by a factor of 3 by inserting zero + * values. + */ + { + int i = 13; + + assert(0 <= Mc && Mc <= 3); + + switch (Mc) { + case 3: *ep++ = 0; + case 2: do { + *ep++ = 0; + case 1: *ep++ = 0; + case 0: *ep++ = *xMp++; + } while (--i); + } + while (++Mc < 4) *ep++ = 0; + + /* + + int i, k; + for (k = 0; k <= 39; k++) ep[k] = 0; + for (i = 0; i <= 12; i++) { + ep[ Mc + (3*i) ] = xMp[i]; + } + */ + } + + /* 4.2.18 */ + + /* This procedure adds the reconstructed long term residual signal + * ep[0..39] to the estimated signal dpp[0..39] from the long term + * analysis filter to compute the reconstructed short term residual + * signal dp[-40..-1]; also the reconstructed short term residual + * array dp[-120..-41] is updated. + */ + + #if 0 /* Has been inlined in code.c */ + void Gsm_Update_of_reconstructed_short_time_residual_signal P3((dpp, ep, dp), + word * dpp, /* [0...39] IN */ + word * ep, /* [0...39] IN */ + word * dp) /* [-120...-1] IN/OUT */ + { + int k; + + for (k = 0; k <= 79; k++) + dp[ -120 + k ] = dp[ -80 + k ]; + + for (k = 0; k <= 39; k++) + dp[ -40 + k ] = gsm_add( ep[k], dpp[k] ); + } + #endif /* Has been inlined in code.c */ + + void Gsm_RPE_Encoding P5((S,e,xmaxc,Mc,xMc), + + struct gsm_state * S, + + word * e, /* -5..-1][0..39][40..44 IN/OUT */ + word * xmaxc, /* OUT */ + word * Mc, /* OUT */ + word * xMc) /* [0..12] OUT */ + { + word x[40]; + word xM[13], xMp[13]; + word mant, exp; + + Weighting_filter(e, x); + RPE_grid_selection(x, xM, Mc); + + APCM_quantization( xM, xMc, &mant, &exp, xmaxc); + APCM_inverse_quantization( xMc, mant, exp, xMp); + + RPE_grid_positioning( *Mc, xMp, e ); + + } + + void Gsm_RPE_Decoding P5((S, xmaxcr, Mcr, xMcr, erp), + struct gsm_state * S, + + word xmaxcr, + word Mcr, + word * xMcr, /* [0..12], 3 bits IN */ + word * erp /* [0..39] OUT */ + ) + { + word exp, mant; + word xMp[ 13 ]; + + APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant ); + APCM_inverse_quantization( xMcr, mant, exp, xMp ); + RPE_grid_positioning( Mcr, xMp, erp ); + + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/short_term.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/short_term.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/short_term.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,429 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/short_term.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include <stdio.h> + #include <assert.h> + + #include "private.h" + + #include "gsm.h" + #include "proto.h" + + /* + * SHORT TERM ANALYSIS FILTERING SECTION + */ + + /* 4.2.8 */ + + static void Decoding_of_the_coded_Log_Area_Ratios P2((LARc,LARpp), + word * LARc, /* coded log area ratio [0..7] IN */ + word * LARpp) /* out: decoded .. */ + { + register word temp1 /* , temp2 */; + register long ltmp; /* for GSM_ADD */ + + /* This procedure requires for efficient implementation + * two tables. + * + * INVA[1..8] = integer( (32768 * 8) / real_A[1..8]) + * MIC[1..8] = minimum value of the LARc[1..8] + */ + + /* Compute the LARpp[1..8] + */ + + /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) { + * + * temp1 = GSM_ADD( *LARc, *MIC ) << 10; + * temp2 = *B << 1; + * temp1 = GSM_SUB( temp1, temp2 ); + * + * assert(*INVA != MIN_WORD); + * + * temp1 = GSM_MULT_R( *INVA, temp1 ); + * *LARpp = GSM_ADD( temp1, temp1 ); + * } + */ + + #undef STEP + #define STEP( B, MIC, INVA ) \ + temp1 = GSM_ADD( *LARc++, MIC ) << 10; \ + temp1 = GSM_SUB( temp1, B << 1 ); \ + temp1 = GSM_MULT_R( INVA, temp1 ); \ + *LARpp++ = GSM_ADD( temp1, temp1 ); + + STEP( 0, -32, 13107 ); + STEP( 0, -32, 13107 ); + STEP( 2048, -16, 13107 ); + STEP( -2560, -16, 13107 ); + + STEP( 94, -8, 19223 ); + STEP( -1792, -8, 17476 ); + STEP( -341, -4, 31454 ); + STEP( -1144, -4, 29708 ); + + /* NOTE: the addition of *MIC is used to restore + * the sign of *LARc. + */ + } + + /* 4.2.9 */ + /* Computation of the quantized reflection coefficients + */ + + /* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8] + */ + + /* + * Within each frame of 160 analyzed speech samples the short term + * analysis and synthesis filters operate with four different sets of + * coefficients, derived from the previous set of decoded LARs(LARpp(j-1)) + * and the actual set of decoded LARs (LARpp(j)) + * + * (Initial value: LARpp(j-1)[1..8] = 0.) + */ + + static void Coefficients_0_12 P3((LARpp_j_1, LARpp_j, LARp), + register word * LARpp_j_1, + register word * LARpp_j, + register word * LARp) + { + register int i; + register longword ltmp; + + for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) { + *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 )); + *LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1)); + } + } + + static void Coefficients_13_26 P3((LARpp_j_1, LARpp_j, LARp), + register word * LARpp_j_1, + register word * LARpp_j, + register word * LARp) + { + register int i; + register longword ltmp; + for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) { + *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 )); + } + } + + static void Coefficients_27_39 P3((LARpp_j_1, LARpp_j, LARp), + register word * LARpp_j_1, + register word * LARpp_j, + register word * LARp) + { + register int i; + register longword ltmp; + + for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) { + *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 )); + *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 )); + } + } + + + static void Coefficients_40_159 P2((LARpp_j, LARp), + register word * LARpp_j, + register word * LARp) + { + register int i; + + for (i = 1; i <= 8; i++, LARp++, LARpp_j++) + *LARp = *LARpp_j; + } + + /* 4.2.9.2 */ + + static void LARp_to_rp P1((LARp), + register word * LARp) /* [0..7] IN/OUT */ + /* + * The input of this procedure is the interpolated LARp[0..7] array. + * The reflection coefficients, rp[i], are used in the analysis + * filter and in the synthesis filter. + */ + { + register int i; + register word temp; + register longword ltmp; + + for (i = 1; i <= 8; i++, LARp++) { + + /* temp = GSM_ABS( *LARp ); + * + * if (temp < 11059) temp <<= 1; + * else if (temp < 20070) temp += 11059; + * else temp = GSM_ADD( temp >> 2, 26112 ); + * + * *LARp = *LARp < 0 ? -temp : temp; + */ + + if (*LARp < 0) { + temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp); + *LARp = - ((temp < 11059) ? temp << 1 + : ((temp < 20070) ? temp + 11059 + : GSM_ADD( temp >> 2, 26112 ))); + } else { + temp = *LARp; + *LARp = (temp < 11059) ? temp << 1 + : ((temp < 20070) ? temp + 11059 + : GSM_ADD( temp >> 2, 26112 )); + } + } + } + + + /* 4.2.10 */ + static void Short_term_analysis_filtering P4((S,rp,k_n,s), + struct gsm_state * S, + register word * rp, /* [0..7] IN */ + register int k_n, /* k_end - k_start */ + register word * s /* [0..n-1] IN/OUT */ + ) + /* + * This procedure computes the short term residual signal d[..] to be fed + * to the RPE-LTP loop from the s[..] signal and from the local rp[..] + * array (quantized reflection coefficients). As the call of this + * procedure can be done in many ways (see the interpolation of the LAR + * coefficient), it is assumed that the computation begins with index + * k_start (for arrays d[..] and s[..]) and stops with index k_end + * (k_start and k_end are defined in 4.2.9.1). This procedure also + * needs to keep the array u[0..7] in memory for each call. + */ + { + register word * u = S->u; + register int i; + register word di, zzz, ui, sav, rpi; + register longword ltmp; + + for (; k_n--; s++) { + + di = sav = *s; + + for (i = 0; i < 8; i++) { /* YYY */ + + ui = u[i]; + rpi = rp[i]; + u[i] = sav; + + zzz = GSM_MULT_R(rpi, di); + sav = GSM_ADD( ui, zzz); + + zzz = GSM_MULT_R(rpi, ui); + di = GSM_ADD( di, zzz ); + } + + *s = di; + } + } + + #if defined(USE_FLOAT_MUL) && defined(FAST) + + static void Fast_Short_term_analysis_filtering P4((S,rp,k_n,s), + struct gsm_state * S, + register word * rp, /* [0..7] IN */ + register int k_n, /* k_end - k_start */ + register word * s /* [0..n-1] IN/OUT */ + ) + { + register word * u = S->u; + register int i; + + float uf[8], + rpf[8]; + + register float scalef = 3.0517578125e-5; + register float sav, di, temp; + + for (i = 0; i < 8; ++i) { + uf[i] = u[i]; + rpf[i] = rp[i] * scalef; + } + for (; k_n--; s++) { + sav = di = *s; + for (i = 0; i < 8; ++i) { + register float rpfi = rpf[i]; + register float ufi = uf[i]; + + uf[i] = sav; + temp = rpfi * di + ufi; + di += rpfi * ufi; + sav = temp; + } + *s = di; + } + for (i = 0; i < 8; ++i) u[i] = uf[i]; + } + #endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */ + + static void Short_term_synthesis_filtering P5((S,rrp,k,wt,sr), + struct gsm_state * S, + register word * rrp, /* [0..7] IN */ + register int k, /* k_end - k_start */ + register word * wt, /* [0..k-1] IN */ + register word * sr /* [0..k-1] OUT */ + ) + { + register word * v = S->v; + register int i; + register word sri, tmp1, tmp2; + register longword ltmp; /* for GSM_ADD & GSM_SUB */ + + while (k--) { + sri = *wt++; + for (i = 8; i--;) { + + /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) ); + */ + tmp1 = rrp[i]; + tmp2 = v[i]; + tmp2 = ( tmp1 == MIN_WORD && tmp2 == MIN_WORD + ? MAX_WORD + : 0x0FFFF & (( (longword)tmp1 * (longword)tmp2 + + 16384) >> 15)) ; + + sri = GSM_SUB( sri, tmp2 ); + + /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) ); + */ + tmp1 = ( tmp1 == MIN_WORD && sri == MIN_WORD + ? MAX_WORD + : 0x0FFFF & (( (longword)tmp1 * (longword)sri + + 16384) >> 15)) ; + + v[i+1] = GSM_ADD( v[i], tmp1); + } + *sr++ = v[0] = sri; + } + } + + + #if defined(FAST) && defined(USE_FLOAT_MUL) + + static void Fast_Short_term_synthesis_filtering P5((S,rrp,k,wt,sr), + struct gsm_state * S, + register word * rrp, /* [0..7] IN */ + register int k, /* k_end - k_start */ + register word * wt, /* [0..k-1] IN */ + register word * sr /* [0..k-1] OUT */ + ) + { + register word * v = S->v; + register int i; + + float va[9], rrpa[8]; + register float scalef = 3.0517578125e-5, temp; + + for (i = 0; i < 8; ++i) { + va[i] = v[i]; + rrpa[i] = (float)rrp[i] * scalef; + } + while (k--) { + register float sri = *wt++; + for (i = 8; i--;) { + sri -= rrpa[i] * va[i]; + if (sri < -32768.) sri = -32768.; + else if (sri > 32767.) sri = 32767.; + + temp = va[i] + rrpa[i] * sri; + if (temp < -32768.) temp = -32768.; + else if (temp > 32767.) temp = 32767.; + va[i+1] = temp; + } + *sr++ = va[0] = sri; + } + for (i = 0; i < 9; ++i) v[i] = va[i]; + } + + #endif /* defined(FAST) && defined(USE_FLOAT_MUL) */ + + void Gsm_Short_Term_Analysis_Filter P3((S,LARc,s), + + struct gsm_state * S, + + word * LARc, /* coded log area ratio [0..7] IN */ + word * s /* signal [0..159] IN/OUT */ + ) + { + word * LARpp_j = S->LARpp[ S->j ]; + word * LARpp_j_1 = S->LARpp[ S->j ^= 1 ]; + + word LARp[8]; + + #undef FILTER + #if defined(FAST) && defined(USE_FLOAT_MUL) + # define FILTER (* (S->fast \ + ? Fast_Short_term_analysis_filtering \ + : Short_term_analysis_filtering )) + + #else + # define FILTER Short_term_analysis_filtering + #endif + + Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j ); + + Coefficients_0_12( LARpp_j_1, LARpp_j, LARp ); + LARp_to_rp( LARp ); + FILTER( S, LARp, 13, s); + + Coefficients_13_26( LARpp_j_1, LARpp_j, LARp); + LARp_to_rp( LARp ); + FILTER( S, LARp, 14, s + 13); + + Coefficients_27_39( LARpp_j_1, LARpp_j, LARp); + LARp_to_rp( LARp ); + FILTER( S, LARp, 13, s + 27); + + Coefficients_40_159( LARpp_j, LARp); + LARp_to_rp( LARp ); + FILTER( S, LARp, 120, s + 40); + } + + void Gsm_Short_Term_Synthesis_Filter P4((S, LARcr, wt, s), + struct gsm_state * S, + + word * LARcr, /* received log area ratios [0..7] IN */ + word * wt, /* received d [0..159] IN */ + + word * s /* signal s [0..159] OUT */ + ) + { + word * LARpp_j = S->LARpp[ S->j ]; + word * LARpp_j_1 = S->LARpp[ S->j ^=1 ]; + + word LARp[8]; + + #undef FILTER + #if defined(FAST) && defined(USE_FLOAT_MUL) + + # define FILTER (* (S->fast \ + ? Fast_Short_term_synthesis_filtering \ + : Short_term_synthesis_filtering )) + #else + # define FILTER Short_term_synthesis_filtering + #endif + + Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j ); + + Coefficients_0_12( LARpp_j_1, LARpp_j, LARp ); + LARp_to_rp( LARp ); + FILTER( S, LARp, 13, wt, s ); + + Coefficients_13_26( LARpp_j_1, LARpp_j, LARp); + LARp_to_rp( LARp ); + FILTER( S, LARp, 14, wt + 13, s + 13 ); + + Coefficients_27_39( LARpp_j_1, LARpp_j, LARp); + LARp_to_rp( LARp ); + FILTER( S, LARp, 13, wt + 27, s + 27 ); + + Coefficients_40_159( LARpp_j, LARp ); + LARp_to_rp( LARp ); + FILTER(S, LARp, 120, wt + 40, s + 40); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/table.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/table.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/table.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,63 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/table.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + /* Most of these tables are inlined at their point of use. + */ + + /* 4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP + * CODER AND DECODER + * + * (Most of them inlined, so watch out.) + */ + + #define GSM_TABLE_C + #include "private.h" + #include "gsm.h" + + /* Table 4.1 Quantization of the Log.-Area Ratios + */ + /* i 1 2 3 4 5 6 7 8 */ + word gsm_A[8] = {20480, 20480, 20480, 20480, 13964, 15360, 8534, 9036}; + word gsm_B[8] = { 0, 0, 2048, -2560, 94, -1792, -341, -1144}; + word gsm_MIC[8] = { -32, -32, -16, -16, -8, -8, -4, -4 }; + word gsm_MAC[8] = { 31, 31, 15, 15, 7, 7, 3, 3 }; + + + /* Table 4.2 Tabulation of 1/A[1..8] + */ + word gsm_INVA[8]={ 13107, 13107, 13107, 13107, 19223, 17476, 31454, 29708 }; + + + /* Table 4.3a Decision level of the LTP gain quantizer + */ + /* bc 0 1 2 3 */ + word gsm_DLB[4] = { 6554, 16384, 26214, 32767 }; + + + /* Table 4.3b Quantization levels of the LTP gain quantizer + */ + /* bc 0 1 2 3 */ + word gsm_QLB[4] = { 3277, 11469, 21299, 32767 }; + + + /* Table 4.4 Coefficients of the weighting filter + */ + /* i 0 1 2 3 4 5 6 7 8 9 10 */ + word gsm_H[11] = {-134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 }; + + + /* Table 4.5 Normalized inverse mantissa used to compute xM/xmax + */ + /* i 0 1 2 3 4 5 6 7 */ + word gsm_NRFAC[8] = { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 }; + + + /* Table 4.6 Normalized direct mantissa used to compute xM/xmax + */ + /* i 0 1 2 3 4 5 6 7 */ + word gsm_FAC[8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 }; Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,787 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "toast.h" + + /* toast -- lossy sound compression using the gsm library. + */ + + char * progname; + + int f_decode = 0; /* decode rather than encode (-d) */ + int f_cat = 0; /* write to stdout, not foo.gsm (-c) */ + int f_force = 0; /* force deletion (-f) */ + int f_precious = 0; /* avoid deletion (-p) */ + int f_fast = 0; /* use faster fpt algorithm (-F) */ + int f_verbose = 0; /* debugging (-V) */ + + struct stat instat; /* stat (inname) */ + + FILE *in, *out; + char *inname, *outname; + + /* + * The function (*output)() writes a frame of 160 samples given as + * 160 signed 16 bit values (gsm_signals) to <out>. + * The function (*input)() reads one such frame from <in>. + * The function (*init_output)() begins output (e.g. writes a header)., + * The function (*init_input)() begins input (e.g. skips a header). + * + * There are different versions of input, output, init_input and init_output + * for different formats understood by toast; which ones are used + * depends on the command line arguments and, in their absence, the + * filename; the fallback is #defined in toast.h + * + * The specific implementations of input, output, init_input and init_output + * for a format `foo' live in toast_foo.c. + */ + + int (*output ) P((gsm_signal *)), + (*input ) P((gsm_signal *)); + int (*init_input) P((void)), + (*init_output) P((void)); + + static int generic_init P0() { return 0; } /* NOP */ + + struct fmtdesc { + + char * name, * longname, * suffix; + + int (* init_input ) P((void)), + (* init_output) P((void)); + + int (* input ) P((gsm_signal * )), + (* output) P((gsm_signal * )); + + } f_audio = { + "audio", + "8 kHz, 8 bit u-law encoding with Sun audio header", ".au", + audio_init_input, + audio_init_output, + ulaw_input, + ulaw_output + }, f_ulaw = { + "u-law", "plain 8 kHz, 8 bit u-law encoding", ".u", + generic_init, + generic_init, + ulaw_input, + ulaw_output + + }, f_alaw = { + "A-law", "8 kHz, 8 bit A-law encoding", ".A", + generic_init, + generic_init, + alaw_input, + alaw_output + + }, f_linear = { + "linear", + "16 bit (13 significant) signed 8 kHz signal", ".l", + generic_init, + generic_init, + linear_input, + linear_output + }; + + struct fmtdesc * alldescs[] = { + &f_audio, + &f_alaw, + &f_ulaw, + &f_linear, + (struct fmtdesc *)NULL + }; + + #define DEFAULT_FORMAT f_ulaw /* default audio format, others */ + /* are: f_alaw,f_audio,f_linear */ + struct fmtdesc * f_format = 0; + + /* + * basename + suffix of a pathname + */ + static char * endname P1((name), char * name) + { + if (name) { + char * s = strrchr(name, '/'); + if (s && s[1]) name = s + 1; + } + return name; + + } + + /* + * Try to figure out what we're supposed to do from the argv[0], if + * any, and set the parameters accordingly. + */ + static void parse_argv0 P1((av0), char * av0 ) + { + int l; + + progname = av0 = endname(av0 ? av0 : "toast"); + + /* If the name starts with `un', we want to decode, not code. + * If the name ends in `cat', we want to write to stdout, + * and decode as well. + */ + + if (!strncmp(av0, "un", 2)) f_decode = 1; + if ( (l = strlen(av0)) >= 3 /* strlen("cat") */ + && !strcmp( av0 + l - 3, "cat" )) f_cat = f_decode = 1; + } + + + /* + * Check whether the name (possibly generated by appending + * .gsm to something else) is short enough for this system. + */ + static int length_okay P1((name), char * name) + { + long max_filename_length = 0; + char * end; + + /* If our _pathname_ is too long, we'll usually not be + * able to open the file at all -- don't worry about that. + * + * But if the _filename_ is too long, there is danger of + * silent truncation on some systems, which results + * in the target replacing the source! + */ + + if (!name) return 0; + end = endname(name); + + #ifdef NAME_MAX + max_filename_length = NAME_MAX; + #else + #ifdef _PC_NAME_MAX + #ifdef USE_PATHCONF + { char * s, tmp; + + /* s = dirname(name) + */ + if ((s = end) > name) { + if (s > name + 1) s--; + tmp = s; + *s = 0; + } + + errno = 0; + max_filename_length = pathconf(s > name ? name : ".", + _PC_NAME_MAX); + if (max_filename_length == -1 && errno) { + perror( s > name ? name : "." ); + fprintf(stderr, + "%s: cannot get dynamic filename length limit for %s.\n", + progname, s > name ? name : "."); + return 0; + } + if (s > name) *s = tmp; + } + #endif /* USE_PATHCONF */ + #endif /* _PC_NAME_MAX */ + #endif /* !NAME_MAX */ + + if (max_filename_length > 0 && strlen(end) > max_filename_length) { + fprintf(stderr, + "%s: filename \"%s\" is too long (maximum is %ld)\n", + progname, endname(name), max_filename_length ); + return 0; + } + + return 1; + } + + /* + * Return a pointer the suffix of a string, if any. + * A suffix alone has no suffix, an empty suffix can not be had. + */ + static char * suffix P2((name, suf), char *name, char * suf) + { + size_t nlen = strlen(name); + size_t slen = strlen(suf); + + if (!slen || nlen <= slen) return (char *)0; + name += nlen - slen; + return memcmp(name, suf, slen) ? (char *)0 : name; + } + + + static void catch_signals P1((fun), SIGHANDLER_T (*fun) ()) + { + #ifdef SIGHUP + signal( SIGHUP, fun ); + #endif + #ifdef SIGINT + signal( SIGINT, fun ); + #endif + #ifdef SIGPIPE + signal( SIGPIPE, fun ); + #endif + #ifdef SIGTERM + signal( SIGTERM, fun ); + #endif + #ifdef SIGXFSZ + signal( SIGXFSZ, fun ); + #endif + } + + static SIGHANDLER_T onintr P0() + { + char * tmp = outname; + + #ifdef HAS_SYSV_SIGNALS + catch_signals( SIG_IGN ); + #endif + + outname = (char *)0; + if (tmp) (void)unlink(tmp); + + exit(1); + } + + /* + * Allocate some memory and complain if it fails. + */ + static char * emalloc P1((len), size_t len) + { + char * s; + if (!(s = malloc(len))) { + fprintf(stderr, "%s: failed to malloc %d bytes -- abort\n", + progname, len); + onintr(); + exit(1); + } + return s; + } + + static char* normalname P3((name, want, cut), char *name, char *want,char *cut) + { + size_t maxlen; + char * s, * p; + + p = (char *)0; + if (!name) return p; + + maxlen = strlen(name) + 1 + strlen(want) + strlen(cut); + p = strcpy(emalloc(maxlen), name); + + if (s = suffix(p, cut)) strcpy(s, want); + else if (*want && !suffix(p, want)) strcat(p, want); + + return p; + } + + /* + * Generate a `plain' (non-encoded) name from a given name. + */ + static char * plainname P1((name), char *name) + { + return normalname(name, "", SUFFIX_TOASTED ); + } + + /* + * Generate a `code' name (foo.Z) from a given name. + */ + static char * codename P1((name), char *name) + { + return normalname( name, SUFFIX_TOASTED, "" ); + } + + /* + * If we're supposed to ask (fileno (stderr) is a tty, and f_force not + * set), ask the user whether to overwrite a file or not. + */ + static int ok_to_replace P1(( name ), char * name) + { + int reply, c; + + if (f_force) return 1; /* YES, do replace */ + if (!isatty(fileno(stderr))) return 0; /* NO, don't replace */ + + fprintf(stderr, + "%s already exists; do you wish to overwrite %s (y or n)? ", + name, name); + fflush(stderr); + + for (c = reply = getchar(); c != '\n' && c != EOF; c = getchar()) ; + if (reply == 'y') return 1; + + fprintf(stderr, "\tnot overwritten\n"); + return 0; + } + + static void update_mode P0() + { + if (!instat.st_nlink) return; /* couldn't stat in */ + + #ifdef HAS_FCHMOD + if (fchmod(fileno(out), instat.st_mode & 07777)) { + perror(outname); + fprintf(stderr, "%s: could not change file mode of \"%s\"\n", + progname, outname); + } + #else + if (outname && chmod(outname, instat.st_mode & 07777)) { + perror(outname); + fprintf(stderr, "%s: could not change file mode of \"%s\"\n", + progname, outname); + } + #endif /* HAS_FCHMOD */ + } + + static void update_own P0() + { + if (!instat.st_nlink) return; /* couldn't stat in */ + #ifdef HAS_FCHOWN + (void)fchown(fileno(out), instat.st_uid, instat.st_gid); + #else + (void)chown(outname, instat.st_uid, instat.st_gid); + #endif /* HAS_FCHOWN */ + } + + static void update_times P0() + { + if (!instat.st_nlink) return; /* couldn't stat in */ + + #ifdef HAS_UTIMES + if (outname) { + struct timeval tv[2]; + + tv[0].tv_sec = instat.st_atime; + tv[1].tv_sec = instat.st_mtime; + tv[0].tv_usec = tv[1].tv_usec = 0; + (void) utimes(outname, tv); + } + #else + #ifdef HAS_UTIME + + if (outname) { + + #ifdef HAS_UTIMBUF + struct utimbuf ut; + + ut.actime = instat.st_atime; + ut.modtime = instat.st_mtime; + + # ifdef HAS_UTIMEUSEC + ut.acusec = instat.st_ausec; + ut.modusec = instat.st_musec; + # endif /* HAS_UTIMEUSEC */ + + (void) utime(outname, &ut); + + #else /* UTIMBUF */ + + time_t ut[2]; + + ut[0] = instat.st_atime; + ut[1] = instat.st_mtime; + + (void) utime(outname, ut); + + #endif /* UTIMBUF */ + } + #endif /* HAS_UTIME */ + #endif /* HAS_UTIMES */ + } + + + static int okay_as_input P3((name,f,st), char* name, FILE* f, struct stat * st) + { + # ifdef HAS_FSTAT + if (fstat(fileno(f), st) < 0) + # else + if (stat(name, st) < 0) + # endif + { + perror(name); + fprintf(stderr, "%s: cannot stat \"%s\"\n", progname, name); + return 0; + } + + if (!S_ISREG(st->st_mode)) { + fprintf(stderr, + "%s: \"%s\" is not a regular file -- unchanged.\n", + progname, name); + return 0; + } + if (st->st_nlink > 1 && !f_cat && !f_precious) { + fprintf(stderr, + "%s: \"%s\" has %s other link%s -- unchanged.\n", + progname,name,st->st_nlink - 1,"s" + (st->st_nlink<=2)); + return 0; + } + return 1; + } + + static void prepare_io P1(( desc), struct fmtdesc * desc) + { + output = desc->output; + input = desc->input; + + init_input = desc->init_input; + init_output = desc->init_output; + } + + static struct fmtdesc * grok_format P1((name), char * name) + { + char * c; + struct fmtdesc ** f; + + if (name) { + c = plainname(name); + + for (f = alldescs; *f; f++) + if ( (*f)->suffix + && *(*f)->suffix + && suffix(c, (*f)->suffix)) { + + free(c); + return *f; + } + + free(c); + } + return (struct fmtdesc *)0; + } + + static int open_input P2((name, st), char * name, struct stat * st) + { + struct fmtdesc * f = f_format; + + st->st_nlink = 0; /* indicates `undefined' value */ + if (!name) { + inname = (char *)NULL; + in = stdin; + } + else { + if (f_decode) inname = codename(name); + else { + if (!f_cat && suffix(name, SUFFIX_TOASTED)) { + fprintf(stderr, + "%s: %s already has \"%s\" suffix -- unchanged.\n", + progname, name, SUFFIX_TOASTED ); + return 0; + } + inname = strcpy(emalloc(strlen(name)+1), name); + } + if (!(in = fopen(inname, READ))) { + perror(inname); /* not guaranteed to be valid here */ + fprintf(stderr, "%s: cannot open \"%s\" for reading\n", + progname, inname); + return 0; + } + if (!okay_as_input(inname, in, st)) return 0; + if (!f) f = grok_format(inname); + } + prepare_io( f ? f : & DEFAULT_FORMAT ); + return 1; + } + + static int open_output P1((name), char *name) + { + if (!name || f_cat) { + out = stdout; + outname = (char *)NULL; + } + else { + int outfd = -1; + char * o; + + o = (*(f_decode ? plainname : codename))(name); + if (!length_okay(o)) return 0; + if ((outfd = open(o, O_WRITE_EXCL, 0666)) >= 0) + out = fdopen(outfd, WRITE); + else if (errno != EEXIST) out = (FILE *)NULL; + else if (ok_to_replace(o)) out = fopen(o, WRITE); + else return 0; + + if (!out) { + perror(o); + fprintf(stderr, + "%s: can't open \"%s\" for writing\n", + progname, o); + if (outfd >= 0) (void)close(outfd); + return 0; + } + + outname = o; + } + return 1; + } + + static int process_encode P0() + { + gsm r; + gsm_signal s[ 160 ]; + gsm_frame d; + + int cc; + + if (!(r = gsm_create())) { + perror(progname); + return -1; + } + (void)gsm_option(r, GSM_OPT_FAST, &f_fast); + (void)gsm_option(r, GSM_OPT_VERBOSE, &f_verbose); + + while ((cc = (*input)(s)) > 0) { + if (cc < sizeof(s) / sizeof(*s)) + memset((char *)(s+cc), 0, sizeof(s)-(cc * sizeof(*s))); + gsm_encode(r, s, d); + if (fwrite((char *)d, sizeof(d), 1, out) != 1) { + perror(outname ? outname : "stdout"); + fprintf(stderr, "%s: error writing to %s\n", + progname, outname ? outname : "stdout"); + gsm_destroy(r); + return -1; + } + } + if (cc < 0) { + perror(inname ? inname : "stdin"); + fprintf(stderr, "%s: error reading from %s\n", + progname, inname ? inname : "stdin"); + gsm_destroy(r); + return -1; + } + gsm_destroy(r); + + return 0; + } + + static int process_decode P0() + { + gsm r; + gsm_frame s; + gsm_signal d[ 160 ]; + + int cc; + + if (!(r = gsm_create())) { /* malloc failed */ + perror(progname); + return -1; + } + (void)gsm_option(r, GSM_OPT_FAST, &f_fast); + (void)gsm_option(r, GSM_OPT_VERBOSE, &f_verbose); + + while ((cc = fread(s, 1, sizeof(s), in)) > 0) { + + if (cc != sizeof(s)) { + if (cc >= 0) fprintf(stderr, + "%s: incomplete frame (%d byte%s missing) from %s\n", + progname, sizeof(s) - cc, + "s" + (sizeof(s) - cc == 1), + inname ? inname : "stdin" ); + gsm_destroy(r); + errno = 0; + return -1; + } + if (gsm_decode(r, s, d)) { + fprintf(stderr, "%s: bad frame in %s\n", + progname, inname ? inname : "stdin"); + gsm_destroy(r); + errno = 0; + return -1; + } + + if ((*output)(d) < 0) { + perror(outname); + fprintf(stderr, "%s: error writing to %s\n", + progname, outname); + gsm_destroy(r); + return -1; + } + } + + if (cc < 0) { + perror(inname ? inname : "stdin" ); + fprintf(stderr, "%s: error reading from %s\n", progname, + inname ? inname : "stdin"); + gsm_destroy(r); + return -1; + } + + gsm_destroy(r); + return 0; + } + + static int process P1((name), char * name) + { + int step = 0; + + out = (FILE *)0; + in = (FILE *)0; + + outname = (char *)0; + inname = (char *)0; + + if (!open_input(name, &instat) || !open_output(name)) + goto err; + + if ((*(f_decode ? init_output : init_input))()) { + fprintf(stderr, "%s: error %s %s\n", + progname, + f_decode ? "writing header to" : "reading header from", + f_decode ? (outname ? outname : "stdout") + : (inname ? inname : "stdin")); + goto err; + } + + if ((*(f_decode ? process_decode : process_encode))()) + goto err; + + if (fflush(out) < 0 || ferror(out)) { + perror(outname ? outname : "stdout"); + fprintf(stderr, "%s: error writing \"%s\"\n", progname, + outname ? outname:"stdout"); + goto err; + } + + if (out != stdout) { + + update_times(); + update_mode (); + update_own (); + + if (fclose(out) < 0) { + perror(outname); + fprintf(stderr, "%s: error writing \"%s\"\n", + progname, outname); + goto err; + } + if (outname != name) free(outname); + outname = (char *)0; + } + out = (FILE *)0; + if (in != stdin) { + (void)fclose(in), in = (FILE *)0; + if (!f_cat && !f_precious) { + if (unlink(inname) < 0) { + perror(inname); + fprintf(stderr, + "%s: source \"%s\" not deleted.\n", + progname, inname); + } + goto err; + } + if (inname != name) free(inname); + inname = (char *)0; + } + return 0; + + /* + * Error handling and cleanup: + * - error out: close out, unlink it, close in, free the names. + * - + */ + err: + if (out && out != stdout) { + (void)fclose(out), out = (FILE *)0; + if (unlink(outname) < 0 && errno != ENOENT && errno != EINTR) { + perror(outname); + fprintf(stderr, "%s: could not unlink \"%s\"\n", + progname, outname); + } + } + if (in && in != stdin) (void)fclose(in), in = (FILE *)0; + + if (inname && inname != name) free(inname); + if (outname && outname != name) free(outname); + + return -1; + } + + static void version P0() + { + printf( "%s 1.0, version %s\n", + progname, + "$Id: toast.c,v 1.1 2007/01/09 23:44:35 lattner Exp $" ); + } + + static void help P0() + { + printf("Usage: %s [-fcpdhvaulsF] [files...]\n", progname); + printf("\n"); + + printf(" -f force Replace existing files without asking\n"); + printf(" -c cat Write to stdout, do not remove source files\n"); + printf(" -d decode Decode data (default is encode)\n"); + printf(" -p precious Do not delete the source\n"); + printf("\n"); + + printf(" -u u-law Force 8 kHz/8 bit u-law in/output format\n"); + printf(" -s sun .au Force Sun .au u-law in/output format\n"); + printf(" -a A-law Force 8 kHz/8 bit A-law in/output format\n"); + printf(" -l linear Force 16 bit linear in/output format\n"); + printf("\n"); + + printf(" -F fast Sacrifice conformance to performance\n"); + printf(" -v version Show version information\n"); + printf(" -h help Print this text\n"); + printf("\n"); + } + + + static void set_format P1((f), struct fmtdesc * f) + { + if (f_format && f_format != f) { + fprintf( stderr, + "%s: only one of -[uals] is possible (%s -h for help)\n", + progname, progname); + exit(1); + } + + f_format = f; + } + + int main P2((ac, av), int ac, char **av) + { + int opt; + extern int optind; + + parse_argv0( *av ); + + while ((opt = getopt(ac, av, "fcdpvhuaslVF")) != EOF) + switch (opt) { + + case 'd': f_decode = 1; break; + case 'f': f_force = 1; break; + case 'c': f_cat = 1; break; + case 'p': f_precious = 1; break; + case 'F': f_fast = 1; break; + + #ifndef NDEBUG + case 'V': f_verbose = 1; break; /* undocumented */ + #endif + + case 'u': set_format( &f_ulaw ); break; + case 'l': set_format( &f_linear ); break; + case 'a': set_format( &f_alaw ); break; + case 's': set_format( &f_audio ); break; + + case 'v': version(); exit(0); + case 'h': help(); exit(0); + + default: + fprintf(stderr, + "Usage: %s [-fcpdhvuaslF] [files...] (-h for help)\n", + progname); + exit(1); + } + + f_precious |= f_cat; + + av += optind; + ac -= optind; + + catch_signals(onintr); + + if (ac <= 0) process( (char *)0 ); + else while (ac--) process( *av++ ); + + exit(0); + } Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.h diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.h:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.h Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,105 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast.h,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #ifndef TOAST_H + #define TOAST_H /* Guard against multiple includes */ + + #include "config.h" + + #include <sys/types.h> + #include <sys/stat.h> + + #include <stdio.h> + #include <ctype.h> + #include <signal.h> + + #include <errno.h> + #ifndef HAS_ERRNO_DECL + extern int errno; + #endif + + #ifdef HAS_LIMITS_H + #include <limits.h> + #endif + + #ifdef HAS_FCNTL_H + # include <fcntl.h> + #endif + + #ifdef HAS_UTIME + # ifdef HAS_UTIME_H + # include <utime.h> + # endif + #endif + + #include "gsm.h" + + #ifndef S_ISREG + #define S_ISREG(x) ((x) & S_IFREG) + #endif /* S_ISREG */ + + + # define READ "rb" + # define WRITE "wb" + # define O_WRITE_EXCL O_WRONLY|O_CREAT|O_EXCL + + #ifndef SIGHANDLER_T + #define SIGHANDLER_T void /* what does a signal handler return? */ + #endif + + + #ifdef HAS_STRING_H + #include <string.h> + #else + # ifdef HAS_STRINGS_H + # include <strings.h> + # else + # include "proto.h" + + extern int strlen P((char *)); + extern char * strcpy P((char *, char *)); + extern char * strcat P((char *, char *)); + extern char * strrchr P((char *, int)); + + # include "unproto.h" + # endif + #endif + + + #ifdef HAS_STDLIB_H + #include <stdlib.h> + #else + # include "proto.h" + # ifdef HAS_MALLOC_H + # include <malloc.h> + # else + extern char * malloc P((unsigned)); + # endif + extern int exit P((int)); + # include "unproto.h" + #endif + + + #ifdef HAS_UNISTD_H + # include <unistd.h> + #endif + + /* + * This suffix is tacked onto/removed from filenames + * similar to the way freeze and compress do it. + */ + #define SUFFIX_TOASTED ".gsm" + + #include "proto.h" + + extern int audio_init_input P((void)), audio_init_output P((void)); + extern int ulaw_input P((gsm_signal*)), ulaw_output P((gsm_signal *)); + extern int alaw_input P((gsm_signal*)), alaw_output P((gsm_signal *)); + extern int linear_input P((gsm_signal*)), linear_output P((gsm_signal *)); + + #endif /* TOAST_H */ Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast_alaw.c diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast_alaw.c:1.1 *** /dev/null Tue Jan 9 17:45:03 2007 --- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast_alaw.c Tue Jan 9 17:44:35 2007 *************** *** 0 **** --- 1,333 ---- + /* + * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische + * Universitaet Berlin. See the accompanying file "COPYRIGHT" for + * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + */ + + /* $Header: /var/cvs/llvm/llvm-test/MultiSource/Benchmarks/MiBench/telecomm-gsm/toast_alaw.c,v 1.1 2007/01/09 23:44:35 lattner Exp $ */ + + #include "toast.h" + + /* toast_alaw.c -- manipulate A-law encoded sound. + */ + + extern FILE * in, * out; + + #define A2S(x) (a2s[ (unsigned char )(x) ]) + #define S2A(x) (s2a[ ((unsigned short)(x)) >> 4 ]) + + static unsigned short a2s[] = { + + 5120,60160, 320,65200,20480,44032, 1280,64192, + 2560,62848, 64,65456,10240,54784, 640,64864, + 7168,58112, 448,65072,28672,35840, 1792,63680, + 3584,61824, 192,65328,14336,50688, 896,64608, + 4096,61184, 256,65264,16384,48128, 1024,64448, + 2048,63360, 0,65520, 8192,56832, 512,64992, + 6144,5913