void write_dac(int16 data) { BYTE cmd[3]; BYTE i; cmd[0]=data; cmd[1]=(data>>8); cmd[2]=0x03; output_high(DAC_LDAC); output_low(DAC_CLK); output_low(DAC_CS); for(i=0; i<=23; ++i) { if(i<4 || (i>7 && i<12)) shift_left(cmd,3,0); else { output_bit(DAC_DI, shift_left(cmd,3,0)); output_high(DAC_CLK); output_low(DAC_CLK); } } output_high(DAC_CS); output_low(DAC_LDAC); delay_us(10); output_HIGH(DAC_LDAC); }
set_pot (int pot_num, int new_value) { byte i; byte cmd[3]; if (pot_num >= NUM_POTS) return; pots[pot_num] = new_value; cmd[0]=pots[0]; cmd[1]=pots[1]; cmd[2]=0; for(i=1;i<=7;i++) shift_left(cmd,3,0); output_high(RST1); delay_us(2); for(i=1;i<=17;i++) { output_bit(DI, shift_left(cmd,3,0)); delay_us(2); output_high(CLK); delay_us(2); if(i==17) output_low(RST1); output_low(CLK); delay_us(2); } }
bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) { assert(left != result, "should be different registers"); if (is_power_of_2(c + 1)) { __ shift_left(left, log2_intptr(c + 1), result); __ sub(result, left, result); return true; } else if (is_power_of_2(c - 1)) { __ shift_left(left, log2_intptr(c - 1), result); __ add(result, left, result); return true; } return false; }
int basic_tokenize (char string[], char *token[], int maximum) /* Input/Output: string[]; NOTE: will be destroyed! */ /* Output: token[0..maximum-1]. */ /* This routine parses the given string and breaks it up into different tokens. The tokens are delimited by blanks. Use quotes ("balh blah") when a token is to contain blanks. Use \" for the quote character and \\ for the backslash. The function returns the number of tokens parsed or -1 when it would have exceeded the maximum. */ { int j = 0, i = 0; while (string[i]) { while (string[i] == ' ') i ++; if (string[i]) { if (j == maximum) return (-1); token[j++] = &(string[i]); while (string[i] and (string[i] != ' ')) { /* parse token */ if ((string[i] == '\\') and (string[i+1] == '"')) shift_left (&(string[i])); /* quote as a character */ else if (string[i] == '"') { /* parse quoted token */ shift_left (&(string[i])); while (string[i]) { if ((string[i] == '\\') and (string[i+1] == '"')) { /* quote as a character within quoted string */ shift_left (&(string[i])); i ++; } else if (string[i] == '"') string[i] = 0; else i ++; } } i ++; } if (string[i]) { string[i] = 0; i ++; } } } return (j); }
int16_t outpos_del (SOBJ * obj, int16_t pos) { struct segm * segm; /* curr pos segm */ LT * symb; /* end of curr pos */ LT * lt; /* beg of curr pos */ int16_t lth=0; int16_t endposp, endpos; int16_t pi; /* curr pos */ getpos_bel (obj, pos, <, &symb, <h); /* get beg(lt), end(symb) & lth */ segm = obj->pos[pos].tif_ref.segm; /* segm arg of the pos */ shift_left(lth,segm,(char *)symb); /* shift-to-left: lth, segm. symb */ /* correct all obj->pos[P].lt & obj->pos[P].alt[K].lt with the same segm: */ /* shift-to-left needed in all of them */ endposp = obj->pos_part_nmb; /* last pos index in partitioning-list */ endpos = obj->pos_part[endposp]; /* last pos of obj */ for (pi=pos+1; pi<endpos; pi++) { if (obj->pos[pi].tif_ref.segm == segm) /* if the same segm => shift : */ corrpos_lt (obj, pi, -((int32_t)(lth))); /* correct lt of pos & alts */ else break; } #ifdef EDPR_CORR PRINTF ("\n %d. !!! ED-file corrected: DELETE pos %d", obj->nmb, pos); #endif return(OK); }
bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) { if (tmp->is_valid()) { if (is_power_of_2(c + 1)) { __ move(left, tmp); __ shift_left(left, log2_intptr(c + 1), left); __ sub(left, tmp, result); return true; } else if (is_power_of_2(c - 1)) { __ move(left, tmp); __ shift_left(left, log2_intptr(c - 1), left); __ add(left, tmp, result); return true; } } return false; }
static void menu(void) { draw_glyph(modes[mode_id].glyph_id); while(state == STATE_MENU) { if(keypresses & KEY_LEFT) { keypresses &= ~KEY_LEFT; if(mode_id > 0) { mode_id--; const uint8_t glyph_id = modes[mode_id].glyph_id; for(uint8_t i = 0; i < 8; i++) { shift_right(); display[0] = read_glyph_column(glyph_id, 7 - i); _delay_ms(50); } } } else if(keypresses & KEY_RIGHT) { keypresses &= ~KEY_RIGHT; if(modes[mode_id + 1].run != NULL) { mode_id++; const uint8_t glyph_id = modes[mode_id].glyph_id; for(uint8_t i = 0; i < 8; i++) { shift_left(); display[7] = read_glyph_column(glyph_id, i); _delay_ms(50); } } } else if(keypresses & KEY_ENTER) { keypresses &= ~KEY_ENTER; state = STATE_NORMAL; } } }
//----------------------------------------------------------------------- // read_data() //----------------------------------------------------------------------- // long read_data() { int i; int data; // Tri-state the SDIO pin output_float(SDIO); // Minium delay between address and reading data delay_us(100); // Read data for(i=0; i < DATA_BITS; i++){ // Leading edge of serial clock (data is clocked out ADNS-2051) output_low(SCLK); // Some extra delay before read delay_us(25); // put here code to shift data in on shift_left(&data, 1, input(SDIO) ); // Trailling edge of serial clock output_high(SCLK); } return data; }
/* * Bitpack_gets() - This function takes an unsigned 64 bit word, a field * width to extract a value from, and the least significant * bit of the field to be extracted. This function returns * the signed value extracted from the original word */ int64_t Bitpack_gets(uint64_t word, unsigned width, unsigned lsb) { word = Bitpack_getu(word, width, lsb); word = shift_left(word, (WORD_SIZE - width)); return shift_rights(word, (WORD_SIZE - width)); }
int main(void) { int a[10]; rand_a(a, 10); print_a(a, 10); printf("max ele is: %d\n", max(a, 10)); printf("min ele is: %d\n", min(a, 10)); printf("shift left 3 eles:\n"); shift_left(a, 10, 3); print_a(a, 10); printf("shift right 3 eles:\n"); shift_right(a, 10, 3); print_a(a, 10); printf("reverse:\n"); reverse(a, 10); print_a(a, 10); printf("sort:\n"); bubble_sort(a, 10); print_a(a, 10); return 0; }
static xid removexid(int bits, xid data) { int i; xid tmp; tmp = shift_right(shift_left(data, bits), bits); return tmp; }
void key_delete() { char *s; s = command_line(NULL); if (s[cursor(-2)]) shift_left(s + cursor(-2), 1); }
void CppInterpreterGenerator::generate_adjust_callers_stack() { StackFrame frame; const int frame_header_size = frame.unaligned_size() + slop_factor; const Address param_words_addr( Rmethod, methodOopDesc::size_of_parameters_offset()); const Address local_words_addr( Rmethod, methodOopDesc::size_of_locals_offset()); const Register param_words = r3; const Register local_words = r4; Label loop, done; // Check whether extra locals are actually required __ lhz (param_words, param_words_addr); __ lhz (local_words, local_words_addr); __ compare (param_words, local_words); __ beq (done); // Extend the frame if necessary const Register required_bytes = r5; const Register available_bytes = r6; __ shift_left (required_bytes, local_words, LogBytesPerWord); __ sub (available_bytes, Rlocals, r1); __ subi (available_bytes, available_bytes, frame_header_size); __ maybe_extend_frame (required_bytes, available_bytes); // Zero the extra locals const Register dst = r7; __ shift_left (dst, param_words, LogBytesPerWord); __ sub (dst, Rlocals, dst); __ sub (r0, local_words, param_words); __ mtctr (r0); __ load (r0, 0); __ bind (loop); __ store (r0, Address(dst, 0)); __ subi (dst, dst, wordSize); __ bdnz (loop); __ bind (done); }
/* * Remove "bits" bits from data */ XID removeXID(int bits, XID data) { int i; XID tmp; tmp = shift_right(shift_left(data, bits), bits); return tmp; }
void restore_key(Node *pnt, int k){ if (k==0) if (pnt->branch[1]->count >MIN_ORDER) shift_left(pnt,1); else merge(pnt,1); else if (k==pnt->count) if (pnt->branch[k-1]->count >MIN_ORDER) shift_right(pnt,k); else merge(pnt,k); else if (pnt->branch[k-1]->count>MIN_ORDER) shift_right(pnt,k); else if (pnt->branch[k+1]->count>MIN_ORDER) shift_left(pnt,k+1); else merge(pnt,k); }
/* * Bitpack_fitsu() - This function takes an unsigned 64 bit value * and a field width and returns a bool indicating whether * or not the given value can be represented in "width" * bits. */ bool Bitpack_fitsu(uint64_t n, unsigned width) { if (width >= WORD_SIZE) return true; /*the >= operator is used here*/ if (width == ZERO) return false; /*since a width greater than */ /*wordsize will always fit */ /*the word */ return (n < shift_left(ONE, width)); }
int can_move_left(board *b) { board *tmp; tmp = dup_board(b); shift_left(tmp); merge_left(tmp); shift_left(tmp); if (cmp_board(b, tmp)) { free(tmp); return 0; } else { free(tmp); return 1; } }
void CppInterpreterGenerator::generate_convert_result(address* converter_array) { __ load (r5, (intptr_t) converter_array); __ lwz (r0, Address(Rmethod, methodOopDesc::result_index_offset())); __ shift_left (r0, r0, LogBytesPerWord); __ load_indexed (r0, r5, r0); __ mtctr (r0); __ bctrl (); }
// Function that splits multiple of two large numbers into // multiplication of numbers about same size. It does it in // divide and conquer fashion by splitting one that is larger // than the other in half i.e. (A1*2^N+A0)*B=A1*B*2^N+A0*B large_int* mult_kar(large_int* a, large_int* b) { int n; large_int *c,*d; // Depending on which is larger these become either a or b large_int c0,c1; // Split in half large half of the a or b large_int *mc0,*mc1,*result; if (debug) printf("Calling mult_kar\n"); // Decide which number is larger if (a->size>b->size && a->size>2*b->size) { n=a->size/2; c0.size=n; c1.size=a->size-n; c=a; d=b; } else if (b->size>a->size && b->size>2*a->size) { n=b->size/2; c0.size=n; c1.size=b->size-n; c=b; d=a; } else { // Numbers close to equal in size, we call on Karatsuba algorithm return mult_kar_eqsize(a,b); } // Allocate memory and copy data for c0, c1 c0.int_array=malloc(sizeof(unsigned int)*c0.size); c1.int_array=malloc(sizeof(unsigned int)*c1.size); if (c0.int_array==NULL || c1.int_array==NULL) die("memory allocation error"); memcpy(c0.int_array,c->int_array,c0.size*sizeof(unsigned int)); memcpy(c1.int_array,(char*)c->int_array+((size_t)c0.size*sizeof(unsigned int)),c1.size*sizeof(unsigned int)); // Recursive step that can be parallelized #pragma omp parallel sections default (shared) { mc0=mult_kar(&c0,d); #pragma omp section mc1=mult_kar(&c1,d); } // Shift and make one number shift_left(mc1,n); result=ADD(mc1,mc0); // Free and Return free(c0.int_array); free(c1.int_array); free(mc0->int_array); free(mc1->int_array); free(mc0); free(mc1); return result; }
/* * Extract length bits starting at pos from data */ XID extractXID(int pos, int length, XID data) { int i; XID tmp; // length = 0 is handled in the boolean expression and is short-circuit // even though length of zero works in case of xids tmp = shift_right(shift_left(data, pos), (160-length)); return tmp; }
void ext_flash_getBytes(char* data, int16 size) { int16 i, j; for(i = 0; i < size; i++) { for(j = 0; j < 8; j++) { output_high(FLASH_CLOCK); shift_left(data + i, 1, input(FLASH_DO)); output_low(FLASH_CLOCK); } } }
int list_delete(list_t * self, int index) { resetStatus(self); if(!isEmpty(self) && index - 1 <= self->size - 1) { shift_left(self, index); (self->size)--; } else self->status = LIST_EMPTY; }
void write_ext_eeprom(EEPROM_ADDRESS address, byte data) { byte cmd[3]; byte i; cmd[0]=data; cmd[1]=address; cmd[2]=0xa; for(i=1;i<=4;++i) shift_left(cmd,3,0); output_high(EEPROM_SELECT); for(i=1;i<=20;++i) { output_bit(EEPROM_DI, shift_left(cmd,3,0)); output_high(EEPROM_CLK); output_low(EEPROM_CLK); } output_low(EEPROM_DI); output_low(EEPROM_SELECT); delay_ms(11); }
void key_backspace() { char *s; s = command_line(NULL); if (cursor(-2)) { shift_left(s + cursor(-2) - 1, 1); cursor(cursor(-2) - 1); } }
static inline void mul_(num *a,num *b,num *c){ register int i; num t; c->n=1; c->a[0]=0; for(i=0;i<b->n;++i){ shift_left(c,1); mul1_(a,b->a[i],&t); add_(c,&t,c); rm0(c); } }
static size_t decode_sequence(const char *coded, char *plain) { assert(coded && plain); plain[0] = '\0'; for (int block = 0; block < 8; block++) { int offset = get_offset(block); int octet = get_octet(block); int c = decode_char(coded[block]); if (c < 0) { return (size_t)octet; } plain[octet] |= shift_left(c, offset); if (offset < 0) { assert(octet < 4); plain[octet + 1] = shift_left(c, 8 + offset); } } return 5; }
static void setup_low( limb_type *limbs, std::size_t &limb_cnt, int32_t exp10, fp_value_t<T> const &val ) { auto num(limbs); auto bound(num + limb_cnt); assign_pow5(bound, limb_cnt, -exp10); shift_left(bound, limb_cnt, -exp10); if (Pow2) { assign_pow5(num, limb_cnt, -exp10); shift_left( num, limb_cnt, 2 + value_traits::mantissa_bits - exp10 ); } else { assign_mantissa(num, limb_cnt, val.m); multiply_pow5(num, limb_cnt, -exp10); shift_left(num, limb_cnt, 1 - exp10); } }
static void setup_mid( limb_type *limbs, std::size_t &limb_cnt, int32_t exp10, fp_value_t<T> const &val ) { auto num(limbs); auto bound(num + limb_cnt); auto denom(bound + limb_cnt); bound[0] = 1; assign_pow5(denom, limb_cnt, exp10); if (Pow2) { shift_left(denom, limb_cnt, exp10 + 2 - val.exp); assign_pow2( num, limb_cnt, 2 + value_traits::mantissa_bits ); } else { shift_left(denom, limb_cnt, exp10 + 1 - val.exp); assign_mantissa(num, limb_cnt, val.m); shift_left_near(num, limb_cnt, 1); } }
byte read_ext_eeprom(EEPROM_ADDRESS address) { byte cmd[3]; byte i,data; cmd[0]=0; cmd[1]=address; cmd[2]=0xc; for(i=1;i<=4;++i) shift_left(cmd,3,0); output_high(EEPROM_SELECT); for(i=1;i<=20;++i) { output_bit(EEPROM_DI, shift_left(cmd,3,0)); output_high(EEPROM_CLK); output_low(EEPROM_CLK); if(i>12) shift_left(&data,1,input(EEPROM_DO)); } output_low(EEPROM_SELECT); return(data); }
void write_adc_byte(byte data) { byte i; output_low(ADC_CS); for(i=1;i<=8;++i) { output_low(ADC_CLK); output_bit(ADC_DI, shift_left(&data,1,0)); output_high(ADC_CLK); } output_high(ADC_CS); }