Merge "tweak vp8_regular_quantize_b_sse2"
[libvpx.git] / vpx_mem / memory_manager / hmm_alloc.c
blob22c4a54eec781861641838328195a6138261d2fb
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 /* This code is in the public domain.
13 ** Version: 1.1 Author: Walt Karas
16 #include "hmm_intrnl.h"
18 void *U(alloc)(U(descriptor) *desc, U(size_aau) n)
20 #ifdef HMM_AUDIT_FAIL
22 if (desc->avl_tree_root)
23 AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
24 #endif
26 if (desc->last_freed)
28 #ifdef HMM_AUDIT_FAIL
29 AUDIT_BLOCK(desc->last_freed)
30 #endif
32 U(into_free_collection)(desc, (head_record *)(desc->last_freed));
34 desc->last_freed = 0;
37 /* Add space for block header. */
38 n += HEAD_AAUS;
40 /* Convert n from number of address alignment units to block alignment
41 ** units. */
42 n = DIV_ROUND_UP(n, HMM_BLOCK_ALIGN_UNIT);
44 if (n < MIN_BLOCK_BAUS)
45 n = MIN_BLOCK_BAUS;
48 /* Search for the first node of the bin containing the smallest
49 ** block big enough to satisfy request. */
50 ptr_record *ptr_rec_ptr =
51 U(avl_search)(
52 (U(avl_avl) *) & (desc->avl_tree_root), (U(size_bau)) n,
53 AVL_GREATER_EQUAL);
55 /* If an approprate bin is found, satisfy the allocation request,
56 ** otherwise return null pointer. */
57 return(ptr_rec_ptr ?
58 U(alloc_from_bin)(desc, ptr_rec_ptr, (U(size_bau)) n) : 0);