github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/cmd/cc/bv.c (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include <u.h> 6 #include "cc.h" 7 8 enum { 9 WORDSIZE = sizeof(uint32), 10 WORDBITS = 32, 11 }; 12 13 uintptr 14 bvsize(uintptr n) 15 { 16 return ((n + WORDBITS - 1) / WORDBITS) * WORDSIZE; 17 } 18 19 Bvec* 20 bvalloc(int32 n) 21 { 22 Bvec *bv; 23 uintptr nbytes; 24 25 if(n < 0) 26 fatal(Z, "bvalloc: initial size is negative\n"); 27 nbytes = sizeof(Bvec) + bvsize(n); 28 bv = malloc(nbytes); 29 if(bv == nil) 30 fatal(Z, "bvalloc: malloc failed\n"); 31 memset(bv, 0, nbytes); 32 bv->n = n; 33 return bv; 34 } 35 36 void 37 bvset(Bvec *bv, int32 i) 38 { 39 uint32 mask; 40 41 if(i < 0 || i >= bv->n) 42 fatal(Z, "bvset: index %d is out of bounds with length %d\n", i, bv->n); 43 mask = 1 << (i % WORDBITS); 44 bv->b[i / WORDBITS] |= mask; 45 }