~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/bit/functions.cc

  • Committer: Brian Aker
  • Date: 2011-02-23 23:48:30 UTC
  • mto: (2197.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2198.
  • Revision ID: brian@tangent.org-20110223234830-dl6ukpsv0ydz5dni
Bit functions/fix for <<

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
 
 
22
#include <drizzled/function/bit/functions.h>
 
23
 
 
24
namespace drizzled
 
25
{
 
26
 
 
27
namespace function
 
28
{
 
29
 
 
30
namespace bit
 
31
{
 
32
 
 
33
int64_t ShiftLeft::val_int()
 
34
{
 
35
  assert(fixed == 1);
 
36
  uint32_t shift;
 
37
  uint64_t res= ((uint64_t) args[0]->val_int() <<
 
38
                  (shift=(uint) args[1]->val_int()));
 
39
  if (args[0]->null_value || args[1]->null_value)
 
40
  {
 
41
    null_value=1;
 
42
    return 0;
 
43
  }
 
44
  null_value=0;
 
45
 
 
46
  return (shift < sizeof(int64_t)*8 ? (int64_t) res : 0LL);
 
47
}
 
48
 
 
49
int64_t ShiftRight::val_int()
 
50
{
 
51
  assert(fixed == 1);
 
52
  uint32_t shift;
 
53
  uint64_t res= (uint64_t) args[0]->val_int() >>
 
54
    (shift=(uint) args[1]->val_int());
 
55
 
 
56
  if (args[0]->null_value || args[1]->null_value)
 
57
  {
 
58
    null_value=1;
 
59
    return 0;
 
60
  }
 
61
  null_value=0;
 
62
 
 
63
  return (shift < sizeof(int64_t)*8 ? (int64_t) res : 0LL);
 
64
}
 
65
 
 
66
 
 
67
int64_t Neg::val_int()
 
68
{
 
69
  assert(fixed == 1);
 
70
  uint64_t res= (uint64_t) args[0]->val_int();
 
71
 
 
72
  if ((null_value=args[0]->null_value))
 
73
    return 0;
 
74
 
 
75
  return ~res;
 
76
}
 
77
 
 
78
 
 
79
int64_t Xor::val_int()
 
80
{
 
81
  assert(fixed == 1);
 
82
  uint64_t arg1= (uint64_t) args[0]->val_int();
 
83
  uint64_t arg2= (uint64_t) args[1]->val_int();
 
84
 
 
85
  if ((null_value= (args[0]->null_value || args[1]->null_value)))
 
86
    return 0;
 
87
 
 
88
  return (int64_t) (arg1 ^ arg2);
 
89
}
 
90
 
 
91
int64_t Or::val_int()
 
92
{
 
93
  assert(fixed == 1);
 
94
 
 
95
  uint64_t arg1= (uint64_t) args[0]->val_int();
 
96
  if (args[0]->null_value)
 
97
  {
 
98
    null_value=1; /* purecov: inspected */
 
99
    return 0; /* purecov: inspected */
 
100
  }
 
101
 
 
102
  uint64_t arg2= (uint64_t) args[1]->val_int();
 
103
  if (args[1]->null_value)
 
104
  {
 
105
    null_value=1;
 
106
    return 0;
 
107
  }
 
108
  null_value=0;
 
109
 
 
110
  return (int64_t) (arg1 | arg2);
 
111
}
 
112
 
 
113
int64_t And::val_int()
 
114
{
 
115
  assert(fixed == 1);
 
116
 
 
117
  uint64_t arg1= (uint64_t) args[0]->val_int();
 
118
 
 
119
  if (args[0]->null_value)
 
120
  {
 
121
    null_value=1; /* purecov: inspected */
 
122
    return 0; /* purecov: inspected */
 
123
  }
 
124
 
 
125
  uint64_t arg2= (uint64_t) args[1]->val_int();
 
126
 
 
127
  if (args[1]->null_value)
 
128
  {
 
129
    null_value=1; /* purecov: inspected */
 
130
    return 0; /* purecov: inspected */
 
131
  }
 
132
  null_value=0;
 
133
 
 
134
  return (int64_t) (arg1 & arg2);
 
135
}
 
136
 
 
137
} /* namespace bit */
 
138
} /* namespace function */
 
139
} // namespace drizzled